Added cellular data popup in DataUsage

+ If the user attempts to enable data usage on a SIM that is not the
default, the system will confirm that the user wants data to go through
the new SIM.

Change-Id: Ia1652a30a3641bb29eadad20b2dc61321227a961
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index 6ee0ef0..6ad1b9c 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -1112,7 +1112,12 @@
             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 @@
         }
     };
 
+    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 @@
         private void addMobileTab(Context context, List<SubInfoRecord> 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 @@
             }
         }
 
+        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