use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetResourceValue.
// static jint NativeGetResourceValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid,
// jshort density, jobject typed_value,
// jboolean resolve_references) {
@Implementation(minSdk = P)
protected static int nativeGetResourceValue(long ptr, @AnyRes int resid, short density, @NonNull TypedValue typed_value, boolean resolve_references) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
final Ref<Res_value> value = new Ref<>(null);
final Ref<ResTable_config> selected_config = new Ref<>(null);
final Ref<Integer> flags = new Ref<>(0);
ApkAssetsCookie cookie = assetmanager.GetResource(resid, false, /*may_be_bag*/
(short) (density), value, selected_config, flags);
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
final Ref<Integer> ref = new Ref<>(resid);
if (resolve_references) {
cookie = assetmanager.ResolveReference(cookie, value, selected_config, flags, ref);
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
}
return CopyValue(cookie, value.get(), ref.get(), flags.get(), selected_config.get(), typed_value);
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeApplyStyle_measured.
private static void nativeApplyStyle_measured(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, long xml_parser_ptr, @NonNull int[] java_attrs, long out_values_ptr, long out_indices_ptr) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
CHECK(theme.GetAssetManager() == assetmanager);
// (void) assetmanager;
ResXMLParser xml_parser = xml_parser_ptr == 0 ? null : NATIVE_RES_XML_PARSERS.getNativeObject(xml_parser_ptr);
// int[] out_values = reinterpret_cast<int*>(out_values_ptr);
// int[] out_indices = reinterpret_cast<int*>(out_indices_ptr);
ShadowVMRuntime shadowVMRuntime = Shadow.extract(VMRuntime.getRuntime());
int[] out_values = (int[]) shadowVMRuntime.getObjectForAddress(out_values_ptr);
int[] out_indices = (int[]) shadowVMRuntime.getObjectForAddress(out_indices_ptr);
int attrs_len = java_attrs.length;
int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
java_attrs;
// if (attrs == null) {
// return;
// }
ApplyStyle(theme, xml_parser, (int) (def_style_attr), (int) (def_style_resid), attrs, attrs_len, out_values, out_indices);
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetAssignedPackageIdentifiers.
// static jobject NativeGetAssignedPackageIdentifiers(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
@Implementation(minSdk = P, maxSdk = Q)
@NonNull
protected static SparseArray<String> nativeGetAssignedPackageIdentifiers(long ptr) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
SparseArray<String> sparse_array = new SparseArray<>();
if (sparse_array == null) {
// An exception is pending.
return null;
}
assetmanager.ForEachPackage((String package_name, byte package_id) -> {
// env.NewStringUTF(package_name);
String jpackage_name = package_name;
if (jpackage_name == null) {
// An exception is pending.
return;
}
// env.CallVoidMethod(sparse_array, gSparseArrayOffsets.put, (int) (package_id),
// jpackage_name);
sparse_array.put(package_id, jpackage_name);
});
return sparse_array;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeCreate.
// static jlong NativeCreate(JNIEnv* /*env*/, jclass /*clazz*/) {
@Implementation(minSdk = P)
protected static long nativeCreate() {
// AssetManager2 needs to be protected by a lock. To avoid cache misses, we allocate the lock
// and
// AssetManager2 in a contiguous block (GuardedAssetManager).
// return reinterpret_cast<long>(new GuardedAssetManager());
long cppAssetManagerRef;
// we want to share a single instance of the system CppAssetManager2
if (inNonSystemConstructor) {
CppAssetManager2 appAssetManager = new CppAssetManager2();
cppAssetManagerRef = Registries.NATIVE_ASSET_MANAGER_REGISTRY.register(appAssetManager);
} else {
if (systemCppAssetManager2 == null) {
systemCppAssetManager2 = new CppAssetManager2();
systemCppAssetManager2Ref = Registries.NATIVE_ASSET_MANAGER_REGISTRY.register(systemCppAssetManager2);
}
cppAssetManagerRef = systemCppAssetManager2Ref;
}
return cppAssetManagerRef;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeList.
// static jobjectArray NativeList(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring path) {
@Implementation(minSdk = P)
@Nullable
protected static String[] nativeList(long ptr, @NonNull String path) throws IOException {
String path_utf8 = path;
if (path_utf8 == null) {
// This will throw NPE.
return null;
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
AssetDir asset_dir = assetmanager.OpenDir(path_utf8);
if (asset_dir == null) {
throw new FileNotFoundException(path_utf8);
}
int file_count = asset_dir.getFileCount();
// env.NewObjectArray(file_count, g_stringClass, null);
String[] array = new String[file_count];
for (int i = 0; i < file_count; i++) {
String java_string = asset_dir.getFileName(i).string();
// Check for errors creating the strings (if malformed or no memory).
// if (env.ExceptionCheck()) {
// return null;
// }
// env.SetObjectArrayElement(array, i, java_string);
array[i] = java_string;
// If we have a large amount of string in our array, we might overflow the
// local reference table of the VM.
// env.DeleteLocalRef(java_string);
}
return array;
}
Aggregations