frameworks/base/telephony/java/android/telephony/SubscriptionManager
/**
* Set display name by simInfo index
* @param displayName the display name of SIM card
* @param subId the unique SubscriptionInfo index in database
* @return the number of records updated
* @hide
*/
public int setDisplayName(String displayName, int subId) {
return setDisplayName(displayName, subId, NAME_SOURCE_UNDEFINDED);
}
public int setDisplayName(String displayName, int subId, long nameSource) {
if (VDBG) {
logd("[setDisplayName]+ displayName:" + displayName + " subId:" + subId
+ " nameSource:" + nameSource);
}
if (!isValidSubscriptionId(subId)) {
// MTK-START
//logd("[setDisplayName]- fail");
logd("[setDisplayName]- fail, subId = " + subId);
// MTK-END
return -1;
}
int result = 0;
try {
ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
if (iSub != null) {
result = iSub.setDisplayNameUsingSrc(displayName, subId, nameSource); //SubscriptionController
}
} catch (RemoteException ex) {
// ignore it
}
return result;
}
setDisplayName由SubscriptionInfoUpdater里的handleSimLoaded调用
public class SubscriptionInfoUpdater extends Handler {
case SIM_LOADED:
handleSimLoaded(mUserObj.slotId);
break;
private void handleSimLoaded(int slotId) {
mSubscriptionManager.setDisplayName(nameToSet, subId);
运营商的名称最后由TelephonyManager里面更新的
/**
* Returns the Service Provider Name (SPN).
*
* @hide
*/
public String getSimOperatorNameForPhone(int phoneId) {
return getTelephonyProperty(phoneId,
TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, "");
}
/**
* Returns the Service Provider Name (SPN).
* <p>
* Availability: SIM state must be {@link #SIM_STATE_READY}
*
* @see #getSimState
*
* @param subId for which SimOperatorName is returned
* @hide
*/
public String getSimOperatorNameForSubscription(int subId) {
int phoneId = SubscriptionManager.getPhoneId(subId);
return getSimOperatorNameForPhone(phoneId);
}
/**
* Gets the telephony property.
*
* @hide
*/
public static String getTelephonyProperty(int phoneId, String property, String defaultVal) {
String propVal = null;
String prop = SystemProperties.get(property);
Rlog.d(TAG, "getTelephonyProperty prop value= " + prop);
if ((prop != null) && (prop.length() > 0)) {
String values[] = prop.split(",");
if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) {
propVal = values[phoneId];
}
}
return propVal == null ? defaultVal : "6666666";
}
上面是流程,在SubscriptionInfoUpdater里面有一个广播更新状态以及解决方案
在构造方法里面注册
IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
intentFilter.addAction(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
// MTK-START
intentFilter.addAction("android.intent.action.ACTION_SHUTDOWN_IPO");
intentFilter.addAction(TelephonyIntents.ACTION_COMMON_SLOT_NO_CHANGED);
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); // add by larry
if ("OP09".equals(SystemProperties.get("ro.operator.optr"))
&& ("SEGDEFAULT".equals(SystemProperties.get("ro.operator.seg"))
|| "SEGC".equals(SystemProperties.get("ro.operator.seg")))) {
intentFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
}
private final BroadcastReceiver sReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
logd("[Receiver]+");
String action = intent.getAction();
logd("Action: " + action);
if (!action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED) &&
!action.equals(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED) &&
// MTK-START
!action.equals("android.intent.action.ACTION_SHUTDOWN_IPO") &&
!action.equals(TelephonyIntents.ACTION_COMMON_SLOT_NO_CHANGED) &&
!action.equals(Intent.ACTION_CONFIGURATION_CHANGED) && // add by larry
!action.equals(Intent.ACTION_LOCALE_CHANGED)) {
// MTK-END
return;
}
.........
} else if (action.equals(Intent.ACTION_LOCALE_CHANGED) ||action.equals(Intent.ACTION_CONFIGURATION_CHANGED) ){ // modify by larry
int[] subIdList = mSubscriptionManager.getActiveSubscriptionIdList();
for (int subId : subIdList) {
updateSubName(subId);
}
}
private void updateSubName(int subId) {
SubscriptionInfo subInfo =
mSubscriptionManager.getSubscriptionInfo(subId);
if (subInfo != null
&& subInfo.getNameSource() != SubscriptionManager.NAME_SOURCE_USER_INPUT) {
SpnOverride spnOverride = SpnOverride.getInstance();
String nameToSet;
String carrierName = TelephonyManager.getDefault().getSimOperator(subId);
int slotId = SubscriptionManager.getSlotId(subId);
logd("updateSubName, carrierName = " + carrierName + ", subId = " + subId);
if (SubscriptionManager.isValidSlotId(slotId)) {
if (spnOverride.containsCarrierEx(carrierName)) {
nameToSet = spnOverride.lookupOperatorName(subId, carrierName,
true, mContext);
logd("SPN found, name = " + nameToSet);
} else {
nameToSet = "CARD " + Integer.toString(slotId + 1);
logd("SPN not found, set name to " + nameToSet);
}
mSubscriptionManager.setDisplayName(nameToSet, subId);
}
}
}
最后就调用到mSubscriptionManager.setDisplayName(nameToSet, subId);
总结:其实就是一个监听语言改变的广播然后进行更新语言