Bug 1548569 - Fire event from ADB track-devices to unblock aboutdebugging initialization r=Ola
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 03 May 2019 08:11:54 +0000
changeset 531256 3cc662da1cd8d2a81d91912844247b51ce949e69
parent 531255 f52499501a149497888857d4dc23ec5adca2c352
child 531257 80f03c3dd739ce09d18d06c31cc857ed56307e1f
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersOla
bugs1548569
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 1548569 - Fire event from ADB track-devices to unblock aboutdebugging initialization r=Ola Differential Revision: https://phabricator.services.mozilla.com/D29675
devtools/shared/adb/adb.js
devtools/shared/adb/commands/track-devices.js
--- a/devtools/shared/adb/adb.js
+++ b/devtools/shared/adb/adb.js
@@ -28,19 +28,21 @@ class Adb extends EventEmitter {
 
     this._listeners = new Set();
     this._devices = new Map();
     this._runtimes = [];
 
     this._updateAdbProcess = this._updateAdbProcess.bind(this);
     this._onDeviceConnected = this._onDeviceConnected.bind(this);
     this._onDeviceDisconnected = this._onDeviceDisconnected.bind(this);
+    this._onNoDevicesDetected = this._onNoDevicesDetected.bind(this);
 
     this._trackDevicesCommand.on("device-connected", this._onDeviceConnected);
     this._trackDevicesCommand.on("device-disconnected", this._onDeviceDisconnected);
+    this._trackDevicesCommand.on("no-devices-detected", this._onNoDevicesDetected);
     adbAddon.on("update", this._updateAdbProcess);
   }
 
   registerListener(listener) {
     this._listeners.add(listener);
     this.on("runtime-list-updated", listener);
     this._updateAdbProcess();
   }
@@ -121,15 +123,19 @@ class Adb extends EventEmitter {
     this.updateRuntimes();
   }
 
   _onDeviceDisconnected(deviceId) {
     this._devices.delete(deviceId);
     this.updateRuntimes();
   }
 
+  _onNoDevicesDetected() {
+    this.updateRuntimes();
+  }
+
   async _getDeviceRuntimes(device) {
     const socketPaths = [...await device.getRuntimeSocketPaths()];
     return socketPaths.map(socketPath => new AdbRuntime(device, socketPath));
   }
 }
 
 exports.adb = new Adb();
--- a/devtools/shared/adb/commands/track-devices.js
+++ b/devtools/shared/adb/commands/track-devices.js
@@ -118,19 +118,24 @@ class TrackDevicesCommand extends EventE
       }
 
       // Update devices.
       this._devices = newDevices;
     }
   }
 
   _disconnectAllDevices() {
-    for (const [deviceId, status] of this._devices.entries()) {
-      if (status !== ADB_STATUS_OFFLINE) {
-        this.emit("device-disconnected", deviceId);
+    if (this._devices.size === 0) {
+      // If no devices were detected, fire an event to let consumer resume.
+      this.emit("no-devices-detected");
+    } else {
+      for (const [deviceId, status] of this._devices.entries()) {
+        if (status !== ADB_STATUS_OFFLINE) {
+          this.emit("device-disconnected", deviceId);
+        }
       }
     }
     this._devices = new Map();
   }
 
   _fireConnectionEventIfNeeded(deviceId, currentStatus, newStatus) {
     const isCurrentOnline = !!(currentStatus && currentStatus !== ADB_STATUS_OFFLINE);
     const isNewOnline = !!(newStatus && newStatus !== ADB_STATUS_OFFLINE);