ADB (Android Debug Bridge): How it works?



Similar documents
As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.

VM Application Debugging via JTAG: Android TRACE32 JTAG Debug Bridge ADB Architecture Stop-Mode implications for ADB JTAG Transport Outlook

Qualcomm IR-I 2 C Bridge Demo

Android Systems Programming Tips and Tricks

Installing IBM Websphere Application Server 7 and 8 on OS4 Enterprise Linux

TIBCO ActiveMatrix BusinessWorks Plug-in for TIBCO Managed File Transfer Software Installation

Chipsee Embedded Industrial Computer Android User Manual V1.0.1

Running a Program on an AVD

CDH installation & Application Test Report

What else can you do with Android? Inside Android. Chris Simmonds. Embedded Linux Conference Europe Copyright 2010, 2net Limited.

How to simulate network devices using the Verax SNMP Simulator (Linux/Windows)

Command Line Interface User Guide for Intel Server Management Software

Android Programming and Security

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Lab 4 In class Hands-on Android Debugging Tutorial

Yocto Project Eclipse plug-in and Developer Tools Hands-on Lab

AlienVault Unified Security Management (USM) 4.x-5.x. Deploying HIDS Agents to Linux Hosts

How to Install Applications (APK Files) on Your Android Phone

UPS MONITORING SOFTWARE USER MANUAL

EXPLORING LINUX KERNEL: THE EASY WAY!

NetSpective Logon Agent Guide for NetAuditor

How To Install Storegrid Server On Linux On A Microsoft Ubuntu 7.5 (Amd64) Or Ubuntu (Amd86) (Amd77) (Orchestra) (For Ubuntu) (Permanent) (Powerpoint

file://d:\webs\touch-base.com\htdocs\documentation\androidplatformnotes52.htm

Setting Up the Site Licenses

INSTALLING KAAZING WEBSOCKET GATEWAY - HTML5 EDITION ON AN AMAZON EC2 CLOUD SERVER

Using Symantec NetBackup with Symantec Security Information Manager 4.5

How To Develop Android On Your Computer Or Tablet Or Phone

Dragonframe License Manager User Guide Version 1.2.2

Intrusion Detection and Prevention: Network and IDS Configuration and Monitoring using Snort

HONEYD (OPEN SOURCE HONEYPOT SOFTWARE)

Linux Networking: IP Packet Filter Firewalling

Android Framework. How to use and extend it

Pentesting Android Mobile Application

MuL SDN Controller HOWTO for pre-packaged VM

Android Environment Emulator

Linux Firewalls (Ubuntu IPTables) II

Network Licensing. White Paper 0-15Apr014ks(WP02_Network) Network Licensing with the CRYPTO-BOX. White Paper

Virtual Systems with qemu

INASP: Effective Network Management Workshops

Verax Service Desk Installation Guide for UNIX and Windows

Pen Test Tips 2. Shell vs. Terminal

Comodo MyDLP Software Version 2.0. Installation Guide Guide Version Comodo Security Solutions 1255 Broad Street Clifton, NJ 07013

SIOS Protection Suite for Linux v Postfix Recovery Kit Administration Guide

Getting started with ARM-Linux

Android: How To. Thanks. Aman Nijhawan

1 Introduction FrontBase is a high performance, scalable, SQL 92 compliant relational database server created in the for universal deployment.

Make a folder named Lab3. We will be using Unix redirection commands to create several output files in that folder.

Procedure to Create and Duplicate Master LiveUSB Stick

LOCKSS on LINUX. Installation Manual and the OpenBSD Transition 02/17/2011

2015 Exelis Visual Information Solutions, Inc., a subsidiary of Harris Corporation

Setting Up Specify to use a Shared Workstation as a Database Server

Decision Support System to MODEM communications

Silk Test Testing Mobile Applications

SNMP Peach Pit Data Sheet

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

A DirectX 9 capable graphics card is recommended. A DirectX 10 capable graphics card from ATI or nvidia is required for Volume Rendering.

Silk Test Testing Mobile Web Applications

UPSMON PRO Linux --- User Manual

Defeating Firewalls : Sneaking Into Office Computers From Home

End-User troubleshooting guide For Sentinel SuperPro/UltraPro and Sentinel Hardware Keys

Desktop : Ubuntu Desktop, Ubuntu Desktop Server : RedHat EL 5, RedHat EL 6, Ubuntu Server, Ubuntu Server, CentOS 5, CentOS 6

ONLINE BACKUP MANAGER TROUBLESHOOTING MISSING BACKUP JOBS

Apache Server Implementation Guide

µtasker Document FTP Client

Adjusting Prevention Policy Options Based on Prevention Events. Version 1.0 July 2006

Moxa Device Manager 2.0 User s Guide

Wavelink Avalanche Mobility Center Linux Reference Guide

Android Hands-On Labs

PetaLinux SDK User Guide. Application Development Guide

Developing for MSI Android Devices

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Mercury User Guide v1.1

ipta iptables Log Analyzer Anders Sikvall ichimusai.org

2. Boot using the Debian Net Install cd and when prompted to continue type "linux26", this will load the 2.6 kernel

Smart Cloud Integration Pack. For System Center Operation Manager. v User's Guide

How To Install The Safenet-Inc.Com Software On A Pc Or Mac Or Macintosh (For A Powerpoint) With A Powerline (For Windows) Or Ipad (For Mac) With The Safetime (For Pc

How To Install Netbackup Access Control (Netbackup) On A Netbackups (Net Backup) On Unix And Non Ha (Net Backup) (Net Backups) (Unix) (Non Ha) (Windows) (

Local Caching Servers (LCS): User Manual

Andreas Burghart 6 October 2014 v1.0

Cisco Setting Up PIX Syslog

Cisco ISE Command-Line Interface

Remote Support Proxy Installation and User's Guide

Oracle EXAM - 1Z Oracle Weblogic Server 11g: System Administration I. Buy Full Product.

Symantec ApplicationHA 6.1 Generic Agent Configuration Guide - AIX on IBM PowerVM

CommandCenter Secure Gateway

HOST LINKS GSFTP G&R. Gateway between FTP and SFTP.

NetPoint Configuration Guide. for thin clients

Instructions for Adding a MacOS 10.4.x Server to ASURITE for File Sharing. Installation Section

readme_asm.txt README.TXT

Mobile Labs Plugin for IBM Urban Code Deploy

OnCommand Performance Manager 1.1

INSTALL ZENTYAL SERVER

CLC Server Command Line Tools USER MANUAL

The embedded Linux quick start guide lab notes

Installing Platform Product Suite for SAS (Windows)

Security Correlation Server Quick Installation Guide

Trend Micro Worry- Free Business Security st time setup Tips & Tricks

Transcription:

ADB (Android Debug Bridge): How it works? 2012.2.6 early draft Tetsuyuki Kobayashi 1

Let's talk about inside of Android. http://www.kmckk.co.jp/eng/kzma9/ http://www.kmckk.co.jp/eng/jet_index.html 2

Who am I? 20+ years involved in embedded systems 10 years in real time OS, such as itron 10 years in embedded Java Virtual Machine Now GCC, Linux, QEMU, Android, Blogs http://d.hatena.ne.jp/embedded/ (Personal) http://blog.kmckk.com/ (Corporate) http://kobablog.wordpress.com/(english) Twitter @tetsu_koba 3

What is ADB? If you are an Android builder, you have used adb logcat, adb shell Even if you only use DDMS in Eclipse, adb is working under the hood. Using adb, you can connect emulator or actual target device. adb kill-server? what does it mean? 4

How to connect? Host Target device Emulator Adb clients adb shell Adbd How to connect? QEMU Adbd 5

ADB overview Host Target device Emulator Adb clients Execute services on new thread/subprocess Adbd TCP port:5037 QEMU TCP Adb server USB/TCP Adbd 6

2 roles of ADB Providing Transport communication path between host and target device USB or TCP: but clients don't have to aware Providing Services executing something on the target devices through the transport. adb shell for executing command adb push/pull for file transfer 7

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 8

When does adb server start? Explicitly, adb start-server It starts adb server as back ground process. Usually it does automatically on demand. You don't have to do adb start-server. When you want to restart adb server, do adb kill-server Actually, adb clients and adb server shares same executable adb start-server equals adb fork-server server & 9

ADB internal Source code How to get ADB logs Sequence chart Simple ruby script to connect adb server Command details Secure mode Add USB Vendor ID Switching transport mode 10

Source code system/core/adb in Android source tree From this directory adb and adbd are built Don't confuse. common files between adb and adbd adb.c, fdevent.c, transort.c, transport_local.c, tansport_usb.c, service.c, sockets.c, util.c #if ADB_HOST /* code for adb*/ #else /* code for adbd */ #endif 11

files only for adbd files only for adb backup_service.c, file_sync_service.c, jdwp_service.c, framebuffer_service.c, remount_services.c, usb_linux_clients.c, log_service.c console.c, adb_clients.c, file_sync_client.c, usb_vendors.c, get_my_path_{linux,darwin,windows,freebsd}.c, usb_{linux,macos,libusb,windows}.c 12

How to get ADB logs For adb clients and adb server, set environment variable ADB_TRACE For adbd, set system property persist.adb.trace_mask http://blog.kmckk.com/archives/4080002.html 13

Sequence chart Adb client adb shell ls Adb server adbd host:version Check version OKAY0004001d host:transport-any Specify the destination OKAY Command to adbd shell:ls OKAY [OPEN]shell:ls [OPEN]shell:ls subprocess ls [WRITE]len=247 len=247 stdout len=247 14

Simple ruby script to connect to adb server require 'socket' def error_exit puts "Error" exit 1 end def send_to_adb(s, msg) s.printf("%04x%s", msg.length, msg) end def check_okay(s) (s.read(4) == "OKAY") end def check_version(s) (s.read(12) == "OKAY0004001d") end hostname = 'localhost' port = 5037 s = TCPSocket.open(hostname, port) send_to_adb(s, "host:version") error_exit if! check_version(s) s.close s = TCPSocket.open(hostname, port) send_to_adb(s, "host:transport-any") error_exit if! check_okay(s) send_to_adb(s, "shell:ls") error_exit if! check_okay(s) while line = s.gets puts line.chop end s.close change shell:ls as you like. http://blog.kmckk.com/archives/4092210.html 15

Command details adb logcat adb install/uninstall adb reboot screen capture from DDMS 16

Secure mode Android smart phone products have adbd. Usually it runs on secure mode. (secure = 1) if secure == 1, change adbd as SHELL user(= not privileged), else it keeps running as root user In secure mode, all services invoked by adbd ran as SHELL user. Some causes permission denied. 17

How secure mode decided Running on emulator secure = 0 System property ro.secure == 1 secure = 1 if ro.debuggable == 1, you can restart adb unsecure by adb root All Android phone products are shipped in ro.secure = 1, ro.debuggable = 0. See adb.c: adb_main 18

Add USB Vendor ID When connecting USB device, adb checks USB Vendor ID Many USB Vendor IDs are hard coded in adb. (But not enough) To add USB Vendor ID, make $HOME/.android/adb_usb.ini and write one ID in one line See usb_vendors.c 19

Switching transport mode Switching USB mode to TCP mode $ adb shell netcfg lo UP 127.0.0.1 255.0.0.0 0x00000049 eth0 UP 192.168.1.139 255.255.255.0 0x00001043 $ adb tcpip 5555 restarting in TCP mode port : 5555 $ adb devices List of devices attached $ disconnected from USB. Then restart adb server with specifying target IP address. $ adb kill-server $ ADBHOST=192.168.1.139 adb devices * daemon not running. starting it now on port 5037 * * daemon started successfully * List of devices attached emulator-5554 device $ 20

Switching transport mode (What happen inside?) See service.c restart_tcp_service property_set( service.adb.tcp.port, value); Note: before Android 4.0, this cause permission denied in secure mode and ignored silently! After that, exit(1); init restarts adbd. service.adb.tcp.port is checked in adb.c adb_main 21

Tips adb emu adb backup/restore Joke commands Modify emulator to allow any server socket 22

adb emu You can send a single command to emulator console easily send only. can not receive. For emulator console, http://developer.android.com/guide/developing/devices/emulator.html Simple example. adb emu window scale 0.5 after starting emulator http://blog.kmckk.com/archives/4091258.html 23

adb backup/restore New in Android 4.0 You can backup/restore installed applications with their saved status. 24

Joke commands adb hell same as adb shell except hell color :) Just try. adb lolcat same as adb logcat 25

Modify emulator to allow any server socket Other host Host Adb clients Emulator Adb clients TCP port:5037 Adbd TCP port:5037 Adb server QEMU TCP Adb server All server sockets in Android emulator accepts only from localhost. If you feel inconvenient in this restriction, apply the patch in next page. http://blog.kmckk.com/archives/3882865.html 26

Patch to allow any server socket (for experience) diff --git a/slirp-android/socket.c b/slirp-android/socket.c index 439590a..ed16d5a 100644 --- a/slirp-android/socket.c +++ b/slirp-android/socket.c @@ -650,7 +650,7 @@ solisten(u_int port, u_int32_t laddr, u_int lport, int flags) so->so_laddr_ip = laddr; /* Ditto */ so->so_haddr_port = port; - s = socket_loopback_server( port, SOCKET_STREAM ); + s = socket_inaddr_any_server( port, SOCKET_STREAM ); if (s < 0) return NULL; diff --git a/sockets.c b/sockets.c index 1063339..55b5d57 100644 --- a/sockets.c +++ b/sockets.c @@ -1337,6 +1337,11 @@ socket_in_client( SockAddress* to, SocketType type ) return socket_connect_client( s, to ); } +int +socket_inaddr_any_server( int port, SocketType type ) +{ + return socket_in_server( INADDR_ANY, port, type ); +} int socket_loopback_server( int port, SocketType type ) 27

Advanced Topics adb in Android device Port adbd to other than Android 28

adb in Android device Usually, adb is running on the host side, such as Linux, MacOS and Windows In Android 4.0 there is /system/bin/adb in Android file system What for is this? 29

Connect its own adbd by adb Restart adbd in TCP mode Then type adb devices It can connect its own adbd by local loop back Target device Adb clients But what is the use case? Adbd TCP Adb server TCP port:5038 http://blog.kmckk.com/archives/4092970.html 30

Connect other Android device by adb on Android NexusOne (Android 2.3.6) USB Host (A connector) USB device (micro B connector) KZM-A9-Dual board (Android 4.0.3) http://blog.kmckk.com/archives/4094716.html 31

At the serial console on KZM-A9-Dual board # adb devices * daemon not running. starting it now on port 5038 * * daemon started successfully * List of devices attached HT015P803242 device # It worked! You can do adb shell, adb logcat, too. Even you can install application from the board to NexusOne by adb install foo.apk. 32

Port adbd to other than Android Quick hack! Consider dependency for better porting 33

Quick hack! /sbin/adbd is statically linked executable. Just copy this file to ARM Ubuntu 11.10 just for experience (using Android patched kernel) Somehow, it worked without any recompilation sudo chmod 666 /dev/android_adb* make symbolic link /bin/sh to /system/bin/sh adbd runs in secure mode It worked adb shell, adb push/pull http://blog.kmckk.com/archives/4093193.html 34

Consider dependency for better porting Some service requires other android commands adb install/uninstall, adb bugreport framebuffer service invokes /system/bin/screencap Adbd uses Android property system At the binary experiment, all property_get returns default values. That's why adbd ran in secure mode. Switching adbd mode assumed that init restarts adbd process 35

Q & A Thank you for listening! Any comments to blogs are welcome. 36