Set device features on device initialization

Summary:
1. Identify if device supports screenshots/screen recording when it is created.
2. Disable screen recording/screenshot buttons when they are not supported

Reviewed By: passy

Differential Revision: D34611133

fbshipit-source-id: 82ad2d67e4af482d9becf7995187667b5d99bc36
This commit is contained in:
Andrey Goncharov
2022-03-04 02:00:23 -08:00
committed by Facebook GitHub Bot
parent 04e7c7282b
commit 6c74f2dd18
19 changed files with 81 additions and 75 deletions

View File

@@ -26,6 +26,10 @@ export default class DummyDevice extends ServerDevice {
deviceType: 'dummy',
title,
os,
features: {
screenCaptureAvailable: false,
screenshotAvailable: false,
},
});
}
}

View File

@@ -44,25 +44,19 @@ export abstract class ServerDevice {
*/
disconnect(): void {
this.connected = false;
this.info.features.screenCaptureAvailable = false;
this.info.features.screenshotAvailable = false;
this.logListener.stop();
this.crashWatcher.stop();
this.flipperServer.pluginManager.stopAllServerAddOns(this.info.serial);
}
async screenshotAvailable(): Promise<boolean> {
return false;
}
screenshot(): Promise<Buffer> {
return Promise.reject(
new Error('No screenshot support for current device'),
);
}
async screenCaptureAvailable(): Promise<boolean> {
return false;
}
async startScreenCapture(_destination: string): Promise<void> {
throw new Error('startScreenCapture not implemented on BaseDevice ');
}

View File

@@ -49,6 +49,10 @@ export default class AndroidDevice extends ServerDevice {
specs,
abiList,
sdkVersion,
features: {
screenCaptureAvailable: false,
screenshotAvailable: false,
},
});
this.adb = adb;
@@ -115,7 +119,7 @@ export default class AndroidDevice extends ServerDevice {
});
}
async screenCaptureAvailable(): Promise<boolean> {
async screenRecordAvailable(): Promise<boolean> {
try {
await this.executeShellOrDie(
`[ ! -f /system/bin/screenrecord ] && echo "File does not exist"`,

View File

@@ -26,10 +26,4 @@ export default class KaiOSDevice extends AndroidDevice {
'KaiOS',
]);
}
async screenCaptureAvailable() {
// 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
return false;
}
}

View File

@@ -86,6 +86,18 @@ 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;
androidLikeDevice.info.features.screenshotAvailable =
screenRecordAvailable;
}
resolve(androidLikeDevice);
} catch (e) {
reject(e);

View File

@@ -18,6 +18,10 @@ export default class MacDevice extends ServerDevice {
title: 'Mac',
os: 'MacOS',
icon: 'app-apple',
features: {
screenCaptureAvailable: false,
screenshotAvailable: false,
},
});
}
}

View File

@@ -18,6 +18,10 @@ export default class WindowsDevice extends ServerDevice {
title: 'Windows',
os: 'Windows',
icon: 'app-microsoft-windows',
features: {
screenCaptureAvailable: false,
screenshotAvailable: false,
},
});
}
}

View File

@@ -36,6 +36,10 @@ export default class IOSDevice extends ServerDevice {
title,
os: 'iOS',
icon: 'mobile',
features: {
screenCaptureAvailable: true,
screenshotAvailable: true,
},
});
this.buffer = '';
this.iOSBridge = iOSBridge;
@@ -76,10 +80,6 @@ export default class IOSDevice extends ServerDevice {
});
}
async screenCaptureAvailable() {
return this.connected;
}
async startScreenCapture(destination: string) {
const recording = this.recording;
if (recording) {

View File

@@ -64,6 +64,10 @@ export default class MetroDevice extends ServerDevice {
title: 'React Native',
os: 'Metro',
icon: 'mobile',
features: {
screenCaptureAvailable: false,
screenshotAvailable: false,
},
});
if (ws) {
this.ws = ws;