Bug 1493104 - Listen to ADB extension updates in about:debugging usb-runtime helper;r=ladybenko,daisuke
☠☠ backed out by c24bf7117053 ☠ ☠
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 10 Oct 2018 11:30:36 +0000
changeset 496175 f7ecf841eb8fc2cdc516a9720f0a555c7f1e9b16
parent 496174 fa20c2c68c4286c28c3ea4a8371d5d55396355cf
child 496176 cb9f55dd42570c4568d45c54ceb5176c3543df1c
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko, daisuke
bugs1493104
milestone64.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 1493104 - Listen to ADB extension updates in about:debugging usb-runtime helper;r=ladybenko,daisuke Depends on D7872. This fixes the bug where about:debugging thinks the addon is uninstalled the first time it starts. Differential Revision: https://phabricator.services.mozilla.com/D7873
devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
devtools/client/webide/content/addons.js
--- a/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
@@ -6,37 +6,50 @@
 
 loader.lazyRequireGetter(this, "adbAddon", "devtools/shared/adb/adb-addon", true);
 loader.lazyRequireGetter(this, "ADB_ADDON_STATES", "devtools/shared/adb/adb-addon", true);
 loader.lazyGetter(this, "adbScanner", () => {
   const { ADBScanner } = require("devtools/shared/adb/adb-scanner");
   return new ADBScanner();
 });
 
+function _onAdbAddonUpdate() {
+  // We are only listening to adbAddon updates if usb-runtimes are enabled.
+  if (adbAddon.status === ADB_ADDON_STATES.INSTALLED) {
+    // If the status switched to installed, the scanner should be enabled.
+    adbScanner.enable();
+  } else {
+    // Otherwise disable the scanner. disable() can be called several times without side
+    // effect.
+    adbScanner.disable();
+  }
+}
+
 /**
  * This module provides a collection of helper methods to detect USB runtimes whom Firefox
  * is running on.
  */
 function addUSBRuntimesObserver(listener) {
   adbScanner.on("runtime-list-updated", listener);
 }
 exports.addUSBRuntimesObserver = addUSBRuntimesObserver;
 
 function disableUSBRuntimes() {
-  adbScanner.disable();
+  if (adbAddon.status === ADB_ADDON_STATES.INSTALLED) {
+    adbScanner.disable();
+  }
+  adbAddon.off("update", _onAdbAddonUpdate);
 }
 exports.disableUSBRuntimes = disableUSBRuntimes;
 
 async function enableUSBRuntimes() {
-  if (adbAddon.status !== ADB_ADDON_STATES.INSTALLED) {
-    console.error("ADB extension is not installed");
-    return;
+  if (adbAddon.status === ADB_ADDON_STATES.INSTALLED) {
+    adbScanner.enable();
   }
-
-  adbScanner.enable();
+  adbAddon.on("update", _onAdbAddonUpdate);
 }
 exports.enableUSBRuntimes = enableUSBRuntimes;
 
 function getUSBRuntimes() {
   return adbScanner.listRuntimes();
 }
 exports.getUSBRuntimes = getUSBRuntimes;
 
--- a/devtools/client/webide/content/addons.js
+++ b/devtools/client/webide/content/addons.js
@@ -32,19 +32,19 @@ function CloseUI() {
   window.parent.UI.openProject();
 }
 
 function BuildUI() {
   function onAddonUpdate(arg) {
     progress.removeAttribute("value");
     li.setAttribute("status", adbAddon.status);
     status.textContent = Strings.GetStringFromName("addons_status_" + adbAddon.status);
-    if (adbAddon.status == ADB_ADDON_STATES.INSTALLED) {
+    if (adbAddon.status === ADB_ADDON_STATES.INSTALLED) {
       RuntimeScanners.add(adbScanner);
-    } else if (adbAddon.status == ADB_ADDON_STATES.UNINSTALLED) {
+    } else if (adbAddon.status === ADB_ADDON_STATES.UNINSTALLED) {
       RuntimeScanners.remove(adbScanner);
     }
   }
 
   function onAddonFailure(arg) {
     window.parent.UI.reportError("error_operationFail", arg);
   }