зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1072625 - Cleanup debug in AdbController. r=fabrice
This commit is contained in:
Родитель
eb1c9b72e4
Коммит
d03902f8d0
|
@ -8,8 +8,14 @@
|
||||||
|
|
||||||
// This file is only loaded on Gonk to manage ADB state
|
// 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 = {
|
let AdbController = {
|
||||||
DEBUG: false,
|
|
||||||
locked: undefined,
|
locked: undefined,
|
||||||
remoteDebuggerEnabled: undefined,
|
remoteDebuggerEnabled: undefined,
|
||||||
lockEnabled: undefined,
|
lockEnabled: undefined,
|
||||||
|
@ -17,31 +23,21 @@ let AdbController = {
|
||||||
disableAdbTimeoutHours: 12,
|
disableAdbTimeoutHours: 12,
|
||||||
umsActive: false,
|
umsActive: false,
|
||||||
|
|
||||||
debug: function(str) {
|
|
||||||
dump("AdbController: " + str + "\n");
|
|
||||||
},
|
|
||||||
|
|
||||||
setLockscreenEnabled: function(value) {
|
setLockscreenEnabled: function(value) {
|
||||||
this.lockEnabled = value;
|
this.lockEnabled = value;
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("setLockscreenEnabled = " + this.lockEnabled);
|
||||||
this.debug("setLockscreenEnabled = " + this.lockEnabled);
|
|
||||||
}
|
|
||||||
this.updateState();
|
this.updateState();
|
||||||
},
|
},
|
||||||
|
|
||||||
setLockscreenState: function(value) {
|
setLockscreenState: function(value) {
|
||||||
this.locked = value;
|
this.locked = value;
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("setLockscreenState = " + this.locked);
|
||||||
this.debug("setLockscreenState = " + this.locked);
|
|
||||||
}
|
|
||||||
this.updateState();
|
this.updateState();
|
||||||
},
|
},
|
||||||
|
|
||||||
setRemoteDebuggerState: function(value) {
|
setRemoteDebuggerState: function(value) {
|
||||||
this.remoteDebuggerEnabled = value;
|
this.remoteDebuggerEnabled = value;
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("setRemoteDebuggerState = " + this.remoteDebuggerEnabled);
|
||||||
this.debug("setRemoteDebuggerState = " + this.remoteDebuggerEnabled);
|
|
||||||
}
|
|
||||||
this.updateState();
|
this.updateState();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -59,25 +55,19 @@ let AdbController = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.disableAdbTimeoutHours <= 0) {
|
if (this.disableAdbTimeoutHours <= 0) {
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("Timer to disable ADB not started due to zero timeout");
|
||||||
this.debug("Timer to disable ADB not started due to zero timeout");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("Starting timer to disable ADB in " +
|
||||||
this.debug("Starting timer to disable ADB in " +
|
this.disableAdbTimeoutHours + " hours");
|
||||||
this.disableAdbTimeoutHours + " hours");
|
|
||||||
}
|
|
||||||
let timeoutMilliseconds = this.disableAdbTimeoutHours * 60 * 60 * 1000;
|
let timeoutMilliseconds = this.disableAdbTimeoutHours * 60 * 60 * 1000;
|
||||||
this.disableAdbTimer.initWithCallback(this, timeoutMilliseconds,
|
this.disableAdbTimer.initWithCallback(this, timeoutMilliseconds,
|
||||||
Ci.nsITimer.TYPE_ONE_SHOT);
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
||||||
},
|
},
|
||||||
|
|
||||||
stopDisableAdbTimer: function() {
|
stopDisableAdbTimer: function() {
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("Stopping timer to disable ADB");
|
||||||
this.debug("Stopping timer to disable ADB");
|
|
||||||
}
|
|
||||||
if (this.disableAdbTimer) {
|
if (this.disableAdbTimer) {
|
||||||
this.disableAdbTimer.cancel();
|
this.disableAdbTimer.cancel();
|
||||||
this.disableAdbTimer = null;
|
this.disableAdbTimer = null;
|
||||||
|
@ -90,7 +80,7 @@ let AdbController = {
|
||||||
// The following dump will be the last thing that shows up in logcat,
|
// 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
|
// and will at least give the user a clue about why logcat was
|
||||||
// disconnected, if the user happens to be using logcat.
|
// 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(
|
navigator.mozSettings.createLock().set(
|
||||||
{'debugger.remote-mode': 'disabled'});
|
{'debugger.remote-mode': 'disabled'});
|
||||||
}
|
}
|
||||||
|
@ -110,17 +100,11 @@ let AdbController = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let storage = this.storages[storageIndex];
|
let storage = this.storages[storageIndex];
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("Checking availability of storage: '" + storage.storageName);
|
||||||
this.debug("Checking availability of storage: '" +
|
|
||||||
storage.storageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
let req = storage.available();
|
let req = storage.available();
|
||||||
req.onsuccess = function(e) {
|
req.onsuccess = function(e) {
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("Storage: '" + storage.storageName + "' is '" + e.target.result);
|
||||||
this.debug("Storage: '" + storage.storageName + "' is '" +
|
|
||||||
e.target.result);
|
|
||||||
}
|
|
||||||
if (e.target.result == 'shared') {
|
if (e.target.result == 'shared') {
|
||||||
// We've found a storage area that's being shared with the PC.
|
// We've found a storage area that's being shared with the PC.
|
||||||
// We can stop looking now.
|
// We can stop looking now.
|
||||||
|
@ -131,16 +115,15 @@ let AdbController = {
|
||||||
this.updateStorageState(storageIndex + 1);
|
this.updateStorageState(storageIndex + 1);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
req.onerror = function(e) {
|
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);
|
this.updateStorageState(storageIndex + 1);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateStateInternal: function() {
|
updateStateInternal: function() {
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("updateStateInternal: called");
|
||||||
this.debug("updateStateInternal: called");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.remoteDebuggerEnabled === undefined ||
|
if (this.remoteDebuggerEnabled === undefined ||
|
||||||
this.lockEnabled === undefined ||
|
this.lockEnabled === undefined ||
|
||||||
|
@ -162,18 +145,14 @@ let AdbController = {
|
||||||
//
|
//
|
||||||
// By waiting until both values are properly initialized, we avoid
|
// By waiting until both values are properly initialized, we avoid
|
||||||
// turning adb on or off accidentally.
|
// turning adb on or off accidentally.
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("updateState: Waiting for all vars to be initialized");
|
||||||
this.debug("updateState: Waiting for all vars to be initialized");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have a remote debugging session going on. If so, we won't
|
// Check if we have a remote debugging session going on. If so, we won't
|
||||||
// disable adb even if the screen is locked.
|
// disable adb even if the screen is locked.
|
||||||
let isDebugging = USBRemoteDebugger.isDebugging;
|
let isDebugging = USBRemoteDebugger.isDebugging;
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("isDebugging=" + isDebugging);
|
||||||
this.debug("isDebugging=" + isDebugging);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If USB Mass Storage, USB tethering, or a debug session is active,
|
// 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.
|
// 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
|
// This means that the pref doesn't exist. Which is fine. We just leave
|
||||||
// enableAdb alone.
|
// enableAdb alone.
|
||||||
}
|
}
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("updateState: enableAdb = " + enableAdb +
|
||||||
this.debug("updateState: enableAdb = " + enableAdb +
|
" remoteDebuggerEnabled = " + this.remoteDebuggerEnabled +
|
||||||
" remoteDebuggerEnabled = " + this.remoteDebuggerEnabled +
|
" lockEnabled = " + this.lockEnabled +
|
||||||
" lockEnabled = " + this.lockEnabled +
|
" locked = " + this.locked +
|
||||||
" locked = " + this.locked +
|
" usbFuncActive = " + usbFuncActive);
|
||||||
" usbFuncActive = " + usbFuncActive);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure adb.
|
// Configure adb.
|
||||||
let currentConfig = libcutils.property_get("persist.sys.usb.config");
|
let currentConfig = libcutils.property_get("persist.sys.usb.config");
|
||||||
|
@ -225,14 +202,12 @@ let AdbController = {
|
||||||
}
|
}
|
||||||
let newConfig = configFuncs.join(",");
|
let newConfig = configFuncs.join(",");
|
||||||
if (newConfig != currentConfig) {
|
if (newConfig != currentConfig) {
|
||||||
if (this.DEBUG) {
|
DEBUG && debug("updateState: currentConfig = " + currentConfig);
|
||||||
this.debug("updateState: currentConfig = " + currentConfig);
|
DEBUG && debug("updateState: newConfig = " + newConfig);
|
||||||
this.debug("updateState: newConfig = " + newConfig);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
libcutils.property_set("persist.sys.usb.config", newConfig);
|
libcutils.property_set("persist.sys.usb.config", newConfig);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
dump("Error configuring adb: " + e);
|
Cu.reportError("Error configuring adb: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (useDisableAdbTimer) {
|
if (useDisableAdbTimer) {
|
||||||
|
@ -243,6 +218,7 @@ let AdbController = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SettingsListener.observe("lockscreen.locked", false,
|
SettingsListener.observe("lockscreen.locked", false,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче