Bug 1507126: Execute adb shell command to specified device. r=jdescottes
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Tue, 18 Dec 2018 01:44:15 +0000
changeset 451372 3443db21342415459927cb4dd66cd360db53f3d2
parent 451371 a80057e6229d5253ff7dff6b4b497b6a16d1fcc1
child 451373 8b4fdcb28dbf6b950f7e1f7afff32192d124970f
push id75024
push userjdescottes@mozilla.com
push dateWed, 19 Dec 2018 19:58:52 +0000
treeherderautoland@67c2abcdadaf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1507126
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1507126: Execute adb shell command to specified device. r=jdescottes Depends on D14313 Differential Revision: https://phabricator.services.mozilla.com/D14708
devtools/shared/adb/adb-device.js
devtools/shared/adb/commands/shell.js
--- a/devtools/shared/adb/adb-device.js
+++ b/devtools/shared/adb/adb-device.js
@@ -11,34 +11,30 @@ const { shell } = require("devtools/shar
  * ADB notices a new device is connected.
  */
 class AdbDevice {
   constructor(id) {
     this.id = id;
   }
 
   async initialize() {
-    const model = await shell("getprop ro.product.model");
+    const model = await shell(this.id, "getprop ro.product.model");
     this.model = model.trim();
   }
 
   get name() {
     return this.model || this.id;
   }
 
-  // This method is not using any information from the instance, but in theory getting
-  // runtime socket paths (as well as model) should be device specific. So we should use
-  // information available on the instance when implementing multi device support.
-  // See Bug 1507126.
   async getRuntimeSocketPaths() {
     // A matching entry looks like:
     // 00000000: 00000002 00000000 00010000 0001 01 6551588
     //  /data/data/org.mozilla.fennec/firefox-debugger-socket
     const query = "cat /proc/net/unix";
-    const rawSocketInfo = await shell(query);
+    const rawSocketInfo = await shell(this.id, query);
 
     // Filter to lines with "firefox-debugger-socket"
     let socketInfos = rawSocketInfo.split(/\r?\n/);
     socketInfos = socketInfos.filter(l => l.includes("firefox-debugger-socket"));
 
     // It's possible to have multiple lines with the same path, so de-dupe them
     const socketPaths = new Set();
     for (const socketInfo of socketInfos) {
--- a/devtools/shared/adb/commands/shell.js
+++ b/devtools/shared/adb/commands/shell.js
@@ -6,21 +6,25 @@
 
 "use strict";
 
 const { dumpn } = require("devtools/shared/DevToolsUtils");
 const client = require("../adb-client");
 
 const OKAY = 0x59414b4f;
 
-const shell = async function(command) {
+const shell = async function(deviceId, command) {
+  if (!deviceId) {
+    throw new Error("ADB shell command needs the device id");
+  }
+
   let state;
   let stdout = "";
 
-  dumpn("shell " + command);
+  dumpn("shell " + command + " on " + deviceId);
 
   return new Promise((resolve, reject) => {
     const shutdown = function() {
       dumpn("shell shutdown");
       socket.close();
       reject("BAD_RESPONSE");
     };
 
@@ -29,17 +33,17 @@ const shell = async function(command) {
       let req;
       let ignoreResponseCode = false;
       switch (state) {
         case "start":
           state = "send-transport";
           runFSM();
           break;
         case "send-transport":
-          req = client.createRequest("host:transport-any");
+          req = client.createRequest("host:transport:" + deviceId);
           socket.send(req);
           state = "wait-transport";
           break;
         case "wait-transport":
           if (!client.checkResponse(data, OKAY)) {
             shutdown();
             return;
           }