Search in sources :

Example 26 with ContextWrapper

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);
    }
}
Also used : DropBoxManager(android.os.DropBoxManager) BinderInvocationStub(com.lody.virtual.client.hook.base.BinderInvocationStub) ContextWrapper(android.content.ContextWrapper) ReflectException(com.lody.virtual.helper.utils.ReflectException)

Example 27 with ContextWrapper

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;
}
Also used : Activity(android.app.Activity) ContextWrapper(android.content.ContextWrapper)

Example 28 with ContextWrapper

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);
}
Also used : Context(android.content.Context) ContextWrapper(android.content.ContextWrapper)

Example 29 with ContextWrapper

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());
}
Also used : Context(android.content.Context) View(android.view.View) ContextWrapper(android.content.ContextWrapper) Test(org.junit.Test)

Example 30 with ContextWrapper

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);
}
Also used : ContextWrapper(android.content.ContextWrapper) Before(org.junit.Before)

Aggregations

ContextWrapper (android.content.ContextWrapper)108 Context (android.content.Context)37 Activity (android.app.Activity)25 File (java.io.File)16 Test (org.junit.Test)13 Intent (android.content.Intent)11 MockContentResolver (android.test.mock.MockContentResolver)11 PackageManager (android.content.pm.PackageManager)10 Resources (android.content.res.Resources)9 View (android.view.View)9 IOException (java.io.IOException)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)6 UserManager (android.os.UserManager)6 ThemePreferenceController (com.android.settings.display.ThemePreferenceController)6 OverlayManager (com.android.settings.display.ThemePreferenceController.OverlayManager)6 ArrayList (java.util.ArrayList)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 LayoutInflater (android.view.LayoutInflater)5 JsonParser (com.google.gson.JsonParser)5