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
This commit is contained in:
Oli Lan
2023-06-14 11:26:32 +01:00
parent b4b4f2042d
commit f756b2623f
2 changed files with 5 additions and 3 deletions

View File

@@ -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 -->

View File

@@ -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(