@Implementation(minSdk = P) protected static @Nullable String nativeGetResourceName(long ptr, @AnyRes int resid) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); CppAssetManager2.ResourceName name = new ResourceName();
@Implementation(minSdk = P) protected static @Nullable 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; }
@Implementation(minSdk = P) protected static @Nullable String nativeGetResourceTypeName(long ptr, @AnyRes int resid) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); final ResourceName name = new ResourceName(); if (!assetmanager.GetResourceName(resid, name)) { return null; } if (name.type != null) { return name.type; // } else if (name.get().type16 != null) { // return name.get().type16; // env.NewString(reinterpret_cast<jchar*>(name.type16), name.type_len); } return null; }
@Implementation(minSdk = P) protected static @Nullable 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; }
@Implementation(minSdk = P) protected static @AnyRes 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_)); }
@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); }
@Implementation(minSdk = P) protected static int nativeGetResourceBagValue(long ptr, @AnyRes int resid, int bag_entry_id, @NonNull TypedValue typed_value) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); ResolvedBag bag = assetmanager.GetBag(resid); if (bag == null) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } final Ref<Integer> type_spec_flags = new Ref<>(bag.type_spec_flags); ApkAssetsCookie cookie = K_INVALID_COOKIE; Res_value bag_value = null; for (ResolvedBag.Entry entry : bag.entries) { if (entry.key == (int) (bag_entry_id)) { cookie = entry.cookie; bag_value = entry.value; // Keep searching (the old implementation did that). } } if (cookie.intValue() == kInvalidCookie) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } final Ref<Res_value> value = new Ref<>(bag_value); final Ref<Integer> ref = new Ref<>(resid); final Ref<ResTable_config> selected_config = new Ref<>(null); cookie = assetmanager.ResolveReference(cookie, value, selected_config, type_spec_flags, ref); if (cookie.intValue() == kInvalidCookie) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } return CopyValue(cookie, value.get(), ref.get(), type_spec_flags.get(), null, typed_value); }
@Implementation(minSdk = P) protected static @Nullable String nativeGetResourceName(long ptr, @AnyRes int resid) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); CppAssetManager2.ResourceName name = new ResourceName();
@Implementation(minSdk = P) protected static @Nullable String nativeGetResourceTypeName(long ptr, @AnyRes int resid) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); final ResourceName name = new ResourceName(); if (!assetmanager.GetResourceName(resid, name)) { return null; } if (name.type != null) { return name.type; // } else if (name.get().type16 != null) { // return name.get().type16; // env.NewString(reinterpret_cast<jchar*>(name.type16), name.type_len); } return null; }
@Implementation(minSdk = P) protected static @Nullable 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; }
@Implementation(minSdk = P) protected static @Nullable 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; }
@Implementation(minSdk = P) protected static @AnyRes 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_)); }
@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); }
@Implementation(minSdk = P) protected static int nativeGetResourceBagValue(long ptr, @AnyRes int resid, int bag_entry_id, @NonNull TypedValue typed_value) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); ResolvedBag bag = assetmanager.GetBag(resid); if (bag == null) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } final Ref<Integer> type_spec_flags = new Ref<>(bag.type_spec_flags); ApkAssetsCookie cookie = K_INVALID_COOKIE; Res_value bag_value = null; for (ResolvedBag.Entry entry : bag.entries) { if (entry.key == (int) (bag_entry_id)) { cookie = entry.cookie; bag_value = entry.value; // Keep searching (the old implementation did that). } } if (cookie.intValue() == kInvalidCookie) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } final Ref<Res_value> value = new Ref<>(bag_value); final Ref<Integer> ref = new Ref<>(resid); final Ref<ResTable_config> selected_config = new Ref<>(null); cookie = assetmanager.ResolveReference(cookie, value, selected_config, type_spec_flags, ref); if (cookie.intValue() == kInvalidCookie) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } return CopyValue(cookie, value.get(), ref.get(), type_spec_flags.get(), null, typed_value); }