资源描述:
《android40wifi模块详细解析》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、android4.0wifi模块详细解析rmjustpickinguptheAndroidsourceforafewdays・ThefollowingaresomeoftheprocessesthatareinitializedinICS・Thedocumentsinvolvedinclude:SystemServer・JavaWifiSettings.JavaWifiEnabler・JavaWifiManager・JavaWifiService・JavaWifiStateMachine.Java
2、Androidnetwifiwifi.CPPWifi.CFirst,fromsystemserver・java,itdidthreeactions:AddaConnectivityServiceconnectionservice,whichconnectswirelesslytoallmobilephones,includingwifi,bluetooth,2g,3g,andsoonConnectivity=newConnectivityService(Context,networkManagem
3、ent,networkStats,networkStats;ServiceManager・(context・connectivity_service,connectivity);ManagetheproblemofturningonwifiWifi.CheckAndStartWifi();PublicvoidCheckAndStartWifi()ThemAirplaneModeOn・(getPersistedWifiState());BooleanwifiEnabled二shouldWifiBeE
4、nabled()
5、testanclearwifisavedstate()SetWifiEnabled(wifiEnabled);WifiWatchdogStateMachine二WifiWatchdogStateMachine.MakeWifiWatchdogStateMachine(mContext);Addacoreservicecalledwifiservice,whichregisterswifiWifi二newWifiService(context);ServiceManager・add
6、service(context・wifiservice,wifi);Ok,sothat,stheactionwhenthemachinestarts.Toturnonthewifi,youneedtoopentheuserinterface・,Here,showthewifiisturnedonEnterthewifiSettingsinterface,WifiSettings・JavaThecomponentthatopensWifiisaCompoundButton,whichisassoci
7、atedwithawifienabler・javaclass,whichisinitializedinWifiSettingsBundlesavedinstanceStateWifiEnabler二newWifiEnabler(activity,actionBarSwitch);Whentheuserclicksonthewifibutton,theonCheckedChangedfunctioninWifiEnableristriggeredPublicvoidonCheckedChangedI
8、f(mwifimanager.setwifienabled(isChecked)){・・・MSwitch・SetEnabled(false);}else{Toast・MakeText.IntheonCheckedChangedfunction,thesetWifiEnabledmethodofWifiManageriscalledPublicBooleansetWifiEnabled(Booleanenabled){Try{ReturnmService・SetWifiEnabled(enabled
9、);}catch(RemoteExceptione)Returnfalse;Itreturnsmservice・setwifienabled(enabled),wheremServiceistheproxyforWifiService,soitactuallycallsthesetWifiEnabledfunctioninWifiServicePublicclassWifiServiceextendsIWifiManager・Stub,wecanseeWifiServiceIWif