Merge "Made the WPS icon visisble." into lmp-mr1-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 89d696d..6c2ffbd 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1114,6 +1114,7 @@
         </activity>
 
         <activity android:name=".SetupRedactionInterstitial"
+            android:taskAffinity="com.android.wizard"
             android:theme="@style/SetupWizardDisableAppStartingTheme"/>
 
         <activity android:name=".notification.RedactionInterstitial"/>
@@ -1168,12 +1169,14 @@
 
         <activity android:name="SetupChooseLockPattern"
             android:exported="false"
+            android:taskAffinity="com.android.wizard"
             android:theme="@style/SetupWizardDisableAppStartingTheme" />
 
         <activity android:name="ChooseLockPattern" android:exported="false"/>
 
         <activity android:name="SetupChooseLockPassword"
             android:exported="false"
+            android:taskAffinity="com.android.wizard"
             android:theme="@style/SetupWizardDisableAppStartingTheme"
             android:windowSoftInputMode="stateVisible|adjustResize" />
 
@@ -1181,6 +1184,7 @@
             android:windowSoftInputMode="stateVisible|adjustResize"/>
 
         <activity android:name=".SetupEncryptionInterstitial"
+            android:taskAffinity="com.android.wizard"
             android:theme="@style/SetupWizardDisableAppStartingTheme"/>
 
         <activity android:name=".EncryptionInterstitial"/>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 74062ae..58b8b8e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5519,6 +5519,8 @@
     <string name="sim_calls_always_use">Always use this for calls</string>
     <!-- Message for selecting sim for data in settings.  [CHAR LIMIT=40] -->
     <string name="select_sim_for_data">Select a SIM for data</string>
+    <!-- Message for switching data SIM; switching takes a while -->
+    <string name="data_switch_started">Switching data SIM, this may take up to a minute...</string>
     <!-- Message for selecting sim for call in settings.  [CHAR LIMIT=40] -->
     <string name="select_sim_for_calls">Call with</string>
     <!-- Title for selecting a SIM card.  [CHAR LIMIT=40] -->
diff --git a/src/com/android/settings/deviceinfo/ImeiInformation.java b/src/com/android/settings/deviceinfo/ImeiInformation.java
index 72d3158..38fd335 100644
--- a/src/com/android/settings/deviceinfo/ImeiInformation.java
+++ b/src/com/android/settings/deviceinfo/ImeiInformation.java
@@ -63,8 +63,8 @@
         }
     }
 
-    private void setPreferenceValue(int slotId) {
-        final Phone phone = getPhoneFromSlotId(slotId);
+    private void setPreferenceValue(int phoneId) {
+        final Phone phone = PhoneFactory.getPhone(phoneId);
 
         if (phone != null) {
             if (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
@@ -92,7 +92,7 @@
                 setSummaryText(KEY_IMEI, phone.getDeviceId());
                 setSummaryText(KEY_IMEI_SV,
                         ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
-                        .getDeviceSoftwareVersion(/*slotId*/));
+                        .getDeviceSoftwareVersion(phoneId));
                 // device is not CDMA, do not display CDMA features
                 // check Null in case no specified preference in overlay xml
                 removePreferenceFromScreen(KEY_PRL_VERSION);
@@ -103,24 +103,6 @@
         }
     }
 
-    private Phone getPhoneFromSlotId(int slotIdx) {
-        final SubscriptionInfo subInfo =
-                mSubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(slotIdx);
-
-        if (subInfo == null) {
-            return null;
-        }
-
-        final Phone[] phones = PhoneFactory.getPhones();
-        for (int i = 0; i < phones.length; i++) {
-            if (phones[i].getSubId() == subInfo.getSubscriptionId()) {
-                return phones[i];
-            }
-        }
-
-        return null;
-    }
-
     // Modify the preference key with prefix "_", so new added information preference can be set
     // related phone information.
     private void setNewKey(int slotId) {
diff --git a/src/com/android/settings/deviceinfo/SimStatus.java b/src/com/android/settings/deviceinfo/SimStatus.java
index 6c52412..1300419 100644
--- a/src/com/android/settings/deviceinfo/SimStatus.java
+++ b/src/com/android/settings/deviceinfo/SimStatus.java
@@ -343,7 +343,7 @@
             }
         }
 
-        String rawNumber = mTelephonyManager.getLine1Number();  // may be null or empty
+        String rawNumber = mTelephonyManager.getLine1NumberForSubscriber(mSir.getSubscriptionId());
         String formattedNumber = null;
         if (!TextUtils.isEmpty(rawNumber)) {
             formattedNumber = PhoneNumberUtils.formatNumber(rawNumber);
diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java
index 6aceb46..4201868 100644
--- a/src/com/android/settings/sim/SimDialogActivity.java
+++ b/src/com/android/settings/sim/SimDialogActivity.java
@@ -39,6 +39,7 @@
 import android.widget.ImageView;
 import android.widget.ListAdapter;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.android.settings.R;
 import com.android.settings.Utils;
@@ -115,6 +116,7 @@
     private static void setDefaultDataSubId(final Context context, final int subId) {
         final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
         subscriptionManager.setDefaultDataSubId(subId);
+        Toast.makeText(context, R.string.data_switch_started, Toast.LENGTH_LONG).show();
     }
 
     private static void setDefaultSmsSubId(final Context context, final int subId) {
@@ -198,16 +200,26 @@
                 }
             };
 
+        ArrayList<SubscriptionInfo> callsSubInfoList = new ArrayList<SubscriptionInfo>();
         if (id == CALLS_PICK) {
             final TelecomManager telecomManager = TelecomManager.from(context);
             final Iterator<PhoneAccountHandle> phoneAccounts =
                     telecomManager.getCallCapablePhoneAccounts().listIterator();
 
             list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
+            callsSubInfoList.add(null);
             while (phoneAccounts.hasNext()) {
                 final PhoneAccount phoneAccount =
                         telecomManager.getPhoneAccount(phoneAccounts.next());
                 list.add((String)phoneAccount.getLabel());
+                if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
+                    final String phoneAccountId = phoneAccount.getAccountHandle().getId();
+                    final SubscriptionInfo sir = Utils.findRecordBySubId(context,
+                            Integer.parseInt(phoneAccountId));
+                    callsSubInfoList.add(sir);
+                } else {
+                    callsSubInfoList.add(null);
+                }
             }
         } else {
             for (int i = 0; i < selectableSubInfoLength; ++i) {
@@ -225,7 +237,7 @@
         AlertDialog.Builder builder = new AlertDialog.Builder(context);
 
         ListAdapter adapter = new SelectAccountListAdapter(
-                subInfoList,
+                id == CALLS_PICK ? callsSubInfoList : subInfoList,
                 builder.getContext(),
                 R.layout.select_account_list_item,
                 arr, id);
@@ -274,7 +286,6 @@
                     mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             View rowView;
             final ViewHolder holder;
-            SubscriptionInfo sir;
 
             if (convertView == null) {
                 // Cache views for faster scrolling
@@ -289,14 +300,14 @@
                 holder = (ViewHolder) rowView.getTag();
             }
 
-            if (mDialogId == CALLS_PICK) {
+            final SubscriptionInfo sir = mSubInfoList.get(position);
+            if (sir == null) {
                 holder.title.setText(getItem(position));
                 holder.summary.setText("");
                 holder.icon.setImageDrawable(getResources()
                         .getDrawable(R.drawable.ic_live_help));
                 holder.icon.setAlpha(OPACITY);
             } else {
-                sir = mSubInfoList.get(position);
                 holder.title.setText(sir.getDisplayName());
                 holder.summary.setText(sir.getNumber());
                 holder.icon.setImageBitmap(sir.createIconBitmap(mContext));
diff --git a/src/com/android/settings/sim/SimSettings.java b/src/com/android/settings/sim/SimSettings.java
index 450ffff..92a10d6 100644
--- a/src/com/android/settings/sim/SimSettings.java
+++ b/src/com/android/settings/sim/SimSettings.java
@@ -18,26 +18,21 @@
 
 import android.app.AlertDialog;
 import android.content.Context;
-import android.content.ContentUris;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.Resources;
-import android.database.Cursor;
 import android.graphics.Paint;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.ShapeDrawable;
 import android.graphics.drawable.shapes.OvalShape;
-import android.net.Uri;
 import android.os.Bundle;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
 import android.provider.SearchIndexableResource;
-import android.provider.Telephony;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.telephony.PhoneNumberUtils;
-import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
 import android.text.TextUtils;
@@ -49,12 +44,8 @@
 import android.widget.ImageView;
 import android.widget.Spinner;
 import android.widget.TextView;
-import android.app.Dialog;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
-import android.widget.ListAdapter;
-
-import com.android.internal.telephony.PhoneFactory;
 import com.android.settings.RestrictedSettingsFragment;
 import com.android.settings.Utils;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -62,9 +53,6 @@
 import com.android.settings.R;
 
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
 import java.util.List;
 
 public class SimSettings extends RestrictedSettingsFragment implements Indexable {
@@ -122,6 +110,7 @@
     private SubscriptionManager mSubscriptionManager;
     private Utils mUtils;
 
+
     public SimSettings() {
         super(DISALLOW_CONFIG_SIM);
     }
@@ -283,152 +272,6 @@
         return true;
     }
 
-    @Override
-    public Dialog onCreateDialog(final int id) {
-        final ArrayList<String> list = new ArrayList<String>();
-        final int selectableSubInfoLength = mSelectableSubInfos.size();
-
-        final DialogInterface.OnClickListener selectionListener =
-                new DialogInterface.OnClickListener() {
-                    @Override
-                    public void onClick(DialogInterface dialog, int value) {
-
-                        final SubscriptionInfo sir;
-
-                        if (id == DATA_PICK) {
-                            sir = mSelectableSubInfos.get(value);
-                            mSubscriptionManager.setDefaultDataSubId(sir.getSubscriptionId());
-                        } else if (id == CALLS_PICK) {
-                            final TelecomManager telecomManager =
-                                    TelecomManager.from(getActivity());
-                            final List<PhoneAccountHandle> phoneAccountsList =
-                                    telecomManager.getCallCapablePhoneAccounts();
-                            telecomManager.setUserSelectedOutgoingPhoneAccount(
-                                    value < 1 ? null : phoneAccountsList.get(value - 1));
-                        } else if (id == SMS_PICK) {
-                            sir = mSelectableSubInfos.get(value);
-                            mSubscriptionManager.setDefaultSmsSubId(sir.getSubscriptionId());
-                        }
-
-                        updateActivitesCategory();
-                    }
-                };
-
-        if (id == CALLS_PICK) {
-            final TelecomManager telecomManager = TelecomManager.from(getActivity());
-            final Iterator<PhoneAccountHandle> phoneAccounts =
-                    telecomManager.getCallCapablePhoneAccounts().listIterator();
-
-            list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
-            while (phoneAccounts.hasNext()) {
-                final PhoneAccount phoneAccount =
-                        telecomManager.getPhoneAccount(phoneAccounts.next());
-                list.add((String)phoneAccount.getLabel());
-            }
-        } else {
-            for (int i = 0; i < selectableSubInfoLength; ++i) {
-                final SubscriptionInfo sir = mSelectableSubInfos.get(i);
-                CharSequence displayName = sir.getDisplayName();
-                if (displayName == null) {
-                    displayName = "";
-                }
-                list.add(displayName.toString());
-            }
-        }
-
-        String[] arr = list.toArray(new String[0]);
-
-        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-
-        ListAdapter adapter = new SelectAccountListAdapter(
-                builder.getContext(),
-                R.layout.select_account_list_item,
-                arr, id);
-
-        if (id == DATA_PICK) {
-            builder.setTitle(R.string.select_sim_for_data);
-        } else if (id == CALLS_PICK) {
-            builder.setTitle(R.string.select_sim_for_calls);
-        } else if (id == SMS_PICK) {
-            builder.setTitle(R.string.sim_card_select_title);
-        }
-
-        return builder.setAdapter(adapter, selectionListener)
-            .create();
-    }
-
-    private class SelectAccountListAdapter extends ArrayAdapter<String> {
-        private Context mContext;
-        private int mResId;
-        private int mDialogId;
-        private final float OPACITY = 0.54f;
-
-        public SelectAccountListAdapter(
-                Context context, int resource, String[] arr, int dialogId) {
-            super(context, resource, arr);
-            mContext = context;
-            mResId = resource;
-            mDialogId = dialogId;
-        }
-
-        @Override
-        public View getView(int position, View convertView, ViewGroup parent) {
-            LayoutInflater inflater = (LayoutInflater)
-                    mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-            View rowView;
-            final ViewHolder holder;
-            SubscriptionInfo sir;
-
-            if (convertView == null) {
-                // Cache views for faster scrolling
-                rowView = inflater.inflate(mResId, null);
-                holder = new ViewHolder();
-                holder.title = (TextView) rowView.findViewById(R.id.title);
-                holder.summary = (TextView) rowView.findViewById(R.id.summary);
-                holder.icon = (ImageView) rowView.findViewById(R.id.icon);
-                rowView.setTag(holder);
-            } else {
-                rowView = convertView;
-                holder = (ViewHolder) rowView.getTag();
-            }
-
-            if (mDialogId == CALLS_PICK) {
-                holder.title.setText(getItem(position));
-                if (position == 0) {
-                    holder.icon.setImageDrawable(getResources()
-                            .getDrawable(R.drawable.ic_live_help));
-                    holder.icon.setAlpha(OPACITY);
-                    holder.summary.setText("");
-                } else {
-                    final TelecomManager telecomManager = TelecomManager.from(getActivity());
-                    final Iterator<PhoneAccountHandle> phoneAccounts =
-                            telecomManager.getCallCapablePhoneAccounts().listIterator();
-                    while (phoneAccounts.hasNext()) {
-                        final PhoneAccount phoneAccount =
-                                telecomManager.getPhoneAccount(phoneAccounts.next());
-                        if (getItem(position).equals((String) phoneAccount.getLabel())) {
-                            holder.icon.setImageBitmap(phoneAccount.getIconBitmap());
-                            holder.summary
-                                    .setText(phoneAccount.getAddress().getSchemeSpecificPart());
-                        }
-                    }
-                }
-            } else {
-                sir = mSelectableSubInfos.get(position);
-                holder.title.setText(sir.getDisplayName());
-                holder.summary.setText(getPhoneNumber(sir));
-                holder.icon.setImageBitmap(sir.createIconBitmap(mContext));
-            }
-            return rowView;
-        }
-
-        private class ViewHolder {
-            TextView title;
-            TextView summary;
-            ImageView icon;
-        }
-    }
-
     private class SimPreference extends Preference{
         private SubscriptionInfo mSubInfoRecord;
         private int mSlotId;