Bug 1040779 - Add a button to enable certified app debugging. r=jryans

This commit is contained in:
Paul Rouget 2014-07-22 10:36:00 +02:00
parent 047173bb9f
commit a8fd2b4654
8 changed files with 145 additions and 0 deletions

View File

@ -7,12 +7,18 @@ const {Services} = Cu.import("resource://gre/modules/Services.jsm");
const {require} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
const {AppManager} = require("devtools/webide/app-manager");
const {Connection} = require("devtools/client/connection-manager");
const {Devices} = Cu.import("resource://gre/modules/devtools/Devices.jsm");
const {USBRuntime} = require("devtools/webide/runtimes");
const Strings = Services.strings.createBundle("chrome://webide/content/webide.properties");
window.addEventListener("load", function onLoad() {
window.removeEventListener("load", onLoad);
document.querySelector("#close").onclick = CloseUI;
document.querySelector("#certified-check button").onclick = EnableCertApps;
document.querySelector("#adb-check button").onclick = RootADB;
AppManager.on("app-manager-update", OnAppManagerUpdate);
BuildUI();
CheckLockState();
}, true);
window.addEventListener("unload", function onUnload() {
@ -27,6 +33,7 @@ function CloseUI() {
function OnAppManagerUpdate(event, what) {
if (what == "connection" || what == "list-tabs-response") {
BuildUI();
CheckLockState();
}
}
@ -54,3 +61,83 @@ function BuildUI() {
CloseUI();
}
}
function CheckLockState() {
let adbCheckResult = document.querySelector("#adb-check > .yesno");
let certCheckResult = document.querySelector("#certified-check > .yesno");
let flipCertPerfButton = document.querySelector("#certified-check button");
let adbRootButton = document.querySelector("#adb-check button");
let flipCertPerfAction = document.querySelector("#certified-check > .action");
let adbRootAction = document.querySelector("#adb-check > .action");
let sYes = Strings.GetStringFromName("runtimedetails_checkyes");
let sNo = Strings.GetStringFromName("runtimedetails_checkno");
let sUnknown = Strings.GetStringFromName("runtimedetails_checkunkown");
let sNotUSB = Strings.GetStringFromName("runtimedetails_notUSBDevice");
flipCertPerfButton.setAttribute("disabled", "true");
flipCertPerfAction.setAttribute("hidden", "true");
adbRootAction.setAttribute("hidden", "true");
adbCheckResult.textContent = sUnknown;
certCheckResult.textContent = sUnknown;
if (AppManager.connection &&
AppManager.connection.status == Connection.Status.CONNECTED &&
AppManager.deviceFront) {
// ADB check
if (AppManager.selectedRuntime instanceof USBRuntime) {
let device = Devices.getByName(AppManager.selectedRuntime.id);
if (device.summonRoot) {
device.isRoot().then(isRoot => {
if (isRoot) {
adbCheckResult.textContent = sYes;
flipCertPerfButton.removeAttribute("disabled");
} else {
adbCheckResult.textContent = sNo;
adbRootAction.removeAttribute("hidden");
}
}, e => console.error(e));
} else {
adbCheckResult.textContent = sUnknown;
}
} else {
adbCheckResult.textContent = sNotUSB;
}
// forbid-certified-apps check
try {
let prefFront = AppManager.preferenceFront;
prefFront.getBoolPref("devtools.debugger.forbid-certified-apps").then(isForbidden => {
if (isForbidden) {
certCheckResult.textContent = sYes;
flipCertPerfAction.removeAttribute("hidden");
} else {
certCheckResult.textContent = sNo;
}
}, e => console.error(e));
} catch(e) {
// Exception. pref actor is only accessible if forbird-certified-apps is false
certCheckResult.textContent = sYes;
flipCertPerfAction.removeAttribute("hidden");
}
}
}
function EnableCertApps() {
let device = Devices.getByName(AppManager.selectedRuntime.id);
device.shell(
"stop b2g && " +
"cd /data/b2g/mozilla/*.default/ && " +
"echo 'user_pref(\"devtools.debugger.forbid-certified-apps\", false);' >> prefs.js && " +
"start b2g"
)
}
function RootADB() {
let device = Devices.getByName(AppManager.selectedRuntime.id);
device.summonRoot().then(CheckLockState, (e) => console.error(e));
}

View File

@ -13,6 +13,7 @@
<head>
<meta charset="utf8"/>
<link rel="stylesheet" href="chrome://webide/skin/tabledoc.css" type="text/css"/>
<link rel="stylesheet" href="chrome://webide/skin/runtimedetails.css" type="text/css"/>
<script type="application/javascript;version=1.8" src="chrome://webide/content/runtimedetails.js"></script>
</head>
<body>
@ -23,6 +24,23 @@
<h1>&runtimedetails_title;</h1>
<div id="devicePrivileges">
<p id="adb-check">
&runtimedetails_adbIsRoot;<span class="yesno"></span>
<div class="action">
<button>&runtimedetails_summonADBRoot;</button>
<em>&runtimedetails_ADBRootWarning;</em>
</div>
</p>
<p id="certified-check">
&runtimedetails_restrictedPrivileges;<span class="yesno"></span>
<div class="action">
<button>&runtimedetails_requestPrivileges;</button>
<em>&runtimedetails_privilegesWarning;</em>
</div>
</p>
</div>
<table></table>
</body>
</html>

View File

@ -122,3 +122,9 @@
<!-- Runtime Details -->
<!ENTITY runtimedetails_title "Runtime Info">
<!ENTITY runtimedetails_adbIsRoot "ADB is root: ">
<!ENTITY runtimedetails_summonADBRoot "root device">
<!ENTITY runtimedetails_ADBRootWarning "(requires unlocked bootloader)">
<!ENTITY runtimedetails_restrictedPrivileges "DevTools restricted privileges: ">
<!ENTITY runtimedetails_requestPrivileges "request higher privileges">
<!ENTITY runtimedetails_privilegesWarning "(Will reboot device. Requires root access.)">

View File

@ -41,3 +41,8 @@ addons_status_uninstalled=Not Installed
addons_status_preparing=preparing
addons_status_downloading=downloading
addons_status_installing=installing
runtimedetails_checkno=no
runtimedetails_checkyes=yes
runtimedetails_checkunkown=unknown
runtimedetails_notUSBDevice=Not a USB device

View File

@ -18,6 +18,7 @@ const {AppValidator} = require("devtools/app-manager/app-validator");
const {ConnectionManager, Connection} = require("devtools/client/connection-manager");
const AppActorFront = require("devtools/app-actor-front");
const {getDeviceFront} = require("devtools/server/actors/device");
const {getPreferenceFront} = require("devtools/server/actors/preference");
const {setTimeout} = require("sdk/timers");
const {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
const {USBRuntime, WiFiRuntime, SimulatorRuntime,
@ -332,6 +333,13 @@ exports.AppManager = AppManager = {
return getDeviceFront(this.connection.client, this._listTabsResponse);
},
get preferenceFront() {
if (!this._listTabsResponse) {
return null;
}
return getPreferenceFront(this.connection.client, this._listTabsResponse);
},
disconnectRuntime: function() {
if (this.connection.status != Connection.Status.CONNECTED) {
return promise.resolve();

View File

@ -12,3 +12,4 @@ webide.jar:
skin/addons.css (addons.css)
skin/prefs.css (prefs.css)
skin/tabledoc.css (tabledoc.css)
skin/runtimedetails.css (runtimedetails.css)

View File

@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#devicePrivileges {
font-family: monospace;
padding-left: 6px;
}
.action {
display: inline;
}
.action[hidden] {
display: none;
}

View File

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
body {
background: white;
}