use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 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.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetResourcePackageName.
// static jstring NativeGetResourcePackageName(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint
// resid) {
@Implementation(minSdk = P)
@Nullable
protected static String nativeGetResourcePackageName(long ptr, @AnyRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
final ResourceName name = new ResourceName();
if (!assetmanager.GetResourceName(resid, name)) {
return null;
}
if (name.package_ != null) {
return name.package_;
}
return null;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeRetrieveAttributes.
// static jboolean NativeRetrieveAttributes(JNIEnv* env, jclass /*clazz*/, jlong ptr,
// jlong xml_parser_ptr, jintArray java_attrs,
// jintArray out_java_values, jintArray out_java_indices)
// {
@Implementation(minSdk = P)
protected static boolean nativeRetrieveAttributes(long ptr, long xml_parser_ptr, @NonNull int[] java_attrs, @NonNull int[] out_java_values, @NonNull int[] out_java_indices) {
int attrs_len = java_attrs.length;
int out_values_len = out_java_values.length;
if (out_values_len < (attrs_len * STYLE_NUM_ENTRIES)) {
throw new IndexOutOfBoundsException("outValues too small");
}
int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
java_attrs;
if (attrs == null) {
return JNI_FALSE;
}
int[] out_values = out_java_values;
// reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_values, null));
if (out_values == null) {
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
return JNI_FALSE;
}
int[] out_indices = null;
if (out_java_indices != null) {
int out_indices_len = out_java_indices.length;
if (out_indices_len > attrs_len) {
out_indices = out_java_indices;
// reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_indices, null));
if (out_indices == null) {
// env.ReleasePrimitiveArrayCritical(out_java_values, out_values, JNI_ABORT);
return JNI_FALSE;
}
}
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResXMLParser xml_parser = NATIVE_RES_XML_PARSERS.getNativeObject(xml_parser_ptr);
boolean result = RetrieveAttributes(assetmanager, xml_parser, attrs, attrs_len, out_values, out_indices);
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
return result;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeOpenXmlAsset.
// static jlong NativeOpenXmlAsset(JNIEnv* env, jobject /*clazz*/, jlong ptr, jint jcookie,
// jstring asset_path) {
@Implementation(minSdk = P)
protected static long nativeOpenXmlAsset(long ptr, int jcookie, @NonNull String asset_path) throws FileNotFoundException {
ApkAssetsCookie cookie = JavaCookieToApkAssetsCookie(jcookie);
String asset_path_utf8 = asset_path;
if (asset_path_utf8 == null) {
// This will throw NPE.
return 0;
}
ATRACE_NAME(String.format("AssetManager::OpenXmlAsset(%s)", asset_path_utf8));
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Asset asset;
if (cookie.intValue() != kInvalidCookie) {
asset = assetmanager.OpenNonAsset(asset_path_utf8, cookie, Asset.AccessMode.ACCESS_RANDOM);
} else {
Ref<ApkAssetsCookie> cookieRef = new Ref<>(cookie);
asset = assetmanager.OpenNonAsset(asset_path_utf8, Asset.AccessMode.ACCESS_RANDOM, cookieRef);
cookie = cookieRef.get();
}
if (!isTruthy(asset)) {
throw new FileNotFoundException(asset_path_utf8);
}
// May be nullptr.
DynamicRefTable dynamic_ref_table = assetmanager.GetDynamicRefTableForCookie(cookie);
ResXMLTree xml_tree = new ResXMLTree(dynamic_ref_table);
int err = xml_tree.setTo(asset.getBuffer(true), (int) asset.getLength(), true);
if (err != NO_ERROR) {
throw new FileNotFoundException("Corrupt XML binary file");
}
return NATIVE_RES_XML_TREES.register(xml_tree);
}
use of org.robolectric.res.android.CppAssetManager2 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