use of org.robolectric.res.android.Asset.AccessMode in project robolectric by robolectric.
the class ShadowArscAssetManager method openNonAssetNative.
@HiddenApi
@Implementation
protected final Number openNonAssetNative(int cookie, String fileName, int accessMode) throws FileNotFoundException {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return RuntimeEnvironment.castNativePtr(0);
}
ALOGV("openNonAssetNative in %s (Java object %s)\n", am, AssetManager.class);
String fileName8 = fileName;
if (fileName8 == null) {
return RuntimeEnvironment.castNativePtr(-1);
}
AccessMode mode = AccessMode.fromInt(accessMode);
if (mode != Asset.AccessMode.ACCESS_UNKNOWN && mode != Asset.AccessMode.ACCESS_RANDOM && mode != Asset.AccessMode.ACCESS_STREAMING && mode != Asset.AccessMode.ACCESS_BUFFER) {
throw new IllegalArgumentException("Bad access mode");
}
Asset a = isTruthy(cookie) ? am.openNonAsset(cookie, fileName8, mode) : am.openNonAsset(fileName8, mode, null);
if (a == null) {
throw new FileNotFoundException(fileName8);
}
long assetId = Registries.NATIVE_ASSET_REGISTRY.register(a);
// todo: something better than this [xw]
a.onClose = () -> destroyAsset(assetId);
// printf("Created Asset Stream: %p\n", a);
return RuntimeEnvironment.castNativePtr(assetId);
}
Aggregations