Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a1b3e84 authored by Reema Bajwa's avatar Reema Bajwa Committed by Automerger Merge Worker
Browse files

Merge "Fix bug in permission checking" into udc-dev am: 16d277ab

parents a8bfe25e 16d277ab
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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);
    }

+8 −5
Original line number Diff line number Diff line
@@ -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) {