title: Run adb on the device itself, i.e. as if it were the PC issuing the commands
body: <p>My goal is to write an app which runs on a handset and lets the user choose from a list of APK's, then installs the one selected to an Android Things device on the same network.</p>
  
  <p>We can actually forget Android Things because the same code would work between two handsets, it's just that there it would be pointless because the target can just receive the APK in many other ways such as an attachment, BT etc. AT devices only have ADB for this, apart from the recently announced Android Things Console which is overkill for regular local development. I'm therefore looking to replicate the sequence a PC would go through to install it, i.e. "adb connect, adb install ..." etc but from the handset itself. We can assume all devices involved are rooted.</p>
  
  <p>It seems to me this means my app has to issue these commands as a process, but I'm having a hard time getting it fully working. When I issue "adb help" I get back the help message, and when I issue "adb reboot" the device reboots, so I think I'm on the right lines. It's when I try anything apart from those I get nothing back - the example of "adb shell ping -c 1 192.168.62.40" fails, but is OK from ADB on the PC. Also, it's very curious "adb version" fails which again is OK from the terminal.</p>
  
  <p>At first I thought the handsets might only have an "adb lite" installed which has just enough to get them to work as an adb target, but using a shell from a PC showed that's not the case.</p>
  
  <p>Here's the code I'm trying:</p>
  
  <pre><code>Process process = Runtime.getRuntime().exec("su adb help");
  //Process process = Runtime.getRuntime().exec("su adb reboot");
  //Process process = Runtime.getRuntime().exec("su adb version");   
  //Process process = Runtime.getRuntime().exec("su adb shell ping -c 1 192.168.62.40");
  process.waitFor();
  
  Log.d("PROCESS", "Status: "+process.exitValue());
  BufferedReader bufferedReader = new BufferedReader(
          new InputStreamReader(process.getInputStream()));
  
  StringBuilder everything = new StringBuilder();
  String line;
  while( (line = bufferedReader.readLine()) != null) {
      everything.append(line);
  }
  
  Log.d("PROCESS", "Process output: "+everything.toString());
  
  Toast.makeText(MainActivity.this, everything.toString(), Toast.LENGTH_SHORT).show();
  </code></pre>