一張簡圖就是最基本的初始化過程啦!
稍微描述如下列各項:
1) 透過 new WifiService(context) 開啟wifi的服務, 也透過ConnectivityService() 開啟 connectivity服務
位置: android/frameworks/base/services/java/com/android/server/SystemServer.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
try { Slog.i(TAG, "Wi-Fi Service"); wifi = new WifiService(context); ServiceManager.addService(Context.WIFI_SERVICE, wifi); } catch (Throwable e) { reportWtf("starting Wi-Fi Service", e); } try { int enableCne = 1; if (!deviceHasSufficientMemory()) { enableCne = SystemProperties.getInt("persist.cne.override.memlimit", 0); } int cneFeature = (enableCne == 1) ? SystemProperties.getInt("persist.cne.feature", 0) : 0; if ( cneFeature > 0 && cneFeature < 10 ) { Slog.i(TAG, "QcConnectivity Service"); PathClassLoader qcsClassLoader = new PathClassLoader("/system/framework/services-ext.jar", ClassLoader.getSystemClassLoader()); Class qcsClass = qcsClassLoader.loadClass("com.android.server.QcConnectivityService"); Constructor qcsConstructor = qcsClass.getConstructor (new Class[] {Context.class, INetworkManagementService.class, INetworkStatsService.class, INetworkPolicyManager.class}); qcCon = qcsConstructor.newInstance( context, networkManagement, networkStats, networkPolicy); connectivity = (ConnectivityService) qcCon; } else { Slog.i(TAG, "Connectivity Service"); <strong>connectivity = new ConnectivityService( context, networkManagement, networkStats, networkPolicy);</strong> } if (connectivity != null) { ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); networkStats.bindConnectivityManager(connectivity); networkPolicy.bindConnectivityManager(connectivity); wifi.checkAndStartWifi(); wifiP2p.connectivityServiceReady(); } } catch (Throwable e) { reportWtf("starting Connectivity Service", e); } |
2) 由第一項SystemServer.java裡呼叫 WifiService()定義
位置: android/frameworks/base/services/java/com/android/server/wifi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/** * WifiService handles remote WiFi operation requests by implementing * the IWifiManager interface. * * @hide */ public final class WifiService extends IWifiManager.Stub { private static final String TAG = "WifiService"; private static final boolean DBG = false; final WifiStateMachine mWifiStateMachine; private final Context mContext; .... |
3) 由第一項SystemServer.java裡呼叫 ConnectivityService()
位置: android/frameworks/base/services/java/com/android/server/ConnectivityService.java
1 2 3 4 5 6 7 8 9 10 11 |
/** * @hide */ public class ConnectivityService extends IConnectivityManager.Stub { private static final String TAG = "ConnectivityService"; protected static final boolean DBG = true; protected static final boolean VDBG = false; protected static final boolean LOGD_RULES = false; ... |
4) 由第三項ConnectivityService.java裡呼叫 WifiStateTracker()
位置: android/frameworks/base/services/java/com/android/server/wifi/WifiStateTracker
1 2 3 4 5 6 7 8 |
public WifiStateTracker(int netType, String networkName) { mNetworkInfo = new NetworkInfo(netType, 0, networkName, ""); mLinkProperties = new LinkProperties(); mLinkCapabilities = new LinkCapabilities(); mNetworkInfo.setIsAvailable(false); setTeardownRequested(false); } |
以上的話, 大致wifi的初始化ok