feat(adb): expose read blocking debugging option

This commit is contained in:
Simon Chan 2023-11-15 15:39:09 +08:00
parent 336e0ffd5d
commit 9cd6fb9296
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
2 changed files with 9 additions and 10 deletions

View file

@ -36,6 +36,7 @@ export interface AdbPacketDispatcherOptions {
* Whether to preserve the connection open after the `AdbPacketDispatcher` is closed. * Whether to preserve the connection open after the `AdbPacketDispatcher` is closed.
*/ */
preserveConnection?: boolean | undefined; preserveConnection?: boolean | undefined;
debugSlowRead?: boolean | undefined;
} }
/** /**
@ -229,7 +230,7 @@ export class AdbPacketDispatcher implements Closeable {
let handled = false; let handled = false;
await Promise.race([ await Promise.race([
delay(5000).then(() => { delay(5000).then(() => {
if (!handled) { if (this.options.debugSlowRead && !handled) {
throw new Error( throw new Error(
`packet for \`${socket.service}\` not handled in 5 seconds`, `packet for \`${socket.service}\` not handled in 5 seconds`,
); );

View file

@ -41,6 +41,7 @@ interface AdbDaemonAuthenticationOptions {
* Whether to preserve the connection open after the `AdbDaemonTransport` is closed. * Whether to preserve the connection open after the `AdbDaemonTransport` is closed.
*/ */
preserveConnection?: boolean | undefined; preserveConnection?: boolean | undefined;
debugSlowRead?: boolean | undefined;
} }
interface AdbDaemonSocketConnectorConstructionOptions { interface AdbDaemonSocketConnectorConstructionOptions {
@ -53,6 +54,7 @@ interface AdbDaemonSocketConnectorConstructionOptions {
* Whether to preserve the connection open after the `AdbDaemonTransport` is closed. * Whether to preserve the connection open after the `AdbDaemonTransport` is closed.
*/ */
preserveConnection?: boolean | undefined; preserveConnection?: boolean | undefined;
debugSlowRead?: boolean | undefined;
} }
export class AdbDaemonTransport implements AdbTransport { export class AdbDaemonTransport implements AdbTransport {
@ -69,7 +71,7 @@ export class AdbDaemonTransport implements AdbTransport {
connection, connection,
credentialStore, credentialStore,
authenticators = ADB_DEFAULT_AUTHENTICATORS, authenticators = ADB_DEFAULT_AUTHENTICATORS,
preserveConnection, ...options
}: AdbDaemonAuthenticationOptions): Promise<AdbDaemonTransport> { }: AdbDaemonAuthenticationOptions): Promise<AdbDaemonTransport> {
// Initially, set to highest-supported version and payload size. // Initially, set to highest-supported version and payload size.
let version = 0x01000001; let version = 0x01000001;
@ -193,7 +195,7 @@ export class AdbDaemonTransport implements AdbTransport {
version, version,
maxPayloadSize, maxPayloadSize,
banner, banner,
preserveConnection, ...options,
}); });
} }
@ -214,9 +216,8 @@ export class AdbDaemonTransport implements AdbTransport {
return this.#protocolVersion; return this.#protocolVersion;
} }
#maxPayloadSize: number;
get maxPayloadSize() { get maxPayloadSize() {
return this.#maxPayloadSize; return this.#dispatcher.options.maxPayloadSize;
} }
#banner: AdbBanner; #banner: AdbBanner;
@ -232,9 +233,8 @@ export class AdbDaemonTransport implements AdbTransport {
serial, serial,
connection, connection,
version, version,
maxPayloadSize,
banner, banner,
preserveConnection, ...options
}: AdbDaemonSocketConnectorConstructionOptions) { }: AdbDaemonSocketConnectorConstructionOptions) {
this.#serial = serial; this.#serial = serial;
this.#connection = connection; this.#connection = connection;
@ -253,12 +253,10 @@ export class AdbDaemonTransport implements AdbTransport {
this.#dispatcher = new AdbPacketDispatcher(connection, { this.#dispatcher = new AdbPacketDispatcher(connection, {
calculateChecksum, calculateChecksum,
appendNullToServiceString, appendNullToServiceString,
maxPayloadSize, ...options,
preserveConnection,
}); });
this.#protocolVersion = version; this.#protocolVersion = version;
this.#maxPayloadSize = maxPayloadSize;
} }
connect(service: string): ValueOrPromise<AdbSocket> { connect(service: string): ValueOrPromise<AdbSocket> {