Bug 912898 - B2G: Don't kill adb (or lock the screen) if a debugger client is connected r=past
authorFabrice Desré <fabrice@mozilla.com>
Sat, 07 Sep 2013 16:28:51 -0700
changeset 146048 0b719ae93f4e3ed325b36bb9df9c63521d0109e2
parent 146047 97570ed1ad80224f15f55fdacc947d9535d8a928
child 146049 789594eff47b38d0cb6e835f61c3f00f2c0900c9
push id806
push userfdesre@mozilla.com
push dateSat, 07 Sep 2013 23:31:00 +0000
treeherderb2g-inbound@0b719ae93f4e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs912898
milestone26.0a1
Bug 912898 - B2G: Don't kill adb (or lock the screen) if a debugger client is connected r=past
b2g/chrome/content/settings.js
b2g/chrome/content/shell.js
toolkit/devtools/server/main.js
--- a/b2g/chrome/content/settings.js
+++ b/b2g/chrome/content/settings.js
@@ -309,18 +309,25 @@ let AdbController = {
       //
       // By waiting until both values are properly initialized, we avoid
       // turning adb on or off accidentally.
       if (this.DEBUG) {
         this.debug("updateState: Waiting for all vars to be initialized");
       }
       return;
     }
+
+    // Check if we have a remote debugging session going on. If so, we won't
+    // disable adb even if the screen is locked.
+    let isDebugging = Object.keys(DebuggerServer._connections).length > 0;
+    debug("isDebugging=" + isDebugging);
+
     let enableAdb = this.remoteDebuggerEnabled &&
-      !(this.lockEnabled && this.locked);
+      (!(this.lockEnabled && this.locked) || isDebugging);
+
     let useDisableAdbTimer = true;
     try {
       if (Services.prefs.getBoolPref("marionette.defaultPrefs.enabled")) {
         // Marionette is enabled. Marionette requires that adb be on (and also
         // requires that remote debugging be off). The fact that marionette
         // is enabled also implies that we're doing a non-production build, so
         // we want adb enabled all of the time.
         enableAdb = true;
@@ -361,17 +368,17 @@ let AdbController = {
       }
       try {
         libcutils.property_set("persist.sys.usb.config", newConfig);
       } catch(e) {
         dump("Error configuring adb: " + e);
       }
     }
     if (useDisableAdbTimer) {
-      if (enableAdb) {
+      if (enableAdb && !isDebugging) {
         this.startDisableAdbTimer();
       } else {
         this.stopDisableAdbTimer();
       }
     }
   }
 };
 
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -1020,16 +1020,20 @@ let RemoteDebugger = {
           DebuggerServer.addActors("resource://gre/modules/devtools/server/actors/profiler.js");
         }
         DebuggerServer.addActors("resource://gre/modules/devtools/server/actors/styleeditor.js");
         DebuggerServer.enableWebappsContentActor = true;
       }
       DebuggerServer.addActors('chrome://browser/content/dbg-browser-actors.js');
       DebuggerServer.addActors("resource://gre/modules/devtools/server/actors/webapps.js");
       DebuggerServer.registerModule("devtools/server/actors/device");
+
+      DebuggerServer.onConnectionChange = function(what) {
+        AdbController.updateState();
+      }
     }
 
     let port = Services.prefs.getIntPref('devtools.debugger.remote-port') || 6000;
     try {
       DebuggerServer.openListener(port);
     } catch (e) {
       dump('Unable to start debugger server: ' + e + '\n');
     }
--- a/toolkit/devtools/server/main.js
+++ b/toolkit/devtools/server/main.js
@@ -173,16 +173,29 @@ var DebuggerServer = {
   /**
    * The windowtype of the chrome window to use for actors that use the global
    * window (i.e the global style editor). Set this to your main window type,
    * for example "navigator:browser".
    */
   chromeWindowType: null,
 
   /**
+   * Set that to a function that will be called anytime a new connection
+   * is opened or one is closed.
+   */
+  onConnectionChange: null,
+
+  _fireConnectionChange: function(aWhat) {
+    if (this.onConnectionChange &&
+        typeof this.onConnectionChange === "function") {
+      this.onConnectionChange(aWhat);
+    }
+  },
+
+  /**
    * Prompt the user to accept or decline the incoming connection. This is the
    * default implementation that products embedding the debugger server may
    * choose to override.
    *
    * @return true if the connection should be permitted, false otherwise
    */
   _defaultAllowConnection: function DS__defaultAllowConnection() {
     let title = L10N.getStr("remoteIncomingPromptTitle");
@@ -270,16 +283,19 @@ var DebuggerServer = {
     gRegisteredModules = {};
 
     this.closeListener();
     this.globalActorFactories = {};
     this.tabActorFactories = {};
     delete this._allowConnection;
     this._transportInitialized = false;
     this._initialized = false;
+
+    this._fireConnectionChange("closed");
+
     dumpn("Debugger server is shut down.");
   },
 
   /**
    * Load a subscript into the debugging global.
    *
    * @param aURL string A url that will be loaded as a subscript into the
    *        debugging global.  The user must load at least one script
@@ -541,24 +557,26 @@ var DebuggerServer = {
         conn.rootActor.actorID = aForwardingPrefix + ":root";
       else
         conn.rootActor.actorID = "root";
       conn.addActor(conn.rootActor);
       aTransport.send(conn.rootActor.sayHello());
     }
     aTransport.ready();
 
+    this._fireConnectionChange("opened");
     return conn;
   },
 
   /**
    * Remove the connection from the debugging server.
    */
   _connectionClosed: function DS_connectionClosed(aConnection) {
     delete this._connections[aConnection.prefix];
+    this._fireConnectionChange("closed");
   },
 
   // DebuggerServer extension API.
 
   /**
    * Registers handlers for new tab-scoped request types defined dynamically.
    * This is used for example by add-ons to augment the functionality of the tab
    * actor. Note that the name or actorPrefix of the request type is not allowed