Search in sources :

Example 6 with Resetter

use of org.robolectric.annotation.Resetter in project robolectric by robolectric.

the class ShadowContextImpl method reset.

@Resetter
public static void reset() {
    String prefsCacheFieldName = RuntimeEnvironment.getApiLevel() >= N ? "sSharedPrefsCache" : "sSharedPrefs";
    Object prefsDefaultValue = RuntimeEnvironment.getApiLevel() >= KITKAT ? null : new HashMap<>();
    Class<?> contextImplClass = ReflectionHelpers.loadClass(ShadowContextImpl.class.getClassLoader(), "android.app.ContextImpl");
    ReflectionHelpers.setStaticField(contextImplClass, prefsCacheFieldName, prefsDefaultValue);
    if (RuntimeEnvironment.getApiLevel() <= VERSION_CODES.LOLLIPOP_MR1) {
        HashMap<String, Object> fetchers = ReflectionHelpers.getStaticField(contextImplClass, "SYSTEM_SERVICE_MAP");
        Class staticServiceFetcherClass = ReflectionHelpers.loadClass(ShadowContextImpl.class.getClassLoader(), "android.app.ContextImpl$StaticServiceFetcher");
        for (Object o : fetchers.values()) {
            if (staticServiceFetcherClass.isInstance(o)) {
                ReflectionHelpers.setField(staticServiceFetcherClass, o, "mCachedInstance", null);
            }
        }
        if (RuntimeEnvironment.getApiLevel() >= KITKAT) {
            Object windowServiceFetcher = fetchers.get(Context.WINDOW_SERVICE);
            ReflectionHelpers.setField(windowServiceFetcher.getClass(), windowServiceFetcher, "mDefaultDisplay", null);
        }
    }
}
Also used : RealObject(org.robolectric.annotation.RealObject) Resetter(org.robolectric.annotation.Resetter)

Example 7 with Resetter

use of org.robolectric.annotation.Resetter in project robolectric by robolectric.

the class ShadowWindowManagerImpl method reset.

@Resetter
public static void reset() {
    defaultDisplayJB = null;
    views.clear();
    if (getApiLevel() <= VERSION_CODES.JELLY_BEAN) {
        ReflectionHelpers.setStaticField(WindowManagerImpl.class, "sWindowManager", ReflectionHelpers.newInstance(WindowManagerImpl.class));
        HashMap windowManagers = ReflectionHelpers.getStaticField(WindowManagerImpl.class, "sCompatWindowManagers");
        windowManagers.clear();
    }
}
Also used : WindowManagerImpl(android.view.WindowManagerImpl) HashMap(java.util.HashMap) Resetter(org.robolectric.annotation.Resetter)

Aggregations

Resetter (org.robolectric.annotation.Resetter)7 Looper (android.os.Looper)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LooperMode (org.robolectric.annotation.LooperMode)2 WindowManagerImpl (android.view.WindowManagerImpl)1 BackgroundThread (com.android.internal.os.BackgroundThread)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 RealObject (org.robolectric.annotation.RealObject)1