From f75f9b9b46e38ef3d6e0ff139b35c540e5e91daf Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Sun, 16 Jul 2023 17:30:52 +0800 Subject: [PATCH] Hide warnings on XiaoMi devices --- .../main/java/com/genymobile/scrcpy/CameraEncoder.java | 1 - .../main/java/com/genymobile/scrcpy/SurfaceEncoder.java | 1 + .../src/main/java/com/genymobile/scrcpy/Workarounds.java | 9 +++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/CameraEncoder.java b/server/src/main/java/com/genymobile/scrcpy/CameraEncoder.java index e31b5ff78e..e79697aaf9 100644 --- a/server/src/main/java/com/genymobile/scrcpy/CameraEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/CameraEncoder.java @@ -12,7 +12,6 @@ import android.media.MediaCodec; import android.os.Handler; import android.os.HandlerThread; -import android.os.Looper; import android.view.Surface; import java.util.Arrays; diff --git a/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java b/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java index c9f2abf0ff..29b9af8c73 100644 --- a/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/SurfaceEncoder.java @@ -8,6 +8,7 @@ import android.media.MediaCodec; import android.media.MediaCodecInfo; import android.media.MediaFormat; +import android.os.Looper; import android.os.SystemClock; import android.view.Surface; diff --git a/server/src/main/java/com/genymobile/scrcpy/Workarounds.java b/server/src/main/java/com/genymobile/scrcpy/Workarounds.java index 5753147e38..6c893f57a7 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Workarounds.java +++ b/server/src/main/java/com/genymobile/scrcpy/Workarounds.java @@ -158,8 +158,17 @@ private static void fillAppContext() { } } + @SuppressLint("PrivateApi") public static Context getSystemContext() throws ReflectiveOperationException { if (systemContext == null) { + try { + // Hide warnings on XiaoMi devices + Class themeManagerStubClass = Class.forName("android.content.res.ThemeManagerStub"); + Field sResourceField = themeManagerStubClass.getDeclaredField("sResource"); + sResourceField.setAccessible(true); + sResourceField.set(null, null); + } catch (ReflectiveOperationException ignore) { } + Object activityThread = getActivityThread(); Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext"); systemContext = (Context) getSystemContextMethod.invoke(activityThread);