Lockdown VPN handles its own connection teardown.

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
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
index 10c7e27..e7d1fa4 100644
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -95,7 +95,8 @@
     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 @@
         }
     }
 
+    /**
+     * 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 @@
         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 @@
             IntentFilter filter = new IntentFilter();
             filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
             mContext.registerReceiver(mBroadcastReceiver, filter);
-
         }
 
         public void check(String interfaze) {