Merge "Add parameters to @PermissionMethod"

This commit is contained in:
Matt Gilbride
2022-11-28 20:07:34 +00:00
committed by Android (Google) Code Review
3 changed files with 20 additions and 3 deletions

View File

@@ -6201,7 +6201,7 @@ public abstract class Context {
*/
@CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
@PackageManager.PermissionResult
@PermissionMethod
@PermissionMethod(orSelf = true)
public abstract int checkCallingOrSelfPermission(@NonNull @PermissionName String permission);
/**
@@ -6269,7 +6269,7 @@ public abstract class Context {
*
* @see #checkCallingOrSelfPermission(String)
*/
@PermissionMethod
@PermissionMethod(orSelf = true)
public abstract void enforceCallingOrSelfPermission(
@NonNull @PermissionName String permission, @Nullable String message);

View File

@@ -33,4 +33,20 @@ import java.lang.annotation.Target;
*/
@Retention(CLASS)
@Target({METHOD})
public @interface PermissionMethod {}
public @interface PermissionMethod {
/**
* Hard-coded list of permissions checked by this method
*/
@PermissionName String[] value() default {};
/**
* If true, the check passes if the caller
* has any ONE of the supplied permissions
*/
boolean anyOf() default false;
/**
* Signifies that the permission check passes if
* the calling process OR the current process has
* the permission
*/
boolean orSelf() default false;
}

View File

@@ -6142,6 +6142,7 @@ public class ActivityManagerService extends IActivityManager.Stub
/**
* This can be called with or without the global lock held.
*/
@PermissionMethod(anyOf = true)
private void enforceCallingHasAtLeastOnePermission(String func, String... permissions) {
for (String permission : permissions) {
if (checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) {