From Gentoo Wiki
Jump to:navigation Jump to:search
This wiki article has been created for non-rooted devices. For rooted devices please create another article or add a rooted section at bottom.

ADB stands for Android Debug Bridge[1], and it is a part of the Android Software Development Kit (SDK)[2]. It can be installed with dev-util/android-sdk-update-manager.

root #emerge --ask dev-util/android-sdk-update-manager


Install ADB and Fastboot

Fastboot is included with ADB inside the dev-util/android-tools package:

root #emerge --ask dev-util/android-tools

Enable USB debugging

Enable the USB Debugging option on the Android device under Settings > Developer options.

For Android 4.2 and later, Developer options is hidden by default; use the following stepsː

  1. On the device, go to Settings > About <device>.
  2. Tap the Build number seven times to make Settings > Developer options available enable.
  3. Go back to system settings and scroll down to bottom > Developer Options.
  4. Now hit Enable USB-Debugging.

Tips: You might also want to enable the Stay awake option, to prevent Device from sleeping while plugged into the USB port.

Detect devices

If the device is listed then connect to the android devices shell (the first time an authorized request on the device must be accepted when typing adb shell):

user $adb devices
List of devices attached 
8NH7N17B0XX9898        device

To run adb without root privileges then the unprivileged user account must be added to the plugdev group:

root #gpasswd -a <username> plugdev

Enter shell

user $adb shell

Multiple devices connected

When multiple devices are connected to the PC then the -s option will be needed to specify which device. If the device has not been specified, an error message message similar to the following will appearː

error: more than one device/emulator
user $adb devices
List of devices attached
9QZ7N11B0ZX8999        device
8NH7N17B0XX9898        device
user $adb -s <device̠-number> shell

Connect to ADB via WiFi

Set TCP port

To use adb over a WiFi connection instead of using the cable, type the below command with the USB plugged in first timeː

user $adb tcpip 5555
restarting in TCP mode port: 5555

Print IP address

To get the IP of the connected Android device (cabled connection):

user $adb shell ip route | awk '{print $9}' 


Once the IP address is known, use it to connect to the device:

user $adb connectː5555
connected to

Now control the device as usual via adb.

It is highly not recommended to flash, or perform any similar action to that can brick the device if the connection is lost, when connecting over WiFi.

Control daemon

Start ADB daemon

user $adb start-server

Kill ADB daemon

Sometimes it may be necessary to kill adb if the device is not showing up connect. This can occur when adb is running before connecting the device. In this case kill and restart the adb server:

user $adb kill-server


System reboot

The device can be rebooted from adb:

user $adb reboot

Recovery mode

user $adb reboot recovery

Bootloader mode

user $adb reboot bootloader

File transfer

Push a file

user $adb push mypicture.png /storage/on/device

Push a folder

user $adb push myfolder /storage/on/device

Push all files in a folder

Files from the myfolder/ directory will be transferred into storage/on/device. Notice the trailing slash on the directory name is specifiied in the command:

user $adb push myfolder/ /storage/on/device

Pull a file

user $adb pull /storage/on/device/mypicture.png

Pull a folder

user $adb pull /storage/on/device /home/̩$(whoami)/android-folder/

Pull all files in a folder

Notice the trailing slash after the myfolder/ directory name:

user $adb push myfolder/ /storage/on/device

ADB properties

Print properties

user $adb shell getprop

Set a property service

user $adb shell setprop key value

ADB service

Service syntax

user $adb shell service call <your_service_name> <number at which the function appears in your_service_name.aidl> <type of the argument like i32 or i64> <argument>

List all services

user $adb shell service list
iphonesubinfo: []
phone: []

Exampleː Make a call via service

user $adb shell service call phone 1 s16 '+6512345678'

Exampleː Print IMEI via a call service

user $adb shell service call iphonesubinfo 1
Result: Parcel(
  0x00000000: 00000000 0000000f 00360038 00340034 '........'
  0x00000010: 00330036 00330030 00300035 00350032 ''
  0x00000020: 00370038 00000038                   '8.7.8...        ')

Convert the output to a readable formatː

user $adb shell service call iphonesubinfo 1| cut -d "'" -f2| grep -Eo '[0-9]'| xargs| sed 's/\ //g'

Print IMEI 1 & IMEI 2

Imei 1:

user $service call iphonesubinfo 3 i32 1 | grep -oE '[0-9a-f]{8} ' | while read hex; do echo -ne "\u${hex:4:4}\u${hex:0:4}"; done; echo

Imei 2:

user $service call iphonesubinfo 3 i32 2 | grep -oE '[0-9a-f]{8} ' | while read hex; do echo -ne "\u${hex:4:4}\u${hex:0:4}"; done; echo


Enable accessibility

user $adb shell content insert --uri content://settings/secure --bind name:s:accessibility_enabled --bind value:s:1

Enable on accessibility injection accessibility

user $adb shell content insert --uri content://settings/secure --bind name:s:accessibility_script_injection, --bind value:s:1

Enable lock feature

user $adb shell content insert --uri content://settings/secure --bind name:s:lock_function_val --bind value:s:0

Allow us to use volume buttons

user $adb shell content insert --uri content://settings/secure --bind name:s:volume_controller_service_component --bind value:s:1

Enable max brightness (Default: 72)

user $adb shell content insert --uri content://settings/secure --bind name:s:brightness_pms_marker_screen --bind value:s:255

ADB Activity Manager

Take a photo by open camera application

user $am start -a"

Take photo

user $input keyevent 27

Open Default Camera Application in Photo Mode

user $adb shell am start -a

Open Camera in 'Photo Mode' and Take Photo

user $adb shell am start -a
user $adb shell input keyevent 66

Open Camera in Video mode

user $adb shell am start -a

Start recording

user $adb shell input keyevent 66

Stop recording

user $adb shell input keyevent 66

Set wallpaper

When an image is open in the photo gallery, set the image as wallpaper for all screens with below

user $adb shell am start -a android.intent.action.SET_WALLPAPER

Open any URL in default browser

user $adb shell am start -a android.intent.action.VIEW -d

Launch video player and play sound

user $am start -a android.intent.action.VIEW -d file:///sdcard/sound.ogg -t audio/ogg

Open developer settings

user $am start -a

Open power settings

user $am start -a\$PowerUsageSummaryActivity

Launch Android Settings, subsettings for connection settings

user $adb shell am start

Launch video player and play a movie

user $am start -a android.intent.action.VIEW -d file:///sdcard/video.mkv -t video/mkv

Open Google Maps with fixed coordinates

user $adb shell am start -a android.intent.action.VIEW -d "geo:46.457398,-119.407305"

Open contacts application

user $am start -a android.intent.action.VIEW content://contacts/people/

Simulate pressing home button

user $am start -W -c android.intent.category.HOME -a android.intent.action.MAIN

Enabling Night Mode (If Supported)

user $adb shell am start --ez show_night_mode true

Start facebook application inbox by using URI

user $adb shell am start -a android.intent.action.VIEW -d facebook://

Open a vcard file from sdcard (will open contacts app)

user $adb shell am start -a android.intent.action.VIEW -d file:///sdcard/me.vcard -t text/x-vcard

Open an application to get content

user $adb shell am start -a android.intent.action.GET_CONTENT -t image/jpeg

There is several ways to send a SMS via AM, here is just one of several ways

user $adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"

Add contact without GUI

user $am start -a android.intent.action.INSERT -t -e name 'larry the cow' -e phone 123456789

Add contact via GUI simulation

user $adb shell am start -a android.intent.action.INSERT -t -e name 'Larry' -e phone '+467277777' -e email '' -e postal '12345, FooStreet 10, Sweden'

For save the contact enter keyevent 4 twice

user $adb shell input keyevent 4;sleep 0.2; adb shell input keyevent 4

ADB package manager (pm)

'pm list' commands have moved! Run 'adb shell cmd package' instead

List installed packages

user $adb shell pm list packages

List enabled packages

user $adb shell pm list packages -e

List disabled packages

user $adb shell pm list packages -d

List third party packages installed by user

user $adb shell pm list packages -3

List users

user $adb shell pm list users
       UserInfo{0:Owner:13} running

List permission groups

user $adb shell pm list permission-groups
permission group:android.permission-group.LOCATION
permission group:android.permission-group.STORAGE
permission group:android.permission-group.MICROPHONE

List features

user $adb shell pm list features

Uninstall a package

user $pm uninstall --user 0


user $pm uninstall --user 0 com.facebook.orca

Tip: Uninstalling several packages at once can be achieved by a loop:

user $for packages in com.package1 com.package2; do adb shell pm uninstall --user 0 $packages; done

Make a Demo Call

Establishes a fake Bluetooth connection to Dialer and must be called first to enable access to all call-related commands.

1) Connect to device

user $adb shell am broadcast -a --es "action" "connect"

2) Place outgoing call from car dialer

user $ am broadcast -a \--es "action" "addCall" --es "id" "123456789"

3) Receive the incoming call from car mode

user $adb shell am broadcast -a --es "action" "rcvCall" --es "id" "123456789"

4) Hold Current Call

user $adb shell am broadcast -a --es "action" "holdCall"

5) Unhold the current call

user $adb shell am broadcast -a --es "action" "unholdCall"

6) Merge Calls

user $adb shell am broadcast -a --es "action" "unholdCall"

4) End current call

user $adb shell am broadcast -a --es "action" "endCall" --es "id" "123456789"


A tool that runs on Android devices and provides information about system services. To get a diagnostic output for all system services for the connected device, simply run adb shell dumpsys. However, this outputs far more information than typically needed. For more manageable output, specify the service to examine by including it in the command.

Dumpsys syntax

user $adb shell dumpsys [-t timeout] [--help] [-l] [--skip services] [service] [arguments] [-c] [-h]

Exampleː Print battery stats

user $adb shell dumpsys battery
  AC powered: false
  USB powered: true
  Wireless powered: false
  Max charging current: 500000
  Max charging voltage: 5000000
  Charge counter: 0
  status: 2
  health: 2
  present: true
  level: 45
  scale: 100
  voltage: 3826
  temperature: 240
  technology: Li-poly

List options

user $dumpsys -l

If above command does not work then useː

user $dumpsys | grep -a 'DUMP OF SERVICE'

Print current application in use via dumpsys

This is a good command to figure out how to start the application via am:

user $dumpsys window windows | grep 'mCurrentFocus'

Tips and tricks

Show network speed at top beside battery icon

user $settings put system show_network_speed_enabled 1

Enter a number to phone application without pressing on call

user $service call phone 1 s16 "+4612345678"

Debug an application by simulating 10000 touches

user $monkey -p com.example.myapp -v 10000

Allow device to trace GPS position

user $settings put secure location_providers_allowed gps

Disallow GPS tracing

user $settings put secure location_providers_allowed gps ' '

Allow installing applications outside play store

user $settings put secure install_non_market_apps 1

Allow taking photo via fingerprint

user $settings put secure fp_take_photo 0

Allow notifications to be viewed at home screen when its locked

user $settings put secure lock_screen_allow_private_notifications 1

Enable owners message at lock screen

user $settings put secure lock_screen_owner_info_enabled 0

Swipe down notification center via input

user $input swipe 0 0 0 300

Get bluetooth mac-addr

user $settings get secure bluetooth_address


WARNING: adb backup is deprecated and may be removed in a future release

Create full backup

user $adb backup -all -f <filepath>/backup.ab“

Create shared backup

user $adb backup -apk -shared -all -f <filepath>/backup.ab“

Restore a backup

user $adb restore <filepath>/backup.ab

Extract a backup (.ab extension) on PC

user $( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 backup.ab ) | tar xfvz -

HTC backup

With a non rooted device, the only things you can backup locally is what the couple device/android will let you do. That is pretty much the same files you can copy with the already mentioned software. With the Android 4.x devices, a nice solution to make such a partial backup is the so-called "adb backup".

user $adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|nosystem] [<packages...>]


  • -f : the path of the *.ab file that will be saved on your computer. This file is a compressed file that contains an archive of the data/apks from your device.
  • -apk|-noapk : indicates if the *.apk files should be backed up (default is -noapk)
  • -shared|-noshared: enable/disable backup of the device's shared storage / SD card contents (default is -noshared)
  • -all : indicates that you want the entire system backed up. you can use the packages filter to just backup specific packages, or use -all for a full system backup.
  • -system|-nosystem: indicates if all the system applications and data are included when backing up. (default is -system)
  • <packages> : this is where you can list specific packages to backup. Use these if you want to back up only specific applications. If using -all, you do not need to specify packages.

To backup the phone into ~/HTC_backup

user $cd ~
user $mkdir HTC_backup
user $adb devices

will start the daemon and show you the devices on the USB.

user $adb backup -apk -shared -all -system -f ~/HTC_backup/backup<date_of_the_day>.ab

will backup every thing the device will let you to backup.

user $adb restore ~/HTC_backup/backup<date_of_the_day>.ab

will restore the backup into the device.

To stop the daemon:

user $adb kill-server