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