Debug Remotely on Android using adb via SSH Tunnel

Start adb daemon on remote device

adb devices
$ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached 
5200fe4259bcc000	device

do client to server port forwarding using ssh on port 5037

References
https://dontbelievethebyte.github.io/articles/2015/01/15/debug-remotely-on-android-via-ssh-tunnel/
https://developer.android.com/studio/command-line/adb
https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp

Download apk file using Download Manager on Android

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
//get destination to update file and set Uri
   //TODO: First I wanted to store my update .apk file on internal storage for my app but apparently android does not allow you to open and install
   //aplication with existing package from there. So for me, alternative solution is Download directory in external storage. If there is better
   //solution, please inform us in comment
   String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
   String fileName = "AppName.apk";
   destination += fileName;
   final Uri uri = Uri.parse("file://" + destination);

   //Delete update file if exists
   File file = new File(destination);
   if (file.exists())
   //file.delete() - test this, I think sometimes it doesnt work
       file.delete();

   //get url of app on server
   String url = Main.this.getString(R.string.update_app_url);

   //set downloadmanager
   DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
   request.setDescription(Main.this.getString(R.string.notification_description));
   request.setTitle(Main.this.getString(R.string.app_name));

   //set destination
   request.setDestinationUri(uri);

   // get download service and enqueue file
   final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
   final long downloadId = manager.enqueue(request);

   //set BroadcastReceiver to install app when .apk is downloaded
   BroadcastReceiver onComplete = new BroadcastReceiver() {
       public void onReceive(Context ctxt, Intent intent) {
           Intent install = new Intent(Intent.ACTION_VIEW);
           install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
           install.setDataAndType(uri,
                   manager.getMimeTypeForDownloadedFile(downloadId));
           startActivity(install);

           unregisterReceiver(this);
           finish();
       }
   };
   //register receiver for when .apk download is compete
   registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

References
https://stackoverflow.com/questions/4967669/android-install-apk-programmatically
https://stackoverflow.com/questions/39147608/android-install-apk-with-intent-view-action-not-working-with-file-provider/40131196#40131196