use of android.content.ContextWrapper in project VirtualApp by asLody.
the class ContextFixer method fixContext.
/**
* Fuck AppOps
*
* @param context Context
*/
public static void fixContext(Context context) {
try {
context.getPackageName();
} catch (Throwable e) {
return;
}
InvocationStubManager.getInstance().checkEnv(GraphicsStatsStub.class);
int deep = 0;
while (context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
deep++;
if (deep >= 10) {
return;
}
}
ContextImpl.mPackageManager.set(context, null);
try {
context.getPackageManager();
} catch (Throwable e) {
e.printStackTrace();
}
if (!VirtualCore.get().isVAppProcess()) {
return;
}
DropBoxManager dm = (DropBoxManager) context.getSystemService(Context.DROPBOX_SERVICE);
BinderInvocationStub boxBinder = InvocationStubManager.getInstance().getInvocationStub(DropBoxManagerStub.class);
if (boxBinder != null) {
try {
Reflect.on(dm).set("mService", boxBinder.getProxyInterface());
} catch (ReflectException e) {
e.printStackTrace();
}
}
String hostPkg = VirtualCore.get().getHostPkg();
ContextImpl.mBasePackageName.set(context, hostPkg);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
ContextImplKitkat.mOpPackageName.set(context, hostPkg);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ContentResolverJBMR2.mPackageName.set(context.getContentResolver(), hostPkg);
}
}
use of android.content.ContextWrapper in project ahbottomnavigation by aurelhubert.
the class AHHelper method unwrap.
/**
* Unwrap wactivity
*
* @param context Context
* @return Activity
*/
public static Activity unwrap(Context context) {
while (!(context instanceof Activity)) {
ContextWrapper wrapper = (ContextWrapper) context;
context = wrapper.getBaseContext();
}
return (Activity) context;
}
use of android.content.ContextWrapper in project HoloEverywhere by Prototik.
the class _HoloFragmentInflater method inflate.
public static View inflate(LayoutInflater layoutInflater, AttributeSet attrs, View parent, Fragment fragment) {
FragmentActivity activity = layoutInflater.getFragmentActivity();
if (activity != null) {
return inflate(attrs, parent, activity, fragment);
}
Context context = layoutInflater.getContext();
while (context instanceof ContextWrapper) {
if (context instanceof FragmentActivity) {
activity = (FragmentActivity) context;
break;
}
context = ((ContextWrapper) context).getBaseContext();
}
if (activity == null) {
throw new IllegalStateException("Cannot find any reference to FragmentActivity");
}
return inflate(attrs, parent, activity, fragment);
}
use of android.content.ContextWrapper in project robolectric by robolectric.
the class ShadowContextWrapperTest method shouldReturnApplicationContext_forViewContextInflatedWithApplicationContext.
@Test
public void shouldReturnApplicationContext_forViewContextInflatedWithApplicationContext() throws Exception {
View view = LayoutInflater.from(ApplicationProvider.getApplicationContext()).inflate(R.layout.custom_layout, null);
Context viewContext = new ContextWrapper(view.getContext());
assertThat(viewContext.getApplicationContext()).isEqualTo(ApplicationProvider.getApplicationContext());
}
use of android.content.ContextWrapper in project robolectric by robolectric.
the class ShadowContextWrapperTest method setUp.
@Before
public void setUp() throws Exception {
transcript = new ArrayList<>();
contextWrapper = new ContextWrapper(context);
}
Aggregations