android connectivity_service,ConnectivityManager ConnectivityService in Android

connectivity manager (封装了ConnectivityService)

管理多种连接方式 mobile/wifi/ether/bt/usb-tether/etc   要新加一个type,需要很复杂的改动(patch)

同一时刻只有一个active的数据连接 见NetworkInfo  getActiveNetworkInfo()  (也就是说不支持3G wifi同时开着)

(但是,将来很可能会改成支持多个网络同时连接,见:

private static class RadioAttributes {

public int mSimultaneity;

...

)

connection type的优先顺序

ConncectionManager.java 提供了getNetworkPreference setNetworkPreference方法

preference的网络可以是任何type,比如mobile, wifi, bt都可以。

目前preference网络只能有一个  也就是不支持优先级列表,比如最prefer wifi,其次prefer ether,再次prefer mobile 3G

(但是,将来很可能改成支持优先列表,见:

// priority order of the nettrackers

// (excluding dynamically set mNetworkPreference)

// TODO - move mNetworkTypePreference into this

private int[] mPriorityList;、

)

当调用setNetworkPreference时,perfer的网络会被持久化,记录在数据库中

当调用getNetworkPreference时,会从数据库中取回,如果没有记录,就默认wifi

(详见ConnectivityManager.java的hard code : public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;)

这里,只是说优先wifi连接模式,不能设置哪个AP/SSID优先

(AP/SSID优先也能做,另有N种实现方法,都不难)

已经保存了优先网络,如何enforcePreference? todo

当WiFi连上,已经存在的连接(e.g. mobile GPRS,3G,etc)会自动断开 (因为同时不能存在两个active连接)

当离开wifi热点,信号不足时,wifi断开,如仍有数据连接请求,会尝试使用其它连接,如mobile。

这些逻辑保存在ConnectivityService.java中handleConnected handleDisconnect等方法中,未深入研究

network config, radio attribute等配置文件在 /frameworks/base/core/res/res/values/config.xml

(也可针对device定制config.xml,保存在device目录中)

通过读这个文件初始化ConnectivityService的 mNetConfigs mRadioAttributes,见下面xml comments

107    

109    

112    

113    

114         "wifi,1,1,1,-1,true"

115         "mobile,0,0,0,-1,true"

116         "mobile_mms,2,0,2,60000,true"

117         "mobile_supl,3,0,2,60000,true"

118         "mobile_hipri,5,0,3,60000,true"

119         "mobile_fota,10,0,2,60000,true"

120         "mobile_ims,11,0,2,60000,true"

121         "mobile_cbs,12,0,2,60000,true"

122         "wifi_p2p,13,1,0,-1,true"

123    

...

138    

139         "1,1"

140         "0,1"

141    

另外,ConnectivityService与DNS,×××,Tether,Proxy相关的代码,均未深入研究

ConnectivityManager提供了抽象的连接管理功能,与具体连接物理层无关,

例如wifi的链接管理,需要看 wifi manager/ wifi service , which I did not investigate yet.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值