Apply workarounds only on error
To avoid NullPointerException on some devices, workarounds have been
implemented. But these workaround produce (harmless) internal errors
causing exceptions to be printed in the console.
To avoid this problem, apply the workarounds only if it fails without
them.
Fixes <https://github.com/Genymobile/scrcpy/issues/994>
Refs <https://github.com/Genymobile/scrcpy/issues/365>
Refs <https://github.com/Genymobile/scrcpy/issues/940>
@@ -47,8 +47,20 @@ public class ScreenEncoder implements Device.RotationListener {
public void streamScreen(Device device, FileDescriptor fd) throws IOException {
Workarounds.prepareMainLooper();
+
+ try {
+ internalStreamScreen(device, fd);
+ } catch (NullPointerException e) {
+ // Retry with workarounds enabled:
+ // <https://github.com/Genymobile/scrcpy/issues/365>
+ // <https://github.com/Genymobile/scrcpy/issues/940>
+ Ln.d("Applying workarounds to avoid NullPointerException");
Workarounds.fillAppInfo();
+ internalStreamScreen(device, fd);
+ }
+ }
+ private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException {
MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL);
device.setRotationListener(this);
boolean alive;
