summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Oli Lan <olilan@google.com> 2023-06-14 11:26:32 +0100
committer Oli Lan <olilan@google.com> 2023-06-15 13:02:38 +0100
commitf756b2623fa76b9d0c3ca2ee9f2894856bb1e448 (patch)
tree61c49f96293f7abb8d4c45a67ca21598cdd2446a
parentb4b4f2042d2b5dead672703d214dd7d8d1f39325 (diff)
Fix crash opening avatar picker in non-en-US locale.
This fixes a crash seen when opening the avatar picker if the current language is not en-US. The crash occurs because content descriptions are provided in a sring array in an overlay, but the base empty array has been translated and is replacing the actual descriptions in non-default locales. This CL adds translatable=false to the base array, and adds a check to not crash if the content descriptions array is smaller than the images array. Bug: 284422901 Test: Manual, try opening avatar picker in various locales. Change-Id: I4a518cd37c4ca7139d182612cd02d79489948474
-rw-r--r--packages/SettingsLib/res/values/arrays.xml6
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java2
2 files changed, 5 insertions, 3 deletions
diff --git a/packages/SettingsLib/res/values/arrays.xml b/packages/SettingsLib/res/values/arrays.xml
index 3e2b800d5a2c..3adb882bc1b1 100644
--- a/packages/SettingsLib/res/values/arrays.xml
+++ b/packages/SettingsLib/res/values/arrays.xml
@@ -643,8 +643,10 @@
array must also be populated with a content description for each image. -->
<array name="avatar_images"/>
- <!-- Content descriptions for each of the images in the avatar_images array. -->
- <string-array name="avatar_image_descriptions"/>
+ <!-- Content descriptions for each of the images in the avatar_images array. When overlaid
+ these values should be translated, but this empty array must not be translated or it may
+ replace the real descriptions with an empty array. -->
+ <string-array name="avatar_image_descriptions" translatable="false"/>
<!-- NOTE: if you change this, you must also add the corresponding scale key and lookup table to
frameworks/base/core/java/android/content/res/FontScaleConverterFactory.java -->
diff --git a/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java b/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java
index bcbd1caa45d3..848b177c821f 100644
--- a/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java
+++ b/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java
@@ -243,7 +243,7 @@ public class AvatarPickerActivity extends Activity {
int index = indexFromPosition(position);
viewHolder.setSelected(position == mSelectedPosition);
viewHolder.setDrawable(mImageDrawables.get(index));
- if (mImageDescriptions != null) {
+ if (mImageDescriptions != null && index < mImageDescriptions.size()) {
viewHolder.setContentDescription(mImageDescriptions.get(index));
} else {
viewHolder.setContentDescription(getString(