首次由preferred_network_mode转换成preferred_network_mode1和preferred_network_mode2是在SubscriptionInfoUpdater类中的handleSimLoaded方法
我们机器设备默认的是:
[ro.telephony.default_network]: [22,20]
但是双sim卡,会对网络进行设置,会有一个设置的过程:
类->方法流程
click选择某张运营商卡为主卡:
IExtTelephony extTelephony =
IExtTelephony.Stub.asInterface(ServiceManager.getService("extphone"));
extTelephony.setPrimaryCardOnSlot(targetSub);
调用ExtTelephony的setPrimaryCardOnSlot方法
-》ExtTelephonyServiceImpl
-》setPrimaryCardOnSlot()
-》QtiPrimaryCardController.getInstance().setPrimaryCardOnSlot(slotId);
-》QtiPrimaryCardController
-》setPrimaryCardOnSlot()
-》synchronized private void setPrimaryCardOnSlot(int primarySlotId, Message msg)
-》在setPrimaryCardOnSlot方法中:
mPrefNwModes = mPriorityHandler.getNwModesFromConfig(primarySlotId);
//通过getNwModesFromConfig获取两种网络模式
for (int i = 0; i < QtiPrimaryCardUtils.PHONE_COUNT; i++) {
saveNwModesToDB(mPrefNwModes[i], i); //保存到数据库重要的一步
}
-》QtiPrimaryCardPriorityHandler
-》getNwModesFromConfig()
-》
for (int i = 0; i < QtiPrimaryCardUtils.PHONE_COUNT; i++) {
if (mCurrPriorityConfigs[i] != null) {
prefNwModes[i] = (i == primarySlotId) ? mCurrPriorityConfigs[i].network1 :
mCurrPriorityConfigs[i].network2;
//获取该类中的mCurrPriorityConfigs的network1和network2
} else {
prefNwModes[i] = defaultNwMode;
}
}
-》而mCurrPriorityConfigs的计算和获取是通过:
-》loadCurrentPriorityConfigs()
-》
public void loadCurrentPriorityConfigs(boolean override) {
if(!mLoadingConfigCompleted) {
logd("getPrefPrimarySlot: All Config Loading not done. EXIT!!!");
return;
}
if(override || !mLoadingCurrentConfigsDone) {
//get Current Priority config applicable for each slot
for (int i = 0; i < QtiPrimaryCardUtils.PHONE_COUNT; i++) {
mCurrPriorityConfigs[i] = getPriorityConfig(i);
}
mLoadingCurrentConfigsDone = true;
}
}
-》getPriorityConfig()
-》PriorityConfig pConfig = mAllPriorityConfigs.get(i);
-》 private HashMap<Integer, PriorityConfig> mAllPriorityConfigs =
new HashMap<Integer, PriorityConfig>();
从mAllPriorityConfigs 这个HashMap中来
-》在初始化的时候:
QtiPrimaryCardPriorityHandler(Context context){
mContext = context;
mCurrPriorityConfigs = new PriorityConfig[QtiPrimaryCardUtils.PHONE_COUNT];
tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
readPriorityConfigFromXml();
}
-》readPriorityConfigFromXml()
-》
private void readPriorityConfigFromXml() {
XmlResourceParser parser = null;
try {
Resources res = mContext.getPackageManager().getResourcesForApplication(packageName);
if (res == null) loge("res is null");
int resId = res.getIdentifier(QtiPrimaryCardUtils.getConfigXml(), "xml", packageName);
parser = res.getXml(resId);
//Clear all old configs from hash map.
mAllPriorityConfigs.clear();
mPriorityCount = 0;
XmlUtils.beginDocument(parser, "priority_config");
//2TODO: here we can read the operator config and feed it to pcutils
XmlUtils.nextElement(parser);
while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
savePriorityConfig(parser);
XmlUtils.nextElement(parser);
}
mLoadingConfigCompleted = true;
} catch (Exception e) {
Rlog.e(LOG_TAG, "Exception while reading priority configs: " + e.getMessage(), e);
mLoadingConfigCompleted = false;
} finally {
logi("mAllPriorityConfigs: " + mAllPriorityConfigs);
if (parser != null) {
parser.close();
}
}
}
-》是从QtiPrimaryCardUtils.getConfigXml()中读取xml文件
-》xml的文件名分别是:
public static String getConfigXml() {
if (isBitSetInConfig(ConfigBits.PRIORITY_CONFIG_3)) {
return "priority_config_3";
} else if (isBitSetInConfig(ConfigBits.PRIORITY_CONFIG_2)) {
return "priority_config_2";
} else if (isBitSetInConfig(ConfigBits.PRIORITY_CONFIG_1)) {
return "priority_config_1";
}
return "priority_config_2";
}
-》打开xml文件:
config_3:
<priority_config>
<!--[ODM][pref_network] enable config primary sub setable,modify the default config START-->
<!--
<priority priority="0" iin_pattern="^8986(?=03|11)" card_type="CARDTYPE_2G" network1="7" network2="7" />
<priority priority="1" iin_pattern="^8986(?=03|11)" card_type="CARDTYPE_3G" network1="7" network2="7"/>
<priority priority="2" iin_pattern="^8986(?=01|09)" card_type="CARDTYPE_2G" network1="1" network2="1" />
<priority priority="3" iin_pattern="^8986(?=01|09)" card_type="CARDTYPE_3G" network1="1" network2="1"/>
<priority priority="4" iin_pattern="^(?!8986)" card_type="CARDTYPE_2G" network1="18" network2="1" />
<priority priority="5" iin_pattern="^(?!8986)" card_type="CARDTYPE_3G" network1="20" network2="1"/>
<priority priority="6" iin_pattern="^8986(?!01|03|09|11)" card_type="CARDTYPE_2G" network1="18" network2="1"/>
<priority priority="7" iin_pattern="^8986(?!01|03|09|11)" card_type="CARDTYPE_3G" network1="20" network2="1"/>
-->
<priority priority="4" iin_pattern="^(?!8986)" card_type="CARDTYPE_4G" network1="22" network2="22"/>
<priority priority="5" iin_pattern="^898600" card_type="CARDTYPE_4G" network1="20" network2="17"/>
<priority priority="6" iin_pattern="^898602" card_type="CARDTYPE_4G" network1="20" network2="17"/>
<priority priority="7" iin_pattern="^898607" card_type="CARDTYPE_4G" network1="20" network2="17"/>
<!--CU-->
<priority priority="8" iin_pattern="^898601" card_type="CARDTYPE_4G" network1="20" network2="9"/>
<priority priority="9" iin_pattern="^898609" card_type="CARDTYPE_4G" network1="20" network2="9"/>
<!--CT-->
<priority priority="0" iin_pattern="^898603" card_type="CARDTYPE_4G" network1="22" network2="8"/>
<priority priority="1" iin_pattern="^898606" card_type="CARDTYPE_4G" network1="22" network2="8"/>
<priority priority="2" iin_pattern="^898611" card_type="CARDTYPE_4G" network1="22" network2="8"/>
<priority priority="3" iin_pattern="^898530" card_type="CARDTYPE_4G" network1="22" network2="8"/>
<!--end-->
<!--[ODM][pref_network] enable config primary sub setable,modify the default config END-->
</priority_config>
config_2:
<priority_config>
<priority priority="0" iin_pattern="^[0-9]{6,}" card_type="CARDTYPE_2G" network1="3" network2="1" />
<priority priority="1" iin_pattern="^[0-9]{6,}" card_type="CARDTYPE_3G" network1="9" network2="1"/>
<priority priority="2" iin_pattern="^[0-9]{6,}" card_type="CARDTYPE_4G" network1="9" network2="1"/>
</priority_config>
config_1:
<priority_config>
<priority priority="0" iin_pattern="^(?!8986)" card_type="CARDTYPE_2G" network1="18" network2="1" />
<priority priority="1" iin_pattern="^(?!8986)" card_type="CARDTYPE_3G" network1="20" network2="1"/>
<priority priority="2" iin_pattern="^8986(?!01|03|09|11)" card_type="CARDTYPE_2G" network1="18" network2="1"/>
<priority priority="3" iin_pattern="^8986(?!01|03|09|11)" card_type="CARDTYPE_3G" network1="20" network2="1"/>
</priority_config>