Merge "Move 'is already always-on' check into Vpn.java" into nyc-dev

This commit is contained in:
Robin Lee
2016-06-16 10:06:10 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 11 deletions

View File

@@ -3417,10 +3417,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
Slog.w(TAG, "User " + userId + " has no Vpn configuration");
return false;
}
// If the current VPN package is the same as the new one, this is a no-op
if (TextUtils.equals(packageName, vpn.getAlwaysOnPackage())) {
return true;
}
if (!vpn.setAlwaysOnPackage(packageName, lockdown)) {
return false;
}

View File

@@ -259,28 +259,39 @@ public class Vpn {
*
* @param packageName the package to designate as always-on VPN supplier.
* @param lockdown whether to prevent traffic outside of a VPN, for example while connecting.
* @return {@code true} if the package has been set as always-on, {@code false} otherwise.
*/
public synchronized boolean setAlwaysOnPackage(String packageName, boolean lockdown) {
enforceControlPermissionOrInternalCaller();
if (VpnConfig.LEGACY_VPN.equals(packageName)) {
Log.w(TAG, "Not setting legacy VPN \"" + packageName + "\" as always-on.");
return false;
}
// Disconnect current VPN.
prepareInternal(VpnConfig.LEGACY_VPN);
// Pre-authorize new always-on VPN package.
if (packageName != null) {
// Pre-authorize new always-on VPN package.
if (!setPackageAuthorization(packageName, true)) {
return false;
}
prepareInternal(packageName);
mAlwaysOn = true;
} else {
packageName = VpnConfig.LEGACY_VPN;
mAlwaysOn = false;
}
mAlwaysOn = (packageName != null);
mLockdown = (mAlwaysOn && lockdown);
if (!isCurrentPreparedPackage(packageName)) {
prepareInternal(packageName);
}
maybeRegisterPackageChangeReceiverLocked(packageName);
setVpnForcedLocked(mLockdown);
return true;
}
private static boolean isNullOrLegacyVpn(String packageName) {
return packageName == null || VpnConfig.LEGACY_VPN.equals(packageName);
}
private void unregisterPackageChangeReceiverLocked() {
// register previous intent filter
if (mIsPackageIntentReceiverRegistered) {
@@ -293,7 +304,7 @@ public class Vpn {
// Unregister IntentFilter listening for previous always-on package change
unregisterPackageChangeReceiverLocked();
if (packageName != null) {
if (!isNullOrLegacyVpn(packageName)) {
mIsPackageIntentReceiverRegistered = true;
IntentFilter intentFilter = new IntentFilter();