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

Commit 04e04fe3 authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "fix network disconnection handling"

parents b85bb89a 9b3710b2
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -152,6 +152,26 @@ public enum SupplicantState implements Parcelable {
        return state != UNINITIALIZED && state != INVALID;
    }

    static boolean isConnecting(SupplicantState state) {
        switch(state) {
            case ASSOCIATING:
            case ASSOCIATED:
            case FOUR_WAY_HANDSHAKE:
            case GROUP_HANDSHAKE:
            case COMPLETED:
                return true;
            case DISCONNECTED:
            case INACTIVE:
            case SCANNING:
            case DORMANT:
            case UNINITIALIZED:
            case INVALID:
                return false;
            default:
                throw new IllegalArgumentException("Unknown supplicant state");
        }
    }

    /** Implement the Parcelable interface {@hide} */
    public int describeContents() {
        return 0;
+24 −7
Original line number Diff line number Diff line
@@ -344,6 +344,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
     */
    private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */

    private static final int MIN_RSSI = -200;
    private static final int MAX_RSSI = 256;

    /* Default parent state */
    private HierarchicalState mDefaultState = new DefaultState();
    /* Temporary initial state */
@@ -1239,7 +1242,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
     */
    private void fetchRssiAndLinkSpeedNative() {
        int newRssi = WifiNative.getRssiCommand();
        if (newRssi != -1 && -200 < newRssi && newRssi < 256) { // screen out invalid values
        if (newRssi != -1 && MIN_RSSI < newRssi && newRssi < MAX_RSSI) { // screen out invalid values
            /* some implementations avoid negative values by adding 256
             * so we need to adjust for that here.
             */
@@ -1264,7 +1267,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
            }
            mLastSignalLevel = newSignalLevel;
        } else {
            mWifiInfo.setRssi(-200);
            mWifiInfo.setRssi(MIN_RSSI);
        }
        int newLinkSpeed = WifiNative.getLinkSpeedCommand();
        if (newLinkSpeed != -1) {
@@ -1386,15 +1389,17 @@ public class WifiStateMachine extends HierarchicalStateMachine {
        /* Disable interface */
        NetworkUtils.disableInterface(mInterfaceName);

        /* send event to CM & network change broadcast */
        setNetworkDetailedState(DetailedState.DISCONNECTED);
        sendNetworkStateChangeBroadcast(mLastBssid);

        /* Reset data structures */
        mWifiInfo.setInetAddress(null);
        mWifiInfo.setBSSID(null);
        mWifiInfo.setSSID(null);
        mWifiInfo.setNetworkId(-1);
        mWifiInfo.setRssi(MIN_RSSI);
        mWifiInfo.setLinkSpeed(-1);

        /* send event to CM & network change broadcast */
        setNetworkDetailedState(DetailedState.DISCONNECTED);
        sendNetworkStateChangeBroadcast(mLastBssid);

        /* Clear network properties */
        mLinkProperties.clear();
@@ -2363,7 +2368,10 @@ public class WifiStateMachine extends HierarchicalStateMachine {
                    // 50023 supplicant_state_changed (custom|1|5)
                    EventLog.writeEvent(EVENTLOG_SUPPLICANT_STATE_CHANGED, state.ordinal());
                    mWifiInfo.setSupplicantState(state);
                    // Network id is only valid when we start connecting
                    if (SupplicantState.isConnecting(state)) {
                        mWifiInfo.setNetworkId(stateChangeResult.networkId);
                    }
                    if (state == SupplicantState.ASSOCIATING) {
                        /* BSSID is valid only in ASSOCIATING state */
                        mWifiInfo.setBSSID(stateChangeResult.BSSID);
@@ -2741,6 +2749,15 @@ public class WifiStateMachine extends HierarchicalStateMachine {
            }
            return HANDLED;
        }
        @Override
        public void exit() {
            /* If a scan result is pending in connected state, the supplicant
             * is in SCAN_ONLY_MODE. Restore CONNECT_MODE on exit
             */
            if (mScanResultIsPending) {
                WifiNative.setScanResultHandlingCommand(CONNECT_MODE);
            }
        }
    }

    class DisconnectingState extends HierarchicalState {