@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()); }
@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 @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 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()); }
@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); }