Merge "Update material colors" into lmp-dev
diff --git a/res/layout/preference_app_restrictions.xml b/res/layout/preference_app_restrictions.xml
index 753099d..fe575a2 100644
--- a/res/layout/preference_app_restrictions.xml
+++ b/res/layout/preference_app_restrictions.xml
@@ -19,7 +19,8 @@
     android:layout_height="wrap_content"
     android:minHeight="?android:attr/listPreferredItemHeight"
     android:gravity="center_vertical"
-    android:paddingStart="@*android:dimen/preference_item_padding_side">
+    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" >
 
     <LinearLayout
         android:layout_width="wrap_content"
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index c2295e6..9a09647 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -37,9 +37,8 @@
 import android.os.UserHandle;
 import android.os.storage.IMountService;
 import android.os.storage.StorageManager;
-
-import android.phone.PhoneManager;
 import android.provider.Settings;
+import android.telecomm.TelecommManager;
 import android.telephony.TelephonyManager;
 import android.text.Editable;
 import android.text.TextUtils;
@@ -133,6 +132,9 @@
     // how long we wait to clear a wrong pattern
     private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 1500;
 
+    // how long we wait to clear a right pattern
+    private static final int RIGHT_PATTERN_CLEAR_TIMEOUT_MS = 500;
+
     private Runnable mClearPatternRunnable = new Runnable() {
         public void run() {
             mLockPatternView.clearPattern();
@@ -167,6 +169,10 @@
             if (failedAttempts == 0) {
                 // The password was entered successfully. Simply do nothing
                 // and wait for the service restart to switch to surfacefligner
+                if (mLockPatternView != null) {
+                    mLockPatternView.removeCallbacks(mClearPatternRunnable);
+                    mLockPatternView.postDelayed(mClearPatternRunnable, RIGHT_PATTERN_CLEAR_TIMEOUT_MS);
+                }
             } else if (failedAttempts == MAX_FAILED_ATTEMPTS) {
                 // Factory reset the device.
                 sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
@@ -409,6 +415,7 @@
             new AsyncTask<Void, Void, Void>() {
                 int type = StorageManager.CRYPT_TYPE_PASSWORD;
                 String owner_info;
+                boolean pattern_visible;
 
                 @Override
                 public Void doInBackground(Void... v) {
@@ -416,6 +423,7 @@
                         final IMountService service = getMountService();
                         type = service.getPasswordType();
                         owner_info = service.getField("OwnerInfo");
+                        pattern_visible = !("0".equals(service.getField("PatternVisible")));
                     } catch (Exception e) {
                         Log.e(TAG, "Error calling mount service " + e);
                     }
@@ -445,6 +453,10 @@
 
                     passwordEntryInit();
 
+                    if (mLockPatternView != null) {
+                        mLockPatternView.setInStealthMode(!pattern_visible);
+                    }
+
                     if (mCooldown > 0) {
                         setBackFunctionality(false);
                         cooldown(); // in case we are cooling down and coming back from emergency dialler
@@ -875,7 +887,7 @@
         }
 
         int textId;
-        if (getPhoneManager().isInAPhoneCall()) {
+        if (getTelecommManager().isInCall()) {
             // Show "return to call"
             textId = R.string.cryptkeeper_return_to_call;
         } else {
@@ -889,9 +901,9 @@
     }
 
     private void takeEmergencyCallAction() {
-        PhoneManager phoneManager = getPhoneManager();
-        if (phoneManager.isInAPhoneCall()) {
-            phoneManager.showCallScreen(false /* showDialpad */);
+        TelecommManager telecommManager = getTelecommManager();
+        if (telecommManager.isInCall()) {
+            telecommManager.showInCallScreen(false /* showDialpad */);
         } else {
             launchEmergencyDialer();
         }
@@ -910,8 +922,8 @@
         return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
     }
 
-    private PhoneManager getPhoneManager() {
-        return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
+    private TelecommManager getTelecommManager() {
+        return (TelecommManager) getSystemService(Context.TELECOMM_SERVICE);
     }
 
     /**
diff --git a/src/com/android/settings/CryptKeeperConfirm.java b/src/com/android/settings/CryptKeeperConfirm.java
index 71d5e96..7641525 100644
--- a/src/com/android/settings/CryptKeeperConfirm.java
+++ b/src/com/android/settings/CryptKeeperConfirm.java
@@ -25,6 +25,7 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.ServiceManager;
+import android.os.UserHandle;
 import android.os.storage.IMountService;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -32,6 +33,8 @@
 import android.view.ViewGroup;
 import android.widget.Button;
 
+import com.android.internal.widget.LockPatternUtils;
+
 public class CryptKeeperConfirm extends Fragment {
 
     public static class Blank extends Activity {
@@ -90,6 +93,27 @@
                 return;
             }
 
+            /* WARNING - nasty hack!
+               Settings for the lock screen are not available to the crypto
+               screen (CryptKeeper) at boot. We duplicate the ones that
+               CryptKeeper needs to the crypto key/value store when they are
+               modified (see LockPatternUtils).
+               However, prior to encryption, the crypto key/value store is not
+               persisted across reboots, thus modified settings are lost to
+               CryptKeeper.
+               In order to make sure CryptKeeper had the correct settings after
+               first encrypting, we thus need to rewrite them, which ensures the
+               crypto key/value store is up to date. On encryption, this store
+               is then persisted, and the settings will be there on future
+               reboots.
+             */
+            LockPatternUtils utils = new LockPatternUtils(getActivity());
+            utils.setVisiblePatternEnabled(utils.isVisiblePatternEnabled());
+            if (utils.isOwnerInfoEnabled()) {
+                utils.setOwnerInfo(utils.getOwnerInfo(UserHandle.USER_OWNER),
+                                   UserHandle.USER_OWNER);
+            }
+
             Intent intent = new Intent(getActivity(), Blank.class);
             intent.putExtras(getArguments());
 
diff --git a/src/com/android/settings/users/AppRestrictionsFragment.java b/src/com/android/settings/users/AppRestrictionsFragment.java
index 0518f56..9eee4ac 100644
--- a/src/com/android/settings/users/AppRestrictionsFragment.java
+++ b/src/com/android/settings/users/AppRestrictionsFragment.java
@@ -159,34 +159,17 @@
         private boolean panelOpen;
         private boolean immutable;
         private List<Preference> mChildren = new ArrayList<Preference>();
-        private final ColorFilter grayscaleFilter;
 
         AppRestrictionsPreference(Context context, OnClickListener listener) {
             super(context);
             setLayoutResource(R.layout.preference_app_restrictions);
             this.listener = listener;
-
-            ColorMatrix colorMatrix = new ColorMatrix();
-            colorMatrix.setSaturation(0f);
-            float[] matrix = colorMatrix.getArray();
-            matrix[18] = 0.5f;
-            grayscaleFilter = new ColorMatrixColorFilter(colorMatrix);
         }
 
         private void setSettingsEnabled(boolean enable) {
             hasSettings = enable;
         }
 
-        @Override
-        public void setChecked(boolean checked) {
-            if (checked) {
-                getIcon().setColorFilter(null);
-            } else {
-                getIcon().setColorFilter(grayscaleFilter);
-            }
-            super.setChecked(checked);
-        }
-
         void setRestrictions(ArrayList<RestrictionEntry> restrictions) {
             this.restrictions = restrictions;
         }
@@ -246,6 +229,8 @@
                 final Switch toggle = (Switch) widget.getChildAt(0);
                 toggle.setEnabled(!isImmutable());
                 toggle.setTag(this);
+                toggle.setClickable(true);
+                toggle.setFocusable(true);
                 toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                     @Override
                     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {