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

Commit 8d505ff0 authored by Andrei Kapishnikov's avatar Andrei Kapishnikov Committed by Android (Google) Code Review
Browse files

Merge "Introduced DO_NOT_ASK_CREDENTIALS_ON_BOOT flag"

parents 2099ee8a 4eb6a369
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5801,6 +5801,7 @@ package android.app.admin {
    field public static final java.lang.String ACTION_SET_NEW_PASSWORD = "android.app.action.SET_NEW_PASSWORD";
    field public static final java.lang.String ACTION_START_ENCRYPTION = "android.app.action.START_ENCRYPTION";
    field public static final java.lang.String ACTION_SYSTEM_UPDATE_POLICY_CHANGED = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
    field public static final int DO_NOT_ASK_CREDENTIALS_ON_BOOT = 2; // 0x2
    field public static final int ENCRYPTION_STATUS_ACTIVATING = 2; // 0x2
    field public static final int ENCRYPTION_STATUS_ACTIVE = 3; // 0x3
    field public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; // 0x4
+1 −0
Original line number Diff line number Diff line
@@ -5907,6 +5907,7 @@ package android.app.admin {
    field public static final java.lang.String ACTION_SET_PROFILE_OWNER = "android.app.action.SET_PROFILE_OWNER";
    field public static final java.lang.String ACTION_START_ENCRYPTION = "android.app.action.START_ENCRYPTION";
    field public static final java.lang.String ACTION_SYSTEM_UPDATE_POLICY_CHANGED = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
    field public static final int DO_NOT_ASK_CREDENTIALS_ON_BOOT = 2; // 0x2
    field public static final int ENCRYPTION_STATUS_ACTIVATING = 2; // 0x2
    field public static final int ENCRYPTION_STATUS_ACTIVE = 3; // 0x3
    field public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; // 0x4
+29 −1
Original line number Diff line number Diff line
@@ -1634,6 +1634,23 @@ public class DevicePolicyManager {
        return -1;
    }

    /**
     * Queries whether {@link #DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
     *
     * @return true if DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
     * @hide
     */
    public boolean getDoNotAskCredentialsOnBoot() {
        if (mService != null) {
            try {
                return mService.getDoNotAskCredentialsOnBoot();
            } catch (RemoteException e) {
                Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
            }
        }
        return false;
    }

    /**
     * Setting this to a value greater than zero enables a built-in policy
     * that will perform a device wipe after too many incorrect
@@ -1710,6 +1727,16 @@ public class DevicePolicyManager {
     */
    public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;

    /**
     * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
     * If the flag is set, the device can be booted without asking for user password.
     * The absence of this flag does not change the current boot requirements. This flag
     * can be set by the device owner only. If the app is not the device owner, the flag
     * is ignored. Once the flag is set, it cannot be reverted back without resetting the
     * device to factory defaults.
     */
    public static final int DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;

    /**
     * Force a new device unlock password (the password needed to access the
     * entire device, not for individual accounts) on the user.  This takes
@@ -1733,7 +1760,8 @@ public class DevicePolicyManager {
     * <p>Calling this from a managed profile will throw a security exception.
     *
     * @param password The new password for the user. Null or empty clears the password.
     * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
     * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
     *              {@link #DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
     * @return Returns true if the password was applied, or false if it is
     * not acceptable for the current constraints.
     */
+1 −0
Original line number Diff line number Diff line
@@ -224,4 +224,5 @@ interface IDevicePolicyManager {

    boolean setKeyguardEnabledState(in ComponentName admin, boolean enabled);
    void setStatusBarEnabledState(in ComponentName who, boolean enabled);
    boolean getDoNotAskCredentialsOnBoot();
}
+10 −5
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.AsyncTask;
import android.os.IBinder;
import android.os.RemoteException;
@@ -32,7 +31,6 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.IMountService;
import android.os.storage.StorageManager;
import android.provider.Settings;
@@ -544,8 +542,7 @@ public class LockPatternUtils {
            // Update the device encryption password.
            if (userId == UserHandle.USER_OWNER
                    && LockPatternUtils.isDeviceEncryptionEnabled()) {
                final boolean required = isCredentialRequiredToDecrypt(true);
                if (!required) {
                if (!shouldEncryptWithCredentials(true)) {
                    clearEncryptionPassword();
                } else {
                    String stringPattern = patternToString(pattern);
@@ -759,7 +756,7 @@ public class LockPatternUtils {
            // Update the device encryption password.
            if (userHandle == UserHandle.USER_OWNER
                    && LockPatternUtils.isDeviceEncryptionEnabled()) {
                if (!isCredentialRequiredToDecrypt(true)) {
                if (!shouldEncryptWithCredentials(true)) {
                    clearEncryptionPassword();
                } else {
                    boolean numeric = computedQuality
@@ -1238,4 +1235,12 @@ public class LockPatternUtils {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT, required ? 1 : 0);
    }

    private boolean isDoNotAskCredentialsOnBootSet() {
        return mDevicePolicyManager.getDoNotAskCredentialsOnBoot();
    }

    private boolean shouldEncryptWithCredentials(boolean defaultValue) {
        return isCredentialRequiredToDecrypt(defaultValue) && !isDoNotAskCredentialsOnBootSet();
    }
}
Loading