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

Commit c6a1d93b authored by Automerger Merge Worker's avatar Automerger Merge Worker Committed by Rubin Xu
Browse files

Clear binder identity before calling PackageManager API

With the introduction of app enumeration restriction in R,
PackageManager will restrict package visiblity if the caller
is not privileged. This caused regression in existing system
server code where binder identity is not cleared prior to
making PackageManager calls.

Bug: 150398249
Test: com.android.cts.devicepolicy.MixedDeviceOwnerTest#testAlwaysOnVpn
Change-Id: I8744965389883870c569a1b70e75715aafeb7848
Merged-In: I611eb5768bfb73f01c63e6ab02d90f1178f8ec37
(cherry picked from commit f57597c6)
parent 5580360b
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -951,18 +951,18 @@ public class Vpn {
                || isVpnServicePreConsented(context, packageName);
    }

    private int getAppUid(String app, int userHandle) {
    private int getAppUid(final String app, final int userHandle) {
        if (VpnConfig.LEGACY_VPN.equals(app)) {
            return Process.myUid();
        }
        PackageManager pm = mContext.getPackageManager();
        int result;
        return Binder.withCleanCallingIdentity(() -> {
            try {
            result = pm.getPackageUidAsUser(app, userHandle);
                return pm.getPackageUidAsUser(app, userHandle);
            } catch (NameNotFoundException e) {
            result = -1;
                return -1;
            }
        return result;
        });
    }

    private boolean doesPackageTargetAtLeastQ(String packageName) {