Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57666934 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

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
parent f6a2598f
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -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) {
+6 −1
Original line number Diff line number Diff line
@@ -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() {