项目需要模拟一张SIM卡信息用于测试,开始主要还是重点关注的修改TelephonyManager.java,后发现这里虽然可以写入一些参数,比如电话号码,SIM卡状态等,但并不能新增一张卡,所以还要想办法新增一张卡后,再去修改这些参数才有意义。
个人只是简单修改,达到测试目的而已,没时间再深入研究。把简单修改提供给大家参考,后面有再进一步需要,靠你们自己了研究了。
修改路径:
frameworks\opt\telephony\src\java\com\android\internal\telephony\
文件:
SubscriptionController.java
函数:
private SubscriptionInfo getSubInfoRecord(Cursor cursor) {
int id = 1;//cursor.getInt(cursor.getColumnIndexOrThrow( SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID));
String iccId = "898600481";//cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.ICC_ID));
int simSlotIndex = 0;//cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.SIM_SLOT_INDEX));
String displayName = "CMCC";//cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.DISPLAY_NAME));
String carrierName = "CMCC";//cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.CARRIER_NAME));
int nameSource = 1;//cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.NAME_SOURCE));
int iconTint = 16746133;//cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.HUE));
String number = "13xxxxxxxxx";//15002021275 cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.NUMBER));
int dataRoaming = 0;//cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.DATA_ROAMING));
// Get the blank bitmap for this SubInfoRecord
Bitmap iconBitmap = BitmapFactory.decodeResource(mContext.getResources(),
com.android.internal.R.drawable.ic_sim_card_multi_24px_clr);
String mcc = "460";//cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.MCC_STRING));
String mnc = "1";//cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.MNC_STRING));
String ehplmnsRaw = cursor.getString(cursor.getColumnIndexOrThrow(
SubscriptionManager.EHPLMNS));
String hplmnsRaw = cursor.getString(cursor.getColumnIndexOrThrow(
SubscriptionManager.HPLMNS));
String[] ehplmns = ehplmnsRaw == null ? null : ehplmnsRaw.split(",");
String[] hplmns = hplmnsRaw == null ? null : hplmnsRaw.split(",");
// cardId is the private ICCID/EID string, also known as the card string
String cardId = "0";//cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.CARD_ID));
String countryIso = "cn";//cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.ISO_COUNTRY_CODE));
// publicCardId is the publicly exposed int card ID
int publicCardId = mUiccController.convertToPublicCardId(cardId);
boolean isEmbedded = false;//cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.IS_EMBEDDED)) == 1;
int carrierId = -1;//cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.CARRIER_ID));
......
具体要填的参数,可以找一张真卡来参考一下,看下logcat里一般都有相关的打印信息,对照着抄过来就可以了。
关键新增卡信息的调用:
在protected SubscriptionController(Context c) {
internalInit(c);
migrateImsSettings();
String iccId = "898600481";
int slotIndex = 0;
addSubInfoRecord(iccId, slotIndex);//add new sim card
}
大家可能要同时看下frameworks\base\telephony\java\android\telephony\TelephonyManager.java,
可能要把getSimState()也改下,直接返回SIM_STATE_READY,这里应该是最终传给应用层的,在这里改参数也是可以的。
最后要说的是,这样的修改并不能在系统的UI里查看到SIM卡信息,需要安装一个叫设备信息的apk,在里面查看网络可以看到。