Lecture 9 ADB Topics Basic ADB Commands What
Lecture 9: ADB Topics: Basic ADB Commands
What is ADB? • Android Debug Bridge (ADB) is a command line utility to communicate with your Android device. <android_sdk_path>/platform-tools/adb. exe • Uses: • • Listing connected devices. Installing and debugging apps. Copy files to and from the phone. Take screenshots, record screens, etc.
ADB Client-Server Architecture • Three entities are involved: a client, a server, a daemon (adbd). Client Invoked From Terminal Port: 5037 Server Background process Port: 555 X Daemon Background process
Connecting over USB • Remember the first class of the semester? Settings>About Phone> Build number Settings>Developer options> USB Debugging Why?
Testing the ADB • Use a shell to invoke your first command: Ø adb devices -l List of devices attached 071 b 799 a 344 bdc 6 b device product: hammerhead model: Nexus_5 device: hammerhead USB
When things go wrong … • Use a shell to kill and start the server: Ø adb kill-server Ø adb start-server * daemon not running. starting it now at tcp: 5037 * * daemon started successfully * USB
ADB over Wi. Fi • Set TCP port (over USB) and connect (over Wi. Fi) Ø adb tcpip 5555 Ø adb connect [Phone’s IP Addr] (USB must be connected) (USB must be disconnected) To get your phone’s IP address: adb shell ifconfig
ADB Commands • Now, you can communicate with the phone. Ø adb shell screencap /sdcard/s. png Ø adb pull /sdcard/s. png <local> or
Useful ADB Commands • Global Options: Ø adb –d <command> Ø adb –e <command> Ø adb –s <serial number> <command> 071 b 799 a 344 bdc 6 b 071 b 799 a 344 bdxyz
Useful ADB Commands • General adb Commands: Ø devices -l Ø help Ø version • Network/File/Install adb Commands: Ø connect ip[: port] Ø disconnect ip[: port] Ø pull [-a] remote local Ø push local remote Ø install package Ø uninstall package
Useful ADB Commands • backup/debug/scripting adb Commands: Ø backup [-f file] [-apk][-obb][-shared][-all][-system] Ø restore file Ø logcat [option] Ø Ø root unroot usb tcpip port_555 X Ø start-server Ø kill-server Ø reconnect
Issuing shell Commands • Generic format (two ways): Ø adb shell <command> Ø adb shell (execute on device shell) (get a device shell) • Activity Manager (am commands) Ø Ø Ø am am am start [option] intent startservice [option] intent broadcast [option] intent force-stop package kill [option] package kill-all
Issuing shell Commands • Package Manager (pm commands) Ø Ø Ø Ø Ø list packages [options] filter list permissions [options] filter list features list libraries list users install [options] path uninstall [options] package grant package permission revoke package permission • Screen capture Ø screencap filename Ø screenrecord [option] filename
Issuing shell Commands • Many more Unix commands! Ø Ø echo text date time reboot Ø Ø Ø ls cd directory chmod df mkdir rm file rmdir Ø ps Ø top ifconfig iftop netstat ping host
Shell commands from Android APPs • Use ‘Runtime’ and ‘Process’ classes to issue shell commands from an Android app: try { Process p = Runtime. get. Runtime(). exec("ps"); Input. Stream. Reader isr = new Input. Stream. Reader(p. get. Input. Stream()); Buffered. Reader br = new Buffered. Reader(isr); String str =""; while((str = br. read. Line()) != null){ Log. v("Tag", str); } } catch (IOException e) { e. print. Stack. Trace(); }
References • https: //developer. android. com/studio/command-line/adb. html
- Slides: 16