Search in sources :

Example 51 with HiddenApi

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

the class ShadowLegacyAssetManager method openNonAsset.

@HiddenApi
@Implementation
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException {
    final ResName resName = qualifyFromNonAssetFileName(fileName);
    final FileTypedResource typedResource = (FileTypedResource) getResourceTable().getValue(resName, config);
    if (typedResource == null) {
        throw new IOException("Unable to find resource for " + fileName);
    }
    InputStream stream;
    if (accessMode == AssetManager.ACCESS_STREAMING) {
        stream = Fs.getInputStream(typedResource.getPath());
    } else {
        stream = new ByteArrayInputStream(Fs.getBytes(typedResource.getPath()));
    }
    if (RuntimeEnvironment.getApiLevel() >= P) {
        Asset asset = Asset.newFileAsset(typedResource);
        long assetPtr = Registries.NATIVE_ASSET_REGISTRY.register(asset);
        // Camouflage the InputStream as an AssetInputStream so subsequent instanceof checks pass.
        stream = ShadowAssetInputStream.createAssetInputStream(stream, assetPtr, realObject);
    }
    return stream;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Asset(org.robolectric.res.android.Asset) ResName(org.robolectric.res.ResName) FileTypedResource(org.robolectric.res.FileTypedResource) IOException(java.io.IOException) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 52 with HiddenApi

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

the class ShadowLegacyAssetManager method getResourceTextArray.

@HiddenApi
@Implementation
public CharSequence[] getResourceTextArray(int resId) {
    TypedResource value = getAndResolve(resId, config, true);
    if (value == null)
        return null;
    List<TypedResource> items = getConverter(value).getItems(value);
    CharSequence[] charSequences = new CharSequence[items.size()];
    for (int i = 0; i < items.size(); i++) {
        TypedResource typedResource = resolve(items.get(i), config, resId);
        charSequences[i] = getConverter(typedResource).asCharSequence(typedResource);
    }
    return charSequences;
}
Also used : TypedResource(org.robolectric.res.TypedResource) FileTypedResource(org.robolectric.res.FileTypedResource) SuppressLint(android.annotation.SuppressLint) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 53 with HiddenApi

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

the class ShadowParcel method readParcelableCreator.

@HiddenApi
@Implementation(minSdk = JELLY_BEAN_MR2)
public Parcelable.Creator<?> readParcelableCreator(ClassLoader loader) {
    // note: calling `readString` will also consume the string, and increment the data-pointer.
    // which is exactly what we need, since we do not call the real `readParcelableCreator`.
    final String name = realObject.readString();
    if (name == null) {
        return null;
    }
    Parcelable.Creator<?> creator;
    try {
        // If loader == null, explicitly emulate Class.forName(String) "caller
        // classloader" behavior.
        ClassLoader parcelableClassLoader = (loader == null ? getClass().getClassLoader() : loader);
        // Avoid initializing the Parcelable class until we know it implements
        // Parcelable and has the necessary CREATOR field.
        Class<?> parcelableClass = Class.forName(name, false, /* initialize */
        parcelableClassLoader);
        if (!Parcelable.class.isAssignableFrom(parcelableClass)) {
            throw new BadParcelableException("Parcelable protocol requires that the " + "class implements Parcelable");
        }
        Field f = parcelableClass.getField("CREATOR");
        // this is a fix for JDK8<->Android VM incompatibility:
        // Apparently, JDK will not allow access to a public field if its
        // class is not visible (private or package-private) from the call-site.
        f.setAccessible(true);
        if ((f.getModifiers() & Modifier.STATIC) == 0) {
            throw new BadParcelableException("Parcelable protocol requires " + "the CREATOR object to be static on class " + name);
        }
        Class<?> creatorType = f.getType();
        if (!Parcelable.Creator.class.isAssignableFrom(creatorType)) {
            // parcelableClass unnecessarily.
            throw new BadParcelableException("Parcelable protocol requires a " + "Parcelable.Creator object called " + "CREATOR on class " + name);
        }
        creator = (Parcelable.Creator<?>) f.get(null);
    } catch (IllegalAccessException e) {
        Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
        throw new BadParcelableException("IllegalAccessException when unmarshalling: " + name);
    } catch (ClassNotFoundException e) {
        Log.e(TAG, "Class not found when unmarshalling: " + name, e);
        throw new BadParcelableException("ClassNotFoundException when unmarshalling: " + name);
    } catch (NoSuchFieldException e) {
        throw new BadParcelableException("Parcelable protocol requires a " + "Parcelable.Creator object called " + "CREATOR on class " + name);
    }
    if (creator == null) {
        throw new BadParcelableException("Parcelable protocol requires a " + "non-null Parcelable.Creator object called " + "CREATOR on class " + name);
    }
    return creator;
}
Also used : Field(java.lang.reflect.Field) Parcelable(android.os.Parcelable) BadParcelableException(android.os.BadParcelableException) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 54 with HiddenApi

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

the class ShadowResources method loadDrawable.

@HiddenApi
@Implementation(maxSdk = KITKAT_WATCH)
protected Drawable loadDrawable(TypedValue value, int id) {
    Drawable drawable = reflector(ResourcesReflector.class, realResources).loadDrawable(value, id);
    setCreatedFromResId(realResources, id, drawable);
    return drawable;
}
Also used : Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 55 with HiddenApi

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

the class ShadowMotionEvent method nativeAddBatch.

@Implementation(minSdk = LOLLIPOP)
@HiddenApi
protected static void nativeAddBatch(long nativePtr, long eventTimeNanos, PointerCoords[] pointerCoordsObjArray, int metaState) {
    NativeInput.MotionEvent event = getNativeMotionEvent(nativePtr);
    int pointerCount = event.getPointerCount();
    validatePointerCoordsObjArray(pointerCoordsObjArray, pointerCount);
    NativeInput.PointerCoords[] rawPointerCoords = new NativeInput.PointerCoords[pointerCount];
    for (int i = 0; i < pointerCount; i++) {
        PointerCoords pointerCoordsObj = pointerCoordsObjArray[i];
        checkNotNull(pointerCoordsObj);
        rawPointerCoords[i] = pointerCoordsToNative(pointerCoordsObj, event.getXOffset(), event.getYOffset());
    }
    event.addSample(eventTimeNanos, rawPointerCoords);
    event.setMetaState(event.getMetaState() | metaState);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

HiddenApi (org.robolectric.annotation.HiddenApi)61 Implementation (org.robolectric.annotation.Implementation)61 CppAssetManager (org.robolectric.res.android.CppAssetManager)18 Ref (org.robolectric.res.android.Ref)9 ResTable (org.robolectric.res.android.ResTable)9 FileTypedResource (org.robolectric.res.FileTypedResource)8 Asset (org.robolectric.res.android.Asset)8 TypedResource (org.robolectric.res.TypedResource)6 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)6 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 ResTableTheme (org.robolectric.res.android.ResTableTheme)5 SuppressLint (android.annotation.SuppressLint)4 ResName (org.robolectric.res.ResName)4 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)4 ResTable_config (org.robolectric.res.android.ResTable_config)4 IOException (java.io.IOException)3 AttributedOpEntry (android.app.AppOpsManager.AttributedOpEntry)2 OpEntry (android.app.AppOpsManager.OpEntry)2 PackageOps (android.app.AppOpsManager.PackageOps)2