From a81567b7460049185e841b2d741c3437a43a6e73 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Mon, 30 May 2016 20:36:30 +0100 Subject: [PATCH] Fix that fail to setup any vpn after Network Settings reset and always-on vpn is on Cause: It revoked the user consent of the vpn app without reseting always-on vpn. In addition, prepareVpn sets legacy vpn as the current package, the state in Vpn.class is broken, as it thought the current always-on package is legacy vpn, (mAlwaysOn is only for app vpn, not for legacy vpn). As a result, prepareVpn rejects all VpnService.prepare. Bug: 29031820 Change-Id: Id6bf1d6f38cf134a872811806301b8a602fb5725 --- .../java/com/android/server/ConnectivityService.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 5118b3f2ab..c22bc757b4 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -5202,6 +5202,15 @@ public class ConnectivityService extends IConnectivityManager.Stub } if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) { + // Remove always-on package + synchronized (mVpns) { + final String alwaysOnPackage = getAlwaysOnVpnPackage(userId); + if (alwaysOnPackage != null) { + setAlwaysOnVpnPackage(userId, null, false); + setVpnPackageAuthorization(alwaysOnPackage, userId, false); + } + } + // Turn VPN off VpnConfig vpnConfig = getVpnConfig(userId); if (vpnConfig != null) { @@ -5212,7 +5221,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // in the future without user intervention. setVpnPackageAuthorization(vpnConfig.user, userId, false); - prepareVpn(vpnConfig.user, VpnConfig.LEGACY_VPN, userId); + prepareVpn(null, VpnConfig.LEGACY_VPN, userId); } } }