Allow disconnecting always-on VPNs

Bug: 28072644
Change-Id: If7595f7e17747867158368d95db5addf97d3a14c
This commit is contained in:
Robin Lee
2016-04-14 15:41:41 +01:00
parent 41dde76a6b
commit b3c4133a71
2 changed files with 8 additions and 10 deletions

View File

@@ -137,11 +137,8 @@ public class AppDialogFragment extends DialogFragment implements AppDialog.Liste
private void onDisconnect(final DialogInterface dialog) {
final int userId = UserHandle.getUserId(mPackageInfo.applicationInfo.uid);
try {
final VpnConfig vpnConfig = mService.getVpnConfig(userId);
if (vpnConfig == null || vpnConfig.legacy) {
return;
}
if (mPackageInfo.packageName.equals(vpnConfig.user)) {
if (mPackageInfo.packageName.equals(getConnectedPackage(mService, userId))) {
mService.setAlwaysOnVpnPackage(userId, null);
mService.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
}
} catch (RemoteException e) {
@@ -149,4 +146,10 @@ public class AppDialogFragment extends DialogFragment implements AppDialog.Liste
" for user " + userId, e);
}
}
private static String getConnectedPackage(IConnectivityManager service, final int userId)
throws RemoteException {
final VpnConfig config = service.getVpnConfig(userId);
return config != null ? config.user : null;
}
}

View File

@@ -299,11 +299,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
return true;
} else if (preference instanceof AppPreference) {
AppPreference pref = (AppPreference) preference;
if (pref.isAlwaysOn()) {
// User can't disconnect vpn when always-on is enabled
return true;
}
boolean connected = (pref.getState() == AppPreference.STATE_CONNECTED);
if (!connected) {