Throw error and let user know situation when 'adb shell screenrecord' make error.

Summary:
Backgrouds
- For screen recording Flipper use 'adb shell scrrenrecord' and 'adb pull'.
- 'screenrecord' make error and doens't works for some android devices and AOS versions.
- For example, "--bugreport" option doesn't work old version of AOS.
- We can not control 'screenrecord' command yet.
- It is better let user know the situation early.

<AS-IS>
When 'screenrecord' emit error:
- Noting happened for users.
- Result of screen record file is just empty. (pull command create the file)

<TO-BE>
When 'screenrecord' emit error:
- Let users know 'screenrecord' is not working properly.

Reviewed By: passy

Differential Revision: D19643060

fbshipit-source-id: 5caf9df02c956283f371c50c1735060be2158fb2
This commit is contained in:
Chanju Kim
2020-02-04 08:09:55 -08:00
committed by Facebook Github Bot
parent 0e326330c0
commit 959457d1e7
2 changed files with 43 additions and 11 deletions

View File

@@ -102,10 +102,8 @@ class ScreenCaptureButtons extends Component<Props, State> {
return;
}
const videoPath = path.join(CAPTURE_LOCATION, getFileName('mp4'));
await selectedDevice.startScreenCapture(videoPath);
this.setState({
recording: true,
await selectedDevice.startScreenCapture(videoPath).catch(e => {
console.error(e);
});
};
@@ -114,18 +112,23 @@ class ScreenCaptureButtons extends Component<Props, State> {
if (!selectedDevice) {
return;
}
const path = await selectedDevice.stopScreenCapture();
this.setState({
recording: false,
const path = await selectedDevice.stopScreenCapture().catch(e => {
console.error(e);
});
openFile(path);
path ? openFile(path) : 0;
};
onRecordingClicked = () => {
if (this.state.recording) {
this.stopRecording();
this.setState({
recording: false,
});
} else {
this.startRecording();
this.setState({
recording: true,
});
}
};

View File

@@ -132,6 +132,21 @@ export default class AndroidDevice extends BaseDevice {
}
}
private async isValidFile(filePath: string): Promise<boolean> {
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"`,
@@ -140,15 +155,29 @@ 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);
}