Automatically set Android devices into the permissive mode

Reviewed By: nikoant

Differential Revision: D35356211

fbshipit-source-id: 471470c5ca91c824590a409c4474433f2277b1f2
This commit is contained in:
Andrey Goncharov
2022-04-07 02:49:48 -07:00
committed by Facebook GitHub Bot
parent 052f417224
commit 501abc6b55
3 changed files with 34 additions and 0 deletions

View File

@@ -120,6 +120,37 @@ export default class AndroidDevice extends ServerDevice {
});
}
async setIntoPermissiveMode(): Promise<void> {
console.debug('AndroidDevice.setIntoPermissiveMode', this.serial);
try {
try {
await this.adb.root(this.serial);
} catch (e) {
if (
!(e instanceof Error) ||
e.message !== 'adbd is already running as root'
) {
throw e;
}
}
console.debug(
'AndroidDevice.setIntoPermissiveMode -> enabled root',
this.serial,
);
await this.executeShellOrDie('setenforce 0');
console.info(
'AndroidDevice.setIntoPermissiveMode -> success',
this.serial,
);
} catch (e) {
console.info(
'AndroidDevice.setIntoPermissiveMode -> failed',
this.serial,
e,
);
}
}
async screenRecordAvailable(): Promise<boolean> {
try {
await this.executeShellOrDie(

View File

@@ -90,6 +90,8 @@ export class AndroidDeviceManager {
// The default way of capturing screenshots through adb does not seem to work
// There is a way of getting a screenshot through KaiOS dev tools though
if (androidLikeDevice instanceof AndroidDevice) {
await androidLikeDevice.setIntoPermissiveMode();
const screenRecordAvailable =
await androidLikeDevice.screenRecordAvailable();
androidLikeDevice.info.features.screenCaptureAvailable =

View File

@@ -57,6 +57,7 @@ declare module 'adbkit' {
serial: string,
command: string | string[],
) => Promise<NodeJS.ReadStream>;
root: (serial: string) => Promise<true>;
screencap: (serial: string) => Promise<NodeJS.WriteStream>;
pull: (serial: string, path: string) => Promise<PullTransfer>;
openLogcat: (