diff options
| author | Eran Messeri <eranm@google.com> | 2020-11-12 21:17:19 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-11-12 21:17:19 +0000 |
| commit | cb1fecb4b40aedda169f9b819465e7de3acb00de (patch) | |
| tree | a4c05d8697c01f701f25138d96e92d9c5a9624cc /core/java/android | |
| parent | bb5b23639e1ff0950ba58e585b3fc3e968a557b3 (diff) | |
| parent | 1641c5c47e0a2a37d6b853e652a7661a2dd394ab (diff) | |
Merge "Implement setRequiredPasswordComplexity"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/admin/DevicePolicyManager.java | 72 | ||||
| -rw-r--r-- | core/java/android/app/admin/IDevicePolicyManager.aidl | 2 |
2 files changed, 73 insertions, 1 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 01f3932a79ab..f09e7526d6c1 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -2752,6 +2752,9 @@ public class DevicePolicyManager { * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent * profile. * + * <p><strong>Note:</strong> Specifying password requirements using this method clears the + * password complexity requirements set using {@link #setRequiredPasswordComplexity(int)}. + * * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, * {@link #PASSWORD_QUALITY_BIOMETRIC_WEAK}, @@ -3630,13 +3633,18 @@ public class DevicePolicyManager { * <p>Note that when called from a profile which uses an unified challenge with its parent, the * screen lock complexity of the parent will be returned. * + * <p>Apps need the {@link permission#REQUEST_PASSWORD_COMPLEXITY} permission to call this + * method. On Android {@link android.os.Build.VERSION_CODES#S} and above, the calling + * application does not need this permission if it is a device owner or a profile owner. + * * <p>This method can be called on the {@link DevicePolicyManager} instance * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve * restrictions on the parent profile. * * @throws IllegalStateException if the user is not unlocked. * @throws SecurityException if the calling application does not have the permission - * {@link permission#REQUEST_PASSWORD_COMPLEXITY} + * {@link permission#REQUEST_PASSWORD_COMPLEXITY}, and is not a + * device owner or a profile owner. */ @PasswordComplexity @RequiresPermission(android.Manifest.permission.REQUEST_PASSWORD_COMPLEXITY) @@ -3653,6 +3661,66 @@ public class DevicePolicyManager { } /** + * Sets a password complexity requirement for the user's screen lock. + * The complexity level is one of the pre-defined levels. + * + * <p>Note that when called on a profile which uses an unified challenge with its parent, the + * complexity would apply to the unified challenge. + * + * <p>This method can be called on the {@link DevicePolicyManager} instance + * returned by {@link #getParentProfileInstance(ComponentName)} in order to set + * restrictions on the parent profile. + * + * <p><strong>Note:</strong> Specifying password requirements using this method clears any + * password requirements set using the obsolete {@link #setPasswordQuality(ComponentName, int)} + * and any of its associated methods. + * + * @throws SecurityException if the calling application is not a device owner or a profile + * owner. + * @throws IllegalArgumentException if the complexity level is not one of the four above. + */ + public void setRequiredPasswordComplexity(@PasswordComplexity int passwordComplexity) { + if (mService == null) { + return; + } + + try { + mService.setRequiredPasswordComplexity(passwordComplexity, mParentInstance); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + + /** + * Gets the password complexity requirement set by {@link #setRequiredPasswordComplexity(int)}, + * for the current user. + * + * <p>The difference between this method and {@link #getPasswordComplexity()} is that this + * method simply returns the value set by {@link #setRequiredPasswordComplexity(int)} while + * {@link #getPasswordComplexity()} returns the complexity of the actual password. + * + * <p>This method can be called on the {@link DevicePolicyManager} instance + * returned by {@link #getParentProfileInstance(ComponentName)} in order to get + * restrictions on the parent profile. + * + * @throws SecurityException if the calling application is not a device owner or a profile + * owner. + */ + @PasswordComplexity + public int getRequiredPasswordComplexity() { + if (mService == null) { + return PASSWORD_COMPLEXITY_NONE; + } + + try { + return mService.getRequiredPasswordComplexity(mParentInstance); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * When called by a profile owner of a managed profile returns true if the profile uses unified * challenge with its parent user. * @@ -10010,6 +10078,8 @@ public class DevicePolicyManager { * <li>{@link #getRequiredStrongAuthTimeout}</li> * <li>{@link #setRequiredStrongAuthTimeout}</li> * <li>{@link #getAccountTypesWithManagementDisabled}</li> + * <li>{@link #setRequiredPasswordComplexity(int)} </li> + * <li>{@link #getRequiredPasswordComplexity()}</li> * </ul> * <p> * The following methods are supported for the parent instance but can only be called by the diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index f4105e9b0373..58368bc3779a 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -87,6 +87,8 @@ interface IDevicePolicyManager { boolean isProfileActivePasswordSufficientForParent(int userHandle); boolean isPasswordSufficientAfterProfileUnification(int userHandle, int profileUser); int getPasswordComplexity(boolean parent); + void setRequiredPasswordComplexity(int passwordComplexity, boolean parent); + int getRequiredPasswordComplexity(boolean parent); boolean isUsingUnifiedPassword(in ComponentName admin); int getCurrentFailedPasswordAttempts(int userHandle, boolean parent); int getProfileWithMinimumFailedPasswordsForWipe(int userHandle, boolean parent); |
