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:
97
src/com/android/settings/password/PasswordUtils.java
Normal file
97
src/com/android/settings/password/PasswordUtils.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.password;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.IActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public final class PasswordUtils extends com.android.settingslib.Utils {
|
||||
|
||||
private static final String TAG = "Settings";
|
||||
|
||||
private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
|
||||
|
||||
/**
|
||||
* Returns whether the uid which the activity with {@code activityToken} is launched from has
|
||||
* been granted the {@code permission}.
|
||||
*/
|
||||
public static boolean isCallingAppPermitted(Context context, IBinder activityToken,
|
||||
String permission) {
|
||||
try {
|
||||
return context.checkPermission(permission, /* pid= */ -1,
|
||||
ActivityManager.getService().getLaunchedFromUid(activityToken))
|
||||
== PackageManager.PERMISSION_GRANTED;
|
||||
} catch (RemoteException e) {
|
||||
Log.v(TAG, "Could not talk to activity manager.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label of the package which the activity with {@code activityToken} is launched
|
||||
* from or {@code null} if it is launched from the settings app itself.
|
||||
*/
|
||||
@Nullable
|
||||
public static CharSequence getCallingAppLabel(Context context, IBinder activityToken) {
|
||||
String pkg = getCallingAppPackageName(activityToken);
|
||||
if (pkg == null || pkg.equals(SETTINGS_PACKAGE_NAME)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Utils.getApplicationLabel(context, pkg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the package name which the activity with {@code activityToken} is launched from.
|
||||
*/
|
||||
@Nullable
|
||||
private static String getCallingAppPackageName(IBinder activityToken) {
|
||||
String pkg = null;
|
||||
try {
|
||||
pkg = ActivityManager.getService().getLaunchedFromPackage(activityToken);
|
||||
} catch (RemoteException e) {
|
||||
Log.v(TAG, "Could not talk to activity manager.", e);
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/** Crashes the calling application and provides it with {@code message}. */
|
||||
public static void crashCallingApplication(IBinder activityToken, String message) {
|
||||
IActivityManager am = ActivityManager.getService();
|
||||
try {
|
||||
int uid = am.getLaunchedFromUid(activityToken);
|
||||
int userId = UserHandle.getUserId(uid);
|
||||
am.crashApplication(
|
||||
uid,
|
||||
/* initialPid= */ -1,
|
||||
getCallingAppPackageName(activityToken),
|
||||
userId,
|
||||
message);
|
||||
} catch (RemoteException e) {
|
||||
Log.v(TAG, "Could not talk to activity manager.", e);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user