From b1dd4299c4efd92036c76e42180fc04a23d1e7ba Mon Sep 17 00:00:00 2001 From: Michael W Date: Fri, 28 Jul 2017 19:03:51 +0200 Subject: [PATCH] SetupWizard: Fix a few possible NPEs * Accessing SparseArrays with zero-based indexes can fail due to non-used indexes * mCheckBoxes and mRows should always be accessed with the key they were added -> use keyAt(index) when iterating the SparseArray -> use the simSlotIndex when iterating the subInfoRecords BUGBASH-318 BUGBASH-610 (partially) Change-Id: Ib831c3623dafa5bd7d0c95acfa69f4a686644be6 --- .../setupwizard/ChooseDataSimActivity.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/com/cyanogenmod/setupwizard/ChooseDataSimActivity.java b/src/com/cyanogenmod/setupwizard/ChooseDataSimActivity.java index b1de6155..725ade96 100644 --- a/src/com/cyanogenmod/setupwizard/ChooseDataSimActivity.java +++ b/src/com/cyanogenmod/setupwizard/ChooseDataSimActivity.java @@ -327,12 +327,12 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity { private void setDataSubChecked(SubscriptionInfo subInfoRecord) { if (mIsAttached) { for (int i = 0; i < mCheckBoxes.size(); i++) { - if (subInfoRecord.getSimSlotIndex() == i) { - mCheckBoxes.get(i).setChecked(true); + int key = mCheckBoxes.keyAt(i); + if (subInfoRecord.getSimSlotIndex() == key) { + mCheckBoxes.get(key).setChecked(true); } else { - mCheckBoxes.get(i).setChecked(false); + mCheckBoxes.get(key).setChecked(false); } - } } } @@ -341,7 +341,8 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity { if (mIsAttached) { for (int i = 0; i < mSubInfoRecords.size(); i++) { SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i); - mCheckBoxes.get(i).setChecked(SubscriptionManager.getDefaultDataSubscriptionId() + int slot = subInfoRecord.getSimSlotIndex(); + mCheckBoxes.get(slot).setChecked(SubscriptionManager.getDefaultDataSubscriptionId() == subInfoRecord.getSubscriptionId()); if (LOGV) { Log.v(TAG, "updateCurrentDataSub{" + @@ -363,7 +364,7 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity { private void enableRows(boolean enabled) { for (int i = 0; i < mRows.size(); i++) { - final View v = mRows.get(i); + final View v = mRows.get(mRows.keyAt(i)); v.setEnabled(enabled); final SubscriptionInfo subInfoRecord = (SubscriptionInfo)v.getTag(); if (subInfoRecord != null) {