Remove VPN Overflow menu

- Move always-on option for legacy vpn into the legacy vpn config page
- This implementation doesn't show dialogue when replacing existing always-on vpn
- Continue to disable lockdown option for legacy vpn when "persist.radio.imsregrequired" is true.
  Not applying to vpn app
- Force to save account info when legacy vpn is always-on
- When legacy vpn is always-on, don't try to connect. (Otherwise, an exception is thrown)

TODO: Remove EXTRA_PICK_LOCKDOWN in LockdownVpnTracker in framework

Bug: 26950700
Change-Id: Ia80669359c0b7cdb955c84937156c020ac6e9af5
This commit is contained in:
Victor Chang
2016-03-17 20:58:50 +00:00
parent 147fa9f542
commit 6005aefd44
7 changed files with 83 additions and 203 deletions

View File

@@ -22,6 +22,7 @@ import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.os.Bundle;
import android.os.RemoteException;
@@ -112,8 +113,10 @@ public class ConfigDialogFragment extends DialogFragment implements
// Flush out old version of profile
disconnect(profile);
updateLockdownVpn(dialog.isVpnAlwaysOn(), profile);
// If we are not editing, connect!
if (!dialog.isEditing()) {
if (!dialog.isEditing() && !VpnUtils.isVpnLockdown(profile.key)) {
try {
connect(profile);
} catch (RemoteException e) {
@@ -128,15 +131,7 @@ public class ConfigDialogFragment extends DialogFragment implements
KeyStore keyStore = KeyStore.getInstance();
keyStore.delete(Credentials.VPN + profile.key, KeyStore.UID_SELF);
// If this was the current lockdown VPN, clear it.
if (Arrays.equals(profile.key.getBytes(), keyStore.get(Credentials.LOCKDOWN_VPN))) {
keyStore.delete(Credentials.LOCKDOWN_VPN);
try {
mService.updateLockdownVpn();
} catch (RemoteException e) {
Log.e(TAG, "Failed to clear lockdown VPN configuration");
}
}
updateLockdownVpn(false, profile);
}
dismiss();
}
@@ -147,6 +142,30 @@ public class ConfigDialogFragment extends DialogFragment implements
super.onCancel(dialog);
}
private void updateLockdownVpn(boolean isVpnAlwaysOn, VpnProfile profile) {
// Save lockdown vpn
if (isVpnAlwaysOn) {
// Show toast if vpn profile is not valid
if (!profile.isValidLockdownProfile()) {
Toast.makeText(getContext(), R.string.vpn_lockdown_config_error,
Toast.LENGTH_LONG).show();
return;
}
// Update only if lockdown vpn has been changed
if (!VpnUtils.isVpnLockdown(profile.key)) {
final ConnectivityManager conn = ConnectivityManager.from(getActivity());
conn.setAlwaysOnVpnPackageForUser(UserHandle.myUserId(), null);
VpnUtils.setLockdownVpn(getContext(), profile.key);
}
} else {
// update only if lockdown vpn has been changed
if (VpnUtils.isVpnLockdown(profile.key)) {
VpnUtils.clearLockdownVpn(getContext());
}
}
}
private void connect(VpnProfile profile) throws RemoteException {
try {
mService.startLegacyVpn(profile);