19

We used to get Device ID/IMEI using the following command:

adb shell dumpsys iphonesubinfo

But since last Android update (5.0 - Lollilop), this command doesn't return anything, I performed this test on both Nexus 4 and Nexus 5.

I know I can get the IMEI from code, which is still working, but does anyone has a workaround for ADB ?

Jérémy
  • 263
  • 1
  • 3
  • 10
  • 1
    I think this is a bug within 5.0. I tried `adb shell dumpsys iphonesubinfo > info.txt` on 4.4.2 & 5.0, and 4.4.2 put the info into a file, where 5.0 didn't. – BlackHatSamurai Nov 18 '14 at 19:56

4 Answers4

17

You can always just use service call command to call the service methods.

here are the TRANSACTION CODES for the iphonesubinfo service in android-5.0.0_r1:

 1  getDeviceId
 2  getDeviceIdForSubscriber
 3  getImeiForSubscriber
 4  getDeviceSvn
 5  getSubscriberId
 6  getSubscriberIdForSubscriber
 7  getGroupIdLevel1
 8  getGroupIdLevel1ForSubscriber
 9  getIccSerialNumber
10  getIccSerialNumberForSubscriber
11  getLine1Number
12  getLine1NumberForSubscriber
13  getLine1AlphaTag
14  getLine1AlphaTagForSubscriber
15  getMsisdn
16  getMsisdnForSubscriber
17  getVoiceMailNumber
18  getVoiceMailNumberForSubscriber
19  getCompleteVoiceMailNumber
20  getCompleteVoiceMailNumberForSubscriber
21  getVoiceMailAlphaTag
22  getVoiceMailAlphaTagForSubscriber
23  getIsimImpi
24  getIsimDomain
25  getIsimImpu
26  getIsimIst
27  getIsimPcscf
28  getIsimChallengeResponse
29  getIccSimChallengeResponse

Most methods require root. But fortunately getDeviceId (the one you need to get device's IMEI/MEID) does not.

For proper parsing of the service call command output on the device side and without external dependencies see my answer here

Also read Calling Android services from ADB shell for more details.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • Thanks, I already tried service call commands but I need to do this without rooting phones. – Jérémy Nov 18 '14 at 22:30
  • 1
    `getDeviceId` does not require `root` – Alex P. Apr 20 '15 at 19:03
  • 1
    Actually this is not working for Android 5.0 and 5.0.1, only for Android 5.1 and above. – Jérémy Apr 21 '15 at 20:45
  • Here is a workaround for all Android versions: http://stackoverflow.com/a/37940140/1140682 – saschoar Jun 21 '16 at 09:14
  • Hi @AlexP. , Could you clarify how to get this code-method list? I found [IPhoneSubInfo.aidl source code](https://android.googlesource.com/platform/frameworks/base/+/master/telephony/java/com/android/internal/telephony/IPhoneSubInfo.aidl), but didn't found a list file – Weekend Jul 16 '19 at 10:01
12

IMEI for sim 1

adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed '1 d' | tr -d '.' | awk '{print}' ORS=
Sooraj S
  • 291
  • 5
  • 13
  • 3
    I've modified it to work on Windows: `adb shell "service call iphonesubinfo 1 | awk -F \"'\" '{print $2}' | sed '1 d' | tr -d '.' | awk '{print}' ORS="` – Robyer Nov 20 '19 at 12:51
7

ADB command to get device IMEI:

adb shell "service call iphonesubinfo 1 | cut -c 52-66 | tr -d '.[:space:]'"

ADB command to get device phone number:

adb shell "service call iphonesubinfo 18 | cut -c 52-66 | tr -d '.[:space:]+'"

ADB command to get Android ID:

adb shell settings get secure android_id

ADB command to get device Serial Number:

adb shell getprop ro.serialno

Note: No root is needed for any of the above commands

Devlpr
  • 165
  • 2
  • 5
4

i agree with alex P and jeremy we can get phone IMEI by service call but that results in packet which is complicated to see so after so much juggling with cmd as im not a programmer i have found solution to get IMEI alone and decided to share it as it can help to many . so here is script i made to get IMEI from lollypop 5.1 and it works with non rooted phones

@echo off
setlocal enabledelayedexpansion
for /f "tokens=6*" %%a in ('adb shell "service call iphonesubinfo 1 ^| grep -m 1 \"'\""') do (
set imei1=%%a)
for /f "tokens=6*" %%b in ('adb shell "service call iphonesubinfo 1 ^| grep -m 2 \"'\""') do (
set imei2=%%b)
for /f "tokens=4*" %%c in ('adb shell "service call iphonesubinfo 1 ^| grep -m 3 \"'\""') do (
set imei3=%%c) 
set imei=!imei1!!imei2!!imei3!
echo !imei! > imei.txt
for /f "delims=" %%d in (imei.txt) do (
set DeviceIMEI=%%d
set DeviceIMEI=!DeviceIMEI:'=!
set DeviceIMEI=!DeviceIMEI:.=!
set OIMEI=Phone IMEI  !DeviceIMEI!
)
echo %OIMEI%
pause

it will result in " Phone IMEI 'whatever phone IMEI is'" *keep in mind it will only show imei of sim port which is default set for calling. if anyone can short this script it would be great.