Fix crash issue when NetworkSelectSettings UI goes OFF and then ON

When updating selected preference instance by index, since
mPreferenceCategory hasn't been updated yet, and then there is a
possibility that the index is over the size of preference, so this
would result to Settings crash because IndexOutOfBoundsException
was detected in NetworkSelectSettings.
After updating the network preferences of mPreferenceCategory, update
the selected preference.

Test: manual - Checked that crash does not occur when
NetworkSelectSettings UI goes OFF and then ON.
Test: auto - Passed NetworkSelectSettingsTest.
Bug: 179754915

Change-Id: Ib736fe8fdcc82c3ac01ad1828d0f2a1c24610f2b
This commit is contained in:
Jing Ji
2021-01-26 17:57:24 +08:00
committed by takeshi tanigawa
parent ace5a90870
commit 492e985708

View File

@@ -343,16 +343,6 @@ public class NetworkSelectSettings extends DashboardFragment {
mPreferenceCategory.getPreference(numberOfPreferences));
}
// update selected preference instance by index
for (int index = 0; index < mCellInfoList.size(); index++) {
final CellInfo cellInfo = mCellInfoList.get(index);
if ((mSelectedPreference != null) && mSelectedPreference.isSameCell(cellInfo)) {
mSelectedPreference = (NetworkOperatorPreference)
(mPreferenceCategory.getPreference(index));
}
}
// update the content of preference
NetworkOperatorPreference connectedPref = null;
for (int index = 0; index < mCellInfoList.size(); index++) {
@@ -386,6 +376,16 @@ public class NetworkSelectSettings extends DashboardFragment {
}
}
// update selected preference instance by index
for (int index = 0; index < mCellInfoList.size(); index++) {
final CellInfo cellInfo = mCellInfoList.get(index);
if ((mSelectedPreference != null) && mSelectedPreference.isSameCell(cellInfo)) {
mSelectedPreference = (NetworkOperatorPreference)
(mPreferenceCategory.getPreference(index));
}
}
return connectedPref;
}