Merge "Use the right message for pattern/password." into lmp-mr1-dev
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 961fb2f..9e3161d 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -22,12 +22,12 @@
 
     <color name="memory_used">#F00</color>
     <color name="memory_avail">@color/material_empty_color_light</color>
-    <color name="memory_apps_usage">#77831A</color>
-    <color name="memory_downloads">#476093</color>
-    <color name="memory_dcim">#793A7F</color>
-    <color name="memory_music">#8E562A</color>
-    <color name="memory_cache">#479392</color>
-    <color name="memory_misc">#7C3030</color>
+    <color name="memory_apps_usage">#00796B</color>
+    <color name="memory_downloads">#3367D6</color>
+    <color name="memory_dcim">#0097A7</color>
+    <color name="memory_music">#689F38</color>
+    <color name="memory_cache">#283593</color>
+    <color name="memory_misc">#7B1FA2</color>
     <color name="memory_user_light">#479392</color>
     <color name="memory_user_dark">#316665</color>
 
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 8d6e55c..e150d75 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -60,6 +60,8 @@
 import android.provider.ContactsContract.Profile;
 import android.provider.ContactsContract.RawContacts;
 import android.service.persistentdata.PersistentDataBlockManager;
+import android.telephony.SubInfoRecord;
+import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
@@ -981,4 +983,42 @@
         }
         return sb.toString();
     }
+
+    /**
+     * finds a record with subId.
+     * Since the number of SIMs are few, an array is fine.
+     */
+    public static SubInfoRecord findRecordBySubId(final int subId) {
+        final List<SubInfoRecord> subInfoList = SubscriptionManager.getActiveSubInfoList();
+        final int subInfoLength = subInfoList.size();
+
+        for (int i = 0; i < subInfoLength; ++i) {
+            final SubInfoRecord sir = subInfoList.get(i);
+            if (sir != null && sir.getSubscriptionId() == subId) {
+                return sir;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * finds a record with slotId.
+     * Since the number of SIMs are few, an array is fine.
+     */
+    public static SubInfoRecord findRecordBySlotId(final int slotId) {
+        final List<SubInfoRecord> subInfoList = SubscriptionManager.getActiveSubInfoList();
+        final int subInfoLength = subInfoList.size();
+
+        for (int i = 0; i < subInfoLength; ++i) {
+            final SubInfoRecord sir = subInfoList.get(i);
+            if (sir.getSimSlotIndex() == slotId) {
+                //Right now we take the first subscription on a SIM.
+                return sir;
+            }
+        }
+
+        return null;
+    }
+
 }
diff --git a/src/com/android/settings/sim/SimSettings.java b/src/com/android/settings/sim/SimSettings.java
index f09fb2b..f4b5887 100644
--- a/src/com/android/settings/sim/SimSettings.java
+++ b/src/com/android/settings/sim/SimSettings.java
@@ -115,33 +115,6 @@
     private PreferenceCategory mSimCards = null;
 
     private int mNumSims;
-    /**
-     * Standard projection for the interesting columns of a normal note.
-     */
-    private static final String[] sProjection = new String[] {
-            Telephony.Carriers._ID,     // 0
-            Telephony.Carriers.NAME,    // 1
-            Telephony.Carriers.APN,     // 2
-            Telephony.Carriers.PROXY,   // 3
-            Telephony.Carriers.PORT,    // 4
-            Telephony.Carriers.USER,    // 5
-            Telephony.Carriers.SERVER,  // 6
-            Telephony.Carriers.PASSWORD, // 7
-            Telephony.Carriers.MMSC, // 8
-            Telephony.Carriers.MCC, // 9
-            Telephony.Carriers.MNC, // 10
-            Telephony.Carriers.NUMERIC, // 11
-            Telephony.Carriers.MMSPROXY,// 12
-            Telephony.Carriers.MMSPORT, // 13
-            Telephony.Carriers.AUTH_TYPE, // 14
-            Telephony.Carriers.TYPE, // 15
-            Telephony.Carriers.PROTOCOL, // 16
-            Telephony.Carriers.CARRIER_ENABLED, // 17
-            Telephony.Carriers.BEARER, // 18
-            Telephony.Carriers.ROAMING_PROTOCOL, // 19
-            Telephony.Carriers.MVNO_TYPE,   // 20
-            Telephony.Carriers.MVNO_MATCH_DATA  // 21
-    };
 
     public SimSettings() {
         super(DISALLOW_CONFIG_SIM);
@@ -172,7 +145,7 @@
         mSelectableSubInfos = new ArrayList<SubInfoRecord>();
         mNumSims = 0;
         for (int i = 0; i < numSlots; ++i) {
-            final SubInfoRecord sir = findRecordBySlotId(i);
+            final SubInfoRecord sir = Utils.findRecordBySlotId(i);
             mSimCards.addPreference(new SimPreference(getActivity(), sir, i));
             mAvailableSubInfos.add(sir);
             if (sir != null) {
@@ -192,7 +165,7 @@
         mNumSims = 0;
         mAvailableSubInfos = new ArrayList<SubInfoRecord>(numSlots);
         for (int i = 0; i < numSlots; ++i) {
-            final SubInfoRecord sir = findRecordBySlotId(i);
+            final SubInfoRecord sir = Utils.findRecordBySlotId(i);
             mAvailableSubInfos.add(sir);
             if (sir != null) {
                 mNumSims++;
@@ -223,46 +196,9 @@
         updateSmsValues();
     }
 
-    /**
-     * finds a record with subId.
-     * Since the number of SIMs are few, an array is fine.
-     */
-    private SubInfoRecord findRecordBySubId(final int subId) {
-        final int availableSubInfoLength = mAvailableSubInfos.size();
-
-        for (int i = 0; i < availableSubInfoLength; ++i) {
-            final SubInfoRecord sir = mAvailableSubInfos.get(i);
-            if (sir != null && sir.getSubscriptionId() == subId) {
-                return sir;
-            }
-        }
-
-        return null;
-    }
-
-    /**
-     * finds a record with slotId.
-     * Since the number of SIMs are few, an array is fine.
-     */
-    private SubInfoRecord findRecordBySlotId(final int slotId) {
-        if (mSubInfoList != null){
-            final int availableSubInfoLength = mSubInfoList.size();
-
-            for (int i = 0; i < availableSubInfoLength; ++i) {
-                final SubInfoRecord sir = mSubInfoList.get(i);
-                if (sir.getSimSlotIndex() == slotId) {
-                    //Right now we take the first subscription on a SIM.
-                    return sir;
-                }
-            }
-        }
-
-        return null;
-    }
-
     private void updateSmsValues() {
-        final Preference simPref = (Preference) findPreference(KEY_SMS);
-        final SubInfoRecord sir = findRecordBySubId(SubscriptionManager.getDefaultSmsSubId());
+        final Preference simPref = findPreference(KEY_SMS);
+        final SubInfoRecord sir = Utils.findRecordBySubId(SubscriptionManager.getDefaultSmsSubId());
         simPref.setTitle(R.string.sms_messages_title);
         if (mSubInfoList.size() == 1) {
             simPref.setSummary(mSubInfoList.get(0).getDisplayName());
@@ -276,7 +212,7 @@
 
     private void updateCellularDataValues() {
         final Preference simPref = findPreference(KEY_CELLULAR_DATA);
-        final SubInfoRecord sir = findRecordBySubId(SubscriptionManager.getDefaultDataSubId());
+        final SubInfoRecord sir = Utils.findRecordBySubId(SubscriptionManager.getDefaultDataSubId());
         simPref.setTitle(R.string.cellular_data_title);
         if (mSubInfoList.size() == 1) {
             simPref.setSummary(mSubInfoList.get(0).getDisplayName());
@@ -314,11 +250,11 @@
             final Preference preference) {
         if (preference instanceof SimPreference) {
             ((SimPreference)preference).createEditDialog((SimPreference)preference);
-        } else if ((Preference) findPreference(KEY_CELLULAR_DATA) == preference) {
+        } else if (findPreference(KEY_CELLULAR_DATA) == preference) {
             showDialog(DATA_PICK);
-        } else if ((Preference) findPreference(KEY_CALLS) == preference) {
+        } else if (findPreference(KEY_CALLS) == preference) {
             showDialog(CALLS_PICK);
-        } else if ((Preference) findPreference(KEY_SMS) == preference) {
+        } else if (findPreference(KEY_SMS) == preference) {
             showDialog(SMS_PICK);
         }
 
@@ -460,7 +396,7 @@
     private class SimPreference extends Preference{
         private SubInfoRecord mSubInfoRecord;
         private int mSlotId;
-        private int[] colorArr;
+        private int[] tintArr;
 
         public SimPreference(Context context, SubInfoRecord subInfoRecord, int slotId) {
             super(context);
@@ -469,23 +405,17 @@
             mSlotId = slotId;
             setKey("sim" + mSlotId);
             update();
-            colorArr = context.getResources().getIntArray(com.android.internal.R.array.sim_colors);
+            tintArr = context.getResources().getIntArray(com.android.internal.R.array.sim_colors);
         }
 
         public void update() {
             final Resources res = getResources();
 
             if (mSubInfoRecord != null) {
-                if(TextUtils.isEmpty(mSubInfoRecord.getDisplayName())) {
-                    setTitle(getCarrierName());
-                    String displayName = getCarrierName();
-                    mSubInfoRecord.setDisplayName(displayName);
-                    SubscriptionManager.setDisplayName(displayName,
-                            mSubInfoRecord.getSubscriptionId());
-                } else {
-                    setTitle(mSubInfoRecord.getDisplayName());
-                }
-                setSummary(mSubInfoRecord.getNumber());
+                setTitle(String.format(res.getString(R.string.sim_editor_title),
+                        (mSubInfoRecord.getSimSlotIndex() + 1)));
+                setSummary(mSubInfoRecord.getDisplayName() + " - " +
+                        mSubInfoRecord.getNumber().toString());
                 setEnabled(true);
             } else {
                 setSummary(R.string.sim_slot_empty);
@@ -494,14 +424,6 @@
             }
         }
 
-        public String getCarrierName() {
-            Uri mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,
-                    mSubInfoRecord.getSubscriptionId());
-            Cursor mCursor = getActivity().managedQuery(mUri, sProjection, null, null);
-            mCursor.moveToFirst();
-            return mCursor.getString(1);
-        }
-
         public String getFormattedPhoneNumber() {
             try{
                 final String rawNumber = PhoneFactory.getPhone(mSlotId).getLine1Number();
@@ -532,24 +454,24 @@
             EditText nameText = (EditText)dialogLayout.findViewById(R.id.sim_name);
             nameText.setText(mSubInfoRecord.getDisplayName());
 
-            final Spinner colorSpinner = (Spinner) dialogLayout.findViewById(R.id.spinner);
+            final Spinner tintSpinner = (Spinner) dialogLayout.findViewById(R.id.spinner);
             ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
                     R.array.color_picker, android.R.layout.simple_spinner_item);
             adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-            colorSpinner.setAdapter(adapter);
+            tintSpinner.setAdapter(adapter);
 
-            for (int i = 0; i < colorArr.length; i++) {
-                if (colorArr[i] == mSubInfoRecord.getColor()) {
-                    colorSpinner.setSelection(i);
+            for (int i = 0; i < tintArr.length; i++) {
+                if (tintArr[i] == mSubInfoRecord.getIconTint()) {
+                    tintSpinner.setSelection(i);
                     break;
                 }
             }
 
-            colorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+            tintSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                 @Override
                 public void onItemSelected(AdapterView<?> parent, View view,
                     int pos, long id){
-                    colorSpinner.setSelection(pos);
+                    tintSpinner.setSelection(pos);
                 }
 
                 @Override
@@ -561,7 +483,7 @@
             numberView.setText(simPref.getFormattedPhoneNumber());
 
             TextView carrierView = (TextView)dialogLayout.findViewById(R.id.carrier);
-            carrierView.setText(getCarrierName());
+            carrierView.setText(mSubInfoRecord.getCarrierName());
 
             builder.setTitle(String.format(res.getString(R.string.sim_editor_title),
                     (mSubInfoRecord.getSimSlotIndex() + 1)));
@@ -576,14 +498,14 @@
                     mSubInfoRecord.setDisplayName(displayName);
                     SubscriptionManager.setDisplayName(displayName, subId,
                             SubscriptionManager.NAME_SOURCE_USER_INPUT);
-                    findRecordBySubId(subId).setDisplayName(displayName);
+                    Utils.findRecordBySubId(subId).setDisplayName(displayName);
 
-                    final int colorSelected = colorSpinner.getSelectedItemPosition();
+                    final int tintSelected = tintSpinner.getSelectedItemPosition();
                     int subscriptionId = mSubInfoRecord.getSubscriptionId();
-                    int color = colorArr[colorSelected];
-                    mSubInfoRecord.setColor(color);
-                    SubscriptionManager.setColor(color, subscriptionId);
-                    findRecordBySubId(subscriptionId).setColor(color);
+                    int tint = tintArr[tintSelected];
+                    mSubInfoRecord.setIconTint(tint);
+                    SubscriptionManager.setIconTint(tint, subscriptionId);
+                    Utils.findRecordBySubId(subscriptionId).setIconTint(tint);
 
                     updateAllOptions();
                     update();
@@ -615,7 +537,7 @@
                 public int compare(SubInfoRecord arg0, SubInfoRecord arg1) {
                     int flag = arg0.getSimSlotIndex() - arg1.getSimSlotIndex();
                     if (flag == 0) {
-                        return (int) (arg0.getSubscriptionId() - arg1.getSubscriptionId());
+                        return arg0.getSubscriptionId() - arg1.getSubscriptionId();
                     }
                     return flag;
                 }