[FAQ14410]SIM卡数据/电话/短信的默认卡设定客制化

[DESCRIPTION]
 
    从Android L开始Data/Voice call/SMS的默认卡是在开机之后弹出选择框由用户选择,如果客户要求在开机后,系统根据SIM卡插入的情况自动设定默认卡,则可以参考本FAQ。
 
[SOLUTION]
一、M版本
    只插入一张卡的情况下,默认会弹出对话框请用户确认是否把该卡设置为默认卡,点击确认才会开始设置。如果不需要确认过程,在只插入一张卡的情况直接设置该卡为默认卡可以按照下面的方法客制化。
File Path:/packages/apps/Settings/src/com/android/settings/sim/SimSelectNotification.java


case PREFERRED_PICK:
 /// M: for ALPS02423087, hot plug timing issue, the sub list may already changed @{
 List subs = SubscriptionManager.from(this)
 .getActiveSubscriptionInfoList();
 if (subs == null || subs.size() != 1) {
 Log.w(TAG, "Subscription count is not 1, skip preferred SIM dialog");
 finish();
 return;
 }
 /// @}
 
 //Modify START
 //DEL this line
 displayPreferredDialog(extras.getInt(PREFERRED_SIM));

 //ADD 
 final SubscriptionInfo sir = SubscriptionManager.from(context)
 .getActiveSubscriptionInfoForSimSlotIndex(extras.getInt(PREFERRED_SIM));
 final int subId = sir.getSubscriptionId();
 PhoneAccountHandle phoneAccountHandle =
 subscriptionIdToPhoneAccountHandle(subId);
 setDefaultDataSubId(context, subId);
 setDefaultSmsSubId(context, subId);
 setUserSelectedOutgoingPhoneAccount(phoneAccountHandle);
 Log.w(TAG, "[CUST] Subscription count is 1, skip preferred SIM dialog, set Prefferd SIM SlotId= " + extras.getInt(PREFERRED_SIM));
 //Modify END

 break;

二、L1版本
    Google design是让用户自己去选择,所以在simsetting中静态注册了broadcast ACTION_SUBINFO_RECORD_UPDATED,在SimBootReceiver.java中接受这个broadcast进行判断处理弹出对应的dialog让user做选择。所以客户可以在此文件中做客制化去set DefaultsubId而不是弹出dialog让user选择。具体修改如下:

SimBootReceiver.java在onReceive中的修改如下:

if (notificationSent) {

  Intent intent = new Intent(mContext, SimDialogActivity.class);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  if (numSIMsDetected == 1) {
   intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK);
   intent.putExtra(SimDialogActivity.PREFERRED_SIM, lastSIMSlotDetected);

   //Modify START
   SubscriptionManager.from(this).setDefaultSmsSubId(subId);
   SubscriptionManager.from(this).setDefaultDataSubId(subId);

   PhoneAccountHandle phoneAccount = subscriptionIdToPhoneAccountHandle(subId);
   TelecomManager.from(this).setUserSelectedOutgoingPhoneAccout(phoneAccount);
   //Modify END

 } else if (!isDefaultDataSubInserted()) {
......

其中,subscriptionIdToPhoneAccountHandle()定义如下(参考SimDialogActivity.java):

private PhoneAccountHandle subscriptionIdToPhoneAccountHandle(final int subId) {
 final TelecomManager telecomManager = TelecomManager.from(this);
 final Iterator phoneAccounts =
 telecomManager.getCallCapablePhoneAccounts().listIterator();

 while (phoneAccounts.hasNext()) {
 final PhoneAccountHandle phoneAccountHandle = phoneAccounts.next();
 final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle);
 final String phoneAccountId = phoneAccountHandle.getId();

 if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)
 && TextUtils.isDigitsOnly(phoneAccountId)
 && Integer.parseInt(phoneAccountId) == subId){
 return phoneAccountHandle;
 }
 }

 return null;
 }

三、L0版本
1.Call & SMS
    初始化时,SubInfoRecordUpdater将会去调用SubscriptionManager去设置DefaulSMSSubId和DefaultVoiceCallSubId,在SubscriptionController中对于DefaultVoiceCallSubId和DefaultSMSSubId设置是把对应SubId保存在全局的数据库中,然后发送broadcast ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED(for DefaultVoiceCallSubId)或ACTION_DEFAULT_DEFAULT_SMS_SUBSCRIPTION_CHANGED(for DefaultSMSSubId intent)。
 
2.Cellular Data
SubInfoRecordUpdater.setAllDefaultSub()在开机时并不会去设置默认Data,若客户需要客制化可以在SubInfoRecordUpdater.java中对方法setAllDefaultSub()中添加对DefaultDataSubId的设置。
代码修改如下:

[FAQ14410]SIM卡数据/电话/短信的默认卡设定客制化_第1张图片

你可能感兴趣的:(android)