@Implementation(minSdk = P) protected static @Nullable @AttrRes int[] nativeGetStyleAttributes(long ptr, @StyleRes int resid) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); ResolvedBag bag = assetmanager.GetBag(resid); if (bag == null) { return null; } int[] array = new int[bag.entry_count]; // if (env.ExceptionCheck()) { // return null; // } for (int i = 0; i < bag.entry_count; i++) { int attr_resid = bag.entries[i].key; // env.SetIntArrayRegion(array, i, 1, &attr_resid); array[i] = attr_resid; } return array; }
@Implementation(minSdk = P) protected static boolean nativeResolveAttrs(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, @Nullable int[] java_values, @NonNull int[] java_attrs, @NonNull int[] out_java_values, @NonNull int[] out_java_indices) { int attrs_len = java_attrs.length;
@Implementation(minSdk = P) protected static void nativeApplyStyle(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 = java_attrs; // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null)); // 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); }
@Implementation(minSdk = P) protected static int nativeThemeGetAttributeValue(long ptr, long theme_ptr, @AttrRes int resid, @NonNull TypedValue typed_value, boolean resolve_references) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr); CHECK(theme.GetAssetManager() == assetmanager); // (void) assetmanager; // huh? final Ref<Res_value> value = new Ref<>(null); final Ref<Integer> flags = new Ref<>(null); ApkAssetsCookie cookie = theme.GetAttribute(resid, value, flags); if (cookie.intValue() == kInvalidCookie) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } final Ref<Integer> ref = new Ref<>(0); if (resolve_references) { final Ref<ResTable_config> selected_config = new Ref<>(null); cookie = theme.GetAssetManager().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(), null, typed_value); }
@Implementation(minSdk = P) protected static @Nullable @AttrRes int[] nativeGetStyleAttributes(long ptr, @StyleRes int resid) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); ResolvedBag bag = assetmanager.GetBag(resid); if (bag == null) { return null; } int[] array = new int[bag.entry_count]; // if (env.ExceptionCheck()) { // return null; // } for (int i = 0; i < bag.entry_count; i++) { int attr_resid = bag.entries[i].key; // env.SetIntArrayRegion(array, i, 1, &attr_resid); array[i] = attr_resid; } return array; }
@Implementation(minSdk = P) protected static boolean nativeResolveAttrs(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, @Nullable int[] java_values, @NonNull int[] java_attrs, @NonNull int[] out_java_values, @NonNull int[] out_java_indices) { int attrs_len = java_attrs.length;
@Implementation(minSdk = P) protected static void nativeApplyStyle(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 = java_attrs; // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null)); // 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); }
@Implementation(minSdk = P) protected static int nativeThemeGetAttributeValue(long ptr, long theme_ptr, @AttrRes int resid, @NonNull TypedValue typed_value, boolean resolve_references) { CppAssetManager2 assetmanager = AssetManagerFromLong(ptr); Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr); CHECK(theme.GetAssetManager() == assetmanager); // (void) assetmanager; // huh? final Ref<Res_value> value = new Ref<>(null); final Ref<Integer> flags = new Ref<>(null); ApkAssetsCookie cookie = theme.GetAttribute(resid, value, flags); if (cookie.intValue() == kInvalidCookie) { return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE); } final Ref<Integer> ref = new Ref<>(0); if (resolve_references) { final Ref<ResTable_config> selected_config = new Ref<>(null); cookie = theme.GetAssetManager().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(), null, typed_value); }