Bug 1469054 - Adapt device.js in the adbhelper addon into devtools. r?jdescottes draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 09 Aug 2018 14:27:56 +0900
changeset 827785 13fcdee966bd2a1dee253a1bc98e443b63f8e0f3
parent 827784 afcf47d0fd452889a407f4af171d26461ef8d5ae
child 827786 1423445d7a8d2e9bdd8b254c4c2b1a1b06b40282
push id118583
push userhikezoe@mozilla.com
push dateThu, 09 Aug 2018 06:03:03 +0000
reviewersjdescottes
bugs1469054
milestone63.0a1
Bug 1469054 - Adapt device.js in the adbhelper addon into devtools. r?jdescottes The diff; --- /home/hiro/adbhelper/device.js 2018-07-19 06:18:41.613011481 +0900 +++ devtools/shared/adb/adb-device.js 2018-08-06 10:18:38.808496752 +0900 @@ -4,9 +4,7 @@ "use strict"; -const { ConnectionManager } = - require("./devtools-require")("devtools/shared/client/connection-manager"); -const adb = require("./adb"); +const { ADB } = require("devtools/shared/adb/adb"); /** * A Device instance is created and registered with the Devices module whenever @@ -21,34 +19,18 @@ function Device(id) { } Device.prototype = { - /** - * DEPRECATED: This is specific to how we connect to Firefox OS. Use cases - * that interact with other kinds of devices should likely use the more - * general |forwardPort| method directly. - */ - connect(remotePort) { - let port = ConnectionManager.getFreeTCPPort(); - let local = "tcp:" + port; - let remote = "localfilesystem:/data/local/debugger-socket"; - if (remotePort) { - remote = "tcp:" + remotePort; - } - return adb.forwardPort(local, remote) - .then(() => port); - }, - type: "adb", - shell: adb.shell.bind(adb), - forwardPort: adb.forwardPort.bind(adb), - push: adb.push.bind(adb), - pull: adb.pull.bind(adb), - reboot: adb.reboot.bind(adb), - rebootRecovery: adb.rebootRecovery.bind(adb), - rebootBootloader: adb.rebootBootloader.bind(adb), + shell: ADB.shell.bind(ADB), + forwardPort: ADB.forwardPort.bind(ADB), + push: ADB.push.bind(ADB), + pull: ADB.pull.bind(ADB), + reboot: ADB.reboot.bind(ADB), + rebootRecovery: ADB.rebootRecovery.bind(ADB), + rebootBootloader: ADB.rebootBootloader.bind(ADB), isRoot() { - return adb.shell("id").then(stdout => { + return ADB.shell("id").then(stdout => { if (stdout) { let uid = stdout.match(/uid=(\d+)/)[1]; return uid == "0"; @@ -58,7 +40,7 @@ Device.prototype = { }, summonRoot() { - return adb.root(); + return ADB.root(); }, getModel() { MozReview-Commit-ID: FlbKPm6VDs5
devtools/shared/adb/adb-device.js
devtools/shared/adb/moz.build
new file mode 100644
--- /dev/null
+++ b/devtools/shared/adb/adb-device.js
@@ -0,0 +1,52 @@
+/* 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/. */
+
+"use strict";
+
+const { ADB } = require("devtools/shared/adb/adb");
+
+/**
+ * A Device instance is created and registered with the Devices module whenever
+ * ADB notices a new device is connected.
+ */
+function Device(id) {
+  this.id = id;
+}
+
+Device.prototype = {
+  type: "adb",
+
+  shell: ADB.shell.bind(ADB),
+  forwardPort: ADB.forwardPort.bind(ADB),
+  push: ADB.push.bind(ADB),
+  pull: ADB.pull.bind(ADB),
+  reboot: ADB.reboot.bind(ADB),
+  rebootRecovery: ADB.rebootRecovery.bind(ADB),
+  rebootBootloader: ADB.rebootBootloader.bind(ADB),
+
+  isRoot() {
+    return ADB.shell("id").then(stdout => {
+      if (stdout) {
+        let uid = stdout.match(/uid=(\d+)/)[1];
+        return uid == "0";
+      }
+      return false;
+    });
+  },
+
+  summonRoot() {
+    return ADB.root();
+  },
+
+  getModel() {
+    if (this._modelPromise) {
+      return this._modelPromise;
+    }
+    this._modelPromise = this.shell("getprop ro.product.model")
+                             .then(model => model.trim());
+    return this._modelPromise;
+  }
+};
+
+module.exports = Device;
--- a/devtools/shared/adb/moz.build
+++ b/devtools/shared/adb/moz.build
@@ -1,15 +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/.
 
 DevToolsModules(
     'adb-binary.js',
     'adb-client.js',
+    'adb-device.js',
     'adb-running-checker.js',
     'adb-scanner.js',
     'adb-socket.js',
     'adb.js',
 )
 
 with Files('**'):
     BUG_COMPONENT = ('DevTools', 'about:debugging')