Search in sources :

Example 6 with CppAssetManager

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

the class ShadowArscAssetManager method openXmlAssetNative.

// /*package*/@HiddenApi @Implementation public static final @NativeConfig
// int getThemeChangingConfigurations(long theme);
@HiddenApi
@Implementation
protected final Number openXmlAssetNative(int cookie, String fileName) throws FileNotFoundException {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return RuntimeEnvironment.castNativePtr(0);
    }
    ALOGV("openXmlAsset in %s (Java object %s)\n", am, ShadowArscAssetManager.class);
    String fileName8 = fileName;
    if (fileName8 == null) {
        return RuntimeEnvironment.castNativePtr(0);
    }
    int assetCookie = cookie;
    Asset a;
    if (isTruthy(assetCookie)) {
        a = am.openNonAsset(assetCookie, fileName8, AccessMode.ACCESS_BUFFER);
    } else {
        final Ref<Integer> assetCookieRef = new Ref<>(assetCookie);
        a = am.openNonAsset(fileName8, AccessMode.ACCESS_BUFFER, assetCookieRef);
        assetCookie = assetCookieRef.get();
    }
    if (a == null) {
        throw new FileNotFoundException(fileName8);
    }
    final DynamicRefTable dynamicRefTable = am.getResources().getDynamicRefTableForCookie(assetCookie);
    ResXMLTree block = new ResXMLTree(dynamicRefTable);
    int err = block.setTo(a.getBuffer(true), (int) a.getLength(), true);
    a.close();
    if (err != NO_ERROR) {
        throw new FileNotFoundException("Corrupt XML binary file");
    }
    return RuntimeEnvironment.castNativePtr(Registries.NATIVE_RES_XML_TREES.register(block));
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager(org.robolectric.res.android.CppAssetManager) FileNotFoundException(java.io.FileNotFoundException) ResXMLTree(org.robolectric.res.android.ResXMLTree) Asset(org.robolectric.res.android.Asset) DynamicRefTable(org.robolectric.res.android.DynamicRefTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 7 with CppAssetManager

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

the class ShadowArscAssetManager method getArraySize.

@HiddenApi
@Implementation
protected int getArraySize(int id) {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    final ResTable res = am.getResources();
    res.lock();
    final Ref<bag_entry[]> defStyleEnt = new Ref<>(null);
    int bagOff = res.getBagLocked(id, defStyleEnt, null);
    res.unlock();
    return bagOff;
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 8 with CppAssetManager

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

the class ShadowArscAssetManager method openNonAssetFdNative.

@HiddenApi
@Implementation
protected ParcelFileDescriptor openNonAssetFdNative(int cookie, String fileName, long[] outOffsets) throws IOException {
    CppAssetManager am = assetManagerForJavaObject();
    ALOGV("openNonAssetFd in %s (Java object %s)", am, this);
    if (fileName == null) {
        return null;
    }
    Asset a = isTruthy(cookie) ? am.openNonAsset(cookie, fileName, Asset.AccessMode.ACCESS_RANDOM) : am.openNonAsset(fileName, Asset.AccessMode.ACCESS_RANDOM, null);
    if (a == null) {
        throw new FileNotFoundException(fileName);
    }
    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 9 with CppAssetManager

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

the class ShadowArscAssetManager method getResourcePackageName.

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

Example 10 with CppAssetManager

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

the class ShadowArscAssetManager method getResourceEntryName.

@Implementation
protected String getResourceEntryName(int resid) {
    CppAssetManager cppAssetManager = assetManagerForJavaObject();
    ResourceName name = new ResourceName();
    if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
        return null;
    }
    return name.name;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResourceName(org.robolectric.res.android.ResTable.ResourceName) 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