FileDocCategorySizeDatePackage
WifiMonitor.javaAPI DocAndroid 1.5 API12589Wed May 06 22:42:04 BST 2009android.net.wifi

WifiMonitor

public class WifiMonitor extends Object
Listens for events from the wpa_supplicant server, and passes them on to the {@link WifiStateTracker} for handling. Runs in its own thread.
hide

Fields Summary
private static final String
TAG
private static final int
CONNECTED
Events we receive from the supplicant daemon
private static final int
DISCONNECTED
private static final int
STATE_CHANGE
private static final int
SCAN_RESULTS
private static final int
LINK_SPEED
private static final int
TERMINATING
private static final int
DRIVER_STATE
private static final int
UNKNOWN
private static final String
eventPrefix
All events coming from the supplicant start with this prefix
private static final int
eventPrefixLen
private static final String
wpaEventPrefix
All WPA events coming from the supplicant start with this prefix
private static final String
passwordKeyMayBeIncorrectEvent
private static final String
connectedEvent
CTRL-EVENT-CONNECTED - Connection to xx:xx:xx:xx:xx:xx completed
xx:xx:xx:xx:xx:xx is the BSSID of the associated access point
private static final String
disconnectedEvent
CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys
private static final String
stateChangeEvent
CTRL-EVENT-STATE-CHANGE x
x is the numerical value of the new state.
private static final String
scanResultsEvent
CTRL-EVENT-SCAN-RESULTS ready
private static final String
linkSpeedEvent
CTRL-EVENT-LINK-SPEED x Mb/s
{@code x} is the link speed in Mb/sec.
private static final String
terminatingEvent
CTRL-EVENT-TERMINATING - signal x
x is the signal that caused termination.
private static final String
driverStateEvent
CTRL-EVENT-DRIVER-STATE state
state is either STARTED or STOPPED
private static Pattern
mConnectedEventPattern
Regex pattern for extracting an Ethernet-style MAC address from a string. Matches a strings like the following:
CTRL-EVENT-CONNECTED - Connection to 00:1e:58:ec:d5:6d completed (reauth) [id=1 id_str=]
private final WifiStateTracker
mWifiStateTracker
Constructors Summary
public WifiMonitor(WifiStateTracker tracker)


       
        mWifiStateTracker = tracker;
    
Methods Summary
public android.net.NetworkStateTrackergetNetworkStateTracker()

        return mWifiStateTracker;
    
private voidhandleNetworkStateChange(NetworkInfo.DetailedState newState, java.lang.String data)

        String BSSID = null;
        int networkId = -1;
        if (newState == NetworkInfo.DetailedState.CONNECTED) {
            Matcher match = mConnectedEventPattern.matcher(data);
            if (!match.find()) {
                if (Config.LOGD) Log.d(TAG, "Could not find BSSID in CONNECTED event string");
            } else {
                BSSID = match.group(1);
                try {
                    networkId = Integer.parseInt(match.group(2));
                } catch (NumberFormatException e) {
                    networkId = -1;
                }
            }
        }
        mWifiStateTracker.notifyStateChange(newState, BSSID, networkId);
    
private static voidnap(int secs)
Sleep for a period of time.

param
secs the number of seconds to sleep

        try {
            Thread.sleep(secs * 1000);
        } catch (InterruptedException ignore) {
        }
    
public voidstartMonitoring()

        new MonitorThread().start();