预览加载中,请您耐心等待几秒...
1/8
2/8
3/8
4/8
5/8
6/8
7/8
8/8
在线预览结束,喜欢就下载吧,查找使用更方便
如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
HYPERLINK"http://jakielong.iteye.com/blog/731923"Android移植:wifi设计原理(源码分析)
博客分类:
HYPERLINK"http://jakielong.iteye.com/category/118129"Android
HYPERLINK"http://www.iteye.com/blogs/tag/Android"AndroidHYPERLINK"http://www.iteye.com/blogs/tag/EXT"EXT
初始化在SystemServer启动的时候,会生成一个ConnectivityService的实例,try{Log.i(TAG,"StartingConnectivityService.");ServiceManager.addService(Context.CONNECTIVITY_SERVICE,newConnectivityService(context));}catch(Throwablee){Log.e(TAG,"FailurestartingConnectivityService",e);}ConnectivityService的构造函数会创建WifiService,if(DBG)Log.v(TAG,"StartingWifiService.");mWifiStateTracker=newWifiStateTracker(context,handler);WifiServicewifiService=newWifiService(context,mWifiStateTracker);ServiceManager.addService(Context.WIFI_SERVICE,wifiService);WifiStateTracker会创建WifiMonitor接收来自底层的事件,WifiService和WifiMonitor是整个模块的核心。WifiService负责启动关闭wpa_supplicant、启动关闭WifiMonitor监视线程和把命令下发给wpa_supplicant,而WifiMonitor则负责从wpa_supplicant接收事件通知。连接AP1.使能WIFIWirelessSettings在初始化的时候配置了由WifiEnabler来处理Wifi按钮,privatevoidinitToggles(){mWifiEnabler=newWifiEnabler(this,(WifiManager)getSystemService(WIFI_SERVICE),(CheckBoxPreference)findPreference(KEY_TOGGLE_WIFI));当用户按下Wifi按钮后,Android会调用WifiEnabler的onPreferenceChange,再由WifiEnabler调用WifiManager的setWifiEnabled接口函数,通过AIDL,实际调用的是WifiService的setWifiEnabled函数,WifiService接着向自身发送一条MESSAGE_ENABLE_WIFI消息,在处理该消息的代码中做真正的使能工作:首先装载WIFI内核模块(该模块的位置硬编码为"/system/lib/modules/wlan.ko"),然后启动wpa_supplicant(配置文件硬编码为"/data/misc/wifi/wpa_supplicant.conf")再通过WifiStateTracker来启动WifiMonitor中的监视,线程。privatebooleansetWifiEnabledBlocking(booleanenable){finalinteventualWifiState=enable?WIFI_STATE_ENABLED:WIFI_STATE_DISABLED;updateWifiState(enable?WIFI_STATE_ENABLING:WIFI_STATE_DISABLING);if(enable){if(!WifiNative.loadDriver()){Log.e(TAG,"FailedtoloadWi-Fidriver.");updateWifiState(WIFI_STATE_UNKNOWN);returnfalse;}if(!WifiNative.startSupplicant()){WifiNative.unloadDriver();Log.e(TAG,"Failedtostartsupplicantdaemon.");updateWifiState(WIFI_STATE_UNKNOWN);returnfalse