Bug 1072625 - Cleanup debug in AdbController. r=fabrice

This commit is contained in:
Dave Hylands 2014-10-15 19:44:22 -07:00
parent c130319305
commit ce111a63f9

View File

@ -8,8 +8,14 @@
// This file is only loaded on Gonk to manage ADB state
const { utils: Cu } = Components;
const DEBUG = false;
var debug = function(str) {
dump("AdbController: " + str + "\n");
}
let AdbController = {
DEBUG: false,
locked: undefined,
remoteDebuggerEnabled: undefined,
lockEnabled: undefined,
@ -17,31 +23,21 @@ let AdbController = {
disableAdbTimeoutHours: 12,
umsActive: false,
debug: function(str) {
dump("AdbController: " + str + "\n");
},
setLockscreenEnabled: function(value) {
this.lockEnabled = value;
if (this.DEBUG) {
this.debug("setLockscreenEnabled = " + this.lockEnabled);
}
DEBUG && debug("setLockscreenEnabled = " + this.lockEnabled);
this.updateState();
},
setLockscreenState: function(value) {
this.locked = value;
if (this.DEBUG) {
this.debug("setLockscreenState = " + this.locked);
}
DEBUG && debug("setLockscreenState = " + this.locked);
this.updateState();
},
setRemoteDebuggerState: function(value) {
this.remoteDebuggerEnabled = value;
if (this.DEBUG) {
this.debug("setRemoteDebuggerState = " + this.remoteDebuggerEnabled);
}
DEBUG && debug("setRemoteDebuggerState = " + this.remoteDebuggerEnabled);
this.updateState();
},
@ -59,25 +55,19 @@ let AdbController = {
}
}
if (this.disableAdbTimeoutHours <= 0) {
if (this.DEBUG) {
this.debug("Timer to disable ADB not started due to zero timeout");
}
DEBUG && debug("Timer to disable ADB not started due to zero timeout");
return;
}
if (this.DEBUG) {
this.debug("Starting timer to disable ADB in " +
this.disableAdbTimeoutHours + " hours");
}
DEBUG && debug("Starting timer to disable ADB in " +
this.disableAdbTimeoutHours + " hours");
let timeoutMilliseconds = this.disableAdbTimeoutHours * 60 * 60 * 1000;
this.disableAdbTimer.initWithCallback(this, timeoutMilliseconds,
Ci.nsITimer.TYPE_ONE_SHOT);
},
stopDisableAdbTimer: function() {
if (this.DEBUG) {
this.debug("Stopping timer to disable ADB");
}
DEBUG && debug("Stopping timer to disable ADB");
if (this.disableAdbTimer) {
this.disableAdbTimer.cancel();
this.disableAdbTimer = null;
@ -90,7 +80,7 @@ let AdbController = {
// The following dump will be the last thing that shows up in logcat,
// and will at least give the user a clue about why logcat was
// disconnected, if the user happens to be using logcat.
dump("AdbController: ADB timer expired - disabling ADB\n");
debug("ADB timer expired - disabling ADB\n");
navigator.mozSettings.createLock().set(
{'debugger.remote-mode': 'disabled'});
}
@ -110,17 +100,11 @@ let AdbController = {
return;
}
let storage = this.storages[storageIndex];
if (this.DEBUG) {
this.debug("Checking availability of storage: '" +
storage.storageName);
}
DEBUG && debug("Checking availability of storage: '" + storage.storageName);
let req = storage.available();
req.onsuccess = function(e) {
if (this.DEBUG) {
this.debug("Storage: '" + storage.storageName + "' is '" +
e.target.result);
}
DEBUG && debug("Storage: '" + storage.storageName + "' is '" + e.target.result);
if (e.target.result == 'shared') {
// We've found a storage area that's being shared with the PC.
// We can stop looking now.
@ -131,16 +115,15 @@ let AdbController = {
this.updateStorageState(storageIndex + 1);
}.bind(this);
req.onerror = function(e) {
dump("AdbController: error querying storage availability for '" +
this.storages[storageIndex].storageName + "' (ignoring)\n");
Cu.reportError("AdbController: error querying storage availability for '" +
this.storages[storageIndex].storageName + "' (ignoring)\n");
this.updateStorageState(storageIndex + 1);
}.bind(this);
},
updateStateInternal: function() {
if (this.DEBUG) {
this.debug("updateStateInternal: called");
}
DEBUG && debug("updateStateInternal: called");
if (this.remoteDebuggerEnabled === undefined ||
this.lockEnabled === undefined ||
@ -162,18 +145,14 @@ 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");
}
DEBUG && 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 = USBRemoteDebugger.isDebugging;
if (this.DEBUG) {
this.debug("isDebugging=" + isDebugging);
}
DEBUG && debug("isDebugging=" + isDebugging);
// If USB Mass Storage, USB tethering, or a debug session is active,
// then we don't want to disable adb in an automatic fashion (i.e.
@ -199,13 +178,11 @@ let AdbController = {
// This means that the pref doesn't exist. Which is fine. We just leave
// enableAdb alone.
}
if (this.DEBUG) {
this.debug("updateState: enableAdb = " + enableAdb +
" remoteDebuggerEnabled = " + this.remoteDebuggerEnabled +
" lockEnabled = " + this.lockEnabled +
" locked = " + this.locked +
" usbFuncActive = " + usbFuncActive);
}
DEBUG && debug("updateState: enableAdb = " + enableAdb +
" remoteDebuggerEnabled = " + this.remoteDebuggerEnabled +
" lockEnabled = " + this.lockEnabled +
" locked = " + this.locked +
" usbFuncActive = " + usbFuncActive);
// Configure adb.
let currentConfig = libcutils.property_get("persist.sys.usb.config");
@ -225,14 +202,12 @@ let AdbController = {
}
let newConfig = configFuncs.join(",");
if (newConfig != currentConfig) {
if (this.DEBUG) {
this.debug("updateState: currentConfig = " + currentConfig);
this.debug("updateState: newConfig = " + newConfig);
}
DEBUG && debug("updateState: currentConfig = " + currentConfig);
DEBUG && debug("updateState: newConfig = " + newConfig);
try {
libcutils.property_set("persist.sys.usb.config", newConfig);
} catch(e) {
dump("Error configuring adb: " + e);
Cu.reportError("Error configuring adb: " + e);
}
}
if (useDisableAdbTimer) {
@ -243,6 +218,7 @@ let AdbController = {
}
}
}
};
SettingsListener.observe("lockscreen.locked", false,