FileDocCategorySizeDatePackage
SupplicantStateTracker.javaAPI DocAndroid 5.1 API17051Thu Mar 12 22:22:52 GMT 2015com.android.server.wifi

SupplicantStateTracker

public class SupplicantStateTracker extends com.android.internal.util.StateMachine
Tracks the state changes in supplicant and provides functionality that is based on these state changes: - detect a failed WPA handshake that loops indefinitely - authentication failure handling

Fields Summary
private static final String
TAG
private static boolean
DBG
private final WifiStateMachine
mWifiStateMachine
private final WifiConfigStore
mWifiConfigStore
private final com.android.internal.app.IBatteryStats
mBatteryStats
private int
mAuthenticationFailuresCount
private int
mAssociationRejectCount
private boolean
mAuthFailureInSupplicantBroadcast
private static final int
MAX_RETRIES_ON_AUTHENTICATION_FAILURE
private static final int
MAX_RETRIES_ON_ASSOCIATION_REJECT
private boolean
mNetworksDisabledDuringConnect
private final android.content.Context
mContext
private final com.android.internal.util.State
mUninitializedState
private final com.android.internal.util.State
mDefaultState
private final com.android.internal.util.State
mInactiveState
private final com.android.internal.util.State
mDisconnectState
private final com.android.internal.util.State
mScanState
private final com.android.internal.util.State
mHandshakeState
private final com.android.internal.util.State
mCompletedState
private final com.android.internal.util.State
mDormantState
Constructors Summary
public SupplicantStateTracker(android.content.Context c, WifiStateMachine wsm, WifiConfigStore wcs, android.os.Handler t)

        super(TAG, t.getLooper());

        mContext = c;
        mWifiStateMachine = wsm;
        mWifiConfigStore = wcs;
        mBatteryStats = (IBatteryStats)ServiceManager.getService(BatteryStats.SERVICE_NAME);
        addState(mDefaultState);
            addState(mUninitializedState, mDefaultState);
            addState(mInactiveState, mDefaultState);
            addState(mDisconnectState, mDefaultState);
            addState(mScanState, mDefaultState);
            addState(mHandshakeState, mDefaultState);
            addState(mCompletedState, mDefaultState);
            addState(mDormantState, mDefaultState);

        setInitialState(mUninitializedState);
        setLogRecSize(50);
        setLogOnlyTransitions(true);
        //start the state machine
        start();
    
Methods Summary
public voiddump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)

        super.dump(fd, pw, args);
        pw.println("mAuthenticationFailuresCount " + mAuthenticationFailuresCount);
        pw.println("mAuthFailureInSupplicantBroadcast " + mAuthFailureInSupplicantBroadcast);
        pw.println("mNetworksDisabledDuringConnect " + mNetworksDisabledDuringConnect);
        pw.println();
    
voidenableVerboseLogging(int verbose)


       
        if (verbose > 0) {
            DBG = true;
        } else {
            DBG = false;
        }
    
public java.lang.StringgetSupplicantStateName()

        return getCurrentState().getName();
    
private voidhandleNetworkConnectionFailure(int netId, int disableReason)

        if (DBG) {
            Log.d(TAG, "handleNetworkConnectionFailure netId=" + Integer.toString(netId)
                    + " reason " + Integer.toString(disableReason)
                    + " mNetworksDisabledDuringConnect=" + mNetworksDisabledDuringConnect);
        }

        /* If other networks disabled during connection, enable them */
        if (mNetworksDisabledDuringConnect) {
            mWifiConfigStore.enableAllNetworks();
            mNetworksDisabledDuringConnect = false;
        }
        /* Disable failed network */
        mWifiConfigStore.disableNetwork(netId, disableReason);
    
private voidsendSupplicantStateChangedBroadcast(android.net.wifi.SupplicantState state, boolean failedAuth)

        int supplState;
        switch (state) {
            case DISCONNECTED: supplState = BatteryStats.WIFI_SUPPL_STATE_DISCONNECTED; break;
            case INTERFACE_DISABLED:
                supplState = BatteryStats.WIFI_SUPPL_STATE_INTERFACE_DISABLED; break;
            case INACTIVE: supplState = BatteryStats.WIFI_SUPPL_STATE_INACTIVE; break;
            case SCANNING: supplState = BatteryStats.WIFI_SUPPL_STATE_SCANNING; break;
            case AUTHENTICATING: supplState = BatteryStats.WIFI_SUPPL_STATE_AUTHENTICATING; break;
            case ASSOCIATING: supplState = BatteryStats.WIFI_SUPPL_STATE_ASSOCIATING; break;
            case ASSOCIATED: supplState = BatteryStats.WIFI_SUPPL_STATE_ASSOCIATED; break;
            case FOUR_WAY_HANDSHAKE:
                supplState = BatteryStats.WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE; break;
            case GROUP_HANDSHAKE: supplState = BatteryStats.WIFI_SUPPL_STATE_GROUP_HANDSHAKE; break;
            case COMPLETED: supplState = BatteryStats.WIFI_SUPPL_STATE_COMPLETED; break;
            case DORMANT: supplState = BatteryStats.WIFI_SUPPL_STATE_DORMANT; break;
            case UNINITIALIZED: supplState = BatteryStats.WIFI_SUPPL_STATE_UNINITIALIZED; break;
            case INVALID: supplState = BatteryStats.WIFI_SUPPL_STATE_INVALID; break;
            default:
                Slog.w(TAG, "Unknown supplicant state " + state);
                supplState = BatteryStats.WIFI_SUPPL_STATE_INVALID;
                break;
        }
        try {
            mBatteryStats.noteWifiSupplicantStateChanged(supplState, failedAuth);
        } catch (RemoteException e) {
            // Won't happen.
        }
        Intent intent = new Intent(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                | Intent.FLAG_RECEIVER_REPLACE_PENDING);
        intent.putExtra(WifiManager.EXTRA_NEW_STATE, (Parcelable) state);
        if (failedAuth) {
            intent.putExtra(
                WifiManager.EXTRA_SUPPLICANT_ERROR,
                WifiManager.ERROR_AUTHENTICATING);
        }
        mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
    
private voidtransitionOnSupplicantStateChange(StateChangeResult stateChangeResult)

        SupplicantState supState = (SupplicantState) stateChangeResult.state;

        if (DBG) Log.d(TAG, "Supplicant state: " + supState.toString() + "\n");

        switch (supState) {
           case DISCONNECTED:
                transitionTo(mDisconnectState);
                break;
            case INTERFACE_DISABLED:
                //we should have received a disconnection already, do nothing
                break;
            case SCANNING:
                transitionTo(mScanState);
                break;
            case AUTHENTICATING:
            case ASSOCIATING:
            case ASSOCIATED:
            case FOUR_WAY_HANDSHAKE:
            case GROUP_HANDSHAKE:
                transitionTo(mHandshakeState);
                break;
            case COMPLETED:
                transitionTo(mCompletedState);
                break;
            case DORMANT:
                transitionTo(mDormantState);
                break;
            case INACTIVE:
                transitionTo(mInactiveState);
                break;
            case UNINITIALIZED:
            case INVALID:
                transitionTo(mUninitializedState);
                break;
            default:
                Log.e(TAG, "Unknown supplicant state " + supState);
                break;
        }