Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e36087e5 authored by Benjamin Franz's avatar Benjamin Franz
Browse files

Introduce device owner API to disable the keyguard

Let the device owner disable the keyguard to achieve undisturbed single
use mode with multiple apps. Calling this API has no effect if a
password
has been set for the calling user.

Bug: 19533026
Change-Id: I6b726b7f36efb669359e9da4b7e3db1f8031dad5
parent 75f4b766
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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);
+23 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -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);
}
+22 −0
Original line number Diff line number Diff line
@@ -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