From c655c82ada4a2953d85f3e35d60264e772951266 Mon Sep 17 00:00:00 2001 From: Ken Lin Date: Wed, 5 Jul 2023 05:05:29 +0000 Subject: [PATCH] Settings crashed when changing the Screen Resolution Check if index is out of bound Bug: 288256336 Test: Change to Full resolution, set Smallest width to 426 dp, then switch to High resolution Test: atest ScreenResolutionFragmentTest Change-Id: Ida4128e76e097050b01deae91c9d669e58ab9e8f --- .../android/settings/display/ScreenResolutionFragment.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/com/android/settings/display/ScreenResolutionFragment.java b/src/com/android/settings/display/ScreenResolutionFragment.java index de7d25fefb9..daf1793f11f 100644 --- a/src/com/android/settings/display/ScreenResolutionFragment.java +++ b/src/com/android/settings/display/ScreenResolutionFragment.java @@ -369,6 +369,12 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { private void restoreDensity() { final DisplayDensityUtils density = new DisplayDensityUtils(mContext); + /* If current density is the same as a default density of other resolutions, + * then mCurrentIndex may be out of boundary. + */ + if (density.getDefaultDisplayDensityValues().length <= mCurrentIndex) { + mCurrentIndex = density.getCurrentIndexForDefaultDisplay(); + } if (density.getDefaultDisplayDensityValues()[mCurrentIndex] != density.getDefaultDensityForDefaultDisplay()) { density.setForcedDisplayDensity(mCurrentIndex);