Skip to content

Commit

Permalink
feat(usb): expose adb endpoints for external use
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Nov 29, 2023
1 parent 9cd6fb9 commit f4e4cc7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
24 changes: 19 additions & 5 deletions libraries/adb-daemon-webusb/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ export class AdbDaemonWebUsbConnection
}

#inEndpoint: USBEndpoint;
get inEndpoint() {
return this.#inEndpoint;
}

#outEndpoint: USBEndpoint;
get outEndpoint() {
return this.#outEndpoint;
}

#readable: ReadableStream<AdbPacketData>;
get readable() {
Expand All @@ -124,6 +132,7 @@ export class AdbDaemonWebUsbConnection
) {
this.#device = device;
this.#inEndpoint = inEndpoint;
this.#outEndpoint = outEndpoint;

let closed = false;

Expand Down Expand Up @@ -313,11 +322,7 @@ export class AdbDaemonWebUsbDevice implements AdbDaemonDevice {
this.#usbManager = usbManager;
}

/**
* Claim the device and create a pair of `AdbPacket` streams to the ADB interface.
* @returns The pair of `AdbPacket` streams.
*/
async connect(): Promise<AdbDaemonWebUsbConnection> {
async #claimInterface(): Promise<[USBEndpoint, USBEndpoint]> {
if (!this.#raw.opened) {
await this.#raw.open();
}
Expand Down Expand Up @@ -352,6 +357,15 @@ export class AdbDaemonWebUsbDevice implements AdbDaemonDevice {
const { inEndpoint, outEndpoint } = findUsbEndpoints(
alternate.endpoints,
);
return [inEndpoint, outEndpoint];
}

/**
* Claim the device and create a pair of `AdbPacket` streams to the ADB interface.
* @returns The pair of `AdbPacket` streams.
*/
async connect(): Promise<AdbDaemonWebUsbConnection> {
const [inEndpoint, outEndpoint] = await this.#claimInterface();
return new AdbDaemonWebUsbConnection(
this,
inEndpoint,
Expand Down
11 changes: 6 additions & 5 deletions libraries/android-bin/src/logcat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,12 @@ export class Logcat extends AdbCommandBase {
}

async clear(ids?: LogId[]) {
await this.adb.subprocess.spawnAndWait([
"logcat",
"-c",
...(ids ? ["-b", Logcat.joinLogId(ids)] : []),
]);
const args = ["logcat", "-c"];
if (ids && ids.length > 0) {
args.push("-b", Logcat.joinLogId(ids));
}

await this.adb.subprocess.spawnAndWait(args);
}

binary(options?: LogcatOptions): ReadableStream<AndroidLogEntry> {
Expand Down

0 comments on commit f4e4cc7

Please sign in to comment.