From 89df645c5a01bcba56e364f1d36466de6dd7c1ca Mon Sep 17 00:00:00 2001 From: Xayah Date: Wed, 21 Feb 2024 18:58:39 +0800 Subject: [PATCH] fix(dex): Workaround for systemMain exception on miui * Ref: https://github.com/Genymobile/scrcpy/issues/994 Change-Id: I700cee9418881880941fcf75fd813a1e2037173e --- dex/app/src/main/java/com/xayah/dex/HiddenApi.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dex/app/src/main/java/com/xayah/dex/HiddenApi.java b/dex/app/src/main/java/com/xayah/dex/HiddenApi.java index f69b9babc3..141ce2824a 100644 --- a/dex/app/src/main/java/com/xayah/dex/HiddenApi.java +++ b/dex/app/src/main/java/com/xayah/dex/HiddenApi.java @@ -5,15 +5,24 @@ import android.content.pm.PackageManager; import android.os.Looper; +import java.io.FileNotFoundException; +import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.util.Objects; public class HiddenApi { public static Context getContext() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Looper.prepare(); + PrintStream stderr = System.err; + try { + System.setErr(new PrintStream("/dev/null")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } Object thread = Class.forName("android.app.ActivityThread").getMethod("systemMain").invoke(null); Context context = (Context) Class.forName("android.app.ActivityThread").getMethod("getSystemContext").invoke(thread); Objects.requireNonNull(Looper.myLooper()).quit(); + System.setErr(stderr); return context; }