mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 09:49:24 +02:00
feat(adb): add getListenAddresses
to AdbTcpIpCommand
This commit is contained in:
parent
6a4e4e72c6
commit
aeff1f8818
5 changed files with 65 additions and 24 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
@ -2,6 +2,7 @@
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"ADB's",
|
"ADB's",
|
||||||
"adbd",
|
"adbd",
|
||||||
|
"addrs",
|
||||||
"allowlist",
|
"allowlist",
|
||||||
"arraybuffer",
|
"arraybuffer",
|
||||||
"autorun",
|
"autorun",
|
||||||
|
|
|
@ -25,7 +25,7 @@ In this mode, this library talks to a Google ADB server, which is either running
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
| Connection | Chromium-based Browsers | Firefox | Node.js |
|
| Connection | Chromium-based Browsers | Firefox | Node.js |
|
||||||
| ----------------------------------------- | ------------------------------ | --------- | ----------------------------- |
|
| ----------------------------------------- | -------------------------------- | --------- | ----------------------------- |
|
||||||
| USB cable | Supported using [WebUSB] API | No | Supported using `usb` package |
|
| USB cable | Supported using [WebUSB] API | No | Supported using `usb` package |
|
||||||
| Wireless through [WebSocket] <sup>1</sup> | Supported | Supported | Possible using `ws` package |
|
| Wireless through [WebSocket] <sup>1</sup> | Supported | Supported | Possible using `ws` package |
|
||||||
| Wireless through TCP | Waiting for [Direct Sockets] API | No | Possible using `net` module |
|
| Wireless through TCP | Waiting for [Direct Sockets] API | No | Possible using `net` module |
|
||||||
|
|
|
@ -77,30 +77,19 @@ class TcpIpState {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const serviceListenAddresses = await GLOBAL_STATE.adb.getProp(
|
const { serviceListenAddresses, servicePort, persistPort } =
|
||||||
"service.adb.listen_addrs"
|
await GLOBAL_STATE.adb.tcpip.getListenAddresses();
|
||||||
);
|
|
||||||
const servicePort = await GLOBAL_STATE.adb.getProp(
|
|
||||||
"service.adb.tcp.port"
|
|
||||||
);
|
|
||||||
const persistPort = await GLOBAL_STATE.adb.getProp(
|
|
||||||
"persist.adb.tcp.port"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (signal.aborted) {
|
if (signal.aborted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.serviceListenAddresses =
|
this.serviceListenAddresses = serviceListenAddresses;
|
||||||
serviceListenAddresses !== ""
|
|
||||||
? serviceListenAddresses.split(",")
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (servicePort) {
|
if (servicePort) {
|
||||||
this.servicePortEnabled =
|
this.servicePortEnabled = !serviceListenAddresses;
|
||||||
!serviceListenAddresses && servicePort !== "0";
|
this.servicePort = servicePort.toString();
|
||||||
this.servicePort = servicePort;
|
|
||||||
} else {
|
} else {
|
||||||
this.servicePortEnabled = false;
|
this.servicePortEnabled = false;
|
||||||
this.servicePort = "5555";
|
this.servicePort = "5555";
|
||||||
|
@ -109,7 +98,7 @@ class TcpIpState {
|
||||||
if (persistPort) {
|
if (persistPort) {
|
||||||
this.persistPortEnabled =
|
this.persistPortEnabled =
|
||||||
!serviceListenAddresses && !servicePort;
|
!serviceListenAddresses && !servicePort;
|
||||||
this.persistPort = persistPort;
|
this.persistPort = persistPort.toString();
|
||||||
} else {
|
} else {
|
||||||
this.persistPortEnabled = false;
|
this.persistPortEnabled = false;
|
||||||
this.persistPort = undefined;
|
this.persistPort = undefined;
|
||||||
|
@ -124,7 +113,7 @@ class TcpIpState {
|
||||||
|
|
||||||
if (state.servicePortEnabled) {
|
if (state.servicePortEnabled) {
|
||||||
await GLOBAL_STATE.adb.tcpip.setPort(
|
await GLOBAL_STATE.adb.tcpip.setPort(
|
||||||
Number.parseInt(state.servicePort, 10)
|
Number.parseInt(state.servicePort, 10),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await GLOBAL_STATE.adb.tcpip.disable();
|
await GLOBAL_STATE.adb.tcpip.disable();
|
||||||
|
@ -153,7 +142,7 @@ const TcpIp: NextPage = () => {
|
||||||
state.servicePortEnabled = !!value;
|
state.servicePortEnabled = !!value;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleServicePortChange = useCallback(
|
const handleServicePortChange = useCallback(
|
||||||
|
@ -163,7 +152,7 @@ const TcpIp: NextPage = () => {
|
||||||
}
|
}
|
||||||
runInAction(() => (state.servicePort = value));
|
runInAction(() => (state.servicePort = value));
|
||||||
},
|
},
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
10
common/changes/@yume-chan/adb/main_2023-08-25-16-30.json
Normal file
10
common/changes/@yume-chan/adb/main_2023-08-25-16-30.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"changes": [
|
||||||
|
{
|
||||||
|
"packageName": "@yume-chan/adb",
|
||||||
|
"comment": "Add `getListenAddresses` method to `AdbTcpIpCommand` class for retrieving current ADB over WiFi state",
|
||||||
|
"type": "none"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packageName": "@yume-chan/adb"
|
||||||
|
}
|
|
@ -1,6 +1,47 @@
|
||||||
import { AdbCommandBase } from "./base.js";
|
import { AdbCommandBase } from "./base.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ADB daemon checks for the following properties in the order of
|
||||||
|
*
|
||||||
|
* * `serviceListenAddresses` (`service.adb.listen_addrs`)
|
||||||
|
* * `servicePort` (`service.adb.tcp.port`)
|
||||||
|
* * `persistPort` (`persist.adb.tcp.port`)
|
||||||
|
*
|
||||||
|
* Once it finds a non-empty value, it will use it and ignore the rest.
|
||||||
|
*
|
||||||
|
* `serviceListenAddresses` and `persistPort` are fixed at build time,
|
||||||
|
* only `servicePort` can be changed using `setPort` and `disable`.
|
||||||
|
* This means if either `serviceListenAddresses` or `persistPort` is non-empty,
|
||||||
|
* ADB over WiFi is always enabled.
|
||||||
|
*/
|
||||||
|
export interface AdbTcpIpListenAddresses {
|
||||||
|
serviceListenAddresses: string[];
|
||||||
|
servicePort: number | undefined;
|
||||||
|
persistPort: number | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export class AdbTcpIpCommand extends AdbCommandBase {
|
export class AdbTcpIpCommand extends AdbCommandBase {
|
||||||
|
#parsePort(value: string): number | undefined {
|
||||||
|
if (!value || value === "0") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return Number.parseInt(value, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getListenAddresses(): Promise<AdbTcpIpListenAddresses> {
|
||||||
|
const serviceListenAddresses = await this.adb.getProp(
|
||||||
|
"service.adb.listen_addrs",
|
||||||
|
);
|
||||||
|
const servicePort = await this.adb.getProp("service.adb.tcp.port");
|
||||||
|
const persistPort = await this.adb.getProp("persist.adb.tcp.port");
|
||||||
|
|
||||||
|
return {
|
||||||
|
serviceListenAddresses: serviceListenAddresses.split(","),
|
||||||
|
servicePort: this.#parsePort(servicePort),
|
||||||
|
persistPort: this.#parsePort(persistPort),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async setPort(port: number): Promise<string> {
|
async setPort(port: number): Promise<string> {
|
||||||
if (port <= 0) {
|
if (port <= 0) {
|
||||||
throw new Error(`Invalid port ${port}`);
|
throw new Error(`Invalid port ${port}`);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue