adb-device.js (1502B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { 8 shell, 9 } = require("resource://devtools/client/shared/remote-debugging/adb/commands/index.js"); 10 11 /** 12 * A Device instance is created and registered with the Devices module whenever 13 * ADB notices a new device is connected. 14 */ 15 class AdbDevice { 16 constructor(id) { 17 this.id = id; 18 } 19 20 async initialize() { 21 const model = await shell(this.id, "getprop ro.product.model"); 22 this.model = model.trim(); 23 } 24 25 get name() { 26 return this.model || this.id; 27 } 28 29 async getRuntimeSocketPaths() { 30 // A matching entry looks like: 31 // 00000000: 00000002 00000000 00010000 0001 01 6551588 32 // /data/data/org.mozilla.fennec/firefox-debugger-socket 33 const query = "cat /proc/net/unix"; 34 const rawSocketInfo = await shell(this.id, query); 35 36 // Filter to lines with "firefox-debugger-socket" 37 let socketInfos = rawSocketInfo.split(/\r?\n/); 38 socketInfos = socketInfos.filter(l => 39 l.includes("firefox-debugger-socket") 40 ); 41 42 // It's possible to have multiple lines with the same path, so de-dupe them 43 const socketPaths = new Set(); 44 for (const socketInfo of socketInfos) { 45 const socketPath = socketInfo.split(" ").pop(); 46 socketPaths.add(socketPath); 47 } 48 49 return socketPaths; 50 } 51 } 52 53 module.exports = AdbDevice;