Bug 1492700 - Fold FirefoxOnAndroidRuntime.detect in scanner.detectRuntimes;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 27 Nov 2018 12:51:14 +0000
changeset 504695 5db9614af6a5f77a6836009dd781f4d8ab5723f1
parent 504694 d5e67b8fbde32dd9c145ffd02086bf0398fdbd58
child 504696 bbc5bcb72208a7ec7c5bf4a54a6977101e154993
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1492700
milestone65.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 1492700 - Fold FirefoxOnAndroidRuntime.detect in scanner.detectRuntimes;r=daisuke Depends on D12763 Differential Revision: https://phabricator.services.mozilla.com/D12764
devtools/shared/adb/adb-device.js
devtools/shared/adb/adb-scanner.js
--- a/devtools/shared/adb/adb-device.js
+++ b/devtools/shared/adb/adb-device.js
@@ -18,11 +18,36 @@ class AdbDevice {
   async getModel() {
     if (this._model) {
       return this._model;
     }
     const model = await ADB.shell("getprop ro.product.model");
     this._model = model.trim();
     return this._model;
   }
+
+  // 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 ADB.shell(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) {
+      const socketPath = socketInfo.split(" ").pop();
+      socketPaths.add(socketPath);
+    }
+
+    return socketPaths;
+  }
 }
 
 module.exports = AdbDevice;
--- a/devtools/shared/adb/adb-scanner.js
+++ b/devtools/shared/adb/adb-scanner.js
@@ -72,21 +72,24 @@ class ADBScanner extends EventEmitter {
       this._emitUpdated();
       this._updatingPromise = null;
     }, () => {
       this._updatingPromise = null;
     });
     return this._updatingPromise;
   }
 
-  async _detectRuntimes(device) {
-    const model = await device.getModel();
-    const detectedRuntimes =
-      await FirefoxOnAndroidRuntime.detect(device, model);
-    this._runtimes.push(...detectedRuntimes);
+  async _detectRuntimes(adbDevice) {
+    const model = await adbDevice.getModel();
+    const socketPaths = await adbDevice.getRuntimeSocketPaths();
+    for (const socketPath of socketPaths) {
+      const runtime = new FirefoxOnAndroidRuntime(adbDevice, model, socketPath);
+      dumpn("Found " + runtime.name);
+      this._runtimes.push(runtime);
+    }
   }
 
   scan() {
     return this._updateRuntimes();
   }
 
   listRuntimes() {
     return this._runtimes;
@@ -112,41 +115,16 @@ Runtime.prototype = {
     return this._adbDevice.id + "|" + this._socketPath;
   },
 };
 
 function FirefoxOnAndroidRuntime(adbDevice, model, socketPath) {
   Runtime.call(this, adbDevice, model, socketPath);
 }
 
-// This requires Unix socket support from Firefox for Android (35+)
-FirefoxOnAndroidRuntime.detect = async function(adbDevice, model) {
-  const runtimes = [];
-  // 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 ADB.shell(query);
-  let socketInfos = rawSocketInfo.split(/\r?\n/);
-  // Filter to lines with "firefox-debugger-socket"
-  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) {
-    const socketPath = socketInfo.split(" ").pop();
-    socketPaths.add(socketPath);
-  }
-  for (const socketPath of socketPaths) {
-    const runtime = new FirefoxOnAndroidRuntime(adbDevice, model, socketPath);
-    dumpn("Found " + runtime.name);
-    runtimes.push(runtime);
-  }
-  return runtimes;
-};
-
 FirefoxOnAndroidRuntime.prototype = Object.create(Runtime.prototype);
 
 FirefoxOnAndroidRuntime.prototype._channel = function() {
   const packageName = this._packageName();
 
   switch (packageName) {
     case "org.mozilla.firefox":
       return "";