29
Android internals Egor Elizarov SPbSU 2012

Android Internals 10 v1 0

Embed Size (px)

Citation preview

Page 1: Android Internals 10 v1 0

Android internalsEgor ElizarovSPbSU 2012

Page 2: Android Internals 10 v1 0

Egor Elizarov SPbSU 20122

Lecture 10

Debugging / profiling

WiFi / Bluetooth / RIL

http://vk.com/android_internals

Page 3: Android Internals 10 v1 0

Egor Elizarov SPbSU 20123

Previous time

Suspend/Resume process

Android PM main components

Android Input subsystem

*.kl, *.kcm, *.idc configuration files

Sensor subsystem

Input noise reduction approaches

Android data storage

Page 4: Android Internals 10 v1 0

Egor Elizarov SPbSU 20124

Useful host/target configuration

Page 5: Android Internals 10 v1 0

Egor Elizarov SPbSU 20125

Debugging/profiling agenda

Very good presentation about debugging & profiling by Tim Bird

Most popular approaches

Tools covered by Tim in brief

Few words about not covered approaches

Page 6: Android Internals 10 v1 0

Egor Elizarov SPbSU 20126

Debugging approaches

Page 7: Android Internals 10 v1 0

Egor Elizarov SPbSU 20127

Logging

logcat – obtaining android log– For both C/C++ (LOGE) & Java (Log.e) code

– Have rich formatting options

dmesg – obtatining kernel log– printk()

– Extra logs from userspace through /dev/kmsg

Stdio redirection– For both Java (log.redirect-stdio) & Native (xargs) code

Page 8: Android Internals 10 v1 0

Egor Elizarov SPbSU 20128

GNU debugger (gdb)

DDD can be used as graphic backend

On target $ gdbserver :1234 --attach pid Or $gdbserver :1234 /system/bin/app

λ On host $ adb forward tcp:1234 tcp:1234 && gdbclient app :1234 app Or $ arm-eabi-gdb # file ./out/target/product/generic/symbols/system/bin/app_process # set solib-search-path

./out/target/product/generic/symbols/system/lib # target remote target_ip:1234

Page 9: Android Internals 10 v1 0

Egor Elizarov SPbSU 20129

Google debuggers

Fastboot– Protocol & tool to communicate with host over USB

– Install images, erase partitions, booting from host

– Supported in UBoot

ADB

– Remote shell, install, file copy, etc.

– Work over Network/USB

Page 10: Android Internals 10 v1 0

Egor Elizarov SPbSU 201210

Tracing & dumping

Strace– Shows system calls for a process (or set of processes)

Dalvik Debug Monitor Servic (DDMS)– Integrated into Eclipse

– Provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat and much more

Dumpsys / Dumpstate– Dumps huge amounts of information about the system, including

status, counts and statistics

– Dumpsys show status information from Android service

Page 11: Android Internals 10 v1 0

Egor Elizarov SPbSU 201211

Virtual Network Computing

VNC - Graphical desktop sharing system

Transmits input events from host to target

Transmits screen updates from target to host

On target– androidvncserver &

On host– vncviewer target_ip:5901

Page 12: Android Internals 10 v1 0

Egor Elizarov SPbSU 201212

Profiling approaches

Page 13: Android Internals 10 v1 0

Egor Elizarov SPbSU 201213

CPU and memory statistics

Common profiling workflow

Smem– Analyze of system-wide memory usage

OProfile– CPU usage statistic for both kernel & userspace

– Monitors execution point periodically

– Should be enabled in kernel

Page 14: Android Internals 10 v1 0

Egor Elizarov SPbSU 201214

Tracing

Bootchart– Analyze system booting process

– init should be recompiled to add Bootchart support

TraceView– Java methods tracing

– Can be used with DDMS

Page 15: Android Internals 10 v1 0

Egor Elizarov SPbSU 201215

Benchmarks

Rowboat bench– Set of benchmarks for CPU, 2D, 3D, etc.

– Developed by Rowboat team

0xbench– Another set of benchmarks

– Developed by 0xlab team

Lots of benchmarks in Google Play

Page 16: Android Internals 10 v1 0

Egor Elizarov SPbSU 201216

Linux Trace Toolkit next generation

Work for both kernel and userspace

Useful to debug threads and processes

Allow to trace only some events

Allow userspace events (/mnt/debugfs/ltt/write_event)

Kernel patches + ltt-control + ltt-viewer

Page 17: Android Internals 10 v1 0

Egor Elizarov SPbSU 201217

Add LTTng support to Android

Page 18: Android Internals 10 v1 0

Egor Elizarov SPbSU 201218

Different tricks

Activity Manager - control applications– am start -a android.intent.action.MAIN -n

com.android.camera/com.android.camera.Camera &

input keyevent X – send keyboard events

sendevent – send touch events

setprop/getprop - control system properties

sqlite - access database

start/stop - restart whole system

Page 19: Android Internals 10 v1 0

Egor Elizarov SPbSU 201219

WiFi in Android

Supports IEEE 802.11 abgn

Supports both IPv4 and IPv6

Based on customized wpa_supplicant

Wifi drivers compiled as modules (Wifi HAL can changed to support built-in drivers)

Page 20: Android Internals 10 v1 0

Egor Elizarov SPbSU 201220

Wifi subsystem

Page 21: Android Internals 10 v1 0

Egor Elizarov SPbSU 201221

Porting Wifi driver

Page 22: Android Internals 10 v1 0

Egor Elizarov SPbSU 201222

Bluetooth in Android

Bluetooth is covered by IEEE 802.15.1

Android BT is based on the BlueZ stack

Android provides subset of BlueZ functionality

Android supports point-to-point and multiple-point connections

Supports maximum 9 simultaneous cannections

Page 23: Android Internals 10 v1 0

Egor Elizarov SPbSU 201223

Bluetooth workflow

Page 24: Android Internals 10 v1 0

Egor Elizarov SPbSU 201224

Bluetooth subsystem

Page 25: Android Internals 10 v1 0

Egor Elizarov SPbSU 201225

RIL in Android

Most devices have separate Radio Frequency module for signal strength measurement etc.

Modem often have own CPU with running OS (Ex: Mentor Nucleus)

Usually have firmware

Often kernel interface to these devices is PPP

Page 26: Android Internals 10 v1 0

Egor Elizarov SPbSU 201226

RIL subsystem

Page 27: Android Internals 10 v1 0

Egor Elizarov SPbSU 201227

Next Time

Exam

Page 28: Android Internals 10 v1 0

Egor Elizarov SPbSU 201228

Useful links

http://vk.com/android_internals

http://elinux.org/images/c/c9/Android-tips-and-tricks-2010-10.pdf

http://developer.android.com/guide/developing/debugging/index.html

http://source.android.com/tech/debugging/native-memory.html

http://developer.android.com/guide/developing/debugging/ddms.html

Page 29: Android Internals 10 v1 0

Egor Elizarov SPbSU 201229

Useful links (2)

http://code.google.com/p/android-vnc-server/wiki/README

http://softteco.blogspot.com/2011/03/android-low-level-shell-click-on-screen.html

http://lttng.org/

http://softteco.blogspot.com/2011/03/android-low-level-shell-click-on-screen.html

http://www.kandroid.org/online-pdk/guide/telephony.html