From b6475c6c7760fc55389e3d99871002847ef1f968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E8=8B=8F=E6=A5=A0?= Date: Tue, 14 Sep 2021 17:43:47 +0800 Subject: [PATCH] Support Android 12 (preview),and resolve black screen problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 余苏楠 --- .../io/devicefarmer/minicap/provider/SurfaceProvider.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/experimental/app/src/main/java/io/devicefarmer/minicap/provider/SurfaceProvider.kt b/experimental/app/src/main/java/io/devicefarmer/minicap/provider/SurfaceProvider.kt index c0aff60..a9f9e96 100644 --- a/experimental/app/src/main/java/io/devicefarmer/minicap/provider/SurfaceProvider.kt +++ b/experimental/app/src/main/java/io/devicefarmer/minicap/provider/SurfaceProvider.kt @@ -18,6 +18,7 @@ package io.devicefarmer.minicap.provider import android.graphics.Rect import android.media.ImageReader import android.net.LocalSocket +import android.os.Build import android.os.Handler import android.os.IBinder import android.os.Looper @@ -80,7 +81,10 @@ class SurfaceProvider(targetSize: Size, orientation: Int) : BaseProvider(targetS */ private fun initSurface(l: ImageReader.OnImageAvailableListener) { //must be done on the main thread - display = SurfaceControl.createDisplay("minicap", false) + // Support Android 12 (preview),and resolve black screen problem + val secure = + Build.VERSION.SDK_INT < Build.VERSION_CODES.R || Build.VERSION.SDK_INT == Build.VERSION_CODES.R && "S" != Build.VERSION.CODENAME + display = SurfaceControl.createDisplay("minicap", secure) //initialise the surface to get the display in the ImageReader SurfaceControl.openTransaction() try {