|
|
|
@ -7,6 +7,7 @@ import android.content.AttributionSource;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.ContextWrapper;
|
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.media.AudioAttributes;
|
|
|
|
|
import android.media.AudioManager;
|
|
|
|
|
import android.media.AudioRecord;
|
|
|
|
@ -30,6 +31,12 @@ public final class Workarounds {
|
|
|
|
|
|
|
|
|
|
public static void apply(boolean audio, boolean camera) {
|
|
|
|
|
Workarounds.prepareMainLooper();
|
|
|
|
|
try {
|
|
|
|
|
fillActivityThread();
|
|
|
|
|
FakeContext.get();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new AssertionError(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean mustFillAppInfo = false;
|
|
|
|
|
boolean mustFillBaseContext = false;
|
|
|
|
@ -123,6 +130,19 @@ public final class Workarounds {
|
|
|
|
|
ApplicationInfo applicationInfo = new ApplicationInfo();
|
|
|
|
|
applicationInfo.packageName = FakeContext.PACKAGE_NAME;
|
|
|
|
|
|
|
|
|
|
Application application = new Application() {
|
|
|
|
|
@Override
|
|
|
|
|
public String getOpPackageName() {
|
|
|
|
|
return FakeContext.PACKAGE_NAME;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Method method = ContextWrapper.class.getDeclaredMethod("attachBaseContext", Context.class);
|
|
|
|
|
method.invoke(application, retrieveSystemContext());
|
|
|
|
|
|
|
|
|
|
Field initialApplicationField = activityThreadClass.getDeclaredField("mInitialApplication");
|
|
|
|
|
initialApplicationField.setAccessible(true);
|
|
|
|
|
initialApplicationField.set(activityThread, application);
|
|
|
|
|
|
|
|
|
|
// appBindData.appInfo = applicationInfo;
|
|
|
|
|
Field appInfoField = appBindDataClass.getDeclaredField("appInfo");
|
|
|
|
|
appInfoField.setAccessible(true);
|
|
|
|
@ -306,4 +326,16 @@ public final class Workarounds {
|
|
|
|
|
throw new RuntimeException("Cannot create AudioRecord");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Context retrieveSystemContext() {
|
|
|
|
|
try {
|
|
|
|
|
Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
|
|
|
|
|
Context ctx = (Context) getSystemContextMethod.invoke(activityThread);
|
|
|
|
|
Ln.i("===== " + ctx);
|
|
|
|
|
return ctx;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Ln.e("Cannot retrieve system context", e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|