use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetResourceEntryName.
// static jstring NativeGetResourceEntryName(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid)
// {
@Implementation(minSdk = P)
@Nullable
protected static String nativeGetResourceEntryName(long ptr, @AnyRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
final ResourceName name = new ResourceName();
if (!assetmanager.GetResourceName(resid, name)) {
return null;
}
if (name.entry != null) {
return name.entry;
// } else if (name.entry16 != null) {
// return name.entry16; // env.NewString(reinterpret_cast<jchar*>(name.entry16),
// name.entry_len);
}
return null;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 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 ShadowArscAssetManager9 method nativeThemeApplyStyle.
// static void NativeThemeApplyStyle(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong theme_ptr,
// jint resid, jboolean force) {
@Implementation(minSdk = P)
protected static void nativeThemeApplyStyle(long ptr, long theme_ptr, @StyleRes int resid, boolean force) {
// AssetManager is accessed via the theme, so grab an explicit lock here.
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
CHECK(theme.GetAssetManager() == assetmanager);
// (void) assetmanager;
theme.ApplyStyle(resid, force);
// TODO(adamlesinski): Consider surfacing exception when result is failure.
// CTS currently expects no exceptions from this method.
// std::string error_msg = StringPrintf("Failed to apply style 0x%08x to theme", resid);
// throw new IllegalArgumentException(error_msg.c_str());
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetResourceName.
// static jstring NativeGetResourceName(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid) {
@Implementation(minSdk = P)
@Nullable
protected static String nativeGetResourceName(long ptr, @AnyRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
CppAssetManager2.ResourceName name = new ResourceName();
if (!assetmanager.GetResourceName(resid, name)) {
return null;
}
StringBuilder result = new StringBuilder();
if (name.package_ != null) {
result.append(name.package_);
}
if (name.type != null) /*|| name.type16 != null*/
{
if (!(result.length() == 0)) {
result.append(":");
}
// if (name.type != null) {
result.append(name.type);
// } else {
// result.append( /*util.Utf16ToUtf8(StringPiece16(*/ name.type16 /*, name.type_len))*/);
// }
}
if (name.entry != null) /*|| name.entry16 != null*/
{
if (!(result.length() == 0)) {
result.append("/");
}
// if (name.entry != null) {
result.append(name.entry);
// } else {
// result.append( /*util.Utf16ToUtf8(StringPiece16(*/ name.entry16 /*, name.entry_len)*/);
// }
}
return result.toString();
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager9 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);
}
Aggregations