Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86e5c90ed6 |
@@ -112,13 +112,13 @@ public final class Server {
|
||||
// - <https://github.com/Genymobile/scrcpy/issues/994>
|
||||
Workarounds.fillAppInfo();
|
||||
} else if (Build.BRAND.equalsIgnoreCase("honor")) {
|
||||
// Honor devices require in addition a system context as a base context of FakeContext:
|
||||
// Honor devices require both a system context (as a base context of FakeContext) and the same workarounds as for Meizu phones:
|
||||
// - <https://github.com/Genymobile/scrcpy/issues/4015>
|
||||
// The system context must not be set for all devices, because it would cause other problems:
|
||||
// The system context must not be set for all devices, it would cause other problems:
|
||||
// - <https://github.com/Genymobile/scrcpy/issues/4015#issuecomment-1595382142>
|
||||
// - <https://github.com/Genymobile/scrcpy/issues/3805#issuecomment-1596148031>
|
||||
Workarounds.fillAppInfo();
|
||||
Workarounds.fillBaseContext();
|
||||
Workarounds.fillAppInfo();
|
||||
}
|
||||
|
||||
// Before Android 11, audio is not supported.
|
||||
|
||||
@@ -23,6 +23,7 @@ public final class Workarounds {
|
||||
|
||||
private static Class<?> activityThreadClass;
|
||||
private static Object activityThread;
|
||||
private static boolean currentActivityThreadInitialized;
|
||||
|
||||
private Workarounds() {
|
||||
// not instantiable
|
||||
@@ -42,18 +43,26 @@ public final class Workarounds {
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
||||
private static void fillActivityThread() throws Exception {
|
||||
private static void initActivityThread() throws Exception {
|
||||
if (activityThread == null) {
|
||||
// ActivityThread activityThread = new ActivityThread();
|
||||
activityThreadClass = Class.forName("android.app.ActivityThread");
|
||||
Constructor<?> activityThreadConstructor = activityThreadClass.getDeclaredConstructor();
|
||||
activityThreadConstructor.setAccessible(true);
|
||||
activityThread = activityThreadConstructor.newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
||||
private static void fillActivityThread() throws Exception {
|
||||
initActivityThread();
|
||||
|
||||
if (!currentActivityThreadInitialized) {
|
||||
// ActivityThread.sCurrentActivityThread = activityThread;
|
||||
Field sCurrentActivityThreadField = activityThreadClass.getDeclaredField("sCurrentActivityThread");
|
||||
sCurrentActivityThreadField.setAccessible(true);
|
||||
sCurrentActivityThreadField.set(null, activityThread);
|
||||
currentActivityThreadInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +117,7 @@ public final class Workarounds {
|
||||
|
||||
public static void fillBaseContext() {
|
||||
try {
|
||||
fillActivityThread();
|
||||
initActivityThread();
|
||||
|
||||
Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
|
||||
Context context = (Context) getSystemContextMethod.invoke(activityThread);
|
||||
|
||||
Reference in New Issue
Block a user