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     <!-- An Array of "[Connection name],[ConnectivityManager.TYPE_xxxx],
108          [associated radio-type],[priority],[restoral-timer(ms)],[dependencyMet]  -->
109     <!-- the 5th element "resore-time" indicates the number of milliseconds to delay
110          before automatically restore the default connection.  Set -1 if the connection
111          does not require auto-restore. -->
112     <!-- the 6th element indicates boot-time dependency-met value. -->
113     <string-array translatable="false" name="networkAttributes">
114         <item>"wifi,1,1,1,-1,true"</item>
115         <item>"mobile,0,0,0,-1,true"</item>
116         <item>"mobile_mms,2,0,2,60000,true"</item>
117         <item>"mobile_supl,3,0,2,60000,true"</item>
118         <item>"mobile_hipri,5,0,3,60000,true"</item>
119         <item>"mobile_fota,10,0,2,60000,true"</item>
120         <item>"mobile_ims,11,0,2,60000,true"</item>
121         <item>"mobile_cbs,12,0,2,60000,true"</item>
122         <item>"wifi_p2p,13,1,0,-1,true"</item>
123     </string-array>
    ...
138     <string-array translatable="false" name="radioAttributes">
139         <item>"1,1"</item>
140         <item>"0,1"</item>
141     </string-array>
另外,ConnectivityService与DNS,×××,Tether,Proxy相关的代码,均未深入研究
ConnectivityManager提供了抽象的连接管理功能,与具体连接物理层无关,
例如wifi的链接管理,需要看 wifi manager/ wifi service , which I did not investigate yet. 

转载于:https://blog.51cto.com/mengxx/751198

ConnectivityManager ConnectivityService in Android相关推荐

  1. Android Connectivity分析(1)- ConnectivityManager

    Android Connectivity分析(1)- ConnectivityManager 分类: android framework系列分析 2013-03-19 16:29 3302人阅读 评论 ...

  2. Android WiFi —softAP流程分析

    Android WiFi - Ap功能实现与源码分析 0. 前言 wifiAp的ip WifiAp的config分析 2.1 默认的config 2.2 修改wifiAp的config配置流程 开启/ ...

  3. Android组件系列----BroadcastReceiver广播接收器

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  4. Android开发笔记(四十二)Broadcast的生命周期

    Broadcast是什么 广播的特性 广播(Broadcast)用于Android组件之间的灵活通信,它与Activity和Service的区别在于: 1.Activity和Service都只能一对一 ...

  5. Android AsyncTask 详解及注意事项

    AsyncTask是Android提供的轻量级的异步类,它使创建异步任务变得更加简单,不再需要编写任务线程和Handler实例即可完成相同的任务. AsyncTask定义了三种泛型类型 Params, ...

  6. android wifi热点setting

    目录 一.wifi原生setting的入口在WifiTetherSettings.java 二.改热点Setting的时候可以直接只编译Settings.apk,并且替换, 三.wifi热点貌似官方支 ...

  7. Android中判断Wift是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏

    第一个问题:判断手机当前上网用的是sim卡还是wifi,我写了一个封装的方法,以后可以拿来用: [java] view plaincopy print? /** * check the interne ...

  8. 以 Android 11 为目标平台的应用

    只有指定了targetVersion=30时需要适配一下内容. 1.存储与访问机制变更 Android 中存储可以分为两大类:私有存储和共享存储 私有存储 (Private Storage) : 每个 ...

  9. 初学 Android 架构组件之 Lifecycle

    在开发应用时,我们可能会基于一系列的生命周期实现某种功能.为了复用,也为了不让应用组件变得很臃肿,实现该功能时会选择与生命周期组件解藕,独立成一种组件.这样能够很方便地在应用组件中使用,比如:Acti ...

最新文章

  1. magento获取判断当前页或句柄handles
  2. 为什么单片机通常只有那么小的数据内存?
  3. Java程序员涨薪必备技能
  4. 对计算机描述错误的是什么意思,下列对计算机特点的描述中错误的是:________。...
  5. 【工业】工业控制博客汇总
  6. 开源Easydarwin流媒体服务器Windows编译、配置、部署
  7. 每个Java开发人员都必须避免的9个安全错误
  8. MyBatis启动流程分析
  9. android资源编译失败,在android studio中打开一个新项目时,Android资源编译失败
  10. 微服务学习之服务治理、服务注册与发现、Eureka【Hoxton.SR1版】
  11. 第一个被赋予公明身份的机器人_机器人索菲亚扬言要消灭人类!曾经狂妄无比,现在过得如何...
  12. Dev--Config Files
  13. 地址转经纬度(百度)function
  14. 手机屏幕保护DIY全教程
  15. 三年磨一剑大话数据结构——数据结构起源、概念和术语
  16. 查看域名是否支持IPv6
  17. 微信小程序实现文本两端对齐
  18. 【BUG】The import XXX collides with another import statement
  19. Hall Schematic
  20. usd to php exchange,USD to PHP

热门文章

  1. kvm服务器中心管理,IP KVM如何在公共场所数据中心合理应用
  2. 语言余一个负数_C语言学习日记(8)——整数溢出
  3. mysql 5.5.15_mysql5.5.15配置主从数据库
  4. MySQL排序查询示例
  5. 索引方式:真的是用的B+Tree 吗?
  6. Dubbo监控平台安装
  7. stateOffset
  8. ReentrantLock重入锁
  9. 构造方法注入和设值注入有什么区别?
  10. 什么时候需要任务调度?