在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            Android WIFI 詳解

            作者: 時間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

            if (mSelected != null) {

            mWifiManager.updateNetwork(config);

            saveNetworks();

            }

            } else {

            int networkId =mWifiManager.addNetwork(config);

            if (networkId != -1) {

            mWifiManager.enableNetwork(networkId, false);

            config.networkId =networkId;

            if (mDialog.edit || requireKeyStore(config)){

            saveNetworks();

            } else {

            connect(networkId);

            }

            }

            }

            }

            }

            FrameworksbasewifijavaandroidnetwifiWifiManager.java

            public intupdateNetwork(WifiConfiguration config) {

            if(config == null || config.networkId 0) {

            return -1;

            }

            return addOrUpdateNetwork(config);

            }

            private intaddOrUpdateNetwork(WifiConfiguration config) {

            try {

            return mService.addOrUpdateNetwork(config);

            } catch (RemoteException e) {

            return -1;

            }

            }

            WifiService.addOrUpdateNetwork()通過調(diào)用mWifiStateTracker.setNetworkVariable()將連接命令發(fā)送到Wpa_supplicant。

            (4)獲取IP地址

            當(dāng)連接到supplicant后,WifiMonitor就會通知WifiStateTracker。

            Frameworks/base/wifi/java/android/net/wifi/WifiMonitor.java

            Public void Run(){

            if (connectToSupplicant()) {

            // Send a message indicatingthat it is now possible to send commands

            // to the supplicant

            mWifiStateTracker.notifySupplicantConnection();

            } else {

            mWifiStateTracker.notifySupplicantLost();

            return;

            }

            ……

            }

            WifiStateTracker發(fā)送EVENT_SUPPLICANT_CONNECTION消息到消息隊列,這個消息有自己的handlermessage()函數(shù)處理,它會啟動一個DHCP線程,而這個線程會一直等待一個消息事件,來啟動DHCP協(xié)議分配IP地址。

            frameworks/base/wifi/java/android/net/wifi/WifiStateTracker.java

            void notifySupplicantConnection() {

            sendEmptyMessage(EVENT_SUPPLICANT_CONNECTION);

            }

            public void handleMessage(Message msg) {

            Intent intent;

            switch (msg.what) {

            case EVENT_SUPPLICANT_CONNECTION:

            ……

            HandlerThread dhcpThread = newHandlerThread(DHCP Handler Thread);

            dhcpThread.start();

            mDhcpTarget = newDhcpHandler(dhcpThread.getLooper(), this);

            ……

            ……

            }

            當(dāng)Wpa_supplicant連接到AP后,它會發(fā)送一個消息給上層來通知連接成功,WifiMonitor會接受到這個消息并上報給WifiStateTracker。

            Frameworks/base/wifi/java/android/net/wifi/WifiMonitor.java

            void handleEvent(int event, String remainder) {

            switch (event) {

            case DISCONNECTED:

            handleNetworkStateChange(NetworkInfo.DetailedState.DISCONNECTED,remainder);

            break;

            case CONNECTED:

            handleNetworkStateChange(NetworkInfo.DetailedState.CONNECTED,remainder);

            break;

            ……

            }

            private voidhandleNetworkStateChange(NetworkInfo.DetailedState newState, String data) {

            StringBSSID = null;

            intnetworkId = -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 CONNECTEDevent string);

            }else {

            BSSID = match.group(1);

            try {

            networkId = Integer.parseInt(match.group(2));

            } catch (NumberFormatException e) {

            networkId = -1;

            }

            }

            }

            mWifiStateTracker.notifyStateChange(newState,BSSID, networkId);

            }

            void notifyStateChange(DetailedState newState, StringBSSID, int networkId) {

            Messagemsg = Message.obtain(

            this, EVENT_NETWORK_STATE_CHANGED,

            newNetworkStateChangeResult(newState, BSSID, networkId));

            msg.sendToTarget();

            }

            caseEVENT_NETWORK_STATE_CHANGED:

            ……

            configureInterface();

            ……

            private void configureInterface() {

            checkPollTimer();

            mLastSignalLevel = -1;

            if(!mUseStaticIp) { //使用DHCP線程動態(tài)IP

            if(!mHaveIpAddress !mObtainingIpAddress) {

            mObtainingIpAddress = true;

            //發(fā)送啟動DHCP線程獲取IP

            mDhcpTarget.sendEmptyMessage(EVENT_DHCP_START);

            }

            } else { //使用靜態(tài)IP,IP信息從mDhcpInfo中獲取

            intevent;

            if(NetworkUtils.configureInterface(mInterfaceName, mDhcpInfo)) {

            mHaveIpAddress = true;

            event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED;

            if (LOCAL_LOGD) Log.v(TAG, Static IP configurationsucceeded);

            }else {

            mHaveIpAddress = false;

            event = EVENT_INTERFACE_CONFIGURATION_FAILED;

            if (LOCAL_LOGD) Log.v(TAG, Static IP configuration failed);

            }

            sendEmptyMessage(event); //發(fā)送IP獲得成功消息事件

            }

            }

            DhcpThread獲取EVENT_DHCP_START消息事件后,調(diào)用handleMessage()函數(shù),啟動DHCP獲取IP地址的服務(wù)。



            關(guān)鍵詞:

            評論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉