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:
committed by
Facebook Github Bot
parent
0e326330c0
commit
959457d1e7
@@ -102,10 +102,8 @@ class ScreenCaptureButtons extends Component<Props, State> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const videoPath = path.join(CAPTURE_LOCATION, getFileName('mp4'));
|
const videoPath = path.join(CAPTURE_LOCATION, getFileName('mp4'));
|
||||||
await selectedDevice.startScreenCapture(videoPath);
|
await selectedDevice.startScreenCapture(videoPath).catch(e => {
|
||||||
|
console.error(e);
|
||||||
this.setState({
|
|
||||||
recording: true,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -114,18 +112,23 @@ class ScreenCaptureButtons extends Component<Props, State> {
|
|||||||
if (!selectedDevice) {
|
if (!selectedDevice) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const path = await selectedDevice.stopScreenCapture();
|
const path = await selectedDevice.stopScreenCapture().catch(e => {
|
||||||
this.setState({
|
console.error(e);
|
||||||
recording: false,
|
|
||||||
});
|
});
|
||||||
openFile(path);
|
path ? openFile(path) : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
onRecordingClicked = () => {
|
onRecordingClicked = () => {
|
||||||
if (this.state.recording) {
|
if (this.state.recording) {
|
||||||
this.stopRecording();
|
this.stopRecording();
|
||||||
|
this.setState({
|
||||||
|
recording: false,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.startRecording();
|
this.startRecording();
|
||||||
|
this.setState({
|
||||||
|
recording: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
async startScreenCapture(destination: string) {
|
||||||
await this.executeShell(
|
await this.executeShell(
|
||||||
`mkdir -p "${DEVICE_RECORDING_DIR}" && echo -n > "${DEVICE_RECORDING_DIR}/.nomedia"`,
|
`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
|
this.recordingProcess = this.adb
|
||||||
.shell(this.serial, `screenrecord --bugreport "${recordingLocation}"`)
|
.shell(this.serial, `screenrecord --bugreport "${recordingLocation}"`)
|
||||||
.then(adb.util.readAll)
|
.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(
|
.then(
|
||||||
_ =>
|
_ =>
|
||||||
new Promise((resolve, reject) =>
|
new Promise((resolve, reject) => {
|
||||||
this.adb.pull(this.serial, recordingLocation).then(stream => {
|
this.adb.pull(this.serial, recordingLocation).then(stream => {
|
||||||
stream.on('end', resolve);
|
stream.on('end', resolve);
|
||||||
stream.on('error', reject);
|
stream.on('error', reject);
|
||||||
stream.pipe(createWriteStream(destination));
|
stream.pipe(createWriteStream(destination));
|
||||||
}),
|
});
|
||||||
),
|
}),
|
||||||
)
|
)
|
||||||
.then(_ => destination);
|
.then(_ => destination);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user