Merge "Fix 3024522: Add "no lock screen" support to the framework."
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 90423be..bf59753 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -95,6 +95,7 @@
     private final static String PATTERN_EVER_CHOSEN_KEY = "lockscreen.patterneverchosen";
     public final static String PASSWORD_TYPE_KEY = "lockscreen.password_type";
     private final static String LOCK_PASSWORD_SALT_KEY = "lockscreen.password_salt";
+    private final static String DISABLE_LOCKSCREEN_KEY = "lockscreen.disabled";
 
     private final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory";
 
@@ -355,6 +356,26 @@
     }
 
     /**
+     * Disable showing lock screen at all when the DevicePolicyManager allows it.
+     * This is only meaningful if pattern, pin or password are not set.
+     *
+     * @param disable Disables lock screen when true
+     */
+    public void setLockScreenDisabled(boolean disable) {
+        setLong(DISABLE_LOCKSCREEN_KEY, disable ? 1 : 0);
+    }
+
+    /**
+     * Determine if LockScreen can be disabled. This is used, for example, to tell if we should
+     * show LockScreen or go straight to the home screen.
+     *
+     * @return true if lock screen is can be disabled
+     */
+    public boolean isLockScreenDisabled() {
+        return !isSecure() && getLong(DISABLE_LOCKSCREEN_KEY, 0) != 0;
+    }
+
+    /**
      * Save a lock pattern.
      * @param pattern The new pattern to save.
      */
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
index 42b73b9..72af34d 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
@@ -281,7 +281,7 @@
         mUpdateMonitor.registerSimStateCallback(this);
 
         mLockPatternUtils = new LockPatternUtils(mContext);
-        mKeyguardViewProperties 
+        mKeyguardViewProperties
                 = new LockPatternKeyguardViewProperties(mLockPatternUtils, mUpdateMonitor);
 
         mKeyguardViewManager = new KeyguardViewManager(
@@ -589,6 +589,11 @@
                 return;
             }
 
+            if (mLockPatternUtils.isLockScreenDisabled()) {
+                if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
+                return;
+            }
+
             if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
             showLocked();
         }
@@ -1005,7 +1010,7 @@
                 Log.d(TAG, "playSounds: whichSound = " + whichSound + "; soundPath was null");
             }
         }
-    }        
+    }
 
     /**
      * Handle message sent by {@link #showLocked}.