Fix Screen Recording Not Working on Android Marshmallow

Summary: [Reported in the support group](https://fb.workplace.com/groups/flippersupport/permalink/1040131853134139/), screen recording can't be stopped on Android Marshmallow (SDK version 23). This is because the shell commands used in screen recording are different in SDK 23 compared to higher SDK. First, `pgrep` in SDK 23 doesn't have `-L` option. Second, `ls -l` of SDK 23 returns different pattern; we've relied on the 5th number to indicate the file size of a video, while it is on 4th number for SDK 23.

Reviewed By: passy

Differential Revision: D25641605

fbshipit-source-id: 110cb779ef4b2dc63a862bf5e4e5f3a304a0d8ec
This commit is contained in:
Chaiwat Ekkaewnumchai
2020-12-21 09:52:47 -08:00
committed by Facebook GitHub Bot
parent 719608fc5f
commit 28cd62bc99

View File

@@ -139,12 +139,21 @@ export default class AndroidDevice extends BaseDevice {
}
}
private async getSdkVersion(): Promise<number> {
return await this.adb
.shell(this.serial, 'getprop ro.build.version.sdk')
.then(adb.util.readAll)
.then((output) => Number(output.toString().trim()));
}
private async isValidFile(filePath: string): Promise<boolean> {
const sdkVersion = await this.getSdkVersion();
const fileSize = await this.adb
.shell(this.serial, `ls -l "${filePath}"`)
.then(adb.util.readAll)
.then((output: Buffer) => output.toString().trim().split(' '))
.then((x) => Number(x[4]));
.then((x) => x.filter(Boolean))
.then((x) => (sdkVersion > 23 ? Number(x[4]) : Number(x[3])));
return fileSize > 0;
}
@@ -186,7 +195,7 @@ export default class AndroidDevice extends BaseDevice {
if (!recordingProcess) {
return Promise.reject(new Error('Recording was not properly started'));
}
await this.adb.shell(this.serial, `pgrep 'screenrecord' -L 2`);
await this.adb.shell(this.serial, `pkill -2 screenrecord`);
const destination = await recordingProcess;
this.recordingProcess = undefined;
return destination;