近日,一直在研究,默认APN的设置
当我们从代码和手机中看到,默认APN的显示是从content://telephony/carriers/preferapn的数据中查询到的,而这个是通过shared preference来保存的,当手机第一次插卡开机后,我们将preferapn.xml文件导出来后,我们发现其中已经写有值了,但是从TelephonyProvider.Java文件中,我们却没有发现任何写入的地方,那么这个默认APN究竟是如何写入和设定的呢?
结合LOG查看了插卡开机流程多日后,终于找到了其写入的位置,仅以此篇记录近期的成果。
当我们从代码和手机中看到,默认APN的显示是从content://telephony/carriers/preferapn的数据中查询到的,而这个是通过shared preference来保存的,当手机第一次插卡开机后,我们将preferapn.xml文件导出来后,我们发现其中已经写有值了,但是从TelephonyProvider.Java文件中,我们却没有发现任何写入的地方,那么这个默认APN究竟是如何写入和设定的呢?
结合LOG查看了插卡开机流程多日后,终于找到了其写入的位置,仅以此篇记录近期的成果。
首先,SIM卡的开机流程中,我们知道,是从PhoneFactory.java文件的makeDefaultPhone方法中开始的,而在其中,我们可以看到如下段
for (int i = 0; i < numPhones; i++) {
PhoneBase phone = null;
int phoneType = TelephonyManager.getPhoneType(networkModes[i]);
if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
phone = new GSMPhone(context,
sCommandsInterfaces[i], sPhoneNotifier, i);
} else if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
phone = new CDMALTEPhone(context,
sCommandsInterfaces[i], sPhoneNotifier, i);
}
Rlog.i(LOG_TAG, "Creating Phone with type = " + phoneType + " sub = " + i);
sProxyPhones[i] = new PhoneProxy(phone);
}
创建Phone对象,今天我们就以GSMPhone对象来分析这个默认APN的流程
public
GSMPhone(Context context, CommandsInterface ci, PhoneNotifier notifier, int phoneId) {
this(context, ci, notifier, false, phoneId);
}
public
GSMPhone(Context context, CommandsInterface ci,
PhoneNotifier notifier, boolean unitTestMode, int phoneId) {
super("GSM", notifier, context, ci, unitTestMode, phoneId);
if (ci instanceof SimulatedRadioControl) {
mSimulatedRadioControl = (SimulatedRadioControl) ci;
}
mCi.setPhoneType(PhoneConstants.PHONE_TYPE_GSM);
mCT = new GsmCallTracker(this);
mSST = new GsmServiceStateTracker(this);
mDcTracker = new DcTracker(this);
if (!unitTestMode) {
mSimPhoneBookIntManager = new SimPhoneBookInterfaceManager(this);
mSubInfo = new PhoneSubInfo(this);
}
mCi.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
mCi.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
mCi.registerForOn(this, EVENT_RADIO_ON, null);
mCi.setOnUSSD(this, EVENT_USSD, null);
mCi.setOnSuppServiceNotification(this, EVENT_SSN, null);
mSST.registerForNetworkAttached(this, EVENT_REGISTERED_TO_NETWORK, null);
mCi.setOnSs(this, EVENT_SS, null);
setProperties();
log("GSMPhone: constructor: sub = " + mPhoneId);
setProperties();
}
其中,有创建DcTracker对象,查看这个类的构造方法
//***** Constructor
public DcTracker(PhoneBase p) {
super(p);
......
update();
......
}
首先,先调用了其父类的构造方法
/**
* Default constructor
*/
protected DcTrackerBase(PhoneBase phone) {