Get IMEI via ADB only for old Huawei models - android

I need a bit of assistance. I have a Huawei g6-l11 (with Android 4.3) from which I am trying to extract the IMEI via ADB. I know that this device is ancient, but this is one of my tasks. So far I had tried everything I could find on the internet, like:
1) adb shell getprop | grep "<IMEI>"
2) adb shell service call iphonesubinfo N | grep "<IMEI>" - Where N is a number between 1 and 50
3) adb shell settings get secure android_id
4) adb shell content query --uri content://settings/secure | grep "<IMEI>"
5) adb shell content query --uri content://settings/system | grep "<IMEI>"
6) adb shell content query --uri content://settings/global | grep "<IMEI>"
7) adb shell dumpsys | grep "<IMEI>"
So I had made an Android app and run this piece of code on the smartphone:
val tm = this.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
Log.d("Emy_","The IMEI is ${tm.deviceId}")
That worked fine but it is an Android app when I need to do the same thing but only via ADB.
Also, I had found a fastboot command that would help me (like: fastboot oem get-psid). But the problem is that I need to reboot the phone into fast boot mode. Which is taking too long.
My questions are:
1) why is it different for Huawei models with the OS version below Marshmallow to extract the IMEI?
2) how could I replicate the function call done by the Java code to be done with the ADB in the terminal? Or in other words, what other commands would you recommend to me to try to extract the IMEI?

You could display it on screen:
adb am start -a android.intent.action.CALL -d tel:*%2306%23

If you just searching to know the IMEI, You can try this code : *#06#
Or you can try this : adb shell
service call iphonesubinfo 1 | toybox cut -d "'" -f2 | toybox grep -Eo '[0-9]' | toybox xargs | toybox sed 's/\ //g'
hop that help you !

Related

How to get IMEI using adb command on Android 13?

There is a question about Getting IMEI number using ADB commands Android 12.
adb root
adb shell "service call iphonesubinfo 1 i64 0 | cut -c 52-66 | tr -d '.[:space:]'"
I tested the method, and it works well on Android 12.
But from android 13 on, it just returns an error message: "Package does not belong to ..."
Does anyone can help? Thanks!
Below ADB command uses UIAutomator of Android.
Method: Call app -> *#06# -> Get value
adb shell "imei=$(input keyevent KEYCODE_WAKEUP;input keyevent KEYCODE_CALL;sleep 1;input text '*#06#'; uiautomator dump --compressed /dev/stdout|sed s/\>\<\/\\n/g|grep -A1 IMEI1|tail -n1|sed -e 's/.*text=\"//' -e 's/\".*//'); echo ${imei:0:16}"
You can edit to get IMEI1, IMEI2, SN. My phone is Samsung Galaxy, if you use other phone brands, edit it accordingly.
Note: Not work when your phone is locked

adb cannot accurately read IMEI 1 and 2

there are two OPPO phones, using adb cannot accurately read IMEI 1 and 2, but only MEID. How can I read IMEI?
Android version 11 Model PEAM00 and PEMM20
Tried the following command, but it doesn't work, only MEID is returned.
adb shell service call iphonesubinfo 1
adb shell service call iphonesubinfo 2
Found in a different StackOverflow thread that I can't find now:
adb shell "service call iphonesubinfo 1 | cut -c 52-66 | tr -d '.[:space:]'"
This is working on Android 11. If it's not working straight from CMD then type
adb shell
and then the rest of the command (service call ...)

Check if device is landscape via ADB

Is it possible to check a devices orientation via ADB?
Not by installing any software, calling any existing software, just through ADB. Would guess there is a status file somewhere in /proc, but could not find it yet.
This can be done through the following command:
adb shell dumpsys | grep 'SurfaceOrientation' | awk '{ print $2 }'
The output will be an integer ranging from 0 to 3 for each of the four possible orientations. 0 and 2 are landscapes while 1 and 3 are portraits. As the dumpsys output is very large, the command might take a few seconds to complete.
Update: dgmltn's modification is likely much faster:
adb shell dumpsys input | grep 'SurfaceOrientation' | awk '{ print $2 }'
Simpler solution:
adb shell dumpsys window | grep -i surfaceorientation | awk '{ print $2 }'
I found this method content query --uri content://settings/system --projection name:value --where "name='user_rotation'" after opening adb shell . Although doesn't seem to work if entered without opening a shell first.
In addition to the previous answers, I would like to point out that the return value of adb shell dumpsys | grep 'SurfaceOrientation' does not always follow a specific rule across devices ("0 and 2 are landscapes while 1 and 3 are portraits" is wrong).
I improved the method by an additional query, which advises how to interpret the return value, namely
dumpsys window | grep 'mLandscapeRotation'
value 0 means: 0 and 2 are landscapes, 1 and 3 are portraits
value 1 means the opposite situation
I am not sure if something has changed since the last answers were written, or if it is because I am emulating a different device.
but neither SurfaceOrientation nor mLandscapeRotation showed up in dumpsys for me.
After diffing the outputs of dumpsys between rotations I found
mPredictedRotation
#Normal
$./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=0
#Right
$./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=3
#Inverted
$./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=2
$Left
#./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=1

Android adb shell ,ps-ef does not show any process?

i have many application running on my emulator but ps -ef does not show any process y?
It seems like Android's ps does not accept the argument -ef. Try issuing ps only?
adb shell ps | grep com.android.mms | awk '{print $2}'
This gives the process id of the attached process

Can I use adb.exe to find a description of a phone?

If I call the command "adb.exe devices" I get a list of devices with a unique ID for each. These IDs are perfect for programming but not very human readable. Is there any way I can link one of these IDs to a (not necessarily unique) description of the phone? For example, if I have a device with an ID 1234567890abcdef is there any way I can figure that in real life it is a Motorola Droid X?
In Android there is a Model number entry in settings that shows phone name.
There is a way to quickly see this via command line:
adb shell cat /system/build.prop | grep "product"
This is what's shown for Samsung Galaxy S 4G:
ro.product.model=SGH-T959V
ro.product.brand=TMOUS
ro.product.name=SGH-T959V
ro.product.device=SGH-T959V
ro.product.board=SGH-T959V
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.manufacturer=Samsung
ro.product.locale.language=en
ro.product.locale.region=US
# ro.build.product is obsolete; use ro.product.device
ro.build.product=SGH-T959V
On a HTC Desire, the output looks like this:
ro.product.model=HTC Desire
ro.product.brand=htc_wwe
ro.product.name=htc_bravo
ro.product.device=bravo
ro.product.board=bravo
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.manufacturer=HTC
ro.product.locale.language=hdpi
ro.product.locale.region=
You can refine your query to show only one line:
adb shell cat /system/build.prop | grep "ro.product.device"
or
adb shell cat /system/build.prop | grep "ro.product.model"
With newer devices, you can run
adb devices -l
This will list some devices in a more human readable form
Example:
04d9a601ce516d53 device usb:1A134500 product:occam model:Nexus_4 device:mako
015d4b3406280a07 device usb:1A134700 product:nakasi model:Nexus_7 device:grouper
01466E620900F005 device usb:1A134600 product:mysid model:Galaxy_Nexus device:toro
Yes, adb shell cat /system/build.prop is wonderful, but also as #Matt said, it sometimes differs because of different manufacture.
IMHO, the most reliable approach is the built-in command: adb shell getprop
======================================================================
Here is a comparison for an exception (Genymotion emulator):
By adb shell cat /system/build.prop you'll get
ro.product.brand=generic
ro.product.name=vbox86p
ro.product.device=vbox86p
ro.product.board=
ro.product.cpu.abi=x86
ro.product.manufacturer=Genymotion
ro.product.locale.language=en
ro.product.locale.region=US
So there is no model value :(
By adb shell getprop you'll get
[ro.product.manufacturer]: [Genymotion]
[ro.product.model]: [Nexus422ForAutomation]
[ro.product.name]: [vbox86p]
Here you get the model name: Nexus422ForAutomation :)
Unfortunately, there is no reliable way to do this since each manufacturer tweaks their build properties
If you type "adb help" into the command line you can see a list of the adb commands and a description for each.
I'm using this script (on MacOS):
#!/bin/bash
devices=`adb devices | grep "device" | grep -v "List of" | cut -d " " -f 1`
for device in $devices
do
manufacturer=`adb -s $device shell getprop ro.product.manufacturer | sed -e 's/[[:space:]]*\$//'`
model=`adb -s $device shell getprop ro.product.model | sed -e 's/[[:space:]]*\$//'`
echo "$device: $manufacturer $model"
done
It produces e.g. the following output:
T076000UWX: motorola XT1053
C4F12070E5A068E: samsung GT-P7510
4df1ff977b919f91: samsung GT-N7100
4258393032523638324D: Sony Ericsson LT18i

Categories

Resources