android - adb
TRANSCRIPT
Agenda
▣ what is adb▣ adb commands▣ adb scripts ▣ adb files▣ adb over WiFi▣ screen capture/record▣ logcat▣ shell command
□ am□ pm□ dumpsys□ more…
▣ exercise
What is ADB
▣ Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device.
3 elements of ADB
▣ adb clients□ executable with subcommand □ ”adb shell”, ”adb logcat” : the end point of host
side▣ adb server
□ running on host on back-ground□ act as proxy between adb clients and adbd
▣ adb daemon (adbd)□ running on target device□ started by init, if die, restarted by init again
ADB Commands
▣ adb devices□ Print All the connected devices
▣ adb shell □ run remote shell interactively
▣ adb jdwp□ list PIDs of processes hosting a JDWP transport
▣ adb install/uninstall□ un/install the application
▣ adb start-server □ ensure that there is a server running
▣ adb kill-server □ kill the server if it is running
Adb scripts
▣ adb wait-for-device□ block until device is online
▣ adb start-server □ ensure that there is a server running
▣ adb kill-server □ kill the server if it is running
▣ adb get-state□ prints: offline | bootloader | device
▣ adb get-serialno□ prints: <serial-number>
▣ adb get-devpath□ prints: <device-path>
Adb scripts
▣ adb status-window □ continuously print device status for a specified
device▣ adb remount
□ remounts the /system and /vendor (if present) partitions on the device read-write
▣ adb reboot [bootloader|recovery] □ reboots the device, optionally into the bootloader
or recovery program▣ adb reboot-bootloader -
□ reboots the device into the bootloader▣ adb root
□ restarts the adbd daemon with root permissions▣ adb usb
□ restarts the adbd daemon listening on USB
Adb - Files
▣ Copy file to device□ adb push <local> <remote>
▣ Copy file from device□ adb pull <remote> <local>
adb over WiFi
▣ Android Device□ adb shell netcfg
get the android IP address (x.x.x.x)□ adb shell setprop service.adb.tcp.port 5555□ adb shell stop adbd && start adbd
▣ PC device□ adb connect x.x.x.x□ adb -s x.x.x.x:5555 logcat□ adb -s x.x.x.x:5555 logcat |grep -vE "/dalvik"□ adb -s x.x.x.x:5555 shell
BugReport
▣ Command□ adb shell bugreport > bugreport.txt□ java -jar chkbugreport.jar bugreport.txt
▣ JAR download □ https://github.com/sonyxperiadev/ChkBugReport/
downloads
ScreenCapture
▣ Command:□ adb shell screencap -p /sdcard/screen.png□ adb pull /sdcard/screen.png□ adb shell rm /sdcard/screen.png
▣ Other way□ adb shell screencap -p | sed 's/\r$//' > screen.png□ adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g'
> screen.png
ScreenRecord
▣ Command:□ adb shell screenrecord /sdcard/recording.mp4 □ adb pull /sdcard/recording.mp4□ adb shell rm /sdcard/recording.mp4
Adb Key Event
▣ Power Button□ adb shell input keyevent 26
▣ Unlock screen□ adb shell input keyevent 82
▣ Volume down□ adb shell input keyevent 25
▣ List of Keyevent□ http://developer.android.com/reference/android/
view/KeyEvent.html
Logcat - Logging
▣ Filter by tagname□ adb logcat -s TAG_NAME □ adb logcat -s TAG_NAME_1 TAG_NAME_2
▣ Filter by priority□ adb logcat "*:PRIORITY"
V - Verbose (lowest priority) D - Debug I - Info W - Warning E - Error F - Fatal S - Silent (highest priority, on which nothing is
ever printed)
Logcat - Logging
▣ Filter using grep□ adb logcat | grep "SEARCH_TERM"□ Example
adb logcat | grep "Exception"
▣ Clearing the logcat buffer□ adb logcat -c
Logcat - Buffers
▣ radio - adb command “” □ View the buffer that contains radio/telephony
related messages. ▣ events
□ View the buffer containing events-related messages.
▣ main □ View the main log buffer (default)
Run Command “logcat -b <buffer>”
Shell Commands
▣ dumpstate□ Dumps state to a file.
▣ dmesg□ Prints kernel debugging messages to the screen
▣ start□ Starts an emulator/device instance.
▣ stop□ Stops execution of an emulator/device instance.
▣ restart□ restart an emulator/device instance.
Shell Commands
▣ top□ Prints all the running tasks on your device
▣ Service □ Help to communicate with phone services
service list service check <SERVICE_NAME> service call <SERVICE_NAME> CODE
AM - Activity Manager
▣ Start Activity□ am start <packageName/.ActivityClass>
▣ Start/Stop Service□ am startservice -n <packageName/.ServiceClass>□ am stopservice -n <packageName/.ServiceClass>
▣ Send broadcast□ am broadcast -a <action_name>
▣ Users□ am switch-user <USER_ID>□ am start-user <USER_ID>□ am stop-user <USER_ID>
▣ More Commands▣ adb shell am
PM - Package Manager
▣ pm list packages▣ pm list permission-groups▣ pm list users▣ pm install▣ pm create-user▣ pm remove-user USER_ID▣ pm get-max-users
▣ More Commands▣ adb shell pm
Dumpsys
▣ dumpsys□ will show all system data from the device
▣ you can filter it by adding□ dumpsys activity□ dumpsys batterystats□ dumpsys cpuinfo□ dumpsys wifi□ dumpsys meminfo □ dumpsys package ‘package’
▣ More:□ adb shell dumpsys -l
Joke commands
▣ adb hell□ same as ”adb shell” except ”hell” color :)
▣ adb lolcat□ same as ”adb logcat”
Task #1
1. Open Settings Applicationa. main application
2. Open Settings In Inner Activitya. WifiSettings
Task #3
1. Open my Application with intent and extraa. extra keys
i. stringii. booliii. floativ. string_array
▣ Download Apk□ https://goo.gl/IWTGle
▣ Code reference□ https://github.com/yossigruner/AdbSession
Answers
▣ Task #1□ adb shell am start -S com.android.settings/com.android.settings.Settings□ adb shell am start -a android.intent.action.MAIN -n
com.android.settings/.wifi.WifiSettings
▣ Task #2□ adb root□ adb remount□ adb pull /system/priv-app/Dialer/Dialer.apk
▣ Task #3□ adb shell am start -n
com.mike.adbsession/com.mike.adbsession.MainActivity --ez bool false --ef float 1.999 --es string hello --esa string_array hello,world
▣ Task #4□ enable - service call nfc 6
□ disable - service call nfc 5
References
▣ https://community.woodwing.net/sites/default/files/Android%20Debug%20Bridge%20%7C%20Android%20Developers.pdf
▣ https://source.android.com/devices/tech/debug/dumpsys.html