Merge "Add new api to get the button label for background permission"

This commit is contained in:
Evan Severson
2020-01-15 17:59:34 +00:00
committed by Android (Google) Code Review
3 changed files with 37 additions and 0 deletions

View File

@@ -133,6 +133,10 @@ public class ApplicationPackageManager extends PackageManager {
// Default flags to use with PackageManager when no flags are given.
private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
// Name of the resource which provides background permission button string
public static final String APP_PERMISSION_BUTTON_ALLOW_ALWAYS =
"app_permission_button_allow_always";
private final Object mLock = new Object();
@GuardedBy("mLock")
@@ -806,6 +810,26 @@ public class ApplicationPackageManager extends PackageManager {
}
}
@Override
public CharSequence getBackgroundPermissionButtonLabel() {
try {
String permissionController = getPermissionControllerPackageName();
Context context =
mContext.createPackageContext(permissionController, 0);
int textId = context.getResources().getIdentifier(APP_PERMISSION_BUTTON_ALLOW_ALWAYS,
"string", "com.android.permissioncontroller");
// permissionController); STOPSHIP b/147434671
if (textId != 0) {
return context.getText(textId);
}
} catch (NameNotFoundException e) {
Log.e(TAG, "Permission controller not found.", e);
}
return "";
}
@Override
public int checkSignatures(String pkg1, String pkg2) {
try {

View File

@@ -4388,6 +4388,18 @@ public abstract class PackageManager {
@UnsupportedAppUsage
public abstract boolean shouldShowRequestPermissionRationale(@NonNull String permName);
/**
* Gets the string that is displayed on the button which corresponds to granting background
* location in settings. The intended use for this is to help apps instruct users how to
* grant a background permission by providing the string that users will see.
*
* @return the string shown on the button for granting background location
*/
@NonNull
public CharSequence getBackgroundPermissionButtonLabel() {
return "";
}
/**
* Returns an {@link android.content.Intent} suitable for passing to
* {@link android.app.Activity#startActivityForResult(android.content.Intent, int)}