標籤:android wifi 串連優先順序 查看密碼
目前Android的WiFi自動連接的優先順序規則如下:
1、priority值的範圍設定為[0,1000000),如果超出此範圍則會reset;
2、最近串連過的AP擁有最高priority,在自動連接中會首先嘗試串連它;
3、未串連過但是掃描到的AP,按其訊號值強弱排序,越強的顯示靠前,但是,還得綜合
AP的安全因素,基本情況是:WPA/WPA2 > WEP > signal level high > signal level low > noise low > noise
high
4、如果是預置的AP,可能會人為設定其最高的priority;
看一下源碼,代碼路徑:frameworks/base/wifi/java/android/net/wifi/
WifiConfigStore.java
boolean selectNetwork(int netId) { if (VDBG) localLog("selectNetwork", netId); if (netId == INVALID_NETWORK_ID) return false; // Reset the priority of each network at start or if it goes too high. if (mLastPriority == -1 || mLastPriority > 1000000) { Xlog.d(TAG, "Need to reset the priority, mLastPriority:" + mLastPriority); for(WifiConfiguration config : mConfiguredNetworks.values()) { if (config.networkId != INVALID_NETWORK_ID) { config.priority = 0; addOrUpdateNetworkNative(config); } } mLastPriority = 0; } // Set to the highest priority and save the configuration. WifiConfiguration config = new WifiConfiguration(); config.networkId = netId; config.priority = ++mLastPriority; addOrUpdateNetworkNative(config); mWifiNative.saveConfig(); /* Enable the given network while disabling all other networks */ enableNetworkWithoutBroadcast(netId, true); /* Avoid saving the config & sending a broadcast to prevent settings * from displaying a disabled list of networks */ return true; }
有時候,我們會忘記已串連WiFi的密碼,應用市場也有相關的應用可以幫我們讀取。其實如有有Root許可權,用RE檔案管理工具(Root Explorer)就可以查看了。檔案路徑:
/data/misc/wifi/sockets/wpa_supplicant.conf
每一個network包裹起來的就是一個串連過的WiFi熱點,其中ssid是名字,psk就是密碼了,也可以看到其他資訊,包括加密類型key_mgmt和優先順序priority,是否自動連接autojoin等,如:
轉載請註明出處:周木水的CSDN部落格 http://blog.csdn.net/zhoumushui
我的GitHub:周木水的GitHub https://github.com/zhoumushui
Android自動連接WiFi優先順序規則,以及查看已串連WiFi的密碼