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;
|
model(): string;
|
||||||
webViews(): AndroidWebView<Page>[];
|
webViews(): AndroidWebView<Page>[];
|
||||||
webView(selector: { pkg: string }, options?: { timeout?: number }): Promise<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>;
|
open(command: string): Promise<AndroidSocket>;
|
||||||
installApk(file: string | Buffer, options?: { args?: string[] }): Promise<void>;
|
installApk(file: string | Buffer, options?: { args?: string[] }): Promise<void>;
|
||||||
launchBrowser(options?: BrowserContextOptions & { packageName?: string }): Promise<BrowserContext>;
|
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 () => {
|
return this._wrapApiCall('androidDevice.shell', async () => {
|
||||||
const { result } = await this._channel.shell({ command });
|
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> {
|
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> {
|
async open(params: channels.AndroidDeviceOpenParams, metadata?: channels.Metadata): Promise<channels.AndroidDeviceOpenResult> {
|
||||||
|
|
|
||||||
|
|
@ -2747,7 +2747,7 @@ export type AndroidDeviceShellOptions = {
|
||||||
|
|
||||||
};
|
};
|
||||||
export type AndroidDeviceShellResult = {
|
export type AndroidDeviceShellResult = {
|
||||||
result: string,
|
result: Binary,
|
||||||
};
|
};
|
||||||
export type AndroidDeviceInstallApkParams = {
|
export type AndroidDeviceInstallApkParams = {
|
||||||
file: Binary,
|
file: Binary,
|
||||||
|
|
|
||||||
|
|
@ -2303,7 +2303,7 @@ AndroidDevice:
|
||||||
parameters:
|
parameters:
|
||||||
command: string
|
command: string
|
||||||
returns:
|
returns:
|
||||||
result: string
|
result: binary
|
||||||
|
|
||||||
installApk:
|
installApk:
|
||||||
parameters:
|
parameters:
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ export interface DeviceBackend {
|
||||||
status: string;
|
status: string;
|
||||||
close(): Promise<void>;
|
close(): Promise<void>;
|
||||||
init(): Promise<void>;
|
init(): Promise<void>;
|
||||||
runCommand(command: string): Promise<string>;
|
runCommand(command: string): Promise<Buffer>;
|
||||||
open(command: string): Promise<SocketBackend>;
|
open(command: string): Promise<SocketBackend>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ export class AndroidDevice extends EventEmitter {
|
||||||
static async create(android: Android, backend: DeviceBackend): Promise<AndroidDevice> {
|
static async create(android: Android, backend: DeviceBackend): Promise<AndroidDevice> {
|
||||||
await backend.init();
|
await backend.init();
|
||||||
const model = await backend.runCommand('shell:getprop ro.product.model');
|
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();
|
await device._init();
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +138,7 @@ export class AndroidDevice extends EventEmitter {
|
||||||
this._timeoutSettings.setDefaultTimeout(timeout);
|
this._timeoutSettings.setDefaultTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
async shell(command: string): Promise<string> {
|
async shell(command: string): Promise<Buffer> {
|
||||||
const result = await this._backend.runCommand(`shell:${command}`);
|
const result = await this._backend.runCommand(`shell:${command}`);
|
||||||
await this._refreshWebViews();
|
await this._refreshWebViews();
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -288,7 +288,7 @@ export class AndroidDevice extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _refreshWebViews() {
|
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)
|
if (this._isClosed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -304,7 +304,7 @@ export class AndroidDevice extends EventEmitter {
|
||||||
if (this._webViews.has(pid))
|
if (this._webViews.has(pid))
|
||||||
continue;
|
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)
|
if (this._isClosed)
|
||||||
return;
|
return;
|
||||||
let pkg = '';
|
let pkg = '';
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class AdbDevice implements DeviceBackend {
|
||||||
async close() {
|
async close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
runCommand(command: string): Promise<string> {
|
runCommand(command: string): Promise<Buffer> {
|
||||||
return runCommand(command, this.serial);
|
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);
|
debug('pw:adb:runCommand')(command, serial);
|
||||||
const socket = new BufferedSocketWrapper(command, net.createConnection({ port: 5037 }));
|
const socket = new BufferedSocketWrapper(command, net.createConnection({ port: 5037 }));
|
||||||
if (serial) {
|
if (serial) {
|
||||||
|
|
@ -70,9 +70,9 @@ async function runCommand(command: string, serial?: string): Promise<string> {
|
||||||
assert(status.toString() === 'OKAY', status.toString());
|
assert(status.toString() === 'OKAY', status.toString());
|
||||||
if (!command.startsWith('shell:')) {
|
if (!command.startsWith('shell:')) {
|
||||||
const remainingLength = parseInt((await socket.read(4)).toString(), 16);
|
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> {
|
async function open(command: string, serial?: string): Promise<BufferedSocketWrapper> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue