use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeAssetReadChar.
// static jint NativeAssetReadChar(JNIEnv* /*env*/, jclass /*clazz*/, jlong asset_ptr) {
@Implementation(minSdk = P)
protected static int nativeAssetReadChar(long asset_ptr) {
Asset asset = Registries.NATIVE_ASSET_REGISTRY.getNativeObject(asset_ptr);
byte[] b = new byte[1];
int res = asset.read(b, 1);
return res == 1 ? (int) (b[0]) & 0xff : -1;
}
use of org.robolectric.res.android.Asset 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));
}
use of org.robolectric.res.android.Asset 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);
}
use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeOpenAsset.
// static jlong NativeOpenAsset(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring asset_path,
// jint access_mode) {
@Implementation(minSdk = P)
protected static long nativeOpenAsset(long ptr, @NonNull String asset_path, int access_mode) throws FileNotFoundException {
String asset_path_utf8 = asset_path;
if (asset_path_utf8 == null) {
// This will throw NPE.
return 0;
}
ATRACE_NAME(String.format("AssetManager::OpenAsset(%s)", asset_path_utf8));
if (access_mode != Asset.AccessMode.ACCESS_UNKNOWN.mode() && access_mode != Asset.AccessMode.ACCESS_RANDOM.mode() && access_mode != Asset.AccessMode.ACCESS_STREAMING.mode() && access_mode != Asset.AccessMode.ACCESS_BUFFER.mode()) {
throw new IllegalArgumentException("Bad access mode");
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Asset asset = assetmanager.Open(asset_path_utf8, Asset.AccessMode.fromInt(access_mode));
if (!isTruthy(asset)) {
throw new FileNotFoundException(asset_path_utf8);
}
return Registries.NATIVE_ASSET_REGISTRY.register(asset);
}
use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowArscApkAssets9 method nativeOpenXml.
// static jlong NativeOpenXml(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring file_name) {
@Implementation
protected static long nativeOpenXml(long ptr, String file_name) throws FileNotFoundException {
String path_utf8 = file_name;
if (path_utf8 == null) {
return 0;
}
CppApkAssets apk_assets = Registries.NATIVE_APK_ASSETS_REGISTRY.getNativeObject(ptr);
Asset asset = apk_assets.Open(path_utf8, Asset.AccessMode.ACCESS_RANDOM);
if (asset == null) {
throw new FileNotFoundException(path_utf8);
}
// DynamicRefTable is only needed when looking up resource references. Opening an XML file
// directly from an ApkAssets has no notion of proper resource references.
// util.make_unique<ResXMLTree>(nullptr /*dynamicRefTable*/);
ResXMLTree xml_tree = new ResXMLTree(null);
int err = xml_tree.setTo(asset.getBuffer(true), (int) asset.getLength(), true);
if (err != NO_ERROR) {
throw new FileNotFoundException("Corrupt XML binary file");
}
// reinterpret_cast<jlong>(xml_tree.release());
return Registries.NATIVE_RES_XML_TREES.register(xml_tree);
}
Aggregations