本文主要是介绍subId、slotId、SubscriptionInfo和SubscriptionManager的解释及关系说明,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. subid和slotid
slotid或者phoneid是指卡槽,双卡机器的卡槽1值为0,卡槽2值为1,依次类推。
subid:SubscriptionId(Subscription Identifier)。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卡卡号,相当于手机号码的身份证。
SubscriptionInfo的各个成员如下:
//frameworks/base/telephony/java/android/telephony/SubscriptionInfo.java
public class SubscriptionInfo implements Parcelable {//实现Parcelable是为了进程间ipc通信。@Overridepublic void writeToParcel(Parcel dest, int flags) {dest.writeInt(mId); //数据库id,递增主键,每一个iccid的卡会占用1个iddest.writeString(mIccId); //sim卡的iccid,每张sim卡是唯一的dest.writeInt(mSimSlotIndex); //sim卡插入卡槽值,0是卡1,1是卡2,没有插入则是-1dest.writeCharSequence(mDisplayName); //sim卡名称,用户可以自定义dest.writeCharSequence(mCarrierName); //运营商名称dest.writeInt(mNameSource); //名称来源,是用户设置或者是从sim卡读取(一般就是运营商名称)等dest.writeInt(mIconTint); //sim卡图标染色值,tint的概念可以百度googledest.writeString(mNumber); //sim卡关联号码dest.writeInt(mDataRoaming); //sim卡是否启用数据漫游dest.writeInt(mMcc); //mcc,移动国家码,3位数字,中国是460dest.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。
SubscriptionManager //frameworks/base/telephony/java/android/telephony/SubscriptionManager.java1). 获取SubscriptionManager对象public static SubscriptionManager from(Context context);//SubscriptionManager mSubscrMgr = SubscriptionManager.from(mContext);//get Manager2). 第三方app获取slot和subIdpublic int getDefaultDataPhoneId() 默认数据slotIdpublic static int getDefaultDataSubscriptionId() 默认数据subIdpublic int getDefaultSmsPhoneId() 默认短信slotIdpublic static int getDefaultSmsSubscriptionId() 默认短信subIdpublic static int getDefaultVoicePhoneId() 默认通话slotIdpublic static int getDefaultVoiceSubscriptionId() 默认通话subId上述三个都返回-1的话使用public static int getDefaultSubscriptionId() 获取默认subId3). slotid和subId转换public static int getSlotIndex(int subId)public static int getPhoneId(int subId)public static int[] getSubId(int slotIndex)4). 第三方app获取SubscriptionInfopublic SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(int slotIndex) //根据卡槽获取对应的SubscriptionInfopublic SubscriptionInfo getActiveSubscriptionInfo(int subId) //根据subId获取对应的SubscriptionInfo
SubscriptionInfo代表了sim卡的相关数据,其常用方法如下:
SubscriptionInfo//frameworks/base/telephony/java/android/telephony/SubscriptionInfo.javapublic int getDataRoaming();//return the data roaming state for this subscriptionpublic CharSequence getDisplayName() ;//return the name displayed to the user that identifies this subscriptionpublic String getIccId() ;public int getMcc();public int getMnc() ;public String getNumber();//return the number of this subscription.public int getSimSlotIndex() //return the slot index of this Subscription's SIM card.public int getSubscriptionId() //return the subscription ID - subId
可以发现,通过slotId得到对应的subId,再通过SubscriptionManager的getActiviteSubscriptionInfo()方法获取SIM卡的subscriptionInfo,进而可以获取该卡的mcc/mnc/iccid等信息。
也可以直接使用slotId,调用SubscriptionManager的getActiviteSubscriptionInfoFromSimSlotIndex()方法,获取SIM卡的subscriptionInfo。
注:由slotId得到subId,也可使用MtkSubscriptionManager(mtk自己定义的Subscription管理类)的静态方法getSubIdUsingPhoneId()
4. SubscriptionManager和SubscriptionController
SubscriptionManager是SubscriptionController的应用程序接口,提供有关当前电话订阅的信息。
SubscriptionController运行在phone进程中,是双卡相关功能正真实现端,为SubscriptionManager提供服务。
SubscriptionManager的功能基本都是通过binder调用SubscriptionController服务端来实现,使用ISub.aidl和SubscriptionController进行沟通
同理,MtkSubscriptionManager使用IMtkSub.aidl和MtkSubscriptionControllerEx进行沟通
以getSubIdUsingPhoneId()方法展示各个类之间的关系:
MtkSubscriptionManagerpublic static int getSubIdUsingPhoneId(int phoneId) {if (VDBG) Rlog.d(LOG_TAG, "[getSubIdUsingPhoneId]+ phoneId:" + phoneId);int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;try {IMtkSub iSub = IMtkSub.Stub.asInterface(ServiceManager.getService("isubstub"));if (iSub != null) {subId = iSub.getSubIdUsingPhoneId(phoneId);}} catch (RemoteException ex) {// ignore it}return subId;}
其中MtkSubscriptionController.getMtkInstance()返回MtkSubscriptionController实例
public class MtkSubscriptionController extends SubscriptionController {public static MtkSubscriptionController getMtkInstance() {synchronized (MtkSubscriptionController.class) {return sMtkInstance;}}
}
但是MtkSubscriptionController类内并无getSubIdUsingPhoneId()方法,调用的是父类SubscriptionController的getSubIdUsingPhoneId()方法,getSubIdUsingPhoneId()方法调用的是getSubId()方法
public class SubscriptionController extends ISub.Stub {public int getSubIdUsingPhoneId(int phoneId) {int[] subIds = getSubId(phoneId);if (subIds == null || subIds.length == 0) {return SubscriptionManager.INVALID_SUBSCRIPTION_ID;}return subIds[0];}/*** Return the subId for specified slot Id.* @deprecated*/@Override@Deprecatedpublic int[] getSubId(int slotIndex) {if (VDBG) printStackTrace("[getSubId]+ slotIndex=" + slotIndex);// Map default slotIndex to the current default subId.// TODO: Not used anywhere sp consider deleting as it's somewhat nebulous// as a slot maybe used for multiple different type of "connections"// such as: voice, data and sms. But we're doing the best we can and using// getDefaultSubId which makes a best guess.if (slotIndex == SubscriptionManager.DEFAULT_SIM_SLOT_INDEX) {slotIndex = getSlotIndex(getDefaultSubId());if (VDBG) logd("[getSubId] map default slotIndex=" + slotIndex);}......// Create an array of subIds that are in this slot?ArrayList<Integer> subIds = new ArrayList<Integer>();for (Entry<Integer, Integer> entry: sSlotIndexToSubId.entrySet()) {int slot = entry.getKey();int sub = entry.getValue();if (slotIndex == slot) {subIds.add(sub);}}// Convert ArrayList to arrayint numSubIds = subIds.size();if (numSubIds > 0) {int[] subIdArr = new int[numSubIds];for (int i = 0; i < numSubIds; i++) {subIdArr[i] = subIds.get(i);}if (VDBG) logd("[getSubId]- subIdArr=" + subIdArr);return subIdArr;} else {if (DBG) logd("[getSubId]- numSubIds == 0, return DummySubIds slotIndex=" + slotIndex);return getDummySubIds(slotIndex);}}
从SubscriptionController类的继承上可以推测,SubscriptionManager的getSubId()的真正实现也是在SubscriptionController类的getSubId()中
public class SubscriptionManager {/** @hide */public static int[] getSubId(int slotIndex) {if (!isValidSlotIndex(slotIndex)) {logd("[getSubId]- fail");return null;}int[] subId = null;try {ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));if (iSub != null) {subId = iSub.getSubId(slotIndex);}} catch (RemoteException ex) {// ignore it}return subId;}
}
文章转载自
https://www.jianshu.com/p/c43a71bf7815
这篇关于subId、slotId、SubscriptionInfo和SubscriptionManager的解释及关系说明的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!