From 2d3b7e7782b82fba08087381f16def10214c2b8f Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Tue, 29 Oct 2024 15:18:15 +0100 Subject: [PATCH 1/2] pocophone (xiaomi phones) android 13 --- .../android_remote/ScreenEncoder.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java b/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java index da64a31..2731161 100644 --- a/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java +++ b/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java @@ -1,5 +1,7 @@ package org.cagnulein.android_remote; +import static org.cagnulein.android_remote.wrappers.SurfaceControl.createDisplay; + import android.graphics.Rect; import android.hardware.display.VirtualDisplay; import android.media.MediaCodec; @@ -124,18 +126,22 @@ public void streamScreen(Device device, OutputStream outputStream) throws IOExce virtualDisplay = null; } - /*try { - display = createDisplay(); - setDisplaySurface(display, surface, deviceRect, videoRect); - Ln.d("Display: using SurfaceControl API"); - } catch (Exception surfaceControlException )*/ { + { try { virtualDisplay = DisplayManager.createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), 0, surface); Ln.d("Display: using DisplayManager API"); } catch (Exception displayManagerException) { - //Ln.e("Could not create display using SurfaceControl", surfaceControlException); - Ln.e("Could not create display using DisplayManager", displayManagerException); - throw new AssertionError("Could not create display"); + try { + boolean secure = Build.VERSION.SDK_INT < Build.VERSION_CODES.R || (Build.VERSION.SDK_INT == Build.VERSION_CODES.R && !"S".equals( + Build.VERSION.CODENAME)); + display = createDisplay("scrcpy", secure); + setDisplaySurface(display, surface, deviceRect, videoRect); + Ln.d("Display: using SurfaceControl API"); + } catch (Exception surfaceControlException) { + Ln.e("Could not create display using SurfaceControl", surfaceControlException); + Ln.e("Could not create display using DisplayManager", displayManagerException); + throw new AssertionError("Could not create display"); + } } } codec.start(); From 018d0ab679a3b1e184bb83579fa5b0ef18e3a7f8 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Wed, 30 Oct 2024 10:21:56 +0100 Subject: [PATCH 2/2] Update ScreenEncoder.java --- .../java/org/cagnulein/android_remote/ScreenEncoder.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java b/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java index 2731161..5e322ae 100644 --- a/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java +++ b/server/src/main/java/org/cagnulein/android_remote/ScreenEncoder.java @@ -75,12 +75,18 @@ private static void setSize(MediaFormat format, int width, int height) { } private static void setDisplaySurface(IBinder display, Surface surface, Rect deviceRect, Rect displayRect) { + Ln.d("setDisplaySurface 1"); SurfaceControl.openTransaction(); try { + Ln.d("setDisplaySurface 2"); SurfaceControl.setDisplaySurface(display, surface); + Ln.d("setDisplaySurface 3"); SurfaceControl.setDisplayProjection(display, 0, deviceRect, displayRect); + Ln.d("setDisplaySurface 4"); SurfaceControl.setDisplayLayerStack(display, 0); + Ln.d("setDisplaySurface 5"); } finally { + Ln.d("setDisplaySurface 6"); SurfaceControl.closeTransaction(); } } @@ -134,7 +140,9 @@ public void streamScreen(Device device, OutputStream outputStream) throws IOExce try { boolean secure = Build.VERSION.SDK_INT < Build.VERSION_CODES.R || (Build.VERSION.SDK_INT == Build.VERSION_CODES.R && !"S".equals( Build.VERSION.CODENAME)); + Ln.d("Creating display..."); display = createDisplay("scrcpy", secure); + Ln.d("Display created " + display.toString()); setDisplaySurface(display, surface, deviceRect, videoRect); Ln.d("Display: using SurfaceControl API"); } catch (Exception surfaceControlException) {