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

Commit 0049a1bf authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Blacklist APs instead of disable

We currently disable networks upon too many reconnects. This leads to asking
the user input for reconnects. Blacklist it instead.

Bug: 2129037
Change-Id: I23d69daf3964c066ed7f70d32fefb81016f19aa2
parent 5f551ef6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -739,6 +739,8 @@ public class WifiWatchdogService {
        
        // Black list this "bad" AP, this will cause an attempt to connect to another
        blacklistAp(ap.bssid);
        // Initiate an association to an alternate AP
        mWifiStateTracker.reassociate();
    }

    private void blacklistAp(String bssid) {
+7 −1
Original line number Diff line number Diff line
@@ -293,6 +293,7 @@ public class WifiMonitor {
        private void handleSupplicantStateChange(String dataString) {
            String[] dataTokens = dataString.split(" ");

            String BSSID = null;
            int networkId = -1;
            int newState  = -1;
            for (String token : dataTokens) {
@@ -301,6 +302,11 @@ public class WifiMonitor {
                    continue;
                }

                if (nameValue[0].equals("BSSID")) {
                    BSSID = nameValue[1];
                    continue;
                }

                int value;
                try {
                    value = Integer.parseInt(nameValue[1]);
@@ -328,7 +334,7 @@ public class WifiMonitor {
            if (newSupplicantState == SupplicantState.INVALID) {
                Log.w(TAG, "Invalid supplicant state: " + newState);
            }
            mWifiStateTracker.notifyStateChange(networkId, newSupplicantState);
            mWifiStateTracker.notifyStateChange(networkId, BSSID, newSupplicantState);
        }
    }

+27 −9
Original line number Diff line number Diff line
@@ -304,11 +304,13 @@ public class WifiStateTracker extends NetworkStateTracker {
     * thread.
     */
    private static class SupplicantStateChangeResult {
        SupplicantStateChangeResult(int networkId, SupplicantState state) {
        SupplicantStateChangeResult(int networkId, String BSSID, SupplicantState state) {
            this.state = state;
            this.BSSID = BSSID;
            this.networkId = networkId;
        }
        int networkId;
        String BSSID;
        SupplicantState state;
    }

@@ -512,10 +514,10 @@ public class WifiStateTracker extends NetworkStateTracker {
     * @param networkId the configured network on which the state change occurred
     * @param newState the new {@code SupplicantState}
     */
    void notifyStateChange(int networkId, SupplicantState newState) {
    void notifyStateChange(int networkId, String BSSID, SupplicantState newState) {
        Message msg = Message.obtain(
            this, EVENT_SUPPLICANT_STATE_CHANGED,
            new SupplicantStateChangeResult(networkId, newState));
            new SupplicantStateChangeResult(networkId, BSSID, newState));
        msg.sendToTarget();
    }

@@ -884,6 +886,13 @@ public class WifiStateTracker extends NetworkStateTracker {

                int networkId = supplicantStateResult.networkId;

                /**
                 * The SupplicantState BSSID value is valid in ASSOCIATING state only.
                 * The NetworkState BSSID value comes upon a successful connection.
                 */
                if (supplicantStateResult.state == SupplicantState.ASSOCIATING) {
                    mLastBssid = supplicantStateResult.BSSID;
                }
                /*
                 * If we get disconnect or inactive we need to start our
                 * watchdog timer to start a scan
@@ -928,6 +937,7 @@ public class WifiStateTracker extends NetworkStateTracker {
                    setSupplicantState(newState);
                    if (newState == SupplicantState.DORMANT) {
                        DetailedState newDetailedState;
                        Message reconnectMsg = obtainMessage(EVENT_DEFERRED_RECONNECT, mLastBssid);
                        if (mIsScanOnly || mRunState == RUN_STATE_STOPPING) {
                            newDetailedState = DetailedState.IDLE;
                        } else {
@@ -942,7 +952,7 @@ public class WifiStateTracker extends NetworkStateTracker {
                         * milliseconds.
                         */
                        if (mRunState == RUN_STATE_RUNNING && !mIsScanOnly && networkId != -1) {
                            sendEmptyMessageDelayed(EVENT_DEFERRED_RECONNECT, RECONNECT_DELAY_MSECS);
                            sendMessageDelayed(reconnectMsg, RECONNECT_DELAY_MSECS);
                        } else if (mRunState == RUN_STATE_STOPPING) {
                            synchronized (this) {
                                WifiNative.stopDriverCommand();
@@ -1104,15 +1114,19 @@ public class WifiStateTracker extends NetworkStateTracker {
                break;

            case EVENT_DEFERRED_RECONNECT:
                /*
                String BSSID = msg.obj.toString();
                /**
                 * If we've exceeded the maximum number of retries for reconnecting
                 * to a given network, disable the network so that the supplicant
                 * will try some other network, if any is available.
                 * TODO: network ID may have changed since we stored it.
                 * to a given network, blacklist the BSSID to allow a connection attempt on
                 * an alternate BSSID if available
                 */
                if (mWifiInfo.getSupplicantState() != SupplicantState.UNINITIALIZED) {
                    if (++mReconnectCount > getMaxDhcpRetries()) {
                        mWM.disableNetwork(mLastNetworkId);
                        if (LOCAL_LOGD) {
                            Log.d(TAG, "Failed reconnect count: " +
                                    mReconnectCount + " Blacklisting " + BSSID);
                        }
                        addToBlacklist(BSSID);
                    }
                    synchronized(this) {
                        WifiNative.reconnectCommand();
@@ -1684,6 +1698,10 @@ public class WifiStateTracker extends NetworkStateTracker {
        mNumScansSinceNetworkStateChange = 0;
    }
    
    public synchronized boolean reassociate() {
        return WifiNative.reassociateCommand();
    }

    public synchronized boolean addToBlacklist(String bssid) {
        return WifiNative.addToBlacklistCommand(bssid);
    }