Commit b1dd4299 authored by Michael W's avatar Michael W
Browse files

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
parent fe4f0107
...@@ -327,12 +327,12 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity { ...@@ -327,12 +327,12 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity {
private void setDataSubChecked(SubscriptionInfo subInfoRecord) { private void setDataSubChecked(SubscriptionInfo subInfoRecord) {
if (mIsAttached) { if (mIsAttached) {
for (int i = 0; i < mCheckBoxes.size(); i++) { for (int i = 0; i < mCheckBoxes.size(); i++) {
if (subInfoRecord.getSimSlotIndex() == i) { int key = mCheckBoxes.keyAt(i);
mCheckBoxes.get(i).setChecked(true); if (subInfoRecord.getSimSlotIndex() == key) {
mCheckBoxes.get(key).setChecked(true);
} else { } else {
mCheckBoxes.get(i).setChecked(false); mCheckBoxes.get(key).setChecked(false);
} }
} }
} }
} }
...@@ -341,7 +341,8 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity { ...@@ -341,7 +341,8 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity {
if (mIsAttached) { if (mIsAttached) {
for (int i = 0; i < mSubInfoRecords.size(); i++) { for (int i = 0; i < mSubInfoRecords.size(); i++) {
SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i); SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i);
mCheckBoxes.get(i).setChecked(SubscriptionManager.getDefaultDataSubscriptionId() int slot = subInfoRecord.getSimSlotIndex();
mCheckBoxes.get(slot).setChecked(SubscriptionManager.getDefaultDataSubscriptionId()
== subInfoRecord.getSubscriptionId()); == subInfoRecord.getSubscriptionId());
if (LOGV) { if (LOGV) {
Log.v(TAG, "updateCurrentDataSub{" + Log.v(TAG, "updateCurrentDataSub{" +
...@@ -363,7 +364,7 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity { ...@@ -363,7 +364,7 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity {
private void enableRows(boolean enabled) { private void enableRows(boolean enabled) {
for (int i = 0; i < mRows.size(); i++) { 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); v.setEnabled(enabled);
final SubscriptionInfo subInfoRecord = (SubscriptionInfo)v.getTag(); final SubscriptionInfo subInfoRecord = (SubscriptionInfo)v.getTag();
if (subInfoRecord != null) { if (subInfoRecord != null) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment