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

Commit 3b5ce1e1 authored by Jeff Davidson's avatar Jeff Davidson Committed by Android Git Automerger
Browse files

am 0a775ce9: Ensure VPN consent is not revoked in prepare/establish.

* commit '0a775ce9':
  Ensure VPN consent is not revoked in prepare/establish.
parents 23c0fca3 0a775ce9
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -217,14 +217,21 @@ public class Vpn {
     * @return true if the operation is succeeded.
     */
    public synchronized boolean prepare(String oldPackage, String newPackage) {
        if (oldPackage != null && getAppUid(oldPackage, mUserHandle) != mOwnerUID) {
            // The package doesn't match. We return false (to obtain user consent) unless the user
            // has already consented to that VPN package.
        if (oldPackage != null) {
            if (getAppUid(oldPackage, mUserHandle) != mOwnerUID) {
                // The package doesn't match. We return false (to obtain user consent) unless the
                // user has already consented to that VPN package.
                if (!oldPackage.equals(VpnConfig.LEGACY_VPN) && isVpnUserPreConsented(oldPackage)) {
                    prepareInternal(oldPackage);
                    return true;
                }
                return false;
            } else if (!oldPackage.equals(VpnConfig.LEGACY_VPN)
                    && !isVpnUserPreConsented(oldPackage)) {
                // Currently prepared VPN is revoked, so unprepare it and return false.
                prepareInternal(VpnConfig.LEGACY_VPN);
                return false;
            }
        }

        // Return true if we do not need to revoke.
@@ -481,6 +488,10 @@ public class Vpn {
        if (Binder.getCallingUid() != mOwnerUID) {
            return null;
        }
        // Check to ensure consent hasn't been revoked since we were prepared.
        if (!isVpnUserPreConsented(mPackage)) {
            return null;
        }
        // Check if the service is properly declared.
        Intent intent = new Intent(VpnConfig.SERVICE_INTERFACE);
        intent.setClassName(mPackage, config.user);