Fix screen recording on Android 11

Summary:
Instead of relying on system blocks used, we use the file size reported by ls.
Android 11 seems to be more lazy when it comes to fsync'ing so there's a pretty
good chance that if we just check for with `du` or `ls -ls` we will see an "empty" file
because it hasn't been written to disk yet. By the normal `ls` output instead, we'll
just read the file and see how many bytes it's long, which should be more
accurate in all cases.

Changelog: Fix screen recording for Android 11 beta

Reviewed By: jknoxville

Differential Revision: D22283092

fbshipit-source-id: 6d33ca297f1c0734ab4ffc466d9e483aa1a1bdb5
This commit is contained in:
Pascal Hartig
2020-06-29 07:16:18 -07:00
committed by Facebook GitHub Bot
parent dcd909779b
commit 8ff1411f91

View File

@@ -141,14 +141,12 @@ export default class AndroidDevice extends BaseDevice {
private async isValidFile(filePath: string): Promise<boolean> {
const fileSize = await this.adb
.shell(this.serial, `du "${filePath}"`)
.shell(this.serial, `ls -l "${filePath}"`)
.then(adb.util.readAll)
.then((output: Buffer) => output.toString().trim().split('\t'))
.then((x) => Number(x[0]));
.then((output: Buffer) => output.toString().trim().split(' '))
.then((x) => Number(x[4]));
// 4 is what an empty file (touch file) already takes up, so it's
// definitely not a valid video file.
return fileSize > 4;
return fileSize > 0;
}
async startScreenCapture(destination: string) {