Commit Graph
33 Commits
Author SHA1 Message Date
Hiroyuki Ikezoe 8e9e8d2b83 Bug 1483730 - Return null from getFileForAdb if the adb file doesn't exit. r=jdescottes
Summary: Depends on D3463

Reviewers: jdescottes

Reviewed By: jdescottes

Bug #: 1483730

Differential Revision: https://phabricator.services.mozilla.com/D3464
2018-08-17 06:58:42 +09:00
Hiroyuki Ikezoe 6b208d6d76 Bug 1483730 - Call nsIFile.exists method. r=jdescottes
Reviewers: jdescottes

Reviewed By: jdescottes

Bug #: 1483730

Differential Revision: https://phabricator.services.mozilla.com/D3463
2018-08-17 06:56:52 +09:00
Hiroyuki Ikezoe ae5f46b35d Bug 1481699 - Merge two if statements for 'start-server' into a single one. r=jdescottes
And fix some log messages.
2018-08-13 06:12:55 +09:00
Hiroyuki Ikezoe 634d64ba2b Bug 1481699 - Send host:kill command through TCP socket instead of spawning a new adb process with 'kill-server'. r=jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D3170
2018-08-13 06:12:55 +09:00
Hiroyuki Ikezoe c2c68b5f08 Bug 1481699 - Do not process any further data after we started shutting down the ADB server. r=jdescottes
In the genuine adb binary, when it received 'host:kill' command, it exits the
server process soon [1].  Whereas, in our mock adb.py which is based on
SocketServer.TCPServer in python, when we call
SocketServer.TCPServer.shutdown() in the case of 'kill-server' command, the
server process doesn't exit soon since the shutdown() function just sets a
flag [2] and serve_forever() polls it [3] every |poll_interval| seconds,
|poll_interval| is 0.5 seconds by default.  Thus it's possible that new incoming
requests are processed during polling.

This is the real cause of the race condition that the adb server still keeps
alive when 'adb kill-server' finished.  So we don't need to the workaround
for the race condition.

[1] https://android.googlesource.com/platform/system/core/+/4039051d6ddb02324204930fb86d9d0fe405b3fb/adb/adb.cpp#1049
[2] https://github.com/python/cpython/blob/65b5ef02ec1f44e3a19b689a1ecf73d01c82161b/Lib/socketserver.py#L248
[3] https://docs.python.org/2/library/socketserver.html#SocketServer.BaseServer.serve_forever

Differential Revision: https://phabricator.services.mozilla.com/D3169
2018-08-13 06:08:34 +09:00
Hiroyuki Ikezoe 8044398538 Bug 1481699 - Send back 'OKAY' to the client when the adb server received 'kill-server' command. r=jdescottes
Because the genuine adb binary does it [1].  And doing it before shutdown
thread is created to make sure it's sent to the client.

[1] https://android.googlesource.com/platform/system/core/+/4039051d6ddb02324204930fb86d9d0fe405b3fb/adb/adb.cpp#1055

Differential Revision: https://phabricator.services.mozilla.com/D3168
2018-08-13 06:08:34 +09:00
Hiroyuki Ikezoe b39cca4936 Bug 1481699 - Rename ADBServer to ADBRequestHandler. r=jdescottes
Since it's actually a child of SocketServer.BaseRequestHandler.

Differential Revision: https://phabricator.services.mozilla.com/D3167
2018-08-13 06:08:33 +09:00
Hiroyuki Ikezoe 86e5de9c52 Bug 1481691 - Unpack files only if the devtools-adb-extension versionis mismatch or there are no unpacked files. r=jdescottes
getManifestFromUnpacked() and isUnpacked() are mostly the same as they are in
binary-manager.js [1] in the adbhelper addon.  A big difference is that the
manifest.json copied from the extension is the manifest.json for the
devtools-adb-extension itself, not manifest.json(s) in a subdirectory for
each platforms (e.g. linux/manifest.json).

Due to the verion check in each xpcshell test needs to use a different version
for the test extension, otherwise subsequent tests will use unpacked files in
the first test case, thus the ADB mock won't be used at all.

[1] https://github.com/mozilla/adbhelper/blob/0821424b6b895645560089a134054b35b6649ff8/binary-manager.js
2018-08-10 16:57:21 +09:00
Hiroyuki Ikezoe 1b8c70c4f5 Bug 1481691 - Rename extractBinary to extractFiles and make it return a boolean instead of path string. r=jdescottes
In the next patch, we will extract manifest.json in the extension into the
profile directory.  And returning a boolean will make getFileForBinary()
simple with the extension version check which will be also introduced in the
next patch.
2018-08-10 16:32:21 +09:00
Hiroyuki Ikezoe f6e3b58e0b Bug 1481691 - Drop |sync| argument from kill() and stop(). r=jdescottes
We've been using them as synchrous mode only.
2018-08-10 16:32:21 +09:00
Hiroyuki Ikezoe f69ae2febd Bug 1481691 - Use Promise instead of PromiseUtils. r=jdescottes 2018-08-10 16:32:21 +09:00
Hiroyuki Ikezoe 8667665868 Bug 1481691 - Drop root relevant stuff and push and pull. r=jedescottes
As far as I can tell they were all for FirefoxOS.
2018-08-10 16:32:21 +09:00
Hiroyuki Ikezoe 1a6bbdd8a4 Bug 1481691 - Drop code for FirefoxOS. r=jdescottes 2018-08-10 16:32:21 +09:00
Hiroyuki Ikezoe 94497efb29 Bug 1481691 - Drop code and comments for older versions of Firefox. r=jdescottes 2018-08-10 16:32:21 +09:00
Hiroyuki Ikezoe ab630c4f3d Bug 1481691 - Replace console.log and console.debug with dumpn. r=jdescottes 2018-08-10 16:32:21 +09:00
Hiroyuki Ikezoe fb1cbab0ed Bug 1481691 - Add a preference for the devtools-adb-extension id. r=jdescottes 2018-08-10 16:32:20 +09:00
Hiroyuki Ikezoe 253582bf0e Bug 1469054 - Skip some test cases in test_adb.js on Windows. r=jdescottes
On Windows testNoTargetBinaries fails since we don't remove extracted binaries
in the profile directory when the extension is removed.  The original adbhelper
addon doesn't remove them either, so this problem has been underlying
originally.  We will fix it in a later bug.

Also on Windows, testStartAndStop and testTrackDevices fail.  That's because,
I guess, the adb mock (adb.py) isn't launched properly.  I will handle it
once after I take a windows laptop back.

MozReview-Commit-ID: 15wo1S0pX37
2018-08-09 15:43:44 +09:00
Hiroyuki Ikezoe 0fe9ba0f54 Bug 1469054 - Make check() in adb-running-checker fail if a certain period of time elapsed. r=jdescottes
On MacOSX connecting to a port which is not started listening gets stuck
(bug 1481963), to avoid the stuck, we make forcibly the function fail.

MozReview-Commit-ID: COVplVPx3vA
2018-08-09 15:43:44 +09:00
Hiroyuki Ikezoe 4354f08008 Bug 1469054 - Make sure the ADB server is ready to listen from clients when we call adb.start(). r=jdescottes
There is a race condition that when we adb.start() finishes, i.e. the ADB server
is launched, the ADB server is not ready to listen from clients yet.  To avoid
this race condition in adb.start() function, we do wait until the server gets
ready.

MozReview-Commit-ID: EfSLA9uvhI9
2018-08-09 15:43:39 +09:00
Hiroyuki Ikezoe 2c01ee575e Bug 1469054 - Make sure that the adb.py sends all data. r=jdescottes
It seems that, on chaos mode, we can't receive whole data set at once, i.e.
sending data will be split into some chunks, so the adb mock should check the
sent data length and if there remains still data which has to be sent, we have
to continue sending the rest of the data.

MozReview-Commit-ID: 5jeEH8KpNNW
2018-08-09 14:27:57 +09:00
Hiroyuki Ikezoe d6da7931df Bug 1469054 - ESLint: lint fix for adb-device.js. r=jdescottes
MozReview-Commit-ID: AYvHsiirrtt
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe 45ef22bbff 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
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe 13fc14bbda Bug 1469054 - ESLint: lint fix for adb-scanner.js. r=jdescottes
MozReview-Commit-ID: 9riT60wVuCe
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe 9542b49ea1 Bug 1469054 - Adapt scanner.js in the adbhelper addon into devtools. r=jdescottes
A big difference between them is ADBScanner object itself is exported instead of
exporting unregister() method, since in the new about:debugging we have a toggle
button to install the new adbhelper extension, so that we should observe
uninstalling/installing the new adbhelper extension there, which means when the
adbhelper is removed we have to unregister this scanner there.

The diff;
 --- /home/hiro/adbhelper/scanner.js	2018-08-06 09:47:24.199685034 +0900
 +++ devtools/shared/adb/adb-scanner.js	2018-08-06 11:52:05.423496900 +0900
 @@ -2,19 +2,17 @@
   * 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/. */

 -const { Cu } = require("chrome");
 -const EventEmitter =
 -  require("./devtools-require")("devtools/shared/event-emitter");
 -const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
 -const unload = require("./unload");
 +"use strict";
 +
 +const EventEmitter = require("devtools/shared/event-emitter");
  const { ConnectionManager } =
 -  require("./devtools-require")("devtools/shared/client/connection-manager");
 +  require("devtools/shared/client/connection-manager");
  const { Devices } =
 -  require("./devtools-import")("resource://devtools/shared/apps/Devices.jsm");
 -const Runtimes =
 -  require("./devtools-require")("devtools/client/webide/modules/runtimes");
 +  require("devtools/shared/apps/Devices.jsm");
 +const { RuntimeTypes } =
 +  require("devtools/client/webide/modules/runtime-types");

 -let Scanner = {
 +const ADBScanner = {

    _runtimes: [],

 @@ -41,9 +39,9 @@ let Scanner = {
        return this._updatingPromise;
      }
      this._runtimes = [];
 -    let promises = [];
 -    for (let id of Devices.available()) {
 -      let device = Devices.getByName(id);
 +    const promises = [];
 +    for (const id of Devices.available()) {
 +      const device = Devices.getByName(id);
        promises.push(this._detectRuntimes(device));
      }
      this._updatingPromise = Promise.all(promises);
 @@ -56,13 +54,13 @@ let Scanner = {
      return this._updatingPromise;
    },

 -  _detectRuntimes: Task.async(function* (device) {
 -    let model = yield device.getModel();
 -    let detectedRuntimes = yield FirefoxOSRuntime.detect(device, model);
 +  _detectRuntimes: async function(device) {
 +    const model = await device.getModel();
 +    let detectedRuntimes = await FirefoxOSRuntime.detect(device, model);
      this._runtimes.push(...detectedRuntimes);
 -    detectedRuntimes = yield FirefoxOnAndroidRuntime.detect(device, model);
 +    detectedRuntimes = await FirefoxOnAndroidRuntime.detect(device, model);
      this._runtimes.push(...detectedRuntimes);
 -  }),
 +  },

    scan() {
      return this._updateRuntimes();
 @@ -74,7 +72,7 @@ let Scanner = {

  };

 -EventEmitter.decorate(Scanner);
 +EventEmitter.decorate(ADBScanner);

  function Runtime(device, model, socketPath) {
    this.device = device;
 @@ -83,15 +81,15 @@ function Runtime(device, model, socketPa
  }

  Runtime.prototype = {
 -  type: Runtimes.RuntimeTypes.USB,
 +  type: RuntimeTypes.USB,
    connect(connection) {
 -    let port = ConnectionManager.getFreeTCPPort();
 -    let local = "tcp:" + port;
 +    const port = ConnectionManager.getFreeTCPPort();
 +    const local = "tcp:" + port;
      let remote;
      if (this._socketPath.startsWith("@")) {
 -        remote = "localabstract:" + this._socketPath.substring(1);
 +      remote = "localabstract:" + this._socketPath.substring(1);
      } else {
 -        remote = "localfilesystem:" + this._socketPath;
 +      remote = "localfilesystem:" + this._socketPath;
      }
      return this.device.forwardPort(local, remote).then(() => {
        connection.host = "localhost";
 @@ -108,26 +106,26 @@ function FirefoxOSRuntime(device, model)
    Runtime.call(this, device, model, "/data/local/debugger-socket");
  }

 -FirefoxOSRuntime.detect = Task.async(function* (device, model) {
 -  let runtimes = [];
 -  let query = "test -f /system/b2g/b2g; echo $?";
 -  let b2gExists = yield device.shell(query);
 +FirefoxOSRuntime.detect = async function(device, model) {
 +  const runtimes = [];
 +  const query = "test -f /system/b2g/b2g; echo $?";
 +  let b2gExists = await device.shell(query);
    // XXX: Sometimes we get an empty response back.  Likely a bug in our shell
    // code in this add-on.
    // There are also some Android devices that do not have `test` installed.
    for (let attempts = 3; attempts > 0; attempts--) {
 -    b2gExists = yield device.shell(query);
 +    b2gExists = await device.shell(query);
      if (b2gExists.length == 3) {
        break;
      }
    }
    if (b2gExists === "0\r\n") {
 -    let runtime = new FirefoxOSRuntime(device, model);
 +    const runtime = new FirefoxOSRuntime(device, model);
      console.log("Found " + runtime.name);
      runtimes.push(runtime);
    }
    return runtimes;
 -});
 +};

  FirefoxOSRuntime.prototype = Object.create(Runtime.prototype);

 @@ -142,28 +140,29 @@ function FirefoxOnAndroidRuntime(device,
  }

  // This requires Unix socket support from Firefox for Android (35+)
 -FirefoxOnAndroidRuntime.detect = Task.async(function* (device, model) {
 -  let runtimes = [];
 +FirefoxOnAndroidRuntime.detect = async function(device, model) {
 +  const runtimes = [];
    // A matching entry looks like:
 -  // 00000000: 00000002 00000000 00010000 0001 01 6551588 /data/data/org.mozilla.fennec/firefox-debugger-socket
 -  let query = "cat /proc/net/unix";
 -  let rawSocketInfo = yield device.shell(query);
 +  // 00000000: 00000002 00000000 00010000 0001 01 6551588
 +  //  /data/data/org.mozilla.fennec/firefox-debugger-socket
 +  const query = "cat /proc/net/unix";
 +  const rawSocketInfo = await device.shell(query);
    let socketInfos = rawSocketInfo.split(/\r?\n/);
    // Filter to lines with "firefox-debugger-socket"
    socketInfos = socketInfos.filter(l => l.includes("firefox-debugger-socket"));
    // It's possible to have multiple lines with the same path, so de-dupe them
 -  let socketPaths = new Set();
 -  for (let socketInfo of socketInfos) {
 -    let socketPath = socketInfo.split(" ").pop();
 +  const socketPaths = new Set();
 +  for (const socketInfo of socketInfos) {
 +    const socketPath = socketInfo.split(" ").pop();
      socketPaths.add(socketPath);
    }
 -  for (let socketPath of socketPaths) {
 -    let runtime = new FirefoxOnAndroidRuntime(device, model, socketPath);
 +  for (const socketPath of socketPaths) {
 +    const runtime = new FirefoxOnAndroidRuntime(device, model, socketPath);
      console.log("Found " + runtime.name);
      runtimes.push(runtime);
    }
    return runtimes;
 -});
 +};

  FirefoxOnAndroidRuntime.prototype = Object.create(Runtime.prototype);

 @@ -201,21 +200,4 @@ Object.defineProperty(FirefoxOnAndroidRu
    }
  });

 -exports.register = function() {
 -  // Only register our |Scanner| if the API exists
 -  if (Runtimes && Runtimes.RuntimeScanners) {
 -    // There may be an older ADB scanner registered by default
 -    // If so, we must disable it to avoid duplicate runtimes
 -    if (Runtimes.DeprecatedAdbScanner) {
 -      Runtimes.RuntimeScanners.remove(Runtimes.DeprecatedAdbScanner);
 -      unload(() => {
 -        Runtimes.RuntimeScanners.add(Runtimes.DeprecatedAdbScanner);
 -      });
 -    }
 -    // Add our scanner
 -    Runtimes.RuntimeScanners.add(Scanner);
 -    unload(() => {
 -      Runtimes.RuntimeScanners.remove(Scanner);
 -    });
 -  }
 -};
 +exports.ADBScanner = ADBScanner;

MozReview-Commit-ID: 2PC1ochp19E
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe c63eb31442 Bug 1469054 - Add async annotation for adb.start(). r=jdescottes
MozReview-Commit-ID: 534q7l33l7o
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe 528d52c2fd Bug 1469054 - ESLint: Add no-fallthrough annotation. r=jdescottes
MozReview-Commit-ID: 5tBviheMTTk
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe 74d2599110 Bug 1469054 - ESLint: Use integer for the radix on parseInt. r=jdescottes
I am not sure this had caused real issue though.

MozReview-Commit-ID: ISSSJCYcpAm
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe 4d836c951e Bug 1469054 - ESLint: Drop function name. r=jdescottes
MozReview-Commit-ID: LsUzDI0fkVc
2018-08-09 14:27:56 +09:00
Hiroyuki Ikezoe 1110697608 Bug 1469054 - ESLint: Drop 'a' prefix from argument names. r=jdescottes
MozReview-Commit-ID: J3v5NKglA2B
2018-08-09 14:27:55 +09:00
Hiroyuki Ikezoe 4428620ea1 Bug 1469054 - ESLint: Lint fixes. r=jdescottes
Changes are:

- s/let/const/g if applicable
- braces for 'if' block
- identation fixes
- Moved a statement in setTimeout callback on the next line.

MozReview-Commit-ID: HyZ9zrbK3iJ
2018-08-09 14:27:55 +09:00
Hiroyuki Ikezoe 5c9fbb2866 Bug 1469054 - Make sure the adb server stops. r=jdescottes
Without this change, the test in this patch does fail since when the test
starts, the adb server is still running for the previous test, thus
ADB.start() doesn't start a new adb server, then after that when we check
that the adb server is running by adb-running-checker, it tells us the adb
server is NOT running at that moment.

MozReview-Commit-ID: KRo30WmAsAY
2018-08-09 14:27:55 +09:00
Hiroyuki Ikezoe 913c5bc725 Bug 1469054 - Adapt implementations for adb.start() and adb.stop() and relevant stuff. r=jdescottes
MozReview-Commit-ID: LF23OQtXxkj
2018-08-09 14:27:55 +09:00
Hiroyuki Ikezoe 165c9f53b7 Bug 1469054 - Extract adb binary and related files into local profile directory from the extension. r=jdescottes
The new devtools-adb-extension should have adb.json on the top of the extension
directory, and devtools fetches the adb.json and parses it then copies the blobs
into local profile directory.

NOTE: Though we are going to use the same adb.json for all platforms, we will
pack only the corresponding blobs for each platform.  E.g. the extension for
Linux64 will have only linux64/adb.

The adb.json should look like this;

  {
    "Linux": {
      "x86": [
        "linux/adb"
      ],
      "x86_64": [
        "linux64/adb"
      ]
    },
    "Darwin": {
      "x86_64": [
        "mac64/adb"
      ]
    },
    "WINNT": {
      "x86": [
        "win32/adb.exe",
        "win32/AdbWinApi.dll",
        "win32/AdbWinUsbApi.dll"
      ],
      "x86_64": [
        "win32/adb.exe",
        "win32/AdbWinApi.dll",
        "win32/AdbWinUsbApi.dll"
      ]
    }
  }

unpackFile() here is mostly the same as in binary-manager.js in the adbhelper
addon.

MozReview-Commit-ID: 7aprfaaeTAT
2018-08-09 14:27:55 +09:00