Loading libraries/adb/src/crypto.ts +0 −5 Original line number Diff line number Diff line Loading @@ -86,11 +86,6 @@ export function parsePrivateKey(key: ArrayBuffer): [n: bigint, d: bigint] { // I can't understand, but it does work // Only used with numbers less than 2^32 so doesn't need BigInt export function modInverse(a: number, m: number) { // validate inputs [a, m] = [Number(a), Number(m)]; if (Number.isNaN(a) || Number.isNaN(m)) { return NaN; // invalid input } a = (a % m + m) % m; if (!a || m < 2) { return NaN; // invalid input Loading libraries/adb/src/stream/stream.ts +7 −3 Original line number Diff line number Diff line import { once } from '@yume-chan/event'; import { ValueOrPromise } from '@yume-chan/struct'; import { AdbSocket, AdbSocketInfo } from '../socket'; import { EventQueue } from '../utils'; import { EventQueue, EventQueueEndedError } from '../utils'; import { StreamEndedError } from "./buffered-stream"; export class AdbSocketStream implements AdbSocketInfo { Loading Loading @@ -36,9 +36,13 @@ export class AdbSocketStream implements AdbSocketInfo { public async read(): Promise<ArrayBuffer> { try { return await this.queue.dequeue(); } catch { } catch (e) { if (e instanceof EventQueueEndedError) { throw new StreamEndedError(); } throw e; } } public write(data: ArrayBuffer): Promise<void> { Loading libraries/adb/src/utils/event-queue.ts +10 −1 Original line number Diff line number Diff line Loading @@ -58,6 +58,15 @@ class LinkedList<T>{ } } export class EventQueueEndedError extends Error { public constructor() { super('Event queue ended'); // Fix Error's prototype chain when compiling to ES5 Object.setPrototypeOf(this, new.target.prototype); } } /** * Basically an object-mode ReadableStream with Promise-based API * Loading Loading @@ -123,7 +132,7 @@ export class EventQueue<T> { } if (this.ended) { return Promise.reject(new Error('The EventQueue has already ended')); return Promise.reject(new EventQueueEndedError()); } if (this.awaiters.length === this.options.maxWaitCount - 1) { Loading libraries/android-bin/src/bug-report.ts +23 −1 Original line number Diff line number Diff line // cspell: ignore bugreport // cspell: ignore bugreportz import { AdbCommandBase, AdbShellProtocol } from "@yume-chan/adb"; import { AdbCommandBase, AdbShellProtocol, EventQueue, EventQueueEndedError } from "@yume-chan/adb"; export interface BugReportVersion { major: number; Loading Loading @@ -32,4 +32,26 @@ export class BugReport extends AdbCommandBase { minor: parseInt(match[2]!, 10), }; } public bugReportZSupportStream(version: BugReportVersion): boolean { return version.major > 1 || version.minor >= 2; } public async *bugReportZStream(): AsyncGenerator<ArrayBuffer, void, void> { const process = await this.adb.childProcess.spawn(['bugreportz', '-s']); const queue = new EventQueue<ArrayBuffer>(); process.onStdout(buffer => queue.enqueue(buffer)); process.onExit(() => queue.end()); try { while (true) { yield await queue.dequeue(); } } catch (e) { if (e instanceof EventQueueEndedError) { return; } throw e; } } } libraries/android-bin/src/settings.ts +18 −1 Original line number Diff line number Diff line Loading @@ -2,10 +2,11 @@ import { AdbCommandBase } from "@yume-chan/adb"; export type SettingsNamespace = 'system' | 'secure' | 'global'; export type SettingsResetMode = 'untrusted_defaults' | 'untrusted_clear' | 'trusted_defaults'; // frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsService.java export class Settings extends AdbCommandBase { // TODO: `--user <user>` argument // TODO: `reset` command public base(command: string, namespace: SettingsNamespace, ...args: string[]) { return this.adb.childProcess.spawnAndWaitLegacy(['settings', command, namespace, ...args]); Loading @@ -29,4 +30,20 @@ export class Settings extends AdbCommandBase { ...(makeDefault ? ['default'] : []), ); } public reset(namespace: SettingsNamespace, mode: SettingsResetMode): Promise<string>; public reset(namespace: SettingsNamespace, packageName: string, tag?: string): Promise<string>; public reset(namespace: SettingsNamespace, modeOrPackageName: string, tag?: string): Promise<string> { return this.base( 'reset', namespace, modeOrPackageName, ...(tag ? [tag] : []), ); } public async list(namespace: SettingsNamespace): Promise<string[]> { const output = await this.base('list', namespace); return output.split('\n'); } } Loading
libraries/adb/src/crypto.ts +0 −5 Original line number Diff line number Diff line Loading @@ -86,11 +86,6 @@ export function parsePrivateKey(key: ArrayBuffer): [n: bigint, d: bigint] { // I can't understand, but it does work // Only used with numbers less than 2^32 so doesn't need BigInt export function modInverse(a: number, m: number) { // validate inputs [a, m] = [Number(a), Number(m)]; if (Number.isNaN(a) || Number.isNaN(m)) { return NaN; // invalid input } a = (a % m + m) % m; if (!a || m < 2) { return NaN; // invalid input Loading
libraries/adb/src/stream/stream.ts +7 −3 Original line number Diff line number Diff line import { once } from '@yume-chan/event'; import { ValueOrPromise } from '@yume-chan/struct'; import { AdbSocket, AdbSocketInfo } from '../socket'; import { EventQueue } from '../utils'; import { EventQueue, EventQueueEndedError } from '../utils'; import { StreamEndedError } from "./buffered-stream"; export class AdbSocketStream implements AdbSocketInfo { Loading Loading @@ -36,9 +36,13 @@ export class AdbSocketStream implements AdbSocketInfo { public async read(): Promise<ArrayBuffer> { try { return await this.queue.dequeue(); } catch { } catch (e) { if (e instanceof EventQueueEndedError) { throw new StreamEndedError(); } throw e; } } public write(data: ArrayBuffer): Promise<void> { Loading
libraries/adb/src/utils/event-queue.ts +10 −1 Original line number Diff line number Diff line Loading @@ -58,6 +58,15 @@ class LinkedList<T>{ } } export class EventQueueEndedError extends Error { public constructor() { super('Event queue ended'); // Fix Error's prototype chain when compiling to ES5 Object.setPrototypeOf(this, new.target.prototype); } } /** * Basically an object-mode ReadableStream with Promise-based API * Loading Loading @@ -123,7 +132,7 @@ export class EventQueue<T> { } if (this.ended) { return Promise.reject(new Error('The EventQueue has already ended')); return Promise.reject(new EventQueueEndedError()); } if (this.awaiters.length === this.options.maxWaitCount - 1) { Loading
libraries/android-bin/src/bug-report.ts +23 −1 Original line number Diff line number Diff line // cspell: ignore bugreport // cspell: ignore bugreportz import { AdbCommandBase, AdbShellProtocol } from "@yume-chan/adb"; import { AdbCommandBase, AdbShellProtocol, EventQueue, EventQueueEndedError } from "@yume-chan/adb"; export interface BugReportVersion { major: number; Loading Loading @@ -32,4 +32,26 @@ export class BugReport extends AdbCommandBase { minor: parseInt(match[2]!, 10), }; } public bugReportZSupportStream(version: BugReportVersion): boolean { return version.major > 1 || version.minor >= 2; } public async *bugReportZStream(): AsyncGenerator<ArrayBuffer, void, void> { const process = await this.adb.childProcess.spawn(['bugreportz', '-s']); const queue = new EventQueue<ArrayBuffer>(); process.onStdout(buffer => queue.enqueue(buffer)); process.onExit(() => queue.end()); try { while (true) { yield await queue.dequeue(); } } catch (e) { if (e instanceof EventQueueEndedError) { return; } throw e; } } }
libraries/android-bin/src/settings.ts +18 −1 Original line number Diff line number Diff line Loading @@ -2,10 +2,11 @@ import { AdbCommandBase } from "@yume-chan/adb"; export type SettingsNamespace = 'system' | 'secure' | 'global'; export type SettingsResetMode = 'untrusted_defaults' | 'untrusted_clear' | 'trusted_defaults'; // frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsService.java export class Settings extends AdbCommandBase { // TODO: `--user <user>` argument // TODO: `reset` command public base(command: string, namespace: SettingsNamespace, ...args: string[]) { return this.adb.childProcess.spawnAndWaitLegacy(['settings', command, namespace, ...args]); Loading @@ -29,4 +30,20 @@ export class Settings extends AdbCommandBase { ...(makeDefault ? ['default'] : []), ); } public reset(namespace: SettingsNamespace, mode: SettingsResetMode): Promise<string>; public reset(namespace: SettingsNamespace, packageName: string, tag?: string): Promise<string>; public reset(namespace: SettingsNamespace, modeOrPackageName: string, tag?: string): Promise<string> { return this.base( 'reset', namespace, modeOrPackageName, ...(tag ? [tag] : []), ); } public async list(namespace: SettingsNamespace): Promise<string[]> { const output = await this.base('list', namespace); return output.split('\n'); } }