Fix and re-apply "[flipper] Automatically set Android devices into the permissive mode"

Summary: Reverts D36263724 (0ee8f09fe5) and fixes the underlying crash by setting only physical devices in the permissive mode

Reviewed By: passy

Differential Revision: D36275055

fbshipit-source-id: 25a691e9c07e20a3341630db508795c133a9bd81
This commit is contained in:
Andrey Goncharov
2022-05-10 08:42:58 -07:00
committed by Facebook GitHub Bot
parent 56ea2fc782
commit 754afd0d2d
3 changed files with 42 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> { async screenRecordAvailable(): Promise<boolean> {
try { try {
await this.executeShellOrDie( await this.executeShellOrDie(

View File

@@ -87,6 +87,16 @@ export class AndroidDeviceManager {
}); });
} }
// Remote simulators connected via SSH tunnels
const isRemoteDevice = device.id.startsWith('localhost');
if (
androidLikeDevice instanceof AndroidDevice &&
type === 'physical' &&
!isRemoteDevice
) {
await androidLikeDevice.setIntoPermissiveMode();
}
// The default way of capturing screenshots through adb does not seem to work // 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 // There is a way of getting a screenshot through KaiOS dev tools though
if (androidLikeDevice instanceof AndroidDevice) { if (androidLikeDevice instanceof AndroidDevice) {

View File

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