From 98523c8b8b90d011604d3a7e83a6b708f7b5e5ce Mon Sep 17 00:00:00 2001 From: PauloftheWest Date: Tue, 28 Oct 2014 08:30:05 -0700 Subject: [PATCH] Added Cellular Data for Multi-Sim Data Usage + Bug Fix: SimSettings would crash if a SIM was not in the first slot. Change-Id: Iee75ea78dde72dc7d2d588caff1ddd451347a8f5 --- src/com/android/settings/DataUsageSummary.java | 20 +++++++++++++++++--- src/com/android/settings/sim/SimSettings.java | 18 +++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java index ba0d24dad7..6ee0ef056f 100644 --- a/src/com/android/settings/DataUsageSummary.java +++ b/src/com/android/settings/DataUsageSummary.java @@ -941,7 +941,8 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable mMobileDataEnabled = null; } else { //SUB SELECT - isEnable = mTelephonyManager.getDataEnabled() && isMobileDataAvailable(subId); + isEnable = mTelephonyManager.getDataEnabled() + && (subId == SubscriptionManager.getDefaultDataSubId()); } return isEnable; } @@ -2594,8 +2595,21 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable } //SUB SELECT - private boolean isMobileDataAvailable(int subId) { + private boolean isMobileDataAvailable(long subId) { int[] subIds = SubscriptionManager.getSubId(PhoneConstants.SUB1); - return subIds[0] == subId; + if (subIds != null && subIds[0] == subId) { + return true; + } + + subIds = SubscriptionManager.getSubId(PhoneConstants.SUB2); + if (subIds != null && subIds[0] == subId) { + return true; + } + + subIds = SubscriptionManager.getSubId(PhoneConstants.SUB3); + if (subIds != null && subIds[0] == subId) { + return true; + } + return false; } } diff --git a/src/com/android/settings/sim/SimSettings.java b/src/com/android/settings/sim/SimSettings.java index edad591de2..3558ecc219 100644 --- a/src/com/android/settings/sim/SimSettings.java +++ b/src/com/android/settings/sim/SimSettings.java @@ -121,9 +121,11 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable * By UX design we use only one Subscription Information(SubInfo) record per SIM slot. * mAvalableSubInfos is the list of SubInfos we present to the user. * mSubInfoList is the list of all SubInfos. + * mSelectableSubInfos is the list of SubInfos that a user can select for data, calls, and SMS. */ private List mAvailableSubInfos = null; private List mSubInfoList = null; + private List mSelectableSubInfos = null; private SubInfoRecord mCellularData = null; private SubInfoRecord mCalls = null; @@ -186,6 +188,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable final int numSlots = tm.getSimCount(); mAvailableSubInfos = new ArrayList(numSlots); + mSelectableSubInfos = new ArrayList(); mNumSims = 0; for (int i = 0; i < numSlots; ++i) { final SubInfoRecord sir = findRecordBySlotId(i); @@ -193,6 +196,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable mAvailableSubInfos.add(sir); if (sir != null) { mNumSims++; + mSelectableSubInfos.add(sir); } } @@ -345,7 +349,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable @Override public Dialog onCreateDialog(final int id) { final ArrayList list = new ArrayList(); - final int availableSubInfoLength = mAvailableSubInfos.size(); + final int selectableSubInfoLength = mSelectableSubInfos.size(); final DialogInterface.OnClickListener selectionListener = new DialogInterface.OnClickListener() { @@ -355,18 +359,18 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable final SubInfoRecord sir; if (id == DATA_PICK) { - sir = mAvailableSubInfos.get(value); + sir = mSelectableSubInfos.get(value); SubscriptionManager.setDefaultDataSubId(sir.subId); } else if (id == CALLS_PICK) { if (value != 0) { - sir = mAvailableSubInfos.get(value -1); + sir = mSelectableSubInfos.get(value -1); SubscriptionManager.setDefaultVoiceSubId(sir.subId); } else { SubscriptionManager .setDefaultVoiceSubId(SubscriptionManager.ASK_USER_SUB_ID); } } else if (id == SMS_PICK) { - sir = mAvailableSubInfos.get(value); + sir = mSelectableSubInfos.get(value); SubscriptionManager.setDefaultSmsSubId(sir.subId); } @@ -377,12 +381,12 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable if (id == CALLS_PICK) { list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title)); } - for (int i = 0; i < availableSubInfoLength; ++i) { - final SubInfoRecord sir = mAvailableSubInfos.get(i); + for (int i = 0; i < selectableSubInfoLength; ++i) { + final SubInfoRecord sir = mSelectableSubInfos.get(i); list.add(sir.displayName); } - String[] arr = new String[availableSubInfoLength]; + String[] arr = new String[selectableSubInfoLength]; arr = list.toArray(arr); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); -- 2.11.0