diff --git a/res/values/strings.xml b/res/values/strings.xml index f8721c395f2..edbf03ca68e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2114,6 +2114,10 @@ Multiple SIMs found Choose the SIM you prefer for cellular data. + + Change data SIM? + + Use %1$s instead of %2$s for cellular data? diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java index 6ee0ef056fd..6ad1b9c26a8 100644 --- a/src/com/android/settings/DataUsageSummary.java +++ b/src/com/android/settings/DataUsageSummary.java @@ -1112,7 +1112,12 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable final String currentTab = mCurrentTab; if (isMobileTab(currentTab)) { if (dataEnabled) { - setMobileDataEnabled(true); + // If we are showing the Sim Card tile then we are a Multi-Sim device. + if (Utils.showSimCardTile(getActivity())) { + handleMultiSimDataDialog(); + } else { + setMobileDataEnabled(true); + } } else { // disabling data; show confirmation dialog which eventually // calls setMobileDataEnabled() once user confirms. @@ -1124,6 +1129,36 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable } }; + private void handleMultiSimDataDialog() { + final SubInfoRecord currentSir = getCurrentTabSubInfo(getActivity()); + final SubInfoRecord nextSir = SubscriptionManager.getSubInfoForSubscriber( + SubscriptionManager.getDefaultDataSubId()); + + if (currentSir.subId == nextSir.subId) { + setMobileDataEnabled(true); + updateBody(); + return; + } + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + + builder.setTitle(R.string.sim_change_data_title); + builder.setMessage(getActivity().getResources().getString(R.string.sim_change_data_message, + currentSir.displayName, nextSir.displayName)); + + builder.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + SubscriptionManager.setDefaultDataSubId(currentSir.subId); + setMobileDataEnabled(true); + updateBody(); + } + }); + builder.setNegativeButton(R.string.cancel, null); + + builder.create().show(); + } + private View.OnClickListener mDisableAtLimitListener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -2553,7 +2588,7 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable private void addMobileTab(Context context, List subInfoList) { if (subInfoList != null) { for (SubInfoRecord subInfo : mSubInfoList) { - if (hasReadyMobileRadio(context,subInfo.subId)) { + if (hasReadyMobileRadio(context, subInfo.subId)) { mTabHost.addTab(buildTabSpec(mMobileTagMap.get(subInfo.subId), subInfo.displayName)); } @@ -2561,6 +2596,21 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable } } + private SubInfoRecord getCurrentTabSubInfo(Context context) { + if (mSubInfoList != null && mTabHost != null) { + final int currentTagIndex = mTabHost.getCurrentTab(); + int i = 0; + for (SubInfoRecord subInfo : mSubInfoList) { + if (hasReadyMobileRadio(context, subInfo.subId)) { + if (i++ == currentTagIndex) { + return subInfo; + } + } + } + } + return null; + } + /** * Init a map with subId key and mobile tag name * @param subInfoList The subscription Info List