Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit f4e4cc71 authored by Simon Chan's avatar Simon Chan
Browse files

feat(usb): expose adb endpoints for external use

parent 9cd6fb92
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -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() {
@@ -124,6 +132,7 @@ export class AdbDaemonWebUsbConnection
    ) {
        this.#device = device;
        this.#inEndpoint = inEndpoint;
        this.#outEndpoint = outEndpoint;

        let closed = false;

@@ -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();
        }
@@ -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,
+6 −5
Original line number Diff line number Diff line
@@ -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> {