Search in sources :

Example 16 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.

the class ShadowArscAssetManager method openAssetFd.

@HiddenApi
@Implementation
protected ParcelFileDescriptor openAssetFd(String fileName, long[] outOffsets) throws IOException {
    CppAssetManager am = assetManagerForJavaObject();
    ALOGV("openAssetFd in %s", am);
    String fileName8 = fileName;
    if (fileName8 == null) {
        return null;
    }
    Asset a = am.open(fileName8, Asset.AccessMode.ACCESS_RANDOM);
    if (a == null) {
        throw new FileNotFoundException(fileName8);
    }
    return returnParcelFileDescriptor(a, outOffsets);
}
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 17 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.

the class ShadowArscAssetManager method getResourceTypeName.

@Implementation
protected String getResourceTypeName(int resid) {
    CppAssetManager cppAssetManager = assetManagerForJavaObject();
    ResourceName name = new ResourceName();
    if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
        return null;
    }
    return name.type;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResourceName(org.robolectric.res.android.ResTable.ResourceName) Implementation(org.robolectric.annotation.Implementation)

Example 18 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager 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 19 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager 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 20 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager 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

Implementation (org.robolectric.annotation.Implementation)24 CppAssetManager (org.robolectric.res.android.CppAssetManager)24 HiddenApi (org.robolectric.annotation.HiddenApi)18 ResTable (org.robolectric.res.android.ResTable)9 Ref (org.robolectric.res.android.Ref)8 FileNotFoundException (java.io.FileNotFoundException)6 Asset (org.robolectric.res.android.Asset)5 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)5 ResourceName (org.robolectric.res.android.ResTable.ResourceName)4 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)4 ResTable_config (org.robolectric.res.android.ResTable_config)3 String8 (org.robolectric.res.android.String8)2 SparseArray (android.util.SparseArray)1 Path (java.nio.file.Path)1 AccessMode (org.robolectric.res.android.Asset.AccessMode)1 AssetDir (org.robolectric.res.android.AssetDir)1 AssetPath (org.robolectric.res.android.AssetPath)1 DynamicRefTable (org.robolectric.res.android.DynamicRefTable)1 ResStringPool (org.robolectric.res.android.ResStringPool)1 ResTableTheme (org.robolectric.res.android.ResTableTheme)1