use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeOpenAssetFd.
// static jobject NativeOpenAssetFd(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring asset_path,
// jlongArray out_offsets) {
@Implementation(minSdk = P)
protected static ParcelFileDescriptor nativeOpenAssetFd(long ptr, @NonNull String asset_path, long[] out_offsets) throws IOException {
String asset_path_utf8 = asset_path;
if (asset_path_utf8 == null) {
// This will throw NPE.
return null;
}
ATRACE_NAME(String.format("AssetManager::OpenAssetFd(%s)", asset_path_utf8));
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Asset asset = assetmanager.Open(asset_path_utf8, Asset.AccessMode.ACCESS_RANDOM);
if (!isTruthy(asset)) {
throw new FileNotFoundException(asset_path_utf8);
}
return ReturnParcelFileDescriptor(asset, out_offsets);
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetResourceIdentifier.
// static jint NativeGetResourceIdentifier(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring name,
// jstring def_type, jstring def_package) {
@Implementation(minSdk = P)
@AnyRes
protected static int nativeGetResourceIdentifier(long ptr, @NonNull String name, @Nullable String def_type, @Nullable String def_package) {
String name_utf8 = name;
if (name_utf8 == null) {
// This will throw NPE.
return 0;
}
String type = null;
if (def_type != null) {
String type_utf8 = def_type;
CHECK(type_utf8 != null);
type = type_utf8;
}
String package_ = null;
if (def_package != null) {
String package_utf8 = def_package;
CHECK(package_utf8 != null);
package_ = package_utf8;
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
return (int) (assetmanager.GetResourceId(name_utf8, type, package_));
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeOpenNonAssetFd.
// static jobject NativeOpenNonAssetFd(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint jcookie,
// jstring asset_path, jlongArray out_offsets) {
@Implementation(minSdk = P)
@Nullable
protected static ParcelFileDescriptor nativeOpenNonAssetFd(long ptr, int jcookie, @NonNull String asset_path, @NonNull long[] out_offsets) throws IOException {
ApkAssetsCookie cookie = JavaCookieToApkAssetsCookie(jcookie);
String asset_path_utf8 = asset_path;
if (asset_path_utf8 == null) {
// This will throw NPE.
return null;
}
ATRACE_NAME(String.format("AssetManager::OpenNonAssetFd(%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 {
asset = assetmanager.OpenNonAsset(asset_path_utf8, Asset.AccessMode.ACCESS_RANDOM);
}
if (!isTruthy(asset)) {
throw new FileNotFoundException(asset_path_utf8);
}
return ReturnParcelFileDescriptor(asset, out_offsets);
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 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 ShadowArscAssetManager9 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);
}
Aggregations