From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../adb/commands/prepare-tcp-connection.js | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 devtools/client/shared/remote-debugging/adb/commands/prepare-tcp-connection.js (limited to 'devtools/client/shared/remote-debugging/adb/commands/prepare-tcp-connection.js') diff --git a/devtools/client/shared/remote-debugging/adb/commands/prepare-tcp-connection.js b/devtools/client/shared/remote-debugging/adb/commands/prepare-tcp-connection.js new file mode 100644 index 0000000000..dc9103f56b --- /dev/null +++ b/devtools/client/shared/remote-debugging/adb/commands/prepare-tcp-connection.js @@ -0,0 +1,46 @@ +/* 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 { dumpn } = require("resource://devtools/shared/DevToolsUtils.js"); +const { + runCommand, +} = require("resource://devtools/client/shared/remote-debugging/adb/commands/run-command.js"); + +// sends adb forward deviceId, localPort and devicePort +const forwardPort = function (deviceId, localPort, devicePort) { + dumpn("forwardPort " + localPort + " -- " + devicePort); + // Send "host-serial::", + // with set to "forward:;" + // See https://android.googlesource.com/platform/system/core/+/jb-dev/adb/SERVICES.TXT + return runCommand( + `host-serial:${deviceId}:forward:${localPort};${devicePort}` + ).then(function onSuccess(data) { + return data; + }); +}; + +const getFreeTCPPort = function () { + const serv = Cc["@mozilla.org/network/server-socket;1"].createInstance( + Ci.nsIServerSocket + ); + serv.init(-1, true, -1); + const port = serv.port; + serv.close(); + return port; +}; + +// Prepare TCP connection for provided device id and socket path. +// The returned value is a port number of localhost for the connection. +const prepareTCPConnection = async function (deviceId, socketPath) { + const port = getFreeTCPPort(); + const local = `tcp:${port}`; + const remote = socketPath.startsWith("@") + ? `localabstract:${socketPath.substring(1)}` + : `localfilesystem:${socketPath}`; + await forwardPort(deviceId, local, remote); + return port; +}; +exports.prepareTCPConnection = prepareTCPConnection; -- cgit v1.2.3