New extra for ACTION_SET_NEW_PASSWORD to specify the min complexity

When an app that has the permission GET_AND_REQUEST_PASSWORD_COMPLEXITY
launches ACTION_SET_NEW_PASSWORD, it can use the DPM PASSWORD_COMPLEXITY_*
constants to specify the complexity it wants in a new extra
EXTRA_PASSWORD_COMPLEXITY.
The screen lock type picker would then filter out the options which
cannot fulfil the min complexity (and DPM restrictions) and will show a
footer with a brief description of the calling app and the requested type.
The same password requirements UI is used in ChooseLockPassword screen
to display the minimum requirements that can fulfil both DPM
restrictions and the min complexity.

The app must have permission GET_AND_REQUEST_PASSWORD_COMPLEXITY
otherwise the extra would be ignored.

ACTION_SET_NEW_PASSWORD is also updated to always display the calling app
name in the screen lock type picker if it is not launched by Settings,
with or without the new extra.

Bug: 111173457
Test: atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
      atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
      atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
      atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/PasswordUtilsTest.java
      atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
      atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/SetupChooseLockGenericTest.java
      manual test with TestDpc (ag/5901733)

Change-Id: I21a25d28669bf1223c3b02ba85c0755e59feee2e
This commit is contained in:
Bernard Chau
2018-12-17 18:03:24 +00:00
parent da70607f41
commit 92db5bf4f7
18 changed files with 1280 additions and 97 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.testutils.shadow;
import android.app.ActivityManager;
import android.app.IActivityManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@@ -24,6 +25,7 @@ import org.robolectric.annotation.Implements;
@Implements(ActivityManager.class)
public class ShadowActivityManager {
private static int sCurrentUserId = 0;
private static IActivityManager sService = null;
@Implementation
protected static int getCurrentUser() {
@@ -33,4 +35,13 @@ public class ShadowActivityManager {
public static void setCurrentUser(int userId) {
sCurrentUserId = userId;
}
@Implementation
public static IActivityManager getService() {
return sService;
}
public static void setService(IActivityManager service) {
sService = service;
}
}

View File

@@ -1,5 +1,7 @@
package com.android.settings.testutils.shadow;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -23,6 +25,10 @@ public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDev
private boolean mIsAdminActiveAsUser = false;
private ComponentName mDeviceOwnerComponentName;
private int mDeviceOwnerUserId = -1;
private int mPasswordMinQuality = PASSWORD_QUALITY_UNSPECIFIED;
private int mPasswordMaxLength = 16;
private int mPasswordMinLength = 0;
private int mPasswordMinSymbols = 0;
public void setShortSupportMessageForUser(ComponentName admin, int userHandle, String message) {
mSupportMessagesMap.put(Objects.hash(admin, userHandle), message);
@@ -70,6 +76,42 @@ public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDev
mDeviceOwnerComponentName = admin;
}
@Implementation
public int getPasswordQuality(ComponentName admin, int userHandle) {
return mPasswordMinQuality;
}
public void setPasswordQuality(int quality) {
mPasswordMinQuality = quality;
}
@Implementation
public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
return mPasswordMinLength;
}
public void setPasswordMinimumLength(int length) {
mPasswordMinLength = length;
}
@Implementation
public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
return mPasswordMinSymbols;
}
public void setPasswordMinimumSymbols(int numOfSymbols) {
mPasswordMinSymbols = numOfSymbols;
}
@Implementation
public int getPasswordMaximumLength(int quality) {
return mPasswordMaxLength;
}
public void setPasswordMaximumLength(int length) {
mPasswordMaxLength = length;
}
public static ShadowDevicePolicyManager getShadow() {
return (ShadowDevicePolicyManager) Shadow.extract(
RuntimeEnvironment.application.getSystemService(DevicePolicyManager.class));

View File

@@ -59,4 +59,14 @@ public class ShadowLockPatternUtils {
public static void setDeviceEncryptionEnabled(boolean deviceEncryptionEnabled) {
sDeviceEncryptionEnabled = deviceEncryptionEnabled;
}
@Implementation
protected byte[] getPasswordHistoryHashFactor(String currentPassword, int userId) {
return null;
}
@Implementation
protected boolean checkPasswordHistory(String passwordToCheck, byte[] hashFactor, int userId) {
return false;
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.testutils.shadow;
import android.content.Context;
import android.os.IBinder;
import com.android.settings.password.PasswordUtils;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@Implements(PasswordUtils.class)
public class ShadowPasswordUtils {
private static String sCallingAppLabel;
private static Set<String> sGrantedPermissions;
public static void reset() {
sCallingAppLabel = null;
sGrantedPermissions = null;
}
@Implementation
protected static boolean isCallingAppPermitted(Context context, IBinder activityToken,
String permission) {
if (sGrantedPermissions == null) {
return false;
}
return sGrantedPermissions.contains(permission);
}
public static void addGrantedPermission(String... permissions) {
if (sGrantedPermissions == null) {
sGrantedPermissions = new HashSet<>();
}
sGrantedPermissions.addAll(Arrays.asList(permissions));
}
@Implementation
protected static String getCallingAppLabel(Context context, IBinder activityToken) {
return sCallingAppLabel;
}
public static void setCallingAppLabel(String label) {
sCallingAppLabel = label;
}
}