summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/remote-debugging/adb/adb-device.js
blob: def22f27c3fd240dc35fab50d9f5faa42bb37b71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* 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 {
  shell,
} = require("resource://devtools/client/shared/remote-debugging/adb/commands/index.js");

/**
 * A Device instance is created and registered with the Devices module whenever
 * ADB notices a new device is connected.
 */
class AdbDevice {
  constructor(id) {
    this.id = id;
  }

  async initialize() {
    const model = await shell(this.id, "getprop ro.product.model");
    this.model = model.trim();
  }

  get name() {
    return this.model || this.id;
  }

  async getRuntimeSocketPaths() {
    // A matching entry looks like:
    // 00000000: 00000002 00000000 00010000 0001 01 6551588
    //  /data/data/org.mozilla.fennec/firefox-debugger-socket
    const query = "cat /proc/net/unix";
    const rawSocketInfo = await shell(this.id, query);

    // Filter to lines with "firefox-debugger-socket"
    let socketInfos = rawSocketInfo.split(/\r?\n/);
    socketInfos = socketInfos.filter(l =>
      l.includes("firefox-debugger-socket")
    );

    // It's possible to have multiple lines with the same path, so de-dupe them
    const socketPaths = new Set();
    for (const socketInfo of socketInfos) {
      const socketPath = socketInfo.split(" ").pop();
      socketPaths.add(socketPath);
    }

    return socketPaths;
  }
}

module.exports = AdbDevice;