From 4efc2b840064058e096298678ca434c2c4961eb8 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 5 Feb 2020 07:08:18 -0800 Subject: [PATCH] Back out "Throw error and let user know situation when 'adb shell screenrecord' make error." Summary: Original commit changeset: 5caf9df02c95 It backs out the diff as it broke the video recording button in support form. Bug: {F227855063} Reviewed By: passy Differential Revision: D19742486 fbshipit-source-id: 4a275e6ead919b4f4ed94889545a650c101f89b7 --- src/chrome/ScreenCaptureButtons.tsx | 19 +++++++--------- src/devices/AndroidDevice.tsx | 35 +++-------------------------- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/src/chrome/ScreenCaptureButtons.tsx b/src/chrome/ScreenCaptureButtons.tsx index fc6dfea13..d16cb516f 100644 --- a/src/chrome/ScreenCaptureButtons.tsx +++ b/src/chrome/ScreenCaptureButtons.tsx @@ -102,8 +102,10 @@ class ScreenCaptureButtons extends Component { return; } const videoPath = path.join(CAPTURE_LOCATION, getFileName('mp4')); - await selectedDevice.startScreenCapture(videoPath).catch(e => { - console.error(e); + await selectedDevice.startScreenCapture(videoPath); + + this.setState({ + recording: true, }); }; @@ -112,23 +114,18 @@ class ScreenCaptureButtons extends Component { if (!selectedDevice) { return; } - const path = await selectedDevice.stopScreenCapture().catch(e => { - console.error(e); + const path = await selectedDevice.stopScreenCapture(); + this.setState({ + recording: false, }); - path ? openFile(path) : 0; + openFile(path); }; onRecordingClicked = () => { if (this.state.recording) { this.stopRecording(); - this.setState({ - recording: false, - }); } else { this.startRecording(); - this.setState({ - recording: true, - }); } }; diff --git a/src/devices/AndroidDevice.tsx b/src/devices/AndroidDevice.tsx index cf4bc5fe1..693dfb8d8 100644 --- a/src/devices/AndroidDevice.tsx +++ b/src/devices/AndroidDevice.tsx @@ -132,21 +132,6 @@ export default class AndroidDevice extends BaseDevice { } } - private async isValidFile(filePath: string): Promise { - const fileSize = await this.adb - .shell(this.serial, `touch "${filePath}" && ls -l "${filePath}"`) - .then(adb.util.readAll) - .then((output: Buffer) => - output - .toString() - .trim() - .split(' '), - ) - .then(output => Number(output[5])); - - return fileSize > 0; - } - async startScreenCapture(destination: string) { await this.executeShell( `mkdir -p "${DEVICE_RECORDING_DIR}" && echo -n > "${DEVICE_RECORDING_DIR}/.nomedia"`, @@ -155,29 +140,15 @@ export default class AndroidDevice extends BaseDevice { this.recordingProcess = this.adb .shell(this.serial, `screenrecord --bugreport "${recordingLocation}"`) .then(adb.util.readAll) - .then( - output => - new Promise(async (resolve, _) => { - const isValid = await this.isValidFile(recordingLocation); - if (!isValid) { - const outputMessage = output.toString().trim(); - // throw error immediately - throw new Error( - 'Recording was not properly started: \n' + outputMessage, - ); - } - resolve(); - }), - ) .then( _ => - new Promise((resolve, reject) => { + new Promise((resolve, reject) => this.adb.pull(this.serial, recordingLocation).then(stream => { stream.on('end', resolve); stream.on('error', reject); stream.pipe(createWriteStream(destination)); - }); - }), + }), + ), ) .then(_ => destination); }