use of org.robolectric.res.android.CppApkAssets 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);
}
use of org.robolectric.res.android.CppApkAssets in project robolectric by robolectric.
the class ShadowArscApkAssets9 method nativeLoad.
// static jlong NativeLoad(JNIEnv* env, jclass /*clazz*/, jstring java_path, jboolean system,
// jboolean force_shared_lib, jboolean overlay) {
@Implementation
protected static long nativeLoad(String path, boolean system, boolean forceSharedLib, boolean overlay) throws IOException {
if (path == null) {
return 0;
}
ATRACE_NAME(String.format("LoadApkAssets(%s)", path));
CppApkAssets apk_assets;
try {
if (overlay) {
apk_assets = CppApkAssets.LoadOverlay(path, system);
} else if (forceSharedLib) {
apk_assets = CppApkAssets.LoadAsSharedLibrary(path, system);
} else {
apk_assets = CppApkAssets.Load(path, system);
}
} catch (OutOfMemoryError e) {
OutOfMemoryError outOfMemoryError = new OutOfMemoryError("Failed to load " + path);
outOfMemoryError.initCause(e);
throw outOfMemoryError;
}
if (apk_assets == null) {
String error_msg = String.format("Failed to load asset path %s", path);
throw new IOException(error_msg);
}
return Registries.NATIVE_APK_ASSETS_REGISTRY.register(apk_assets);
}
use of org.robolectric.res.android.CppApkAssets in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeSetApkAssets.
// static void NativeSetApkAssets(JNIEnv* env, jclass /*clazz*/, jlong ptr,
// jobjectArray apk_assets_array, jboolean invalidate_caches) {
@Implementation(minSdk = P)
protected static void nativeSetApkAssets(long ptr, @NonNull android.content.res.ApkAssets[] apk_assets_array, boolean invalidate_caches) {
ATRACE_NAME("AssetManager::SetApkAssets");
int apk_assets_len = apk_assets_array.length;
List<CppApkAssets> apk_assets = new ArrayList<>();
// apk_assets.reserve(apk_assets_len);
for (int i = 0; i < apk_assets_len; i++) {
android.content.res.ApkAssets apkAssets = // env.GetObjectArrayElement(apk_assets_array, i);
apk_assets_array[i];
if (apkAssets == null) {
throw new NullPointerException(String.format("ApkAssets at index %d is null", i));
}
long apk_assets_native_ptr = ((ShadowArscApkAssets9) Shadow.extract(apkAssets)).getNativePtr();
// if (env.ExceptionCheck()) {
// return;
// }
apk_assets.add(Registries.NATIVE_APK_ASSETS_REGISTRY.getNativeObject(apk_assets_native_ptr));
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
assetmanager.SetApkAssets(apk_assets, invalidate_caches);
}
Aggregations