【Android架构Telephony篇】Subscription和SubscriptionManager

【Android架构Telephony篇】Subscription和SubscriptionManager_第1张图片

一台设备可以有多张SIM卡,最典型的例子就是眼下流行的“双卡双待”。每一张SIM卡都对应一个Subscription,找不到对应的中文术语,我们求助下翻译软件。

Subscription:谷歌翻译为“订阅”,依旧不明觉厉;继续翻译:

订阅Subscription):定义了请求者与业务或业务操作之间的关联关系。只有定义了订阅关系,才能通过业务策略,控制请求者对某个业务的访问行为

我们用谁家的SIM卡就相当于订阅(Subscription)谁家的业务,对应的SIM卡的信息就是Subscription Information,比如运营商名称、MNC、MCC等,多张SIM卡就有多个Subscription Information

在Android中,针对上述功能的实现、管理就是SubscriptionManager,表现到软件上就是:

【Android架构Telephony篇】Subscription和SubscriptionManager_第2张图片

各个类的实现比较简单自行参看源码。

SubscriptionManager作用有三个:

  • 获取Subscription信息
  • 更改Subscription某些信息
  • 提供OnSubscriptionsChangedListener监听器,方便其他应用监听Subscription的状态改变

是时候看下Subscription了。


Subscription内容:

public class SubscriptionInfo implements Parcelable {
    /**
     * Subscription Identifier, this is a device unique number
     * and not an index into an array
     */
    private int mId;

    /**
     * The GID for a SIM that maybe associated with this subscription, empty if unknown
     */
    private String mIccId;

    /**
     * The index of the slot that currently contains the subscription
     * and not necessarily unique and maybe INVALID_SLOT_ID if unknown
     */
    private int mSimSlotIndex;

    /**
     * The name displayed to the user that identifies this subscription
     */
    private CharSequence mDisplayName;

    /**
     * String that identifies SPN/PLMN
     * TODO : Add a new field that identifies only SPN for a sim
     */
    private CharSequence mCarrierName;

    /**
     * The source of the name, NAME_SOURCE_UNDEFINED, NAME_SOURCE_DEFAULT_SOURCE,
     * NAME_SOURCE_SIM_SOURCE or NAME_SOURCE_USER_INPUT.
     */
    private int mNameSource;

    /**
     * A number presented to the user identify this subscription
     */
    private String mNumber;

    /**
     * Data roaming state, DATA_RAOMING_ENABLE, DATA_RAOMING_DISABLE
     */
    private int mDataRoaming;

    /**
     * Mobile Country Code
     */
    private int mMcc;

    /**
     * Mobile Network Code
     */
    private int mMnc;

    /**
     * ISO Country code for the subscription's provider
     */
    private String mCountryIso;
}
一条Log:

SubscriptionController: [getSubInfoRecord] id:2 iccid:898600020XXXXXXXXXXX simSlotIndex:0 displayName:中国移动 carrierName:No service. nameSource:0 iconTint:-16746133 dataRoaming:0 mcc:460 mnc:2 countIso:cn


看下对应的术语:

ICCIDIntegrate circuit card identity 集成电路卡识别码(固化在手机SIM卡中)。ICCID为IC卡的唯一识别号码,共有20位数字组成:

【Android架构Telephony篇】Subscription和SubscriptionManager_第3张图片

PLMNPublic Land Mobile Network 公共陆地移动网,一般某个国家的一个运营商对应一个PLMN

SPNService Provider Name 运营商名称

MCC:Mobile Country Code,移动国家码,MCC的资源由国际电联(ITU)统一分配和管理,唯一识别移动用户所属的国家,共3位,中国为460

MNC:Mobile Network Code 移动网络号码,用于识别移动用户所归属的移动通信网,2~3位数字组成,如中国移动系统使用00、02、04、07,中国联通GSM系统使用01、06、09

ISO country code: 国际上不同国家的ISO编码,比如我们国家:



那么问题来了,这些信息从哪来?

对于SubscriptionController来说,它是从数据库telephony.db的siminfo表中读取:

/data/data/com.android.providers.telephony/databases

【Android架构Telephony篇】Subscription和SubscriptionManager_第4张图片


siminfo表的创建:

TelephonyProvider.java (g:\rk3288-android6.0f\packages\providers\telephonyprovider\src\com\android\providers\telephony)	105530	2017-04-24
private void createSimInfoTable(SQLiteDatabase db) {
	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_EXTREME_THREAT_ALERT + " INTEGER DEFAULT 1,"
			+ SubscriptionManager.CB_SEVERE_THREAT_ALERT + " INTEGER DEFAULT 1,"
			+ SubscriptionManager.CB_AMBER_ALERT + " INTEGER DEFAULT 1,"
			+ SubscriptionManager.CB_EMERGENCY_ALERT + " INTEGER DEFAULT 1,"
			+ SubscriptionManager.CB_ALERT_SOUND_DURATION + " INTEGER DEFAULT 4,"
			+ SubscriptionManager.CB_ALERT_REMINDER_INTERVAL + " INTEGER DEFAULT 0,"
			+ SubscriptionManager.CB_ALERT_VIBRATE + " INTEGER DEFAULT 1,"
			+ SubscriptionManager.CB_ALERT_SPEECH + " INTEGER DEFAULT 1,"
			+ SubscriptionManager.CB_ETWS_TEST_ALERT + " INTEGER DEFAULT 0,"
			+ SubscriptionManager.CB_CHANNEL_50_ALERT + " INTEGER DEFAULT 1,"
			+ SubscriptionManager.CB_CMAS_TEST_ALERT + " INTEGER DEFAULT 0,"
			+ SubscriptionManager.CB_OPT_OUT_DIALOG + " INTEGER DEFAULT 1"
			+ ");");
	if (DBG) log("dbh.createSimInfoTable:-");
}

那么又要问了,数据库的数据从哪来?自然从SIM中读取的了。

怎么读?通过AT指令读!

怎么通过AT指令读?说过了。

你可能感兴趣的:(Android源码)