Is there any way to view IMSI and ICCID numbers of my SIM-cards? I didn't find such menu neither in About-Status nor anywhere else.
1 Answers
There are APIs available which apps (like this) use to read SIM information. Looking for CLI solution (refer to this, this and this), we can get IMSI and ICCID with following commands respectively (up to Android 9):
~$ service call iphonesubinfo 7
~$ service call iphonesubinfo 10
* Codes depend on order of methods defined here, which may differ on different Android versions.
* For dual SIM device use code 8 and 11 instead and append i32 2 to command to get second SIM information.
Pass the output through following pipes to convert hexadecimal output to a good looking string:
... | grep -oE '[0-9a-f]{8} ' | while read hex; do echo -ne "\u${hex:4:4}\u${hex:0:4}"; done; echo
Terminal emulator apps usually don't have permission READ_PHONE_STATE (though you can grant manually with root) which is required by both functions. So commands need to be executed from adb shell.
Codes 7/8 correspond to getSubscriberId and 10/11 to getSimSerialNumber. However both methods have been removed for normal apps usage in Android 10. Only system apps with READ_PRIVILEGED_PHONE_STATE will be able to get this information. iphonesubinfo service can't be dumped with dumpsys either. So root is the only solution on Android 10+.
RIL may also log the operator/SIM related information to logcat when SIM state changes. With root access it's possible to read telephony database (the component of application framework which interfaces RIL) and also RIL database itself (which interfaces modem). On my Qualcomm device RILD stores information to /data/vendor/radio/qcril.db including ICCID and MCC/MNC.
~# sqlite3 -line /data/user_de/0/com.android.providers.telephony/databases/telephony.db 'select icc_id,card_id,carrier_name,display_name,mcc,mnc from siminfo'
~# sqlite3 /data/vendor/radio/qcril.db 'select ICCID from qcril_manual_prov_table'
As of Android 9 IMSI is also stored in /data/system/netpolicy.xml to set mobile data limits for MNOs separately.
~# grep -o 'subscriberId=[^ ]*' /data/system/netpolicy.xml
RELATED:
- 20,353
- 3
- 70
- 213
i32 2after 8 or 11 doesn't do the job, it gives me the same numbers as w/o this append. Is my command correct? – Suncatcher Dec 18 '19 at 19:04service call iphonesubinfo 11 i32 2 | grep -oE '[0-9a-f]{8} ' | while read hex; do echo -ne "\u${hex:4:4}\u${hex:0:4}"; done; echo– Suncatcher Dec 18 '19 at 19:04i32 1ori32 0. For all Android 9 sub-releases order ofgetSubscriberIdForSubscriberandgetIccSerialNumberForSubscribermethods is 8 and 11. If it doesn't work then possibly Xiaomi changed the source code. You have to do hit and trial. – Irfan Latif Dec 19 '19 at 05:558 i32 3works, and for ICCID11 i32 3gives8938001120308300159Finstead of8938001120308300159. Probably we should correct regex for extraction of ICCID but I have no idea how. I've never dealt with hex-extract in regex – Suncatcher Dec 19 '19 at 15:3000000000in last row. Do you get00000046(which becomesF)? You can ignore last character usingheadortail. – Irfan Latif Dec 19 '19 at 16:51in raw output I get 00000000 in last rowthe same. Interesting why it is so different for 2nd SIM. Tried to append| head -c -1and| sed -e 's/;$//'afterechobut that didn't work. How to cut the last sign correctly? – Suncatcher Dec 21 '19 at 13:4100000000itself turns to two Unicode null characters. So you need to dohead -c -3. – Irfan Latif Dec 21 '19 at 14:33head: -c < 0 (see "head --help")seems to be the wrong syntax – Suncatcher Dec 21 '19 at 14:49busybox head. Android'stoyboxis limited. – Irfan Latif Dec 21 '19 at 15:42