Move checkAnyPermissionOf to PermissionUtils
This is also needed in other classes in subsequent CLs, move to
a common place to prevent from code duplication.
Test: TH
Bug: 275532605
Change-Id: Id460cd231bbc520ebdcfe988a7507c6959500ac4
diff --git a/staticlibs/framework/com/android/net/module/util/PermissionUtils.java b/staticlibs/framework/com/android/net/module/util/PermissionUtils.java
index be5b0cd..8315b8f 100644
--- a/staticlibs/framework/com/android/net/module/util/PermissionUtils.java
+++ b/staticlibs/framework/com/android/net/module/util/PermissionUtils.java
@@ -54,6 +54,20 @@
}
/**
+ * Return true if the context has one of give permission that is allowed
+ * for a particular process and user ID running in the system.
+ */
+ public static boolean checkAnyPermissionOf(@NonNull Context context,
+ int pid, int uid, @NonNull String... permissions) {
+ for (String permission : permissions) {
+ if (context.checkPermission(permission, pid, uid) == PERMISSION_GRANTED) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Enforce permission check on the context that should have one of given permission.
*/
public static void enforceAnyPermissionOf(@NonNull Context context,