Attempt to fix #4392
<https://github.com/Genymobile/scrcpy/issues/4392#issuecomment-1790954884>
This commit is contained in:
parent
446ea818a4
commit
65d6bdb237
@ -18,7 +18,7 @@ public final class FakeContext extends MutableContextWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private FakeContext() {
|
private FakeContext() {
|
||||||
super(null);
|
super(Workarounds.retrieveSystemContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,7 @@ import android.content.AttributionSource;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.media.AudioAttributes;
|
import android.media.AudioAttributes;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.AudioRecord;
|
import android.media.AudioRecord;
|
||||||
@ -30,6 +31,11 @@ public final class Workarounds {
|
|||||||
|
|
||||||
public static void apply(boolean audio, boolean camera) {
|
public static void apply(boolean audio, boolean camera) {
|
||||||
Workarounds.prepareMainLooper();
|
Workarounds.prepareMainLooper();
|
||||||
|
try {
|
||||||
|
fillActivityThread();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
|
||||||
boolean mustFillAppInfo = false;
|
boolean mustFillAppInfo = false;
|
||||||
boolean mustFillBaseContext = false;
|
boolean mustFillBaseContext = false;
|
||||||
@ -123,6 +129,17 @@ public final class Workarounds {
|
|||||||
ApplicationInfo applicationInfo = new ApplicationInfo();
|
ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||||
applicationInfo.packageName = FakeContext.PACKAGE_NAME;
|
applicationInfo.packageName = FakeContext.PACKAGE_NAME;
|
||||||
|
|
||||||
|
Application application = new Application() {
|
||||||
|
@Override
|
||||||
|
public String getOpPackageName() {
|
||||||
|
return FakeContext.PACKAGE_NAME;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Field initialApplicationField = activityThreadClass.getDeclaredField("mInitialApplication");
|
||||||
|
initialApplicationField.setAccessible(true);
|
||||||
|
initialApplicationField.set(activityThread, application);
|
||||||
|
|
||||||
// appBindData.appInfo = applicationInfo;
|
// appBindData.appInfo = applicationInfo;
|
||||||
Field appInfoField = appBindDataClass.getDeclaredField("appInfo");
|
Field appInfoField = appBindDataClass.getDeclaredField("appInfo");
|
||||||
appInfoField.setAccessible(true);
|
appInfoField.setAccessible(true);
|
||||||
@ -306,4 +323,14 @@ public final class Workarounds {
|
|||||||
throw new RuntimeException("Cannot create AudioRecord");
|
throw new RuntimeException("Cannot create AudioRecord");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Context retrieveSystemContext() {
|
||||||
|
try {
|
||||||
|
Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
|
||||||
|
return (Context) getSystemContextMethod.invoke(activityThread);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Ln.e("Cannot retrieve system context", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user