From 28cd62bc997ac329803abca07d4cb08348f394c2 Mon Sep 17 00:00:00 2001 From: Chaiwat Ekkaewnumchai Date: Mon, 21 Dec 2020 09:52:47 -0800 Subject: [PATCH] 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 --- desktop/app/src/devices/AndroidDevice.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/desktop/app/src/devices/AndroidDevice.tsx b/desktop/app/src/devices/AndroidDevice.tsx index 57c6a8ff9..dc5deabbf 100644 --- a/desktop/app/src/devices/AndroidDevice.tsx +++ b/desktop/app/src/devices/AndroidDevice.tsx @@ -139,12 +139,21 @@ export default class AndroidDevice extends BaseDevice { } } + private async getSdkVersion(): Promise { + 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 { + 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;