diff --git a/api/current.txt b/api/current.txt index 540ca605fe24a..ea4aaf9619133 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5713,6 +5713,7 @@ package android.app.admin { method public boolean setDeviceInitializer(android.content.ComponentName, android.content.ComponentName, java.lang.String) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException; method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String); method public void setKeyguardDisabledFeatures(android.content.ComponentName, int); + method public boolean setKeyguardEnabledState(android.content.ComponentName, boolean); method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException; method public void setMasterVolumeMuted(android.content.ComponentName, boolean); method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int); diff --git a/api/system-current.txt b/api/system-current.txt index 8c7d823dd998e..1a28546ca784b 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -5817,6 +5817,7 @@ package android.app.admin { method public boolean setDeviceInitializer(android.content.ComponentName, android.content.ComponentName, java.lang.String) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException; method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String); method public void setKeyguardDisabledFeatures(android.content.ComponentName, int); + method public boolean setKeyguardEnabledState(android.content.ComponentName, boolean); method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException; method public void setMasterVolumeMuted(android.content.ComponentName, boolean); method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int); diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index dd6443673c58f..a0a6c4cd678c4 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -4187,4 +4187,27 @@ public class DevicePolicyManager { } return null; } + + /** + * Called by a device owner to disable the keyguard altogether. + * + *
Setting the keyguard to disabled has the same effect as choosing "None" as the screen + * lock type. However, this call has no effect if a password, pin or pattern is currently set. + * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops + * being disabled. + * + * @param admin Which {@link DeviceAdminReceiver} this request is associated with. + * @param enabled New state of the keyguard. + * + * @return {@code false} if attempting to disable the keyguard while a lock password was in + * place. {@code true} otherwise." + */ + public boolean setKeyguardEnabledState(ComponentName admin, boolean enabled) { + try { + return mService.setKeyguardEnabledState(admin, enabled); + } catch (RemoteException re) { + Log.w(TAG, "Failed talking with device policy service", re); + return false; + } + } } diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index 332d59ed5edae..131b99cb4e4a9 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -221,4 +221,6 @@ interface IDevicePolicyManager { void sendDeviceInitializerStatus(int statusCode, String description); void setOtaPolicy(in ComponentName who, in PersistableBundle policy); PersistableBundle getOtaPolicy(); + + boolean setKeyguardEnabledState(in ComponentName admin, boolean enabled); } diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 26c7130a8a3e6..c7d2b8687b9e5 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -5808,6 +5808,28 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } } + @Override + public boolean setKeyguardEnabledState(ComponentName who, boolean enabled) { + Preconditions.checkNotNull(who, "ComponentName is null"); + synchronized (this) { + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); + } + final int userId = UserHandle.getCallingUserId(); + LockPatternUtils utils = new LockPatternUtils(mContext); + + // disallow disabling the keyguard if a password is currently set + if (!enabled && utils.isSecure(userId)) { + return false; + } + long ident = Binder.clearCallingIdentity(); + try { + utils.setLockScreenDisabled(!enabled, userId); + } finally { + Binder.restoreCallingIdentity(ident); + } + return true; + } + /** * We need to update the internal state of whether a user has completed setup once. After * that, we ignore any changes that reset the Settings.Secure.USER_SETUP_COMPLETE changes