Fix bug in permission checking

Bug: 275254900
Test: built locally

Change-Id: I3e55948da258425609c3161039e917031988562a
This commit is contained in:
Reema Bajwa
2023-03-27 17:35:50 +00:00
parent a8e179cb60
commit f060617555
2 changed files with 10 additions and 6 deletions

View File

@@ -167,7 +167,8 @@ public final class CredentialProviderInfoFactory {
Slog.w(TAG, "Context is null in isSystemProviderWithValidPermission");
return false;
}
return PermissionUtils.hasPermission(context, serviceInfo.packageName,
return PermissionUtils.isSystemApp(context, serviceInfo.packageName)
&& PermissionUtils.hasPermission(context, serviceInfo.packageName,
Manifest.permission.PROVIDE_DEFAULT_ENABLED_CREDENTIAL_SERVICE);
}

View File

@@ -30,16 +30,19 @@ public class PermissionUtils {
/** Checks whether the given package name hold the given permission **/
public static boolean hasPermission(Context context, String packageName, String permission) {
return context.getPackageManager().checkPermission(permission, packageName)
== PackageManager.PERMISSION_GRANTED;
}
/** Checks whether the given package name is a system app on the device **/
public static boolean isSystemApp(Context context, String packageName) {
try {
ApplicationInfo appInfo =
context.getPackageManager()
.getApplicationInfo(
packageName,
.getApplicationInfo(packageName,
PackageManager.ApplicationInfoFlags.of(
PackageManager.MATCH_SYSTEM_ONLY));
if (appInfo != null
&& context.checkPermission(permission, /* pid= */ -1, appInfo.uid)
== PackageManager.PERMISSION_GRANTED) {
if (appInfo != null) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {