Bug 1100964 - Reset phone while enabling unrestricted devtools mode. r=fabrice, r=sicking

--HG--
extra : amend_source : 905e0ea7680baad061c66a0b6dc77dbf23258218
This commit is contained in:
Alexandre Poirot 2014-11-26 06:46:00 -05:00
parent d4a673a986
commit bdbc12be62
5 changed files with 31 additions and 7 deletions

View File

@ -22,6 +22,10 @@ const Cu = Components.utils;
Cu.import('resource://gre/modules/Services.jsm');
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
XPCOMUtils.defineLazyServiceGetter(this, "settings",
"@mozilla.org/settingsService;1",
"nsISettingsService");
function debug(msg) {
log(msg);
}
@ -89,14 +93,19 @@ ProcessGlobal.prototype = {
}
},
processWipeFile: function(text) {
log("processWipeFile " + text);
processCommandsFile: function(text) {
log("processCommandsFile " + text);
let lines = text.split("\n");
lines.forEach((line) => {
log(line);
let params = line.split(" ");
if (params[0] == "wipe") {
this.wipeDir(params[1]);
} else if (params[0] == "root") {
log("unrestrict devtools");
Services.prefs.setBoolPref("devtools.debugger.forbid-certified-apps", false);
let lock = settings.createLock();
lock.set("developer.menu.enabled", true, null);
}
});
},
@ -113,7 +122,7 @@ ProcessGlobal.prototype = {
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.initWithPath(postResetFile);
if (!file.exists()) {
debug("Nothing to wipe.")
debug("No additional command.")
return;
}
@ -122,7 +131,7 @@ ProcessGlobal.prototype = {
(array) => {
file.remove(false);
let decoder = new TextDecoder();
this.processWipeFile(decoder.decode(array));
this.processCommandsFile(decoder.decode(array));
},
function onError(error) {
debug("Error: " + error);

View File

@ -81,19 +81,24 @@ RecoveryService.prototype = {
}
log("factoryReset " + reason);
let commands = [];
if (reason == "wipe") {
let volumeService = Cc["@mozilla.org/telephony/volume-service;1"]
.getService(Ci.nsIVolumeService);
let volNames = volumeService.getVolumeNames();
log("Found " + volNames.length + " volumes");
let text = "";
for (let i = 0; i < volNames.length; i++) {
let name = volNames.queryElementAt(i, Ci.nsISupportsString);
let volume = volumeService.getVolumeByName(name.data);
log("Got volume: " + name.data + " at " + volume.mountPoint);
text += "wipe " + volume.mountPoint + "\n";
commands.push("wipe " + volume.mountPoint);
}
} else if (reason == "root") {
commands.push("root");
}
if (commands.length > 0) {
Cu.import("resource://gre/modules/osfile.jsm");
let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
dir.initWithPath("/persist");
@ -101,6 +106,7 @@ RecoveryService.prototype = {
OS.Path.join("/persist", gFactoryResetFile):
OS.Path.join("/cache", gFactoryResetFile);
let encoder = new TextEncoder();
let text = commands.join("\n");
let array = encoder.encode(text);
let promise = OS.File.writeAtomic(postResetFile, array,
{ tmpPath: postResetFile + ".tmp" });

View File

@ -9,10 +9,13 @@ interface MozWakeLockListener;
* The reason for the factory reset.
* "normal" : simple factory reset.
* "wipe" : will also attempt to wipe all user storage areas.
* "root" : simple factory reset that also root the phone to get more
* privileges when using devtools.
*/
enum FactoryResetReason {
"normal",
"wipe"
"wipe",
"root"
};
/**

View File

@ -1777,6 +1777,8 @@ FactoryReset(FactoryResetReason& aReason)
if (aReason == FactoryResetReason::Wipe) {
recoveryService->FactoryReset("wipe");
} else if (aReason == FactoryResetReason::Root) {
recoveryService->FactoryReset("root");
} else {
recoveryService->FactoryReset("normal");
}

View File

@ -446,6 +446,8 @@ FactoryReset(FactoryResetReason& aReason)
Hal()->SendFactoryReset(NS_LITERAL_STRING("normal"));
} else if (aReason == FactoryResetReason::Wipe) {
Hal()->SendFactoryReset(NS_LITERAL_STRING("wipe"));
} else if (aReason == FactoryResetReason::Root) {
Hal()->SendFactoryReset(NS_LITERAL_STRING("root"));
}
}
@ -870,6 +872,8 @@ public:
reason = FactoryResetReason::Normal;
} else if (aReason.EqualsLiteral("wipe")) {
reason = FactoryResetReason::Wipe;
} else if (aReason.EqualsLiteral("root")) {
reason = FactoryResetReason::Root;
} else {
// Invalid factory reset reason. That should never happen.
return false;