Is there a way to get the phone number of a phone over adb?
I looked at dumpsys as a likely answer, but none of the system services seem to keep track of the phone's own number.
iphonesubinfo service "keeps track" of the subscriber information including phone numbers. Unfortunately iphonesubinfo service does not implement the dump() method so dumpsys shows nothing. You will have to use service call command to call IPhoneSubInfo.getLine1Number() or IPhoneSubInfo.getMsisdn() instead
Depending on the android version and your carrier one or two of the following commands will tell you the phone number (service call commands require root privileges):
service call iphonesubinfo 4
service call iphonesubinfo 5
service call iphonesubinfo 6
service call iphonesubinfo 7
service call iphonesubinfo 8
If you want to find out the proper code for your specific device - download the script from Calling Android services from ADB shell post and run it like this:
./get_android_service_call_numbers.sh iphonesubinfo | grep getLine1Number
UPDATE
Transaction codes for Android 5.0:
service call iphonesubinfo 11 # getLine1Number()
service call iphonesubinfo 15 # getMsisdn()
Transaction codes for Android 5.1:
service call iphonesubinfo 13 # getLine1Number()
service call iphonesubinfo 17 # getMsisdn()
Related
I'm trying to track devices, SIMs and airtime cards for test purposes. I have multiple devices plugged into a computer and since the recent update to Android 12, I am not able to get the device IMEI. The IMEI is basically the device's FCC-required serial number and can be obtained from the UI with relative ease, but how can I obtain it via ADB or in some automated method on multiple devices from multiple carriers and OEMs?
Prior to Android 12 FEB patch, I would use service call iphonesubinfo 1 or service call iphonesubinfo 4. But unfortunately after the update I receive back Result: Parcel(ffffffffc ffffffff 00000000 '................') whereas before I would receive a parcel containing the IMEI for processing via script.
Is there a way to get IMEI on Android 12+? I am trying to stay away from using an app. This is a simple thing, from a privileged user (adb shell). It seems like a basic necessity for tracking and logistics purposes.
This command works to obtain IMEI. It works by pressing the dialer key, then typing *#06#, then parsing the text on screen to find the IMEI Label and the next element which contains the actual IMEI. Finally it parses that element by removing all before text=" and all after ".
adb shell "imei=$(input keyevent KEYCODE_CALL;sleep 1;input text '*#06#'; uiautomator dump --compressed /dev/stdout|sed s/\>\<\/\\n/g|grep -A1 IMEI|tail -n1|sed -e 's/.*text=\"//' -e 's/\".*//'); echo ${imei}"
to get just the 16-digit IMEI without checksum, replace the final echo statement with echo ${imei:0:16}
I found a good solution for Samsung One UI
First, run the About menu
adb shell am start -a com.android.settings.ACTION_DEVICE_INFO_SETTINGS
Then dump the UI
adb shell uiautomator dump
View the dump file
adb shell cat /sdcard/window_dump.xml
The IMEI1 in the <node index="12" and IMEI 2 in <node index="13"
Is there any Adb command to set the volume to a particular value? I know that we can do
adb shell input keyevent
for volume up and down but i want to set it to a particular value. If I change it it DB then I have to reboot the device for the changes to be reflected so i do not want to go that path. Isn't there any API where I can change the value without having to restart it and having to be dependent on Volume up and Down?
media shell command can also be used:
media volume: the options are as follows:
--stream STREAM selects the stream to control, see AudioManager.STREAM_*
controls AudioManager.STREAM_MUSIC if no stream is specified
--set INDEX sets the volume index value
--adj DIRECTION adjusts the volume, use raise|same|lower for the direction
--get outputs the current volume
--show shows the UI during the volume change
examples:
adb shell media volume --show --stream 3 --set 11
adb shell media volume --stream 0 --adj lower
adb shell media volume --stream 3 --get
The first example is probably the one you were looking for (but it probably didn't exist at the time of asking)
I have used the service call audio test to set the volume on an android 2.3 device. In order to be more generic you need to research IBinder and the transaction number.
To find out what you want:
Adb shell service list packages
this will tell you the package file you need to look at for a service (I.e Bluetooth - com.Bluetooth.IBluetooth)
Search for the service class and 'transaction' online ("com.Bluetooth.Ibluetooth transaction")
Find the source files and find the Ibinder transaction details. This will be followed by the details of the input parameters.
I.e the first transaction on Bluetooth is .is enabled(). There are no input parameters
To use it send:
Adb shell service call Bluetooth 1
It should return a parcel containing the answer.
Remember:
- I think it is only for rooted devices
- the transaction number you find has an offset of 1 (transaction 0 is called with service call 'service' 1)
- There are two types of input: i32 for integer or s16 for string
To set the audio there are three input integers for set volume (transaction 6)
To use it send:
Adb shell service call 7 i32 3 i32 15 i32 0
This will set the media volume to 15 (default number of levels for media audio is 15)
On a rooted phone you can call setMasterVolume() with service call audio <code> i32 <volume>. The codes are version specific. Let's say you want to set volume to 50% on a KitKat device. The command will be:
service call audio 9 i32 50
This is an answer for anyone whose Android is too old to have volume subcommand in media command.
Thanks to Alex P's link, I got the inspiration from this guy's blog:
http://ktnr74.blogspot.com/2014/09/calling-android-services-from-adb-shell.html
You can use service command to call functions like void setStreamVolume(int streamType, int index, int flags, String callingPackage) on your Android device - a SO question.
Tried with my un-rooted Android 5.1 device and it worked.
Usage: service [-h|-?]
service list
service check SERVICE
service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
i32: Write the integer INT into the send parcel.
s16: Write the UTF-16 string STR into the send parcel.
But the CODE differs between Android versions. To find the code for setStreamVolume(), first save the Bash script from this gist, change its permission to executable, connect your device via ADB and run the script with audio as argument:
$ ./get_android_service_call_numbers.sh audio
(EDIT: https://github.com/T-vK/android-svc does that script.)
The script pulls info from Google and show you a list like this.
So we know the code for setStreamVolume() is 4, since we know the number for STREAM_MUSIC is 3, we can set music volume to 7 by this command:
$ adb shell service call audio 4 i32 3 i32 7
The maximum music volume on my device is 0xF, you can query yours with int getStreamMaxVolume(int streamType) function:
$ adb shell service call audio 15 i32 3
For those of you struggling with the answer provided by XioRCal, use adb shell cmd media_session instead of adb shell media as it has been removed in Android 11 and 12.
Reference: "media: inaccessible or not found" error when attempting to control device volume via ADB
In android 12 or later, can use cmd media_session shell cmd.
below is the usage: (need replace some media to cmd media_session)
usage: media_session [subcommand] [options]
media_session dispatch KEY
media_session dispatch KEY
media_session list-sessions
media_session monitor <tag>
media_session volume [options]
media_session dispatch: dispatch a media key to the system.
KEY may be: play, pause, play-pause, mute, headsethook,
stop, next, previous, rewind, record, fast-forword.
media_session list-sessions: print a list of the current sessions.
media_session monitor: monitor updates to the specified session.
Use the tag from list-sessions.
media_session volume: the options are as follows:
--stream STREAM selects the stream to control, see AudioManager.STREAM_*
controls AudioManager.STREAM_MUSIC if no stream is specified
--set INDEX sets the volume index value
--adj DIRECTION adjusts the volume, use raise|same|lower for the direction
--get outputs the current volume
--show shows the UI during the volume change
examples:
adb shell media volume --show --stream 3 --set 11
adb shell media volume --stream 0 --adj lower
adb shell media volume --stream 3 --get
I would like to get the cell phone number of any android device using the command line.
I have tried using:
adb shell service call iphonesubinfo 4
and
adb shell service call iphonesubinfo 5/6/7/8
and it returns Permission denied.
I was wondering if anyone has another solution?
Ps: phones are android 4.1 and above
Thanks you in advance.
You have to obtain root access by using :
adb root
Then you'll find those command work. Usually the phone number will be returned by :
adb shell service call iphonesubinfo 5
or by :
adb shell service call iphonesubinfo 6
It depends on the device is single or dual sim. You'll need to do some string parsing work if you need this result to be recognized by machine.
Is it possible to use the android api functions from the adb? If its possible, what is the syntax to do so?
For example I'd like to call the "DATA_CONNECTED" function from android.telephony and get its return value. Link: http://developer.android.com/reference/android/telephony/TelephonyManager.html#CALL_STATE_OFFHOOK
There is no DATA_CONNECTED function in Android TelephonyManager. It is a 0x00000002 constant - one of possible response codes to the getDataState() function.
The way you call getDataState() from adb shell is:
service call phone 32
Update: if your phone runs anything older than jb-mr2, the command should be:
service call phone 31
P.S. just finished my write-up on Calling Android services from ADB shell - it includes a small bash script to look up calling codes for any service/method for a specific device.
I want to know whether media player service (registers with media.player when device boots up) is running or not using adb shell. Is it possible?
I tried running ps command but no success.
As mentioned already, adb shell service list will only list system services.
As explained in Android Emulator: How can I get a list of services that are running, you can look for services created by apps by using
// List all services
adb shell dumpsys activity services
// List all services containing "myservice" in its name
adb shell dumpsys activity services myservice
If it returns something, it means the service is installed. To know if the service is currently started or stopped, look for app=ProcessRecord(...) or app=null respectively.
You can also do it Linux style with a simple
ps | grep myservice
while inside of your shell.
Try the command line
adb shell service list
I get a list of service names and their package names as well.
To simply check whether a specific service is running, use:
adb shell service check <service>
For example, adb shell service check media.player gives Service media.player: found if it's running and Service media.player: not found otherwise.
If you need more detail, try dumpsys <service>. For example, adb shell dumpsys media.player returns information about media.player's clients, open files, etc.
Finally, if you really need serious detail for debugging, try adb shell dumpsys activity services which shows what's going on from ActivityManager's point of view. This includes information about intents, create times, last activity time, bindings, etc., etc. You can redirect the output if you want to store it for later viewing/searching. It's typically rather lengthy.
For Android 10, list all currently running services:
adb shell dumpsys activity services | grep "ServiceRecord" | awk '{print $4}' | sed 's/.$//' | sort
To know whether an app process is running or not (background or foreground):
adb shell pidof <package.name>
It'll return empty string if process is not running else its pid.