feat(adb): make shell return binary (#4695)
This commit is contained in:
parent
7c89ec051a
commit
ad5309ca6b
2
android-types-internal.d.ts
vendored
2
android-types-internal.d.ts
vendored
|
|
@ -27,7 +27,7 @@ export interface AndroidDevice<BrowserContextOptions, BrowserContext, Page> exte
|
|||
model(): string;
|
||||
webViews(): AndroidWebView<Page>[];
|
||||
webView(selector: { pkg: string }, options?: { timeout?: number }): Promise<AndroidWebView<Page>>;
|
||||
shell(command: string): Promise<string>;
|
||||
shell(command: string): Promise<Buffer>;
|
||||
open(command: string): Promise<AndroidSocket>;
|
||||
installApk(file: string | Buffer, options?: { args?: string[] }): Promise<void>;
|
||||
launchBrowser(options?: BrowserContextOptions & { packageName?: string }): Promise<BrowserContext>;
|
||||
|
|
|
|||
|
|
@ -198,10 +198,10 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c
|
|||
});
|
||||
}
|
||||
|
||||
async shell(command: string): Promise<string> {
|
||||
async shell(command: string): Promise<Buffer> {
|
||||
return this._wrapApiCall('androidDevice.shell', async () => {
|
||||
const { result } = await this._channel.shell({ command });
|
||||
return result;
|
||||
return Buffer.from(result, 'base64');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ export class AndroidDeviceDispatcher extends Dispatcher<AndroidDevice, channels.
|
|||
}
|
||||
|
||||
async shell(params: channels.AndroidDeviceShellParams): Promise<channels.AndroidDeviceShellResult> {
|
||||
return { result: await this._object.shell(params.command) };
|
||||
return { result: (await this._object.shell(params.command)).toString('base64') };
|
||||
}
|
||||
|
||||
async open(params: channels.AndroidDeviceOpenParams, metadata?: channels.Metadata): Promise<channels.AndroidDeviceOpenResult> {
|
||||
|
|
|
|||
|
|
@ -2747,7 +2747,7 @@ export type AndroidDeviceShellOptions = {
|
|||
|
||||
};
|
||||
export type AndroidDeviceShellResult = {
|
||||
result: string,
|
||||
result: Binary,
|
||||
};
|
||||
export type AndroidDeviceInstallApkParams = {
|
||||
file: Binary,
|
||||
|
|
|
|||
|
|
@ -2303,7 +2303,7 @@ AndroidDevice:
|
|||
parameters:
|
||||
command: string
|
||||
returns:
|
||||
result: string
|
||||
result: binary
|
||||
|
||||
installApk:
|
||||
parameters:
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export interface DeviceBackend {
|
|||
status: string;
|
||||
close(): Promise<void>;
|
||||
init(): Promise<void>;
|
||||
runCommand(command: string): Promise<string>;
|
||||
runCommand(command: string): Promise<Buffer>;
|
||||
open(command: string): Promise<SocketBackend>;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ export class AndroidDevice extends EventEmitter {
|
|||
static async create(android: Android, backend: DeviceBackend): Promise<AndroidDevice> {
|
||||
await backend.init();
|
||||
const model = await backend.runCommand('shell:getprop ro.product.model');
|
||||
const device = new AndroidDevice(android, backend, model.trim());
|
||||
const device = new AndroidDevice(android, backend, model.toString().trim());
|
||||
await device._init();
|
||||
return device;
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ export class AndroidDevice extends EventEmitter {
|
|||
this._timeoutSettings.setDefaultTimeout(timeout);
|
||||
}
|
||||
|
||||
async shell(command: string): Promise<string> {
|
||||
async shell(command: string): Promise<Buffer> {
|
||||
const result = await this._backend.runCommand(`shell:${command}`);
|
||||
await this._refreshWebViews();
|
||||
return result;
|
||||
|
|
@ -288,7 +288,7 @@ export class AndroidDevice extends EventEmitter {
|
|||
}
|
||||
|
||||
private async _refreshWebViews() {
|
||||
const sockets = (await this._backend.runCommand(`shell:cat /proc/net/unix | grep webview_devtools_remote`)).split('\n');
|
||||
const sockets = (await this._backend.runCommand(`shell:cat /proc/net/unix | grep webview_devtools_remote`)).toString().split('\n');
|
||||
if (this._isClosed)
|
||||
return;
|
||||
|
||||
|
|
@ -304,7 +304,7 @@ export class AndroidDevice extends EventEmitter {
|
|||
if (this._webViews.has(pid))
|
||||
continue;
|
||||
|
||||
const procs = (await this._backend.runCommand(`shell:ps -A | grep ${pid}`)).split('\n');
|
||||
const procs = (await this._backend.runCommand(`shell:ps -A | grep ${pid}`)).toString().split('\n');
|
||||
if (this._isClosed)
|
||||
return;
|
||||
let pkg = '';
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class AdbDevice implements DeviceBackend {
|
|||
async close() {
|
||||
}
|
||||
|
||||
runCommand(command: string): Promise<string> {
|
||||
runCommand(command: string): Promise<Buffer> {
|
||||
return runCommand(command, this.serial);
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ class AdbDevice implements DeviceBackend {
|
|||
}
|
||||
}
|
||||
|
||||
async function runCommand(command: string, serial?: string): Promise<string> {
|
||||
async function runCommand(command: string, serial?: string): Promise<Buffer> {
|
||||
debug('pw:adb:runCommand')(command, serial);
|
||||
const socket = new BufferedSocketWrapper(command, net.createConnection({ port: 5037 }));
|
||||
if (serial) {
|
||||
|
|
@ -70,9 +70,9 @@ async function runCommand(command: string, serial?: string): Promise<string> {
|
|||
assert(status.toString() === 'OKAY', status.toString());
|
||||
if (!command.startsWith('shell:')) {
|
||||
const remainingLength = parseInt((await socket.read(4)).toString(), 16);
|
||||
return (await socket.read(remainingLength)).toString();
|
||||
return (await socket.read(remainingLength));
|
||||
}
|
||||
return (await socket.readAll()).toString();
|
||||
return (await socket.readAll());
|
||||
}
|
||||
|
||||
async function open(command: string, serial?: string): Promise<BufferedSocketWrapper> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue