mirror of
https://github.com/Genymobile/scrcpy.git
synced 2024-09-19 05:31:21 +02:00
systemctx
This commit is contained in:
parent
6414613113
commit
ce8d3ac6d1
1 changed files with 20 additions and 1 deletions
|
@ -2,10 +2,14 @@ package com.genymobile.scrcpy;
|
|||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.AttributionSource;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class FakeContext extends ContextWrapper {
|
||||
|
||||
public static final String PACKAGE_NAME = "com.android.shell";
|
||||
|
@ -13,12 +17,27 @@ public final class FakeContext extends ContextWrapper {
|
|||
|
||||
private static final FakeContext INSTANCE = new FakeContext();
|
||||
|
||||
private static Context retrieveSystemContext() {
|
||||
try {
|
||||
Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
|
||||
Constructor<?> activityThreadConstructor = activityThreadClass.getDeclaredConstructor();
|
||||
activityThreadConstructor.setAccessible(true);
|
||||
Object activityThread = activityThreadConstructor.newInstance();
|
||||
|
||||
Method getSystemContextMethod = activityThread.getClass().getDeclaredMethod("getSystemContext");
|
||||
return (Context) getSystemContextMethod.invoke(activityThread);
|
||||
} catch (Exception e) {
|
||||
Ln.e("Cannot retrieve system context", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static FakeContext get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private FakeContext() {
|
||||
super(null);
|
||||
super(retrieveSystemContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue