From 4ed80d63960ef27ea6f5aa06ea3ed001acbd15ba Mon Sep 17 00:00:00 2001 From: Jeremy Meyer Date: Tue, 20 Sep 2022 23:14:50 +0000 Subject: [PATCH] Pass a copy of style_id_args to theme.rebase() This is because "the native code should not run for an extended period of time before it calls ReleasePrimitiveArrayCritical" and Theme.rebase() can take longer than we would like. Bug: 242005877 Test: relying on presubmit tests Change-Id: Idff98afb84fea4944a592939212f5c57e822ae2f --- core/jni/android_util_AssetManager.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp index 8c23b214b8fe0..bef6715d3fa46 100644 --- a/core/jni/android_util_AssetManager.cpp +++ b/core/jni/android_util_AssetManager.cpp @@ -1293,6 +1293,10 @@ static void NativeThemeRebase(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong th } else { CHECK(style_count == 0) << "style_ids is null while style_count is non-zero"; } + auto style_id_args_copy = std::vector{style_id_args, style_id_args + style_count}; + if (style_ids != nullptr) { + env->ReleasePrimitiveArrayCritical(style_ids, style_id_args, JNI_ABORT); + } jboolean* force_args = nullptr; if (force != nullptr) { @@ -1305,15 +1309,14 @@ static void NativeThemeRebase(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong th } else { CHECK(style_count == 0) << "force is null while style_count is non-zero"; } - - auto theme = reinterpret_cast(theme_ptr); - theme->Rebase(&(*assetmanager), style_id_args, force_args, static_cast(style_count)); - if (style_ids != nullptr) { - env->ReleasePrimitiveArrayCritical(style_ids, style_id_args, JNI_ABORT); - } + auto force_args_copy = std::vector{force_args, force_args + style_count}; if (force != nullptr) { env->ReleasePrimitiveArrayCritical(force, force_args, JNI_ABORT); } + + auto theme = reinterpret_cast(theme_ptr); + theme->Rebase(&(*assetmanager), style_id_args_copy.data(), force_args_copy.data(), + static_cast(style_count)); } static void NativeThemeCopy(JNIEnv* env, jclass /*clazz*/, jlong dst_asset_manager_ptr,