1、注册观察者
--> PhoneFactory.makeDefaultPhones()
--> TelephonyComponentFactory.makeSubscriptionInfoUpdater()
--> new SubscriptionInfoUpdater()
--> PhoneConfigurationManager.registerForMultiSimConfigChange(this, EVENT_MULTI_SIM_CONFIG_CHANGED, null)
--> sMultiSimConfigChangeRegistrants.addUnique(h, what, obj) 观察者注册到通知者中
到这步,注册了对 EVENT_MULTI_SIM_CONFIG_CHANGED 事件的观察,当收到通知者notify时,就由SubscriptionInfoUpdater这个Handler对象来处理事件。
其实只要某个类中调用了PhoneConfigurationManager.registerForMultiSimConfigChange(),就会产生一个观察者并注册到通知者中
比如下面这些类的方法中都有注册观察者

2、触发事件
--> PhoneInterfaceManager.switchMultiSimConfig()
--> RadioConfig.setNumOfLiveModems()
--> RadioConfigProxy.setNumOfLiveModems()
--> 下发modem请求
--> modem返回响应,回调处理事件 EVENT_SWITCH_DSDS_CONFIG_DONE
--> ConfigurationManagerHandler.handleMessage()
--> PhoneConfigurationManager.onMultiSimConfigChanged()
--> broadcastMultiSimConfigChange()
--> notifyMultiSimConfigChange()
--> sMultiSimConfigChangeRegistrants.notifyResult() 1.通知者通知观察者
--> SubscriptionInfoUpdater.handleMessage()
--> onMultiSimConfigChanged()
private void onMultiSimConfigChanged() {
int activeModemCount = ((TelephonyManager) sContext.getSystemService(
Context.TELEPHONY_SERVICE)).getActiveModemCount();
// For inactive modems, reset its states.
for (int phoneId = activeModemCount; phoneId < SUPPORTED_MODEM_COUNT; phoneId++) {
sIccId[phoneId] = null;
sSimCardState[phoneId] = TelephonyManager.SIM_STATE_UNKNOWN;
sSimApplicationState[phoneId] = TelephonyManager.SIM_STATE_UNKNOWN;
}
}
--> Intent intent = new Intent(ACTION_MULTI_SIM_CONFIG_CHANGED); sendBroadcast(intent) 2.发送广播
--> ConfigLoaderBroadcastReceiver.onReceive()
--> sendMessge(EVENT_MULTI_SIM_CONFIG_CHANGED)
--> ConfigHandler.handleMessage()
--> CarrierConfigLoader.onMultiSimConfigChanged()
--> updateConfigForPhoneId()
--> sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
--> handleMessage(EVENT_DO_FETCH_DEFAULT)
config = restoreConfigFromXml(mPlatformCarrierConfigPackage, "", phoneId);
if (config != null) {
logd(
"Loaded config from XML. package="
+ mPlatformCarrierConfigPackage
+ " phoneId="
+ phoneId);
mConfigFromDefaultApp[phoneId] = config;
Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1);
newMsg.getData().putBoolean("loaded_from_xml", true);
mHandler.sendMessage(newMsg);
} else {
...}
== 读取xml配置文件 config = restoreConfigFromXml(mPlatformCarrierConfigPackage, “”, phoneId);==
private PersistableBundle restoreConfigFromXml(@Nullable String packageName,
@NonNull String extraString, int phoneId, boolean isNoSimConfig) {
if (packageName == null) {
loge("Cannot restore config with null packageName");
}
final String version = getPackageVersion(packageName);
if (version == null) {
loge("Failed to get package version for: " + packageName);
return null;
}
String fileName;
String iccid = null;
if (isNoSimConfig) {
fileName = getFilenameForNoSimConfig(packageName);
} else {
if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
!= TelephonyManager.SIM_STATE_LOADED) {
loge("Skip restore config because SIM records are not loaded.");
return null;
}
iccid = getIccIdForPhoneId(phoneId);
final int cid = getSpecificCarrierIdForPhoneId(phoneId);
if (iccid == null) {
loge("Cannot restore config with null iccid.");
return null;
}
fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
}
PersistableBundle restoredBundle = null;
File file = null;

该文详细阐述了Android系统中如何注册并处理多SIM卡配置变化的事件。当配置改变时,一系列的更新和广播过程发生,包括更新SubscriptionInfo、读取配置文件、通知订阅者以及更新订阅信息。整个流程涉及多个组件如PhoneFactory、TelephonyComponentFactory、SubscriptionInfoUpdater和CarrierConfigLoader,确保系统能正确响应SIM卡状态的变化。
最低0.47元/天 解锁文章
875

被折叠的 条评论
为什么被折叠?



