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

Commit 2f8c8439 authored by Chiachang Wang's avatar Chiachang Wang Committed by android-build-merger
Browse files

Merge "Not defer network disconnect event in Probing state"

am: 8292fe9d

Change-Id: I261c20f48a4e00f6ef2cd32bff18f39f926e6b66
parents 7e4d381a 8292fe9d
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -313,6 +313,7 @@ public class NetworkMonitor extends StateMachine {

    private int mReevaluateDelayMs = INITIAL_REEVALUATE_DELAY_MS;
    private int mEvaluateAttempts = 0;
    private volatile int mProbeToken = 0;

    public NetworkMonitor(Context context, Handler handler, NetworkAgentInfo networkAgentInfo,
            NetworkRequest defaultRequest) {
@@ -838,7 +839,8 @@ public class NetworkMonitor extends StateMachine {

        @Override
        public void enter() {
            mThread = new Thread(() -> sendMessage(obtainMessage(CMD_PROBE_COMPLETE,
            final int token = ++mProbeToken;
            mThread = new Thread(() -> sendMessage(obtainMessage(CMD_PROBE_COMPLETE, token, 0,
                    isCaptivePortal())));
            mThread.start();
        }
@@ -847,16 +849,13 @@ public class NetworkMonitor extends StateMachine {
        public boolean processMessage(Message message) {
            switch (message.what) {
                case CMD_PROBE_COMPLETE:
                    // Currently, it's not possible to exit this state without mThread having
                    // terminated. Therefore, this state can never get CMD_PROBE_COMPLETE from a
                    // stale thread that is not mThread.
                    // TODO: As soon as it's possible to exit this state without mThread having
                    // terminated, ensure that CMD_PROBE_COMPLETE from stale threads are ignored.
                    // This could be done via a sequence number, or by changing mThread to a class
                    // that has a stopped volatile boolean or AtomicBoolean.
                    // Ensure that CMD_PROBE_COMPLETE from stale threads are ignored.
                    if (message.arg1 != mProbeToken) {
                        return HANDLED;
                    }

                    final CaptivePortalProbeResult probeResult =
                            (CaptivePortalProbeResult) message.obj;

                    if (probeResult.isSuccessful()) {
                        // Transit EvaluatingPrivateDnsState to get to Validated
                        // state (even if no Private DNS validation required).
@@ -883,6 +882,7 @@ public class NetworkMonitor extends StateMachine {
                case CMD_REEVALUATE:
                    // Leave the event to EvaluatingState. Defer this message will result in reset
                    // of mReevaluateDelayMs and mEvaluateAttempts.
                case CMD_NETWORK_DISCONNECTED:
                    return NOT_HANDLED;
                default:
                    // TODO: Some events may able to handle in this state, instead of deferring to
@@ -894,11 +894,9 @@ public class NetworkMonitor extends StateMachine {

        @Override
        public void exit() {
            // If StateMachine get here, the probe started in enter() is guaranteed to have
            // completed, because in this state, all messages except CMD_PROBE_COMPLETE and
            // CMD_REEVALUATE are deferred. CMD_REEVALUATE cannot be in the queue, because it is
            // only ever sent in EvaluatingState#enter, and the StateMachine reach this state by
            // processing it. Therefore, there is no need to stop the thread.
            if (mThread.isAlive()) {
                mThread.interrupt();
            }
            mThread = null;
        }
    }