Merge "Introduce device owner API to disable the keyguard"

This commit is contained in:
Benjamin Franz
2015-04-14 11:12:31 +00:00
committed by Android (Google) Code Review
5 changed files with 49 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -4187,4 +4187,27 @@ public class DevicePolicyManager {
}
return null;
}
/**
* Called by a device owner to disable the keyguard altogether.
*
* <p>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;
}
}
}

View File

@@ -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);
}

View File

@@ -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