© 2019-2023 by Zack Smith. All rights reserved.
Introduction
The Android Debugger (ADB) offers surprisingly extensive access to the innards of an Android phone.
The adb
command makes it easy to, for instance,
fetch all of your recent photographs and movie recordings off the phone,
and copy podcasts onto the phone.
To jump inside an Android phone and access the command line interface, you will need:
- An Android phone that you have put in Developer Mode.
- A USB cable.
- A computer.
Once you have run your OS's terminal program, there are two ways to ssh into the phone:
If the phone is running a consumer grade (production
) version of Android:
adb shell |
If it is running a development build of the OS, you can ssh as root:
adb root |
Phone characteristics
Get make and model
getprop ro.product.brand |
System-on-Chip (SoC) characteristics
Get processor family
cat /sys/devices/soc0/family |
Get CPU chip name
getprop ro.hardware.chipname |
Get CPU manufacturer
cat /sys/devices/soc0/vendor |
For example, Qualcomm.
Get CPU family
cat /sys/devices/soc0/family |
For example, Snapdragon.
Determine GPU name
dumpsys | grep GLES: |
Get the maximum core frequencies of the CPU
cd /sys/devices/system/cpu |
Get current core frequencies of the CPU
cd /sys/devices/system/cpu |
Memory and storage
Get RAM available to apps
free -h |
Get flash storage information
df -h |
Display
Show display characteristics
Size:
wm size |
Frames per second (fps) and dots per inch (DPI):
dumpsys display | grep DeviceInfo |
Font size
This is a useful feature if you have trouble reading tiny text.
settings put system font_scale 1.25 |
Screenshot
screencap /sdcard/screenshot.png |
Screen recording
screenrecord /sdcard/capture.mp4 |
Options:
- --time-limit (seconds)
- --rotate
- --bit-rate (Mb/sec)
Note! You may find on some devices that screenrecord is broken. If that is the case with your device, you can still record the screen by swiping down twice from the top of the display, from where you can run Android's built-in recorder GUI.
Screen mirroring to your computer
This is possible with screenrecord and mplayer.
adb exec-out screenrecord --bit-rate=16m --output-format=h264 - | mplayer -framedrop -cache 512 -demuxer h264es -fps 6000 -
Networks
Determine phone carrier
getprop gsm.operator.alpha |
Display current network connections 1
netstat -e | grep -e tcp -e udp |
Display current network connections 2
ss -p -t -4 -6 -u |
Turn cellular data on/off
svc data enable |
Send an SMS
am start -a android.intent.action.SENDTO -d sms:+15551212 --es sms_body Test --ez exit_on_sent false
Turn the Wifi on/off
svc wifi enable |
Show Wifi IP address
ifconfig wlan0 |
List Wifi networks that phone has connected to
dumpsys | grep hasEverConnected=1 | grep ssid= |
Show Wifi hotspot name
dumpsys | grep SemSoftApConfiguration |
Get the Bluetooth MAC address
settings get secure bluetooth_address |
Turn the Bluetooth on/off
svc bluetooth enable |
Get/set the phone's Wifi name
settings get global device_name |
Turn NFC data on/off
svc nfc enable |
Camera
The sensors' names are typically in the dumpsys
output and are encoded as decimal ASCII values.
- Adb shell to the phone and type
cd /sdcard; dumpsys media.camera > myfile.txt
- Copy that file back to your computer (
adb pull /sdcard/myfile.txt
) and open it. - Search in that file for
samsung.android.sensor.info.sensorName
and find one entry per sensor, plus maybe an extra one.
Because the sensor name is represented as ASCII decimal values, which you will need to convert it to ASCII e.g. with my converter utility.
Once converted, you may notice a sensor name that begins with IMX
.
That is a Sony sensor (and hopefully not a knock-off).
A sensor name that begins with S5K
is a Samsung sensor.
Here are my phone's sensors:
- 83 53 75 71 87 49 80 = Samsung 64MP S5KGW1P
- 73 77 88 54 49 54 = Sony 32MP IMX616
- 83 53 75 51 76 54 = Samsung 13MP S5K3L6
- 71 67 53 48 51 53 = 5MP GC5035
- 71 67 53 48 51 53 95 77 65 67 82 79 = 5MP GC5035_MACRO
Apps
List all apps
pm list packages |
List third-party apps
pm list packages -3 |
List running apps
ps -fA | grep u0_ | sed 's/^.*:[0-9][0-9] //' | sort |
Determine which core an app is running on
ps -o pid,psr,time,comm -p $(pgrep -x programName) |
Delete an app
Remove an app easily (in this case Webex) with this command:
pm uninstall com.cisco.webex.meetings |
Clear an app's data
Clear out the data associated with an app (in this case Audible's book data) thus:
pm clear com.audible.application |
Remove Samsung's game bloatware
pm uninstall --user 0 com.samsung.android.game.gos |
Disable Samsung Cloud
pm suspend --user 0 com.samsung.android.scloud |
Remove Youtube Music
pm uninstall --user 0 com.google.android.apps.youtube.music |
Remove Google One
pm uninstall --user 0 com.google.android.apps.subscriptions.red |
Remove built-in Facebook apps
Some phone carriers stealthily include Facebook apps on low-end phones. These may run automatically in the background but not appear in the Apps drawer. This is a security concern.
pm uninstall --user 0 com.facebook.services |
Even after all Facebook apps are remove, you may still observe (by using the ss command) periodic connections to Facebook servers such as 2a03:2880:f034:112:face:b00c:0:2.
Disable built-in Microsoft apps
pm suspend com.microsoft.appmanager |
Set up a Linux-like command-line environment
While you can log in via ADB, you can't install a compiler, Vim, or other packages.
To set up a proper command-line environment with a compiler and editor, install Termux.
If you want to use it properly, you must connect a keyboard via the USB-C port.
Home screen
Prevent swipe-right from Home into nauseating news
screen
In Android 11, swiping right from the first home screen takes you to a clickbait news page.
To disable that, tap the menu button, tap Settings and disable personalized news.
Samsung Bixby
Remove Bixby
pm uninstall --user 0 com.samsung.android.app.spage |
On-screen keyboards
Remove Samsung keyboard
pm uninstall -k --user -0 com.sec.android.inputmethod |
Vibrator
Vibrate for a specified number of milliseconds. This works with Android 9. It may not work in Android 11 and later.
cmd vibrator vibrate 100 |
To find out what the vibrator can do:
cmd vibrator capabilities |
On newer Android versions, this will list vibrator devices:
cmd vibrator_manager list |
Simulating input events
Power
* Press power key = input keyevent 26 |
Go to Home screen
input keyevent 3 |
Go back
input keyevent 4 |
Camera app
* Launch the app: input keyevent 27 |
Go to app switcher
input keyevent 187 |
Launch contacts app
input keyevent 207 |
Launch calendar app
input keyevent 208 |
Launch music app
input keyevent 209 |
Launch phone app
input keyevent 5 (launch phone app) |
Launch web browser
input keyevent 64 |
Launch mail application
input keyevent 65 |
Brightness
* Increase = input keyevent 221 |
Sound volume
* Increase = input keyevent 24 |
Clipboard
* Cut = input keyevent 277 |
Google search
input keyevent 84 |
Menus
input keyevent 101 (show or hide menu) |
Tabs
- Close current tab = input keyevent 97
- Next tab = input keyevent 103
- Previous tab = input keyevent 102
Cursor
input keyevent 19 (move cursor up) |
Scrolling
input keyevent 92 (page up) |
Media players
To start playing the current song or audio book:
media dispatch play |
To stop playing the current song or audio book:
media dispatch stop |
To launch the media player and play a video:
am start -a android.intent.action.VIEW -d file:///sdcard/video.mkv -t video/mkv |
To launch the media player and play a sound:
am start -a android.intent.action.VIEW -d file:///sdcard/sound.ogg -t audio/ogg |
Power
Reboot
reboot |
Power down
svc power shutdown |
Backup and restore
The backup mechanism will NOT save your contacts. If possible store those on your SIM card.
adb backup -all -apk -nosystem -f mybackup.ab |
Restore (I have not verified that this works):
adb restore mybackup.ab |
Factory restore
Do this at your own risk!
Don't forgot to:
- Write down your PIN and Google account details.
- Perform a backup.
The PIN will be needed to set up Android.
- Turn off the device.
- Press Volume Up and Power at the same time and hold them.
- When the company logo appears, release only the power button.
- When the Android logo appears, release the volume button.
- This should give you a menu that will let you
wipe data and factory reset
or similar.
From the command line:
adb reboot recovery |
Access service mode
*#0011# |
Scam block
#662# to enable Scam Block |
Links