Android study notes 04: Android platform architecture

Zero, learning goals

  1. Can tell the layers of the Android platform architecture
  2. Use Android device monitors, especially DDMS
  3. Will basically use the Android debugging bridge ADB to enter the Android Linxu kernel

1. Android platform architecture

  • Android is an open source software stack based on Linux, created for various devices and models
  • The main components of the Android platform
    Insert picture description here

(1) Brief description of Android platform architecture

1. Linux kernel

  • The foundation of the Android platform is the Linux kernel. For example, 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 major security features and allows device manufacturers to develop hardware drivers for well-known kernels.

2. Hardware Abstraction Layer (HAL)

The Hardware Abstraction Layer (HAL) provides a standard interface to display device hardware functions to the higher-level Java API framework. HAL contains several library modules, each of which implements an interface for a specific type of hardware component, such as a camera or Bluetooth module. When the framework API requires access to the device hardware, the Android system will load the library module for the hardware component.

3. Android Runtime

  • For devices running Android 5.0 (API level 21) or higher, each application runs in its own process and has its own instance of Android Runtime (ART). ART is written to run multiple virtual machines on low-memory devices by executing DEX files. DEX files are a bytecode format specially designed for Android. It is optimized and uses very little memory. The compilation tool chain (such as Jack) compiles the Java source code into DEX bytecode so that it can run on the Android platform.
  • Before Android version 5.0 (API level 21), Dalvik was the Android Runtime. If your application works well on ART, it should also work on Dalvik, but the reverse is not necessarily true.
  • Android also includes a core runtime library that provides most of the functions in the Java programming language used by the Java API framework, including some Java 8 language functions.

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 show applications the functions of some of the native libraries. For example, you can access OpenGL ES through the Java OpenGL API of the Android framework to support drawing and manipulating 2D and 3D graphics in the application.
  • If you are developing an application that requires C or C++ code, you can use the Android NDK to access some native platform libraries directly from the native code.

5. Java API framework

  • You can use the entire feature set of Android OS through APIs written in Java language. These APIs form the building blocks required to create Android applications. They can simplify the reuse of core modular system components and services, including the following components and services: a rich and extensible view system that can be used to build the application’s UI, including lists, Grids, text boxes, buttons and even embeddable web browsers; Resource Manager, used to access non-code resources, such as localized strings, graphics and layout files; Notification Manager, which allows all applications in the status bar Display custom reminders; Activity manager, used to manage the life cycle of the application, provide a common navigation back stack; content provider, allow the application to access data in other applications (such as the "Contacts" application) or share its own Data; developers can fully access the framework APIs used by Android system applications.

6. System application

  • Android comes with a set of core applications for email, text messaging, calendar, internet browsing, contacts, etc. The apps that come with the platform are the same as the apps that users can choose to install, with no special status. Therefore, third-party applications can become the user's default web browser, SMS Messenger or even the default keyboard (with some exceptions, such as the system's "Settings" application).
  • The system application can be used as a user's application and provide the main functions that the developer can access from his own application. For example, if your application wants to send text messages, you don’t need to build this function yourself. Instead, you can call an installed SMS application to send messages to the recipients you specify.

(2) Advantages of Android's layered architecture

  • The Android system adopts the idea of ​​a layered architecture, with a clear structure, distinct levels, and collaborative work.
  • The Android system architecture not only understands the Android system from a macro level, 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 program 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 get the true knowledge.

2. Android Device Monitor (ADM)

Android Device Monitor is a virtual machine debugging and monitoring service in the Android development environment. It provides us with, for example, taking screenshots of test equipment, viewing running threads and heap information for specific processes Logcat, broadcasting status information, simulating phone calls, receiving SMS, virtual geographic coordinates, and so on.

1. Start the Android device monitor

  • Go to the tools subdirectory of the Android SDK directory and find monitor.bat
    Insert picture description here
  • Double-click monitor.bat to start the Android device monitor
    Insert picture description here
  • Start the Android application [HelloWorld]
    Insert picture description here
  • View Android device monitor, view file explorer (File Explorer) and log capture (LogCat)
    Insert picture description here

2. View File Explorer of DDMS

  • DDMS(Dalvik Debug Monitor Service)
  1. data-memory directory
  2. mnt-external storage directory
    Insert picture description here
  • Click data, its content cannot be viewed at present

  • The emulator currently uses Android 7.0 ( API 24), changed to Android 6.0 ( API 23)
    Insert picture description hereInsert picture description here

  • Click on data/data and find the Android program we are running: net.hw.helloworld
    Insert picture description here

  • The last line of the screenshot is our own Android application: net.hw.helloworld

  • Click on mnt to view its contents
    Insert picture description here Insert picture description here

  • sdcard: secure digital card

  • permission: 10-bit permission character
    1 bit: file type ( d: directory directory l;: link link;: -ordinary file)
    234 bit: indicates the permission the file owner has ( r——read; w——write; ——execute x)
    567 bit: user group members have the authority r( - wreading; - xwrite; - execution)
    8910: that the non-user group members with permissions r( - wreading; - xwrite; - execution)
    from second place to first 10 digits, "-" means that you do not have this permission.

3. Android Debug Bridge (ADB)

1. The role of ADB

Use adb shell to enter the Linux kernel for related operations.

2. ADB operation demonstration

  • Start DOS, enter the directory where the adb program is locatedD:\Android\sdk\platform-tools
    Insert picture description here
  • Enter the adb shell command, and a command prompt appears #(if it is Android 7.0, then the prompt is $)
    Insert picture description here
  • Enter /data/data directory
    Insert picture description here
  • View the contents of this directory
    Insert picture description here
    Insert picture description here
  • Enter the data/data/com.android.providers.contacts directory,
    use the cd command to modify the current directory,
    use the ls command to view the file information in the current directory,
    and then use the cat command to view the content of the text file
    Insert picture description here
  • Type the exit command to exit the adb shell
    Insert picture description here

3. Use adb to kill and start the service process

Encounter problems:The connection to adb is down, and a severe error has occured.

  • First close the Android Studio integrated development environment
  • Start DOS and enter the platform-tools directory of the Android SDK
  • Type adb kill-server (kill the service process)
  • Then enter adb start-server (start the service process)
    Insert picture description here

Guess you like

Origin blog.csdn.net/howard2005/article/details/108535104