- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Android 2.3 拨号上网流程从源码角度进行分析由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
通常,如果我们想使用SIM卡拨号上网功能,我们要在设置中进行简单的配置,步骤如下: 设置 -》无线和网络 -》移动网络 -》(已启用数据/数据漫游/接入点名称/仅使用2G网络/网络运营商) 我们必须选中其中的“已启用数据”选项,然后配置接入点名称后就可以上网了,当然有的设置中已经根据你的SIM卡类型默认设置了接入点,这时候你只选择“已启用数据”项后就可以完成上网功能设置。 这些设置步骤究竟做了哪些事情呢?我们现在就从源码的角度进行分析。 1. 首先,我们找到“移动网络”的设置UI-------Settings.java(/packages/apps/Phone/src/com/android/phone/Settings.java) Settings.java: "已启用数据"选项的相关代码如下:
复制代码 代码如下
...... else if (preference == mButtonDataEnabled) { if (DBG) log("onPreferenceTreeClick: preference == mButtonDataEnabled."); ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); cm.setMobileDataEnabled(mButtonDataEnabled.isChecked()); return true; } ...... 。
代码中,我们得到一个ConnectivityManager对象,并调用该对象的setMobileDataEnable(boolean b)方法,根据传入的参数进行设置,我们看一下ConnectivityManager类。 2. ConnectivityManager.java(/frameworks/base/core/java/android/net/ConnectivityManager.java) 这个时候,数据已经进入frameworks层。 setMobileDataEnable()方法代码如下:
复制代码 代码如下
IConnectivityManager mService; ...... public ConnectivityManager(IConnectivityManager service) { if (service == null) { throw new IllegalArgumentException( "ConnectivityManager() cannot be constructed with null service"); } mService = service; } ...... public void setMobileDataEnabled(boolean enabled) { try { mService.setMobileDataEnabled(enabled); } catch (RemoteException e) { } } 。
这里我们要知道IConnectivityManager类,是根据IConnectivityManager.aidl接口自动生成的一个java类,而我们自己有一个Service则继承了该类的内部类:Stub,在我们自己为拨号上网实现的这个Service就是ConnectivityService,所以根据AIDL只是,我们知道,代码中的mService其实就是ConnectivityService类的对象,所以代码在这里实际上是调用了ConnectivityService对象的setMobileDataEnable()方法。 3. ConnectivityService.java(/frameworks/./base/services/java/com/android/server/ConnectivityService.java) setMobileDataEnable()方法代码如下:
复制代码 代码如下
public void setMobileDataEnabled(boolean enabled) { enforceChangePermission(); if (DBG) Slog.d(TAG, "setMobileDataEnabled(" + enabled + ")"); mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_MOBILE_DATA, (enabled ? ENABLED : DISABLED), 0)); } 。
这里发送了一个消息出去,mHandler收到该消息以后:
复制代码 代码如下
case EVENT_SET_MOBILE_DATA: { boolean enabled = (msg.arg1 == ENABLED); handleSetMobileData(enabled); break; } 。
收到该消息后,调用handleSetMobileData()方法:
复制代码 代码如下
private NetworkStateTracker mNetTrackers[]; ...... private void handleSetMobileData(boolean enabled) { ...... if (enabled) { if (mNetTrackers[ConnectivityManager.TYPE_MOBILE] != null) { if (DBG) { Slog.d(TAG, "starting up " + mNetTrackers[ConnectivityManager.TYPE_MOBILE]); } mNetTrackers[ConnectivityManager.TYPE_MOBILE].reconnect(); } ...... } } 。
如果“已启用数据”选项已经选择,那这个时候传进来的参数“enabled”应该是“true”,所以会处理代码中if语句块,即执行:
复制代码 代码如下
mNetTrackers[ConnectivityManager.TYPE_MOBILE].reconnect(),
而在ConnectivityManager中,TYPE_MOBILE 为 0,所以这里相当于调用了 。
复制代码 代码如下
mNetTracker[0].reconnect() 。
但是,NetworkStateTracker是一个抽象类,所以具体的事情要交给它的子类MobileDataStateTracker.java来干。 4. MobileDataStateTracker.java(/frameworks/base/core/java/android/net/MobileDataStateTracker.java) 该类包含多种数据连接,包括MMS,SUPL,DUN等, 在MobileDataStateTracker.java里面的调用流程是这样的:
复制代码 代码如下
<PRE class=java name="code">mPhoneService = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));</PRE>......<BR> reconnect->mPhoneService.enableApnType(apnType);<P></P> <PRE></PRE> mPhoneService是电话的服务的客户端,它的server端实际上是PhoneInterfaceManager对象 <P></P> <P>5. PhoneInterfaceManager.java(/packages/apps/Phone/src/com/android/phone/PhoneInterfaceManager.java)<BR> </P> <P>看PhoneInterfaceManager的enableApnType方法:</P> <P><PRE class=java name="code"> public int enableApnType(String type) { enforceModifyPermission(); return mPhone.enableApnType(type); } </PRE><P></P> 这样,就将连接apn的请求发送到telephony框架层下去了。apn在设置应用里面有指定,一般在你的工程目录下的system/etc/apns-conf.xml文件<BR> <BR> <P>6. 上面的mPhone是PhoneProxy对象,</P> <P>调用流程:</P> <P>PhoneProxy.java:<BR> </P> <P><PRE class=java name="code">mActivePhone.enableApnType(type)</PRE>mActivePhone是GSMPhone或者CDMAPhone的上溯接口PhoneBase对象<BR> <P></P> <P>PhoneBase.java:</P> <P><PRE class=java name="code">mDataConnection.enableApnType(type);</PRE><P></P> <P>调用到 DataConnectionTracker的enableApnType方法</P> <P>DataConnectionTracker.java:<BR> </P> <P>enableApnType(String type)->setEnabled->onEnableApn->onEnableNewApn<BR> </P> <BR> <P>onEnableNewApn方法在DataConnectionTracker的派生类GsmDataConnectionTracker和CdmaDataConnectionTracker中实现,从而区别不同类型PHONE的数据连接流程。<BR> </P> <P>以GSM为例,调用流程:onEnableNewApn->cleanUpConnection->conn.disconnect<BR> <BR> </P> conn是DataConnection对象,标识一钟数据连接,可以看出这里实际上实现了一个数据连接的状态机。<BR> <P>在DataConnection对象里面数据连接的状态分为:</P> <P><PRE class=java name="code">DcDefaultState,默认状态。 DcInactiveState,非激活状态。 DcActivatingState,正在激活状态 DcActiveState,激活状态 DcDisconnectingState,正在断开状态 DcDisconnectingBadDnsState,断开状态(因为错误的DNS) </PRE><P></P> <P>连接成功以后,notifyDefaultData调用到DefaultPhoneNotifier的notifyDataConnection方法。</P> <P>DefaultPhoneNotifier是ITelephonyRegistry接口的客户端,其服务端是TelephonyRegistry(com.android.server.TelephonyRegistry)</P> <P>TelephonyRegistry的notifyDataConnection方法调用如下语句<BR> <PRE class=java name="code"> r.callback.onDataConnectionStateChanged(state, networkType);</PRE><P></P> <P>r是当前mRecords中的元素,包含有IPhoneStateListener接口的实现callback,TelephonyRegistry中的每个调用都会遍历mRecords中的元素,如果某个元素注册了对应接听,</P> <P>则调用callback的某个函数。</P> <P>客户端通过如下方式调用取得电话状态的监听, 以StatusBarPolicy.java中的mPhoneStateListener为例:</P> <P> ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE))</P> <P> .listen(mPhoneStateListener,<BR> PhoneStateListener.LISTEN_SERVICE_STATE<BR> | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS<BR> | PhoneStateListener.LISTEN_CALL_STATE<BR> | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE<BR> | PhoneStateListener.LISTEN_DATA_ACTIVITY);<BR> </P> <P>mPhoneStateListener是PhoneStateListener实例,PhoneStateListener实现了IPhoneStateListener接口,假如你继承PhoneStateListener子类,首先你要确定你感兴趣的监听</P> <P>事件,然后重写对应的方法。再像上面那样调用listen方法就可以了。</P> <P>TelephonyRegistry的方法、监听动作、已经你要重写的方法对应关系如下:</P> <P>TelephonyRegistry的方法 ---------------------监听动作-------------------------------------------------------PhoneStateListener子类中的中的回调<BR> </P> <P>notifyServiceState ---------- PhoneStateListener.LISTEN_SERVICE_STATE ----------------- public void onServiceStateChanged(ServiceState state) <BR> </P> <P>notifySignalStrength ------- PhoneStateListener.LISTEN_SIGNAL_STRENGTHS --------- -- public void onSignalStrengthsChanged(SignalStrength signalStrength)<BR> </P> <P>notifyCallState ---------------- PhoneStateListener.LISTEN_CALL_STATE ------------------------- public void onCallStateChanged(int state, String incomingNumber)<BR> </P> <P>notifyDataConnection ------- PhoneStateListener.LISTEN_DATA_CONNECTION_STATE --- public void onDataConnectionStateChanged(int state, int networkType)<BR> </P> <P>notifyDataActivity -------------- PhoneStateListener.LISTEN_DATA_ACTIVITY ----------------------- public void onDataActivity(int direction)<BR> </P> <P>。。。。。。。。</P> <P>因此整个调用链是:DefaultPhoneNotifier:notifyDataConnection ---------》 TelephonyRegistry :notifyDataConnection---------》</P> <P>PhoneStateListener.callback:onDataConnectionStateChanged --------------》PhoneStateListener子类的onDataConnectionStateChanged</P> <P>除此之外,TelephonyRegistry还发出一个ACTION_ANY_DATA_CONNECTION_STATE_CHANGED,包含数据连接的详细信息。</P> <P><BR> 而Mobile Data Service里面的MobileDataStateTracker会接收到这个动作,由它的BoadcastReceiver类MobileDataStateReceiver提取出数据连接的信息,然后设置好状态</P> <PRE class=java name="code">setDetailedState(DetailedState.CONNECTING, reason, apnName); </PRE> <P>MobileDataStateTracker根据状态变化给ConnectivityService发送EVENT_STATE_CHANGED消息。</P> <P>ConnectivityService调用handleConnect去执行相关炒作,包括关闭优先级比它低的数据连接,更新状态栏等等。<BR> </P> <P>还有很多地方还没有搞明白,以后再续。<BR> </P> <P><BR> </P> <P><BR> </P> <BR> <P><BR> <BR> </P> 。
最后此篇关于Android 2.3 拨号上网流程从源码角度进行分析的文章就讲到这里了,如果你想了解更多关于Android 2.3 拨号上网流程从源码角度进行分析的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
首先是一些背景;我们正在开发一个数据仓库,并对我们的 ETL 过程使用哪些工具进行一些研究。该团队非常以开发人员为中心,每个人都熟悉 C#。到目前为止,我已经看过 RhinoETL、Pentaho (
我需要具有管理员权限的进程。从this问题和答案来看,似乎没有比启动单独进程更好的方法了。因为我宁愿有一个专用于该过程的过程,而不是仅为此方法在第二个过程中启动我的原始应用程序–我以为我会在VS201
我有这个函数来压平对象 export function flattenObject(object: Object, prefix: string = "") { return Object.key
我正在开发一个基于java的Web应用程序,它要求我使用来自SIP( session 启动协议(protocol))消息的输入生成序列图。我必须表示不同电话和相应服务器之间的调用流程。我可以利用任何工
这是我的代码: Process p=Runtime.getRuntime().exec("something command"); String s; JFrame frame = new JFram
我对 istio 的 mTLS 流程有点困惑。在bookinginfo 示例中,我看到服务通过http 而不是https 进行调用。如果服务之间有 mTLS 那么服务会进行 http 调用吗? 是否可
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
之前做过一个简单的纸牌游戏,对程序的整体流程有自己的想法。我最关心的是卡片触发器。 假设我们有一张名为“Guy”的牌,其效果为“每当你打出另一张牌时,获得 2 点生命”。我将如何将其合并到我的代码中?
我有 4 个 Activity 。 A、B、C 和 D。 用户可以从每个 Activity 开始任何 Activity 。 即 Activity A 有 3 个按钮来启动 B、C 和 D。以同样的方式
我做了一个简单的路由器类,简化后看起来像这样 // @flow import { Container } from 'unstated' type State = { history: Objec
我有两个 Activity ,比如 A1 和 A2。顺序为 A1->A2我从 A1 开始 A2 而没有在 A1 中调用 finish() 。在 A2 中按下后退按钮后,我想在 A1 中触发一个功能。但
我正在考虑在我的下一个项目中使用 BPEL。我试用了 Netbeans BPEL 设计器,我对它很满意。但在我决定使用 BPEL 之前,我想知道它对测试驱动开发的适用程度。不幸的是,我对那个话题知之甚
我需要将两个表格堆叠在一起,前后都有内容。我无法让后面的内容正常流动。堆叠的 table 高度可变。 HTML 结构: ... other content ...
我是 Hibernate 的新手。我无法理解 Hibernate 的流程。请澄清我的疑问。 我有“HibernateUtil.java ”和以下语句 sessionFactory = new Anno
早上好 我开始使用 Ruby,想创建一个小工具来获取我的公共(public) IP 并通过电子邮件发送。我遇到了字符串比较和无法处理的 if/else block 的基本问题。 代码非常简单(见下文)
我目前正尝试在我的团队中建立一个开发流程并阅读有关 GitFlow 的信息。它看起来很有趣,但我可以发现一些问题。 让我们假设以下场景: 我们完成了 F1、F2 和 F3 功能,并将它们 merge
我已经使用 git flow 有一段时间了。我很想了解一个特定的用例。 对于我的一个项目,我有一张新网站功能的门票。此工单取决于许多子任务。我想为主工单创建一个功能分支,然后为每个子任务创建一个脱离父
你怎么知道在一个程序中已经发现并解决了尽可能多的错误? 几年前我读过一篇关于调试的文档(我认为这是某种 HOWTO)。其中,该文档描述了一种技术,其中编程团队故意将错误添加到代码中并将其传递给 QA
我目前正在构建一个微服务架构,并从身份验证服务器和客户端着手。我还想确认使用 token 对用户进行身份验证的最佳流程。 在上图中。第 3 步是我开始感到困惑。我想到了2个解决问题的方法。 每个 ap
我是一名优秀的程序员,十分优秀!