(M)SIM卡开机流程分析之SubscriptionController类分析

首先,看看google对于SubscriptionController类的说明

/**
 * SubscriptionController to provide an inter-process communication to
 * access Sms in Icc.
 *
 * Any setters which take subId, slotId or phoneId as a parameter will throw an exception if the
 * parameter equals the corresponding INVALID_XXX_ID or DEFAULT_XXX_ID.
 *
 * All getters will lookup the corresponding default if the parameter is DEFAULT_XXX_ID. Ie calling
 * getPhoneId(DEFAULT_SUB_ID) will return the same as getPhoneId(getDefaultSubId()).
 *
 * Finally, any getters which perform the mapping between subscriptions, slots and phones will
 * return the corresponding INVALID_XXX_ID if the parameter is INVALID_XXX_ID. All other getters
 * will fail and return the appropriate error value. Ie calling getSlotId(INVALID_SUBSCRIPTION_ID)
 * will return INVALID_SLOT_ID and calling getSubInfoForSubscriber(INVALID_SUBSCRIPTION_ID)
 * will return null.
 *
 */
public class SubscriptionController extends ISub.Stub {
    ......
}
再来看看,其是如何获取到对象的,那么首先我们肯定需要看看其构造方法,搜索发现,其只有两个构造方法,如下

private SubscriptionController(Context c) {
    mContext = c;
    mCM = CallManager.getInstance();
    mTelephonyManager = TelephonyManager.from(mContext);
    mAppOps = mContext.getSystemService(AppOpsManager.class);

    if(ServiceManager.getService("isub") == null) {
            ServiceManager.addService("isub", this);
    }

    if (DBG) logdl("[SubscriptionController] init by Context");
}
private SubscriptionController(Phone phone) {
    mContext = phone.getContext();
    mCM = CallManager.getInstance();
    mAppOps = mContext.getSystemService(AppOpsManager.class);

    if(ServiceManager.getService("isub") == null) {
            ServiceManager.addService("isub", this);
    }

    if (DBG) logdl("[SubscriptionController] init by Phone");
}
这两个构造方法中主要是做了获取一些参数,并新建CallManager对象,TelephonyManager对象,AppOpsManager对象等

这两个构造方法全都是private的,那么从外部是如何获得其对象的呢?

public static SubscriptionController getInstance() {
    if (sInstance == null)
    {
       Log.wtf(LOG_TAG, "getInstance null");
    }

    return sInstance;
}
getInstance方法中获取全局static变量sInstance,但是依旧没有新建对象,搜索sInstance新建位置

// Leo, 构造函数,第二个对象是RIL对象数组,单例模式
public static SubscriptionController init(Context c, CommandsInterface[] ci) {
    synchronized (SubscriptionController.class) {
        if (sInstance == null) {
            sInstance = new SubscriptionController(c);
        } else {
            Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
        }
        return sInstance;
    }
}
原来是在init方法中进行新建的啊,而而且是单例模式

从以上可以看出,如果从外部需要获取SubscriptionController对象,我们可以通过两种方法获取,一种是调用其static init方法,另一个是getInstance方法,但是,如果我们使用getInstance方法,在此之前,一定已经调用过init方法了。

再来看看,这个类中究竟有哪些方法

public void notifySubscriptionInfoChanged() {
     ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
             "telephony.registry"));
     try {
         if (DBG) logd("notifySubscriptionInfoChanged:");
         tr.notifySubscriptionInfoChanged();
     } catch (RemoteException ex) {
         // Should never happen because its always available.
     }

     // FIXME: Remove if listener technique accepted.
     broadcastSimInfoContentChanged();
 }
/**
 * Broadcast when SubscriptionInfo has changed
 * FIXME: Hopefully removed if the API council accepts SubscriptionInfoListener
 */
 private void broadcastSimInfoContentChanged() {
    Intent intent = new Intent(TelephonyIntents.ACTION_SUBINFO_CONTENT_CHANGE);
    mContext.sendBroadcast(intent);
    intent = new Intent(TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED);
    mContext.sendBroadcast(intent);
 }
当SubscriptionInfo数据变化后,发送广播通知

/**
 * Get the SubInfoRecord(s) of the currently inserted SIM(s)
 * @param callingPackage The package making the IPC.
 * @return Array list of currently inserted SubInfoRecord(s)
 */
@Override
public List<SubscriptionInfo> getActiveSubscriptionInfoList(String callingPackage) {
    ......
    if (!canReadPhoneState(callingPackage, "getActiveSubscriptionInfoList")) {
        return null;
    }

    // Now that all security checks passes, perform the operation as ourselves.
    final long identity = Binder.clearCallingIdentity();
    try {
        if (!isSubInfoReady()) {
            ......
            return null;
        }

        List<SubscriptionInfo> subList = getSubInfo(
                SubscriptionManager.SIM_SLOT_INDEX + ">=0", null);

        if (subList != null) {
            // FIXME: Unnecessary when an insertion sort is used!
            Collections.sort(subList, new Comparator<SubscriptionInfo>() {
                @Override
                public int compare(SubscriptionInfo arg0, SubscriptionInfo arg1) {
                    // Primary sort key on SimSlotIndex
                    int flag = arg0.getSimSlotIndex() - arg1.getSimSlotIndex();
                    if (flag == 0) {
                        // Secondary sort on SubscriptionId
 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值