AOSP · PROCESS

AOSP · PROCESS

Creating this article, I understood that most developers have a difficulty in getting up how the Android system works in general. I will try to make it clear and after reading my articles you will be more familiar with how your code makes a magic. Let's start from basics :


AOSP

When you create an android project, you know that it contains resources, fragments, some navigation components, libraries, and much more. Together this gives us a working program with some version, for example 1.0.0.

AOSP is the same program, but all its files together give us the Android operating system. So, if YouTube (version 14.0.0) is the app name with youtube_project in AndroidStudio, so Android (version 14) is the OS name with the aosp_project in AndroidStudio.

Before building this project, we choose on which device the Android should run (Android TV, Android OS, Automotive, Wear OS, or Android Things). Little bit similar process as we did with the flavors for different devices. After building, you will have a firmware instead of good known APK or AAB formats. Then, we can install this one on the corresponding device.

As I told, this is a project, so you are able to make the changes of the LockScreen, Camera, SystemSettings, and whatever you want. For example, Xiaomi took the AOSP and updated its code with their own customizations and design, so in the end we got MIUI. The same workflow for other custom operating systems. AOSP is a project with a minimal version of features the user needs.


Architecture

As in comparison with a common project with Clean Architecture, the AOSP has its own one :

  • Application : each system and non-system app in Android is located in application layer (Instagram, Camera, Whether, GoogleFit). It's the highest level of system with UI and interactions.
  • Framework : layer with an additional tools for developing the app. LocationManager helps you to find the users location, the mentioned ActivityManager is also here. Content Provider, TelephonyManager for making calls, and dozens of other objects that you might use are there.
  • ART : this virtual machine executes the code you write and converts into the machine code. Here also we can find a Garbage Collector that cleans useless data from the Heap.
  • C/C++ library : the library layer with a performance-critical operations, such as graphics rendering, media processing, or database operations (SQLite, MediaFramework, OpenGL, SSL, etc).
  • HAL : Hardware abstraction layer (HAL) makes the hardware components like a camera (the "piece of glass") functional and accessible to the applications and the operating system. HAL acts as a bridge between the device's physical hardware and the higher-level software, providing standard interfaces for interacting with hardware functionalities like the camera, without needing the software to understand the specific hardware details.
  • Linux Kernel : It is the core of the operating system. It manages fundamental functions such as hardware communication, process and memory management, and network stack. It's the lowest level of the Android architecture, interfacing directly with the device hardware, and provides a foundation upon which the rest of the Android system is built.


Process

Creating an app navigation you use the Activities or Fragments to create a required screens. But in AOSP, instead of the mentioned, the system uses applications, or in other words - processes. So, your system processes like Launcher, Camera, Phone, LockScreen, Files are the same as YouTube, Instagram, Twitter, and so on, but they were created by Google as a default apps. By clicking on the screen the user decides where to go and what to do, and the system opens the corresponding process.

How? Let's talk about the most common situation :

  • In your Launcher process there is a list of already installed app. You are clicking on the Instagram icon and using the setOnClickListener the Launcher understands what exactly you want to open.
  • Then, the Launcher process calls ActivityManager using Intent and says: "Hey man, I wanna open the Instagram, please, help".
  • ActivityManager knows that the only one person may open the Instagram - Zygote. It is the parent of all the applications we use. Zygote is a secured detached capsule with all needed resources to run APK/AAB.
  • After ActivityManager's request to open an Instagram it makes own clone and puts a specific instagram.apk inside. Then, the ART virtual machine sees the new created process and runs that APK or AAB file. So, Zygote is like an empty application with no design and logic, but with the required resources to execute an app. This approach with duplicating itself (fork) is useful in load speed because we don't need to create a new process, connect the CPU, GPU, allocate a memory and so on from scratch.
  • After running the APK, the Content Provider is among the first components to be initialized, even before Application or Activity objects. This early initialization ensures that the Content Provider is ready to handle requests from other components or applications as soon as the app starts.
  • Finally, as you know, the Application component starts and then the Activity appears on the screen with a tag below in Manifest file :

android:name="android.intent.category.LAUNCHER"        

要查看或添加评论,请登录

Vlad Kondratiuk的更多文章

  • BUILD

    BUILD

    After writing the code you are clicking on the RUN · GENERATE APK · BUILD · REBUILD buttons depending on the needs, but…

社区洞察

其他会员也浏览了