Bug 1493104 - Listen to ADB extension updates in about:debugging usb-runtime helper;r=ladybenko,daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 05 Oct 2018 11:45:32 +0200
changeset 498960 a56d01a749647c9bb733ee790bc2111e61a7591d
parent 498959 6d25a11674ba1e78587b08c570995e7980c83648
child 498961 5ed3ff9c48f5fb019808b03a4fad45f9dfd74435
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [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
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);
   }