本文主要是介绍数据业务建立流程之DcTracker创建过程(原),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、DcTracker介绍
DcTracker是Telephony框架中负责数据业务的核心(类似于GsmCallTracker是通话业务核心,GsmServiceStateTracker是网络CS业务的核心),所有对数据网络的请求(打开关闭数据开关、切换数据卡、修改APN参数等)都会发送到该处理中心来处理。本节所涉及的大部分代码也都在该对象中。下面我们先来看该对象的初始化流程。
DcTracker是在Phone对象创建过程中被创建的,确切来说,如果当前使用的是GSMPhone,那么在GSMPhone创建过程中就会创建DcTracker对象: @GSMPhone.javapublic GSMPhone (Context context, CommandsInterface ci, PhoneNotifier notifier, boolean unitTestMode) {//创建DcTracker对象,传递的参数就是当前的GSMPhone对象mDcTracker = new DcTracker(this);}
那么DcTracker是什么属性呢?
public final class DcTracker extends DcTrackerBase {}public abstract class DcTrackerBase extends Handler {}
从这里看到,DcTracker的父类是DcTrackerBase,
他们的本质都是Handler。
然后来看DcTracker的初始化过程:
@DcTracker.javapublic DcTracker(PhoneBase p) {super(p);mDataConnectionTracker = this;//注册监听器update();//监听APN状态mApnObserver = new ApnChangeObserver();p.getContext().getContentResolver().registerContentObserver(Telephony.Carriers.CONTENT_URI, true, mApnObserver);//从networkAttributes数组中初始化APN参数initApnContexts();for (ApnContext apnContext : mApnContexts.values()) {IntentFilter filter = new IntentFilter();filter.addAction(INTENT_RECONNECT_ALARM + '.' + apnContext.getApnType());filter.addAction(INTENT_RESTART_TRYSETUP_ALARM + '.' + apnContext.getApnType());mPhone.getContext().registerReceiver(mIntentReceiver, filter, null, mPhone);}ConnectivityManager cm = (ConnectivityManager)p.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);//添加各种网络请求过滤器,用于根据这些过滤器发起不同的数据连接mNetworkFilter = new NetworkCapabilities();mNetworkFilter.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_SUPL);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_FOTA);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_IMS);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_CBS);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_IA);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_RCS);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_XCAP);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_EIMS);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);mNetworkFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);//初始化数据网络的NetworkFactory,并设置数据网络的分值为50mNetworkFactory = new TelephonyNetworkFactory(this.getLooper(), p.getContext(), "TelephonyNetworkFactory", mNetworkFilter);mNetworkFactory.setScoreFilter(50);mNetworkFactoryMessenger = new Messenger(mNetworkFactory);cm.registerNetworkFactory(mNetworkFactoryMessenger, "Telephony");//初始化紧急APNinitEmergencyApnSetting();addEmergencyApnSetting();mProvisionActionName = "com.android.internal.telephony.PROVISION" + p.getPhoneId();}
在上面这个初始化过程中,主要完成了三个任务:
1、初始化各种监听器;
2、初始化TelephonyNetworkFactory对象;
这篇关于数据业务建立流程之DcTracker创建过程(原)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!