Article directory
1. Learning objectives
1. Understand the Android platform architecture
2. Be familiar with the Android device file browser
3. Be able to use the Android debugging bridge
2. Learning new lessons
(1) Brief description of the platform architecture
-
Android is an open source software stack based on Linux. Its platform architecture is shown in the figure below.
-
The Android system adopts the idea of layered architecture, with clear architecture, distinct layers and collaborative work. The system architecture of Android not only understands the Android system from a macro perspective, but also points out the direction for our learning and practice. If you are engaged in Android application development, you should study the Android application framework layer and application layer; if you are engaged in Android system development, you should study the Android system library and Android runtime; if you are engaged in Android driver development, you should study the Android Linux kernel . In short, find the right entry point and practice to gain true knowledge.
1. Linux kernel
- The foundation of the Android platform is the Linux kernel. For example, the Android Runtime (ART) relies on the Linux kernel to perform low-level functions such as threads and low-level memory management.
- Using the Linux kernel allows Android to take advantage of key security features and allows device manufacturers to develop hardware drivers for the famous kernel.
2. Hardware abstraction layer
- The Hardware Abstraction Layer (HAL) provides a standard interface that exposes device hardware capabilities to higher-level Java API frameworks. The HAL consists of several library modules, each of which implements an interface for a specific type of hardware component, such as a camera or Bluetooth module. When a framework API requires access to device hardware, the Android system loads a library module for that hardware component.
3. Android runtime
- For devices running Android 5.0 (API level 21) or higher, each app runs in its own process and has its own instance of the Android Runtime (ART). ART is written to run multiple virtual machines on low-memory devices by executing DEX files, a bytecode format designed specifically for Android and optimized to use very little memory. Compilation toolchains (such as Jack) compile Java source code into DEX bytecode, making it runnable on the Android platform.
- Prior to Android version 5.0 (API level 21), Dalvik was the Android Runtime. If your app runs well on ART, it should also run on Dalvik, but not necessarily the other way around.
- Android also includes a core set of runtime libraries that provide most of the functionality in the Java programming language used by the Java API framework, including some Java 8 language features.
4. Native C/C++ library
- Many core Android system components and services, such as ART and HAL, are built from native code and require native libraries written in C and C++. The Android platform provides Java framework APIs to expose the functionality of some of its native libraries to applications. For example, you can access OpenGL ES through the Android framework's Java OpenGL API to support drawing and manipulating 2D and 3D graphics in your applications.
- If you are developing an application that requires C or C++ code, you can use the Android NDK to access certain native platform libraries directly from native code.
5. Java API framework
- You can use the entire feature set of the Android OS through APIs written in the Java language. These APIs form the building blocks needed to create Android apps, and they simplify the reuse of core modular system components and services, including: A rich, extensible view system for building your app's UI, including lists, Grids, text boxes, buttons and even an embeddable web browser; Resource manager to access non-code resources such as localized strings, graphics and layout files; Notification manager to keep all apps in the status bar Displays custom reminders; Activity manager, which manages the app's lifecycle and provides common navigation backstacks; Content providers, which allow apps to access data from other apps (such as the Contacts app) or share their own Data; developers have full access to the framework API used by Android system applications.
6. System application
- Android comes with a core set of apps for email, text messaging, calendaring, internet browsing, contacts, and more. Apps that come with the platform are just like apps that users can choose to install and have no special status. So a third-party app can become a user's default web browser, SMS messenger, or even default keyboard (with some exceptions, such as the system's Settings app).
- System apps serve as users' apps, as well as provide key functionality that developers can access from their own apps. For example, if your app sends text messages, you don't need to build that functionality yourself; you can instead call an installed SMS app to send messages to the recipients you specify.
(2) Android device file browser
- The new version of Android Studio has been
Android Device Monitor
removed from the menu bar. If you want to view connected Android device files, you need to use the Device File Explorer.
1.1 Start the device file browser
- 单击View | Tool Windows | Device File Explorer
- sdcard: secure digital card
- permissions: 10-bit permission characters,
1 bit: file type (d
: directory;l
: link link;-
: ordinary file)
234 bits: Indicates the permissions of the file owner (owner/user) (r
——read;w
——write;x
—— Execution)
567 bits: Indicates the permissions of user group members (group) (r
——Read;w
——Write;x
——Execute)
8910 bits: Indicates the permissions of non-user group members (other) (r
——Read;w
——Write ) ;x
——Execution)
from the 2nd to the 10th position, "-" means that you do not have this permission.
2. View the memory directory
- Click to open
data/data
and find the Android program we are runningnet.xqf.test
3. Check the external memory card
- Click to open
sdcard
- If we develop a music player and want to play audio files on the memory card, we can upload the audio files to
Music
the directory
(3) Android debugging bridge
- ADB (Android Debug Bridge) tool, we can manage the status of the device or mobile emulator. You can also perform many mobile phone operations, such as installing software, system upgrades, running shelI commands, etc. To put it simply, it is a bridge connecting Android phones and PCs, allowing users to fully operate their phones on their computers.
- Check the location of adb.exe
1. View connected devices
- Excuting an order:
adb devices
2. Check the device connection status
- Excuting an order
adb get-state
- The results may have three situations: offline - the device connection is abnormal, device - normal, unknown - no device is connected.
- If you close the simulator and execute this command again, an error will be reported.
3. View mobile phone logs
- After Ctrl+C, you can view the four buffer logs of the mobile phone, including radio, system, main, and event. Radio stores communication logs, such as call text messages, etc.; event refers to event logs such as mobile phone key output, etc.; main refers to The log of the mobile phone application software is the application layer log output; system is the system component log.
- Excuting an order:
adb logcat
4. View all application package names
- Excuting an order:
adb shell pm list packages
5. Enter shell state
- Android is based on the Linux kernel so Linux commands can be used in the shell state.
- Excuting an order:
adb shell
- Excuting an order:
ls
- Enter the /data/data directory
- Excuting an order:
ls
- Execute
exit
the command and exit adb shell
- To check the resolution, execute the command:
adb shell wm size
- Output battery information and execute the command:
adb shell dumosys battery
- Get the system version number and execute the command:
adb shell getprop ro.build.version.release
6. Kill the service process
- Excuting an order:
adb kill-server