Compare commits

..

1 Commits

Author SHA1 Message Date
Romain Vimont
feb247f782 Add workarounds for Honor devices
Audio did not work on Honor devices.

To make it work, a system context must be set as a base context of
FakeContext (so that a PackageManager is available), and a current
ActivityThread must be initialized.

These workarounds must not be applied for all devices, because they
might cause other issues.

Fixes #4015 <https://github.com/Genymobile/scrcpy/issues/4015>
Refs #3085 <https://github.com/Genymobile/scrcpy/issues/3805>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
2023-06-19 13:11:43 +02:00
2 changed files with 5 additions and 14 deletions

View File

@@ -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 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>
// 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/3805#issuecomment-1596148031>
Workarounds.fillBaseContext();
Workarounds.fillAppInfo();
Workarounds.fillBaseContext();
}
// Before Android 11, audio is not supported.

View File

@@ -23,7 +23,6 @@ public final class Workarounds {
private static Class<?> activityThreadClass;
private static Object activityThread;
private static boolean currentActivityThreadInitialized;
private Workarounds() {
// not instantiable
@@ -43,26 +42,18 @@ public final class Workarounds {
}
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
private static void initActivityThread() throws Exception {
private static void fillActivityThread() 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;
}
}
@@ -117,7 +108,7 @@ public final class Workarounds {
public static void fillBaseContext() {
try {
initActivityThread();
fillActivityThread();
Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
Context context = (Context) getSystemContextMethod.invoke(activityThread);