From Gentoo Wiki
Jump to:navigation Jump to:search

This WIKI has been created for non-rooted devices, for rooted devices please create another wiki OR add a rooted section at bottom

About ADB

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 & Fastboot

Fastboot will get installed under same package as adb

Install dev-util/android-tools:

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

Enable USB debugging

Enable the USB Debugging option under Settings > Developer options.

For Android 4.2 and newer, 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 your device is listed then you can connect to your android devices shell (first time you must accept authorized request on your device when you typing adb shell)

user $adb devices
List of devices attached 
8NH7N17B0XX9898        device

If you want to run adb without root privileges then you must add your user in to plugdev group:

root #gpasswd -a <username> plugdev

Enter shell

user $adb shell

Multiple devices connected

If you have multiple devices connected to your PC then you must use -s for specify which device otherwise you will see a message similar toː

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

If you prefer to use adb over a WiFi connection instead of using the cable you can type below command with the USB plugged in first timeː

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

Print IP address

To get your IP of your connected android device you can typeː

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


Now you should be able to connect to your deviceː

user $adb connectː5555
connected to

Now control your device as usual via adb.

It is not recommended to flash your device over adb via WiFi or similar things that can harm your device if connection will be lost.

Control daemon

Start ADB daemon

user $adb start-server

Kill ADB daemon

user $adb kill-server

Sometimes it might be necessary to kill adb if you your device will not be shown after you have connected the device if it's already running before you connecting the device, then just start the daemon again after you killed adb daemon.


System reboot

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 myfolder will be transferred into storage/on/device Notice the trial slash

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 trial slash

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 & 2 via a call service if you have two sim cards

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

ADB package manager

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

Tips For uninstall several packages at once you must do it in a loop

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


A tool that runs on Android devices and provides information about system services. To get a diagnostic output for all system services for your connected device, simply run adb shell dumpsys. However, this outputs far more information than you would typically want. For more manageable output, specify the service you want 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 you can useː

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

Tips & Tricks

Show network speed at top beside battery icon:

user $settings put system show_network_speed_enabled 1

Print current application in use via dumpsys (good command for figure out how to start the application via am):

user $dumpsys window windows | grep 'mCurrentFocus'

Open any url with your default browser:

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

Enter a number to your phone application without pressing on call:

user $service call phone 1 s16 "+4612345678"

Print all applications so you easily know how to start the application via 'am', see example below:

user $pm list packages| sed -e "s/package://"| while read x;do cmd package resolve-activity --brief $x| tail -n 1M;done
Example Output:$HomeActivity

Now you can run any of above lines with am:

user $am

Take a photo without open camera application:

user $ am start -a

Take a photo by open camera application:

user $ am start -a"

For take the photo when the photo app is running enter:

user $input keyevent 27

Debug your application by simulating 10000 touches:

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

Allow GPS to trace your 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

Extract a backup (.ab) file on PC:

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

Allow taking photo via fingerprint:

user $settings put secure fp_take_photo 0

Open power settings:

user $am start -a\$PowerUsageSummaryActivity

Add a contact via am:

user $am start -a android.intent.action.INSERT -t -e name 'wuseman puzeman' -e phone 123456789

Open Contacts Application:

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

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

Open developer settings:

user $am start -a

Simulate pressing home button:

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

Get bluetooth mac-addr:

user $settings get secure bluetooth_address

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