Search in sources :

Example 36 with HiddenApi

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

the class ShadowArscAssetManager method applyStyle.

@HiddenApi
@Implementation(minSdk = LOLLIPOP, maxSdk = N_MR1)
protected static void applyStyle(long themeToken, int defStyleAttr, int defStyleRes, long xmlParserToken, int[] attrs, int[] outValues, int[] outIndices) {
    ResTableTheme theme = Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeToken);
    ResXMLParser xmlParser = xmlParserToken == 0 ? null : Registries.NATIVE_RES_XML_PARSERS.getNativeObject(xmlParserToken);
    AttributeResolution.ApplyStyle(theme, xmlParser, defStyleAttr, defStyleRes, attrs, attrs.length, outValues, outIndices);
}
Also used : ResTableTheme(org.robolectric.res.android.ResTableTheme) ResXMLParser(org.robolectric.res.android.ResXMLParser) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 37 with HiddenApi

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

the class ShadowArscAssetManager method getArrayStringInfo.

@HiddenApi
@Implementation
protected final int[] getArrayStringInfo(int arrayResId) {
    CppAssetManager am = assetManagerForJavaObject();
    ResTable res = am.getResources();
    final Ref<bag_entry[]> startOfBag = new Ref<>(null);
    final int N = res.lockBag(arrayResId, startOfBag);
    if (N < 0) {
        return null;
    }
    int[] array = new int[N * 2];
    final Ref<Res_value> value = new Ref<>(null);
    bag_entry[] bag = startOfBag.get();
    for (int i = 0, j = 0; i < N; i++) {
        int stringIndex = -1;
        int stringBlock = 0;
        value.set(bag[i].map.value);
        // Take care of resolving the found resource to its final value.
        stringBlock = res.resolveReference(value, bag[i].stringBlock, null);
        if (value.get().dataType == DataType.STRING.code()) {
            stringIndex = value.get().data;
        }
        if (kThrowOnBadId) {
            if (stringBlock == BAD_INDEX) {
                throw new IllegalStateException("Bad resource!");
            }
        }
        // todo: It might be faster to allocate a C array to contain
        // the blocknums and indices, put them in there and then
        // do just one SetIntArrayRegion()
        // env->SetIntArrayRegion(array, j, 1, &stringBlock);
        array[j] = stringBlock;
        // env->SetIntArrayRegion(array, j + 1, 1, &stringIndex);
        array[j + 1] = stringIndex;
        j += 2;
    }
    res.unlockBag(startOfBag);
    return array;
}
Also used : Ref(org.robolectric.res.android.Ref) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) ResTable.bag_entry(org.robolectric.res.android.ResTable.bag_entry) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 38 with HiddenApi

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

the class ShadowArscAssetManager method openAsset.

@HiddenApi
@Implementation
protected final Number openAsset(String fileName, int mode) throws FileNotFoundException {
    CppAssetManager am = assetManagerForJavaObject();
    ALOGV("openAsset in %s", am);
    String fileName8 = fileName;
    if (fileName8 == null) {
        throw new IllegalArgumentException("Empty file name");
    }
    if (mode != AccessMode.ACCESS_UNKNOWN.mode() && mode != AccessMode.ACCESS_RANDOM.mode() && mode != AccessMode.ACCESS_STREAMING.mode() && mode != AccessMode.ACCESS_BUFFER.mode()) {
        throw new IllegalArgumentException("Bad access mode");
    }
    Asset a = am.open(fileName8, AccessMode.fromInt(mode));
    if (a == null) {
        throw new FileNotFoundException(fileName8);
    }
    return RuntimeEnvironment.castNativePtr(Registries.NATIVE_ASSET_REGISTRY.register(a));
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) FileNotFoundException(java.io.FileNotFoundException) Asset(org.robolectric.res.android.Asset) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 39 with HiddenApi

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

the class ShadowArscAssetManager method readAsset.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected final int readAsset(long asset, byte[] bArray, int off, int len) throws IOException {
    Asset a = getAsset(asset);
    if (a == null || bArray == null) {
        throw new NullPointerException("asset");
    }
    if (len == 0) {
        return 0;
    }
    int bLen = bArray.length;
    if (off < 0 || off >= bLen || len < 0 || len > bLen || (off + len) > bLen) {
        throw new IndexOutOfBoundsException();
    }
    byte[] b = bArray;
    int res = a.read(b, off, len);
    if (res > 0)
        return res;
    if (res < 0) {
        throw new IOException();
    }
    return -1;
}
Also used : Asset(org.robolectric.res.android.Asset) IOException(java.io.IOException) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 40 with HiddenApi

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

the class ShadowArscAssetManager method addAssetPathNative.

@HiddenApi
@Implementation(minSdk = VERSION_CODES.N)
protected int addAssetPathNative(String path, boolean appAsLib) {
    if (Strings.isNullOrEmpty(path)) {
        return 0;
    }
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    final Ref<Integer> cookie = new Ref<>(null);
    boolean res = am.addAssetPath(new String8(path), cookie, appAsLib);
    return (res) ? cookie.get() : 0;
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager(org.robolectric.res.android.CppAssetManager) String8(org.robolectric.res.android.String8) 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