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

Commit 387615bf authored by Jackal Guo's avatar Jackal Guo Committed by Android (Google) Code Review
Browse files

Merge "Revise the checking logic of checkPackage"

parents 3dddbd21 66fb9ef9
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -3307,15 +3307,23 @@ public class AppOpsService extends IAppOpsService.Stub {
        Objects.requireNonNull(packageName);
        try {
            verifyAndGetBypass(uid, packageName, null);
            if (filterAppAccessUnlocked(packageName)) {
                return AppOpsManager.MODE_ERRORED;
            }
            // When the caller is the system, it's possible that the packageName is the special
            // one (e.g., "root") which isn't actually existed.
            if (resolveUid(packageName) == uid
                    || (isPackageExisted(packageName) && !filterAppAccessUnlocked(packageName))) {
                return AppOpsManager.MODE_ALLOWED;
            }
            return AppOpsManager.MODE_ERRORED;
        } catch (SecurityException ignored) {
            return AppOpsManager.MODE_ERRORED;
        }
    }

    private boolean isPackageExisted(String packageName) {
        return LocalServices.getService(PackageManagerInternal.class)
                .getPackageSetting(packageName) != null;
    }

    /**
     * This method will check with PackageManager to determine if the package provided should
     * be visible to the {@link Binder#getCallingUid()}.