AndroidSystemDebug官方指導
Google是AOSP項目的主導者,關於Android開發有兩大官網,在“資料收集”篇有提到就是Android Open Source Project與Android Developers官網。在這兩大網站上有關於aosp項目和app開發的一切官方資料。Google公司的工作是值得認可的,所以我們的任務第一步要整理學習前人的工作,避免重復造輪子。
本篇將過濾AOSP與developer官網提到的開發調試工具及方法。本文只給出地址及簡介。
AOSP、Developer兩大官網內容詳實,建議Android系統開發者和app開發者通讀,對了解Adroid OS全貌有幫助。
AuthBlog:秋城https://www.cnblogs.com/houser0323
Contents
1. AOSP
本章列出的內容主要關注Android系統/平台。
Git###
Android選擇使用Git來做工程代碼版本控制
Repo###
簡單來說,repo用來管理繁多的Git倉庫。
In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands.
However, using Repo for basic across-network operations makes your work much simpler. For more details on Repo, see
the Repo Command Reference, Repo README, and the Preupload Hooks (tests) that can be enabled in Repo.
Other-tools###
codereview。
Gerrit is a web-based code review system for projects that use Git. Gerrit encourages a more centralized use of Git by
allowing all authorized users to submit changes, which are automatically merged if they pass code review. In addition,
Gerrit makes reviewing easy, displaying changes side by side in the browser and enabling inline comments.
提示:關於在線閱讀代碼強烈推薦兩個網站:https://cs.android.com/ 與 https://android.googlesource.com/
Android Code Search allows you to search through AOSP without downloading anything. You can use Code Search to
view the AOSP source code, switch between open source branches, and navigate cross-references. For more
information, see the Google Developers site for the Code Search documentation.
時代變了,Android應用開發建議使用AS這個IDE。
Android Studio is the official integrated development environment (IDE) for Android app development.
What is Soong?###
Android系統源碼如此龐大,是如何組織編譯的呢?Android7.0之前只用GNU Make。7.0開始引入了Soong編譯系統。
The Soong build system was introduced in Android 7.0 (Nougat) to replace Make. It leverages the Kati GNU Make
clone tool and Ninja build system component to speed up builds of Android.
See the Android Make Build System description in the Android Open Source Project (AOSP) for general instructions
and Build System Changes for Android.mk Writers to learn about modifications needed to adapt from Make to Soong.
See the build-related entries in the glossary for definitions of key terms and the Soong reference files for complete details.
Set up environment###
提示:這個腳本有大用,特別是查找源碼文件
$ source build/envsetup.sh
Flashing Devices###
編譯好的img如何刷到設備?答:用fastboot與adb。一般用SDK工具包里的,自己用源碼編譯也可Building fastboot and adb
Android Flash Tool###
這個只支持Google的手機平台,例如Pixel,感興趣可以看看。
Using Reference Boards###
Google推薦的開發板,可作了解。
Generic System Images###
這個就是在GMS認證中常提到的GSI,翻譯為“通用系統鏡像”,是純Android實現硬件無關。
GSIs are used for running VTS and CTS-on-GSI tests. The system image of an Android device is replaced with a GSI then
tested with the Vendor Test Suite (VTS) and the Compatibility Test Suite (CTS) to ensure that the device implements
vendor interfaces correctly with the latest version of Android.
https://source.android.google.cn/setup/create/cuttlefish#cuttlefish_and_android_emulator
關於虛擬設備,可作了解。
Compiling with Jack for Android 6.08.1
Jack 工具鏈已被棄用。Jack 是 Android 6.0-8.1 的默認 Android 編譯工具鏈。有關以上版本的Android編譯調試可參考。
Android Continuous Integration
AOSP項目的ci,持續集成。我們目前沒有投入參與到AOSP的開發工作,感興趣可關注。
AOSP Java Code Style for Contributors###
Google官方的AOSP代碼規范/建議。核心思想是保持上下文風格的一致性。
Android Community and Contacts###
關於AOSP項目的社區、論壇、博客等等地址匯總。我們部門目前沒有投入參與到AOSP的開發工作,感興趣可關注。
Android Live-Lock Daemon###
Android10上更新的守護進程,旨在捕獲和減少內核死鎖問題。
Android 10 includes the Android Live-Lock Daemon (llkd), which is designed to catch and mitigate kernel deadlocks. For details on using llkd, refer to the README.md.
Interface Hashing###
HIDL相關,cts-on-gsi遇到過因修改.hal文件但未添加其哈希值到current.txt導致的失敗項。涉及到這個工具Hashing with hidl-gen
Using c2hal###
c2hal用於HAL層開發的工具。
VNDK ABI checker ###
vnedor NDK開發相關,這是芯片廠商的工作內容,可作了解。
VNDK Definition Tool###
vnedor NDK開發相關,這是芯片廠商的工作內容,可作了解。
Additional Resources###
關於Vendor Interface Object開發,這是芯片廠商的工作內容,可作了解。
assemble_vintf;GTest
tinyxml2 (external/tinyxml2) for serializing/deserializing the object to/from XML. BSD-like license.
libselinux (external/selinux/libselinux) for getting policydb version. Public domain license.
libz (external/zlib) for decompressing /proc/config.gz. BSD-like license.
libvintf project uses Apache 2.0 license (with appropriate MODULE_LICENSE_APACHE2 and NOTICE files).
Fastboot in User Space###
fastboot是一個刷寫分區鏡像img的工具。
Android 10 adds support for resizable partitions by relocating the fastboot implementation from bootloader to user
space. This relocation enables moving the flashing code into a maintainable and testable common location with only the
vendor-specific parts of fastboot implemented by a Hardware Abstraction Layer (HAL).
Android Compatibility Definition Document###
傳說中的CDD。只有完全通過GMS認證測試的設備才可稱之為真正的Android兼容設備。沒過的可以理解為衍mo生gai設備。
Color Management###
顯示相關
Android Platform Testing###
測試是軟件工程的重要部分,關於Android平台系統的測試有如下闡述。
instrumentation tests
native tests using the gtest framework.
Android Compatibility Test Suite
Vendor Test Suite
Trade Federation
提示:最后這個頁面是一個cmd-debug工具的總結 Debugging
Reading Bug Reports:如何閱讀bugreport
Diagnosing Native Crashes:如何分析Native層(c/c++)的Crash
以下是性能相關的工具和論述。
Use Simpleperf to evaluate the performance of a device. Simpleperf is a native profiling tool for both applications and
native processes on Android. Use CPU Profiler to inspect app CPU usage and thread activity in real time.
Understanding Systrace
systrace 是分析 Android 設備性能的主要工具.
systrace is the primary tool for analyzing Android device performance. However, it's really a wrapper around other tools. It's the host-side wrapper around atrace, the device-side executable that controls userspace tracing and sets up ftrace, and the primary tracing mechanism in the Linux kernel. systrace uses atrace to enable tracing, then reads the ftrace buffer and wraps it all in a self-contained HTML viewer. (While newer kernels have support for Linux Enhanced Berkeley Packet Filter (eBPF), the following documentation pertains to the 3.18 kernel (no eFPF) as that's what was used on the Pixel/Pixel XL.)
systrace is owned by the Google Android and Google Chrome teams and is open source as part of the Catapult project. In addition to systrace, Catapult includes other useful utilities. For example, ftrace has more features than can be directly enabled by systrace or atrace and contains some advanced functionality that is critical to debugging performance problems. (These features require root access and often a new kernel.)
Using ftrace
ftrace 是一種調試工具,用於了解 Linux 內核中的情況。
ftrace is a debugging tool for understanding what is going on inside the Linux kernel. The following sections detail basic ftrace functionality, ftrace usage with atrace (which captures kernel events), and dynamic ftrace.
Identifying Capacity-Related Jank
關於設備負載能力的卡頓。
Capacity is the total amount of some resource (CPU, GPU, etc.) a device possesses over some amount of time. This page describes how to identify and address capacity-related jank issues.
Identifying Jitter-Related Jank
關於抖動的卡頓。
Jitter is the random system behavior that prevents perceptible work from running. This page describes how to identify and address jitter-related jank issues.
Implementing Test Harness Mode
Android 10中添加的一項功能,適用於希望使一個設備或一組設備自動化的第三方應用程序開發人員。該功能提供了一種擦除 Android設備上所有用戶數據,保留ADB密鑰以及跳過所有首次設置屏幕的方法。這使用戶可以在啟動后立即運行UI測試,而無需任何手動交互。
這個測試框架有點意思,可以進一步研究下。
Test Harness Mode is a feature added in Android 10 for third-party app developers that wish to automate a device or a fleet of devices. The feature provides a method to wipe all user data on an Android device, retain ADB keys, and skip all first-time setup screens. This enables the user to run a UI test immediately after startup without any manual interaction.
Using GDB
用GDB調試Android。
The GNU Project debugger (GDB) is a commonly used UNIX debugger. This page details using gdb to debug Android apps and processes for platform developers. For third-party app development, see Debug your app.
Dumping User and Kernel Stacks on Kernel Events
關於內核調試的論述,發生內核事件時轉儲用戶和內核堆棧。Installing adeb
For more information on trace, see the BCC trace tool documentation. For more information about running BCC on Android devices, see the adeb project's BCC howto.
用於內存調試的7個工具。
Address Sanitizer
Heapprofd
Malloc debug
libmemunreachable
Malloc hooks
Malloc statistics
Dalvik Debug Monitor Server
Network Connectivity Tests
一個網絡連接自測的工具,藍牙WiFi移動網絡。
Android Connectivity Testing Suite (ACTS) tests fill the testing gap between Android’s framework APIs and chipset certifications. These tests validate the functionality of various aspects of the Bluetooth, Wi-Fi, and cellular radios as used by the Android framework.
Rescue Party
一種設備的保護模式,崩潰的信息會存放到 /data/system/uiderrors.txt
永久性的 PackageManager 日志中。
storaged
Android O 添加的storaged守護進程,在Android上收集和發布存儲指標。
Android O adds support for storaged, an Android native daemon that collects and publishes storage metrics on Android devices.
Diskstat (including stalled diskstats) and eMMC information is logged to the Android event log, where a platform checkin service collects the logs.
storaged operations occur automatically and are handled entirely by the Android framework, so you don't need to do any implementation work. This page describes the design of storaged (including new interfaces) and how to use it to get I/O status from the kernel.
Using Strace
查看linux系統調用(system call)的工具。
Strace enables you to see the system calls a process makes and what those system calls return.
Security Enhancements###
關於安全在每個版本都有許多增強安全的工具,此處不一一列舉。
Application Signing###
安全相關,應用簽名的論述。
Validating SELinux###
關於SELinux的開發驗證有以下倆工具,結合dmsg和logcat日志進行分析。
sepolicy-analyze
Using audit2allow
verifiedboot###
關於verifiedboot的功能,實現和驗證。
Generating the hash tree
Security Testing###
關於安全性的測試工具和論述。此處只列舉名稱:AddressSanitizer, HWAddressSanitizer,LLVM Sanitizers,BoundsSanitizer,Scudo,Tagged Pointers,Building a Pixel kernel with KASAN+KCOV,Fuzzing with libFuzzer,Control Flow Integrity,Kernel Control Flow Integrity,Integer Overflow Sanitization,Execute-only Memory (XOM) for AArch64 Binaries,ShadowCallStack。
Measuring Audio Latency###
音頻延遲的測試工具及論述。
The Dr. Rick O'Rang loopback app is an Android app for audio feedback testing. You can download the app from Google Play or get the source code from GitHub.
Dr. Rick O'Rang audio loopback dongleThe Dr. Rick O'Rang audio loopback dongle is handy for measuring round-trip latency over the headset connector.
Audio Debugging###
Bluetooth Verifying and Debugging###
關於藍牙調試的論述。
WLAN###
Testing, Debugging, and Tuning Wi-Fi###
關於WiFi調試的論述。
Running ACTS Telephony Tests###
上面提到過的連接性測試ACTS。
The Android Comms Test Suite (ACTS) performs automated testing of connectivity stacks, such as Wi-Fi, Bluetooth, and cellular services. The testing tool requires adb. and Python, and it can be found in tools/test/connectivity/acts.
This page describes how to run the basic telephony tests available in Android Open Source Project (AOSP) for a user with two phones.
Tracking BufferQueue with Systrace###
用Systrace調試BufferQueue
To understand how graphics buffers move around, use Systrace, a tool that records device activity over a short period of time. The system-level graphics code is well instrumented, as is much of the relevant app framework code.
Tracing Window Transitions###
WinScope是一種記錄分析WindowManager和SurfaceFlinger狀態的工具。
WinScope provides the infrastructure and tools to record and analyze WindowManager and SurfaceFlinger states during and after window transitions. WinScope records all pertinent system service states to a trace file, which you can use to replay and step through the transitions.
Getevent###
提示:inuput流程調試中非常重要的工具,用於動態顯示內核輸入事件。
The getevent tool runs on the device and provides information about input devices and a live dump of kernel input events.
This tool is useful for ensuring device drivers are reporting the expected set of capabilities for each input device and are generating the desired stream of input events.
Validate Keymaps Tool###
按鍵映射開發工作的驗證工具。
The Android framework has a small tool called
validatekeymaps
to validate the syntax of input device configuration files, key layout files, key character maps files and virtual key definition files.
Data Saver mode###
流量監控程序。
APK Caching###
A/B分區方案相關。
Optimizing Boot Times###
提示:優化系統啟動時間的相關論述,很有價值.從內核到BootLoader到init.rc到開機動畫等等。
This document provides partner guidance for improving boot times for specific Android devices. Boot time is an important component of system performance as users must wait for boot to complete before they can use the device. For devices such as cars where cold boot-up happens more frequently, having a quick boot time is critical (no one likes waiting for dozens of seconds just to input a navigation destination).
Android 8.0 allows for reduced boot times by supporting several improvements across a range of components. The following table summarizes these performance improvements (as measured on a Google Pixel and Pixel XL devices).
Bootchart provides CPU and I/O load breakdown of all processes for the whole system. It doesn't require rebuilding system image and can be used as a quick sanity check before diving into systrace.
Systrace allows collecting both kernel and Android traces during boot up. Visualization of systrace can help in analyzing specific problem during the boot-up. (However, to check the average number or accumulated number during the entire boot, it is easier to look into kernel trace directly).
Generating whitelists###
特權白名單檢查生成工具。
Controlling system suspend###
關於電能消耗調試。
Android Runtime (ART) and Dalvik###
關於AndroidRuntime思想架構以及開發調試的內容。
OTA Package Tools###
build/make/tools/releasetools
這個工程路徑下有許多腳本工具,OTA編譯相關。
2. Developer
本章列出的內容主要關注Android 應用(App)。
Generic System Image###
通用系統鏡像。
Dynamic System Update (DSU)###
動態系統更新,Android 10上的實驗功能。
Android App Bundle###
國際市場需要關注這個,新的apk機制,關於Google Play Store中安裝的第三方應用。
Command line tools only###
Android Studio中的基礎工具命令行版本,都在這個套件里。
If you do not need Android Studio, you can download the basic Android command line tools below. You can use the included sdkmanager to download other SDK packages.
These tools are included in Android Studio.
Measure app performance with Android Profiler###
Android Studio 3.0 及更高版本中的 Android Profiler 取代 Android Monitor 工具,提供實時數據,用於獲取 CPU、內存、網絡和電池資源使用情況。
Android5.0及以上的系統才能用。
The Android Profiler in Android Studio 3.0 and higher replaces the Android Monitor tools. The Android Profiler tools provide real-time data to help you to understand how your app uses CPU, memory, network, and battery resources.
For details about each of the profilers, see the following:
The Android Profiler is compatible with Android 5.0 (API level 21) and higher.
Command line tools###
提示:列舉Android SDK中重要的命令行工具。
此處先羅列一下:aapt2,adb,apkanalyzer,apksinger,bmgr,bundletool,d8,dmtracedump,dumpsys,ect1tool,jobb,jetifier-standalone,logcat,mksdcard,sdkmanager,systrace,perfetto,zipalign,Environment variables。
Android SDK Tools
- apkanalyzer
Provides insight into the composition of your APK after the build process completes.- avdmanager
Allows you to create and manage Android Virtual Devices (AVDs) from the command line.- jobb
Allows you to build encrypted and unencrypted APK expansion files in Opaque Binary Blob (OBB) format.- lint
A code scanning tool that can help you to identify and correct problems with the structural quality of your code.- monkeyrunner
Provides the command line interface for running program that can install an Android app or test package, run it, send keystrokes to it, takes screenshots, and more.- sdkmanager
Allows you to view, install, update, and uninstall packages for the Android SDK.
This package includes other tools that you don't need to invoke from the command line (such as ProGuard for code shrinking and obfuscation).
- aapt2
Parses, indexes, and compiles Android resources into a binary format that is optimized for the Android platform, and packages the compiled resources into a single output.- apksigner
Signs APKs and checks whether APK signatures will be verified successfully on all platform versions that a given APK supports.- zipalign
Optimizes APK files by ensuring that all uncompressed data starts with a particular alignment relative to the start of the file.
In addition to downloading from the SDK Manager, you can download the SDK Platform Tools here.
- adb
Android Debug Bridge (adb) is a versatile tool that lets you manage the state of an emulator instance or Android-powered device. You can also use it to install an APK on a device.- etc1tool
A command line utility that lets you encode PNG images to the ETC1 compression standard and decode ETC1 compressed images back to PNG.- fastboot
Flashes a device with platform and other system images. For flashing instructions, see Factory Images for Nexus and Pixel Devices.- logcat
This is a tool invoked via adb to view app and system logs.
Android Vitals###
這個是Google的一項應用性能優化工具,Google Play相關。可作了解。
Diagnose and fix bad behaviors
Core vitals:
ANR rates
Crash rates
Excessive wakeups
Stuck partial wake locks
All other vitals:
Excessive background Wi-Fi scans
Excessive background network usage
App startup time
Slow rendering
Frozen frames
Permission denials
System tracing guides###
提示:第三次提到system trace系統跟蹤,其在Android性能調試中的重要性不言而喻。我們通過system trace工具產生的report來分析應用的性能。
To learn more about system tracing tools, see the following guides:
- Inspect CPU activity with CPU Profiler
Shows how to profile your app’s CPU usage and thread activity in Android Studio.- System Tracing system app
Explains how to capture a system trace directly on any device running Android 9 (API level 28) or higher.- Systrace command-line reference
Defines the different options and flags that you can pass into the command-line interface for Systrace.- Running Perfetto using ADB
Describes how to run the perfetto command-line tool to capture traces.- Running Perfetto
External documentation that describes how to build and run the perfetto command-line tool to capture traces.- Perfetto UI
The Perfetto Web-based trace viewer opens Perfetto traces and displays a complete report. You can also open Systrace traces in this viewer using the legacy UI option.- Navigate a Systrace report
Lists the elements of a typical report, presents keyboard shortcuts for navigating through the report, and describes how to identify types of performance problems.- Define custom events
Describes how you can apply custom labels to specific sections of your code, allowing for easier root-cause analysis in Systrace or Perfetto.
Inspect GPU rendering speed and overdraw###
利用Setting--->>Developer options(開發者選項)中的功能檢查GPU渲染和繪制。
Android includes some on-device developer options that help you visualize where your app might be running into issues rendering its UI, such as performing more rendering work than necessary, or executing long thread and GPU operations. This page describes how to debug GPU overdraw and profile GPU rendering.