From e2867a74a7b7d2f0abaf745447691c8492b0a4d0 Mon Sep 17 00:00:00 2001 From: kongxiaojun Date: Thu, 2 Feb 2023 08:17:33 -0800 Subject: [PATCH] Fixed a bug where the screenshot of some Android phones was unavailable (#4366) Summary: The 'screenrecord' command is not in some Android phones e.g OPPO. So 'screenrecord' command can't be used as a basis for determining whether or not you can take a screenshot. Replace it with 'screencap' command to determine whether you can take a screenshot. ## Changelog Fixed a bug where the screenshot of some Android phones was unavailable Pull Request resolved: https://github.com/facebook/flipper/pull/4366 Test Plan: It passed the test on my Mac and OPPO phone Reno2. Reviewed By: ivanmisuno Differential Revision: D42918902 Pulled By: passy fbshipit-source-id: c1f02f075817d90e0d447f466a1168b6ec932e4e --- .../src/devices/android/AndroidDevice.tsx | 11 +++++++++++ .../src/devices/android/androidDeviceManager.tsx | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/desktop/flipper-server-core/src/devices/android/AndroidDevice.tsx b/desktop/flipper-server-core/src/devices/android/AndroidDevice.tsx index 508367913..92c20214f 100644 --- a/desktop/flipper-server-core/src/devices/android/AndroidDevice.tsx +++ b/desktop/flipper-server-core/src/devices/android/AndroidDevice.tsx @@ -167,6 +167,17 @@ export default class AndroidDevice } } + async screenShotAvailable(): Promise { + try { + await this.executeShellOrDie( + `[ ! -f /system/bin/screencap ] && echo "File does not exist"`, + ); + return true; + } catch (_e) { + return false; + } + } + async executeShell(command: string): Promise { return await this.adb .shell(this.serial, command) diff --git a/desktop/flipper-server-core/src/devices/android/androidDeviceManager.tsx b/desktop/flipper-server-core/src/devices/android/androidDeviceManager.tsx index 14789f4d9..1eefbe2f7 100644 --- a/desktop/flipper-server-core/src/devices/android/androidDeviceManager.tsx +++ b/desktop/flipper-server-core/src/devices/android/androidDeviceManager.tsx @@ -100,12 +100,10 @@ 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) { - const screenRecordAvailable = - await androidLikeDevice.screenRecordAvailable(); androidLikeDevice.info.features.screenCaptureAvailable = - screenRecordAvailable; + await androidLikeDevice.screenRecordAvailable(); androidLikeDevice.info.features.screenshotAvailable = - screenRecordAvailable; + await androidLikeDevice.screenShotAvailable(); } resolve(androidLikeDevice);