Allow disconnecting always-on VPNs
Bug: 28072644 Change-Id: If7595f7e17747867158368d95db5addf97d3a14c
This commit is contained in:
@@ -137,11 +137,8 @@ public class AppDialogFragment extends DialogFragment implements AppDialog.Liste
|
|||||||
private void onDisconnect(final DialogInterface dialog) {
|
private void onDisconnect(final DialogInterface dialog) {
|
||||||
final int userId = UserHandle.getUserId(mPackageInfo.applicationInfo.uid);
|
final int userId = UserHandle.getUserId(mPackageInfo.applicationInfo.uid);
|
||||||
try {
|
try {
|
||||||
final VpnConfig vpnConfig = mService.getVpnConfig(userId);
|
if (mPackageInfo.packageName.equals(getConnectedPackage(mService, userId))) {
|
||||||
if (vpnConfig == null || vpnConfig.legacy) {
|
mService.setAlwaysOnVpnPackage(userId, null);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mPackageInfo.packageName.equals(vpnConfig.user)) {
|
|
||||||
mService.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
|
mService.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -149,4 +146,10 @@ public class AppDialogFragment extends DialogFragment implements AppDialog.Liste
|
|||||||
" for user " + userId, e);
|
" 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -299,11 +299,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
|||||||
return true;
|
return true;
|
||||||
} else if (preference instanceof AppPreference) {
|
} else if (preference instanceof AppPreference) {
|
||||||
AppPreference pref = (AppPreference) preference;
|
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);
|
boolean connected = (pref.getState() == AppPreference.STATE_CONNECTED);
|
||||||
|
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
|
Reference in New Issue
Block a user