1. subid和slotid(phoneid)

slotid(phoneid)是指卡槽:双卡机器的卡槽1值为0,卡槽2值为1,依次类推。


subid:SubscriptionId(SubscriptionIdentifier)。subid是数据库telephony.db的表siminfo的主键递增项,其中telephony.db在"/data/user_de/0/com.android.providers.telephony/databases"下。subid的值从1开始,每插入一个新卡,subId的值就会加1。插入双卡后数据库中就会有subid值为1和2的两个数据条目,拔卡插卡交换卡槽后,数据库并不会增加新项,只有插入一张新的sim卡才会增加一条id为3的数据条目。

注意:
subid对应卡,slotid对应卡槽

2. Subscription和SubscriptionInfo

每一张SIM卡都对应一个Subscription,用谁家的SIM卡就相当于订阅(Subscription)谁家的业务。
SIM卡的信息就是SubscriptionInfo(Subscription Information),比如iccid、MNC、MCC等,多张SIM卡就有多个SubscriptionInfo。
其中ICCID:Integrate circuit card identity,集成电路卡识别码,即SIM卡卡号,相当于手机号码的身份证。

//frameworks/base/telephony/java/android/telephony/SubscriptionInfo.java
public class SubscriptionInfo implements Parcelable {//实现Parcelable是为了进程间ipc通信。
     @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mId);   //数据库id,递增主键,每一个iccid的卡会占用1个id
            dest.writeString(mIccId);  //sim卡的iccid,每张sim卡是唯一的
            dest.writeInt(mSimSlotIndex);  //sim卡插入卡槽值,0是卡1,1是卡2,没有插入则是-1
            dest.writeCharSequence(mDisplayName); //sim卡名称,用户可以自定义
            dest.writeCharSequence(mCarrierName); //运营商名称
            dest.writeInt(mNameSource);  //名称来源,是用户设置或者是从sim卡读取(一般就是运营商名称)等
            dest.writeInt(mIconTint);   //sim卡图标染色值,tint的概念可以百度google
            dest.writeString(mNumber);  //sim卡关联号码
            dest.writeInt(mDataRoaming);  //sim卡是否启用数据漫游
            dest.writeInt(mMcc);    //mcc,移动国家码,3位数字,中国是460
            dest.writeInt(mMnc);    //mnc,移动网络码,2位数字,如00,01等,表示运营商
            dest.writeString(mCountryIso); //国家iso代码
            mIconBitmap.writeToParcel(dest, flags);  //sim卡图标
        }
        ......
}

它是和TelephonyProvider数据库中的siminfo对应的。

//vendor/mediatek/proprietary/packages/providers/TelephonyProvider/src/com/android/providers/telephony/TelephonyProvider.java
private void createSimInfoTable(SQLiteDatabase db) {
    if (DBG) log("dbh.createSimInfoTable:+");
    db.execSQL("CREATE TABLE " + SIMINFO_TABLE + "("
            + SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + SubscriptionManager.ICC_ID + " TEXT NOT NULL,"
            + SubscriptionManager.SIM_SLOT_INDEX + " INTEGER DEFAULT " + SubscriptionManager.SIM_NOT_INSERTED + ","
            + SubscriptionManager.DISPLAY_NAME + " TEXT,"
            + SubscriptionManager.CARRIER_NAME + " TEXT,"
            + SubscriptionManager.NAME_SOURCE + " INTEGER DEFAULT " + SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE + ","
            + SubscriptionManager.COLOR + " INTEGER DEFAULT " + SubscriptionManager.COLOR_DEFAULT + ","
            + SubscriptionManager.NUMBER + " TEXT,"
            + SubscriptionManager.DISPLAY_NUMBER_FORMAT + " INTEGER NOT NULL DEFAULT " + SubscriptionManager.DISPLAY_NUMBER_DEFAULT + ","
            + SubscriptionManager.DATA_ROAMING + " INTEGER DEFAULT " + SubscriptionManager.DATA_ROAMING_DEFAULT + ","
            + SubscriptionManager.MCC + " INTEGER DEFAULT 0,"
            + SubscriptionManager.MNC + " INTEGER DEFAULT 0,"
            ...
            + SubscriptionManager.CB_OPT_OUT_DIALOG + " INTEGER DEFAULT 1"
            + ");");
    if (DBG) log("dbh.createSimInfoTable:-");
}

建表函数createSimInfoTable,常量都是在SubscriptionManager中定义,可以从名字看出和SubscriptionInfo是对应的,当然后面mtk加了不少字段。
3. SubscriptionManager及其相关方法

SubscriptionManager为第三方app层使用,用于:
1). 获取和设置当前双卡设置(如当前默认拨号卡);
2). 进行slotid和subId转换等;
3). 获取当前的卡信息SubscriptionInfo。

转自:

https://www.jianshu.com/p/c43a71bf7815

12-20 12:59