OSDN Git Service

Lockdown VPN handles its own connection teardown.
authorJeff Sharkey <jsharkey@android.com>
Wed, 1 May 2013 00:01:57 +0000 (17:01 -0700)
committerJeff Sharkey <jsharkey@android.com>
Wed, 1 May 2013 16:40:50 +0000 (09:40 -0700)
Recent changes started watching for CONNECTIVITY_ACTION broadcasts
to handle the case where a network is disconnected without the
interface going down.

However, when lockdown VPN is enabled, the broadcast contents are
augmented, and all connections appear disconnected until the VPN
comes online.  This caused a reset feedback loop to occur.

Since LockdownVpnTracker already handles networks being disconnected
separately from interfaces going down, this change disables handling
the broadcast when lockdown is enabled.

Bug: 8755148
Change-Id: I70a348aa97a4b22eaaf23aa5ed344de3e9a9ab0b

services/java/com/android/server/connectivity/Vpn.java
services/java/com/android/server/net/LockdownVpnTracker.java

index 10c7e27..e7d1fa4 100644 (file)
@@ -95,7 +95,8 @@ public class Vpn extends BaseNetworkStateTracker {
     private Connection mConnection;
     private LegacyVpnRunner mLegacyVpnRunner;
     private PendingIntent mStatusIntent;
-    private boolean mEnableNotif = true;
+    private volatile boolean mEnableNotif = true;
+    private volatile boolean mEnableTeardown = true;
     private final IConnectivityManager mConnService;
 
     public Vpn(Context context, VpnCallback callback, INetworkManagementService netService,
@@ -113,10 +114,23 @@ public class Vpn extends BaseNetworkStateTracker {
         }
     }
 
+    /**
+     * Set if this object is responsible for showing its own notifications. When
+     * {@code false}, notifications are handled externally by someone else.
+     */
     public void setEnableNotifications(boolean enableNotif) {
         mEnableNotif = enableNotif;
     }
 
+    /**
+     * Set if this object is responsible for watching for {@link NetworkInfo}
+     * teardown. When {@code false}, teardown is handled externally by someone
+     * else.
+     */
+    public void setEnableTeardown(boolean enableTeardown) {
+        mEnableTeardown = enableTeardown;
+    }
+
     @Override
     protected void startMonitoringInternal() {
         // Ignored; events are sent through callbacks for now
@@ -647,6 +661,8 @@ public class Vpn extends BaseNetworkStateTracker {
         private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
+                if (!mEnableTeardown) return;
+
                 if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                     if (intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE,
                             ConnectivityManager.TYPE_NONE) == mOuterConnection.get()) {
@@ -688,7 +704,6 @@ public class Vpn extends BaseNetworkStateTracker {
             IntentFilter filter = new IntentFilter();
             filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
             mContext.registerReceiver(mBroadcastReceiver, filter);
-
         }
 
         public void check(String interfaze) {
index 5b6e485..e251925 100644 (file)
@@ -128,7 +128,10 @@ public class LockdownVpnTracker {
             mAcceptedEgressIface = null;
             mVpn.stopLegacyVpn();
         }
-        if (egressDisconnected) return;
+        if (egressDisconnected) {
+            hideNotification();
+            return;
+        }
 
         final int egressType = egressInfo.getType();
         if (vpnInfo.getDetailedState() == DetailedState.FAILED) {
@@ -192,6 +195,7 @@ public class LockdownVpnTracker {
         Slog.d(TAG, "initLocked()");
 
         mVpn.setEnableNotifications(false);
+        mVpn.setEnableTeardown(false);
 
         final IntentFilter resetFilter = new IntentFilter(ACTION_LOCKDOWN_RESET);
         mContext.registerReceiver(mResetReceiver, resetFilter, CONNECTIVITY_INTERNAL, null);
@@ -235,6 +239,7 @@ public class LockdownVpnTracker {
 
         mContext.unregisterReceiver(mResetReceiver);
         mVpn.setEnableNotifications(true);
+        mVpn.setEnableTeardown(true);
     }
 
     public void reset() {