Bug 1552108 - Do not wait for runtimes in about:debugging init if ADB not started r=ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 16 May 2019 13:23:40 +0000
changeset 532905 14d8005e2dd100d19c7ce8cdf0e10cc4ca3fc2a7
parent 532904 8e5c0606d1555b052c98ab5d01dc6076b4453039
child 532906 bcab46b227b6a31bc2df5cb83b482db2fc8df23a
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko
bugs1552108
milestone68.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 1552108 - Do not wait for runtimes in about:debugging init if ADB not started r=ladybenko Differential Revision: https://phabricator.services.mozilla.com/D31403
devtools/client/aboutdebugging-new/aboutdebugging.js
devtools/client/aboutdebugging-new/test/browser/helper-mocks.js
devtools/client/aboutdebugging-new/test/browser/mocks/helper-adb-mock.js
devtools/shared/adb/adb.js
--- a/devtools/client/aboutdebugging-new/aboutdebugging.js
+++ b/devtools/client/aboutdebugging-new/aboutdebugging.js
@@ -65,17 +65,21 @@ const AboutDebugging = {
 
     this.actions.createThisFirefoxRuntime();
 
     // Listen to Network locations updates and retrieve the initial list of locations.
     addNetworkLocationsObserver(this.onNetworkLocationsUpdated);
     await this.onNetworkLocationsUpdated();
 
     // Listen to USB runtime updates and retrieve the initial list of runtimes.
-    const onAdbRuntimesReady = adb.once("runtime-list-ready");
+
+    // If ADB is already started, wait for the initial runtime list to be able to restore
+    // already connected runtimes.
+    const isProcessStarted = await adb.isProcessStarted();
+    const onAdbRuntimesReady = isProcessStarted ? adb.once("runtime-list-ready") : null;
     addUSBRuntimesObserver(this.onUSBRuntimesUpdated);
     await onAdbRuntimesReady;
 
     await this.onUSBRuntimesUpdated();
 
     render(
       Provider(
         {
--- a/devtools/client/aboutdebugging-new/test/browser/helper-mocks.js
+++ b/devtools/client/aboutdebugging-new/test/browser/helper-mocks.js
@@ -38,16 +38,18 @@ class Mocks {
       return runtimeDevices.concat(this._usbDevices);
     };
 
     // adb.updateRuntimes should ultimately fire the "runtime-list-updated" event.
     this.adbMock.adb.updateRuntimes = () => {
       this.emitUSBUpdate();
     };
 
+    this.adbMock.adb.isProcessStarted = () => true;
+
     // Prepare a fake observer to be able to emit events from this mock.
     this._observerMock = addObserverMock(this.adbMock.adb);
 
     // Setup the runtime-client-factory mock to rely on the internal _clients map.
     this.runtimeClientFactoryMock = createRuntimeClientFactoryMock();
     this._clients = {
       [RUNTIMES.NETWORK]: {},
       [RUNTIMES.THIS_FIREFOX]: {},
--- a/devtools/client/aboutdebugging-new/test/browser/mocks/helper-adb-mock.js
+++ b/devtools/client/aboutdebugging-new/test/browser/mocks/helper-adb-mock.js
@@ -54,16 +54,20 @@ function createAdbMock() {
   adbMock.unregisterListener = function(listener) {
     console.log("MOCKED METHOD unregisterListener");
   };
 
   adbMock.once = function() {
     console.log("MOCKED METHOD once");
   };
 
+  adbMock.isProcessStarted = function() {
+    console.log("MOCKED METHOD isProcessStarted");
+  };
+
   return { adb: adbMock };
 }
 /* exported createAdbMock */
 
 /**
  * The adb module allows to observe runtime updates. To simulate this behaviour
  * the easiest is to use an EventEmitter-decorated object that can accept listeners and
  * can emit events from the test.
--- a/devtools/shared/adb/adb.js
+++ b/devtools/shared/adb/adb.js
@@ -7,16 +7,17 @@
 const { clearInterval, setInterval } = require("resource://gre/modules/Timer.jsm");
 
 const EventEmitter = require("devtools/shared/event-emitter");
 const { adbProcess } = require("devtools/shared/adb/adb-process");
 const { adbAddon } = require("devtools/shared/adb/adb-addon");
 const AdbDevice = require("devtools/shared/adb/adb-device");
 const { AdbRuntime } = require("devtools/shared/adb/adb-runtime");
 const { TrackDevicesCommand } = require("devtools/shared/adb/commands/track-devices");
+loader.lazyRequireGetter(this, "check", "devtools/shared/adb/adb-running-checker", true);
 
 // Duration in milliseconds of the runtime polling. We resort to polling here because we
 // have no event to know when a runtime started on an already discovered ADB device.
 const UPDATE_RUNTIMES_INTERVAL = 3000;
 
 class Adb extends EventEmitter {
   constructor() {
     super();
@@ -69,16 +70,20 @@ class Adb extends EventEmitter {
   getRuntimes() {
     return this._runtimes;
   }
 
   getDevices() {
     return [...this._devices.values()];
   }
 
+  async isProcessStarted() {
+    return check();
+  }
+
   async _startTracking() {
     this._isTrackingDevices = true;
     await adbProcess.start();
 
     this._trackDevicesCommand.run();
 
     // Device runtimes are detected by running a shell command and checking for
     // "firefox-debugger-socket" in the list of currently running processes.