Getting IMEI with adb command from device on Android 14

246 Views Asked by At

I'm using command: adb shell "service call iphonesubinfo 1 s16 com.android.shell | cut -c 52-66 | tr -d '.[:space:]'" It was working fine on Android 13, but now it gives partly broken IMEI, where 3 numbers came as ' symbol results screenshot It's not just these are additional symbols, what i mean is that exactly 3 numbers comes as symbol As far as i know, every Android 14 devices with IMEI is affected.

I've tried to use command adb shell service call phone 146 i32 0 s16 com.android.shell | cut -d "'" -f2| grep -Eo '[0-9]'| xargs| sed 's/\ //g' as per dougstar potential solution, but it's also for Android 13, plus it does give me an error. an error

//update

Even though original command which i'm using now showing wrong results, it is caused because it catches wrong columns (thanks to micha pringle explaination) It could be fixed with changing from 52-66 columns to 50-64 columns for Android 14 devices

adb shell "service call iphonesubinfo 1 s16 com.android.shell | cut -c 50-64 | tr -d '.[:space:]'"
2

There are 2 best solutions below

0
Fedor Potapenko On

Even though original command which i'm using now showing wrong results, it is caused because it catches wrong columns (thanks to micha pringle explaination) It could be fixed with changing from 52-66 columns to 50-64 columns for Android 14 devices

adb shell "service call iphonesubinfo 1 s16 com.android.shell | cut -c 50-64 | tr -d '.[:space:]'"
0
ale5000 On

First some comments:

  • Using adb shell "some_command | cut" is using cut on the phone but the phone doesn't necessarily have it so I suggest using adb shell "some_command" | cut to use cut on the pc;
  • On Windows you could simply get BusyBox to have all commands available without installation (just download from https://frippery.org/busybox/ and then run busybox.exe ash);
  • cut by column is highly unreliable as you can see, cut by separator is better;
  • Most people miss the most important parameter of cut -s, this will skip the lines that doesn't contain decoded data (decoded data is between ' and ') since iphonesubinfo response may contains them.

Response:

So, this is the most reliable command (executed from busybox ash or bash):

adb shell "service call iphonesubinfo 1 s16 com.android.shell" | cut -d "'" -f 2 -s | tr -d '.[:space:]'

Script:

This is my script that does that and even more: https://github.com/micro5k/microg-unofficial-installer/blob/main/utils/device-info.sh