TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(getApplicationContext().TELEPHONY_SERVICE); String imei = tm.getSimSerialNumber(); //取出ICCID 安卓上层获取ICCID的代码 然后跟踪流程发现执行过程为首先找到 TelephonyManager.java执行如下代码 public String getSimSerialNumber() { return getSimSerialNumber(getSubId()); } 然后本文件中直接定义了此函数 public String getSimSerialNumber(int subId) { try { IPhoneSubInfo info = getSubscriberInfo(); if (info == null) return null; return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName()); } catch (RemoteException ex) { return null; } catch (NullPointerException ex) { // This could happen before phone restarts due to crashing return null; } } 然后通过函数getIccSerialNumberForSubscriber() 去获取ICCID的值,此函数定义在 frameworks/opt/telephony/src/java/com/android/internal/telephony/PhoneSubInfoController.java文件中,函数内容如下
public String getIccSerialNumberForSubscriber(int subId, String callingPackage) { Phone phone = getPhone(subId); if (phone != null) { if (!checkReadPhoneState(callingPackage, “getIccSerialNumber”)) { return null; } Rlog.d(“zxy”,“phone.getIccSerialNumber”); return phone.getIccSerialNumber(); //主要执行的函数 } else { loge(“getIccSerialNumber phone is null for Subscription:” + subId); return null; } } 可以看出上面主要的函数为phone.getIccSerialNumber() 此函数又定义在frameworks/opt/telephony/src/java/com/android/internal/telephony/GsmCdmaPhone.java文件中,函数内容如下 public String getIccSerialNumber() { IccRecords r = mIccRecords.get(); if (!isPhoneTypeGsm() && r == null) { // to get ICCID form SIMRecords because it is on MF. r = mUiccController.getIccRecords(mPhoneId, UiccController.APP_FAM_3GPP); } return (r != null) ? r.getIccId() : null; } 主要执行函数为getIccId(),此函数定义在frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/IccRecords.java文件中,主要内容为 public String getIccId() { return mIccId; } 返回变量mIccId的值,流程到此就结束了。 然后发现这个值是在哪里赋值的呢,可以看到有三个文件继承了含有mIccId值的类 frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/IsimUiccRecords.java 46:public class IsimUiccRecords extends IccRecords implements IsimRecords {
frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/SIMRecords.java 49:public class SIMRecords extends IccRecords {
frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/RuimRecords.java 49:public class RuimRecords extends IccRecords { 但是以上三个文件中只有 frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/SIMRecords.java和frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/RuimRecords.java文件中含有,然后添加打印信息发现frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/SIMRecords.java执行才会获取ICCID值,然后修改 mIccId = mFullIccId; 就可以正确获取完整的ICCID值,然后修改frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/IccUtils.java里面的bchToString函数,支持大写之母字母,如下图所示,至此,就结束了。
|