Android5.0系统WIFI状态如何向应用程序通知

来源:互联网 发布:淘宝350模板 编辑:程序博客网 时间:2024/06/04 23:34

打印的过滤:

logcat -s WifiMonitor wpa_supplicant WifiSettings WifiHW WifiConfigStore WifiStateMachine addOrUpdateNetworkNative WifiManager

1.frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiMonitor.java

public class WifiMonitor {  private static class MonitorThread extends Thread {    public void run() {      //noinspection InfiniteLoopStatement      for (;;) {        String eventStr = mWifiNative.waitForEvent();        // Skip logging the common but mostly uninteresting scan-results event        if (DBG && eventStr.indexOf(SCAN_RESULTS_STR) == -1) {          Log.d(TAG, "Event [" + eventStr + "]");        }        if (mWifiMonitorSingleton.dispatchEvent(eventStr)) {          if (DBG) Log.d(TAG, "Disconnecting from the supplicant, no more events");          break;        }      }    }  }  private boolean dispatchEvent(String eventStr, String iface) {    handleSupplicantStateChange(eventData);  }  private void handleSupplicantStateChange(String dataString) {    notifySupplicantStateChange(networkId, wifiSsid, BSSID, newSupplicantState);  }  void notifySupplicantStateChange(int networkId, WifiSsid wifiSsid, String BSSID,            SupplicantState newState) {    mStateMachine.sendMessage(mStateMachine.obtainMessage(SUPPLICANT_STATE_CHANGE_EVENT,              eventLogCounter, 0, new StateChangeResult(networkId, wifiSsid, BSSID, newState)));  }}
2.frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStateTracker.java
private void sendSupplicantStateChangedBroadcast(SupplicantState state, boolean failedAuth) {  if (failedAuth) {    intent.putExtra(    WifiManager.EXTRA_SUPPLICANT_ERROR,    WifiManager.ERROR_AUTHENTICATING);  }  mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);}
通过广播通知应用程序。




0 1
原创粉丝点击