Android Internals 101 : Essential System Services Demystified.
Bonjour Droids! Welcome again. Till now, we have discussed essential AOSP concepts, which’ve helped us to set the base of our foundational learning of AOSP development. Today we will look pass through further deep inside AOSP system to make sure that we shall not leave any minute details of a system services.
Let’s get started…
Today we are set to uncover important AOSP services which makes things super cool but before that. Let’s understand the services first in the AOSP context.
Android App Services : In android application development. A service is a one of the fundamental components that runs in background in order to perform long running tasks. It also has multiple types i.e. foreground, background and bounded service.
AOSP Services : Android internal services are built-in services that runs on framework level in android operating system. This services are internally leveraged by apps and system to perform essential tasks such as operations related to power management, telephony management, location management, etc.
1. Activity Manager Service :
AMS mainly charge of launching, switching, dispatching and manage the process of application.
It responsible for managing the lifecycle of Activities, Services, Content Provider & Broadcast Receiver, tasks, and processes*.*
AMS is also responsible to do following tasks :
➊ Start or kill the process of the application
➋ Start or schedule the service lifecycle
➌ Register broadcast receiver
➍ Start and publish content provider
➎ Scheduling tasks
➏ Crash handling of application
➐ Query the current operating status of android
Activity Record :
When we work with different apps in android many activities, process and many other components are alive at the same time.
The state or lifecycle of this component is differ based on which screen user is interacting with it. Android manages all these states and lifecycle changes through AMS data structure i.e. Activity Record.
AMS basically uses 2 data structure to handle this.
Activity record is the base data structure which records the characteristics of single activity.
Activity record is a class with multiple attributes and behaviors for a single activity.
Task is basically a collections of multiple activity records.
Task is also a class with many attributes and behaviors.
AMS uses the data structure of process record to maintain state information of process when it runs.
Corresponding class for process record is ProcessRecord.
2. Window Management Service :
Window management consist of :
» Window
» Window Manager
» Window Manager Service
We can easily remember this analogy as :
employee ➡ manager ➡ boss
window ➡ window manager ➡ window manager service
Window — Window is an abstract class, its concrete implementation class called PhoneWindow.
Window Manager — An interface that inherits View Manager, it’s concrete implementation class called WindowManagerImpl.
Window Manager Service — To perform add or delete operations on windows, we always requires window manager service but the operation is strictly handled by WMS.
I) Window
- Window Manager Service communicate across processes through Binder with Window Manager.
Window is a view.
Window manager is used to manage views and the function provided by window manager handled by (WMS) window manager service.
II) Window Manager
Window properties are defined in the internal class called LayoutParams of Window Manager.
Understanding of window properties help us to understand the internal properties of window management service.
There are many kind of window properties. Generally 3 are most usefull in AOSP development which are as follows:
- Window Type
- Window Flag
- Soft InputThere are many types of window
- application window
- system error window
- input method window
- popup window
- dialogsIn general, it is divided in 3 categories :
Application Window (Ranges from 1–99)
Sub Window (Ranges from 1000–1999)
System Window (Ranges from 2000–2999)
Window Z - Order :
WMS determines order of screen based on z-axis, Here z-axis is perpendicular to the screen and point from inside to outside of the screen.
The window type value (range) is used for the ordering of window in z - order.
III) Window Manager Service
It is the boss of the system, responsible for managing entire viewing system.
WMS responsible for the managing listed operations:
¤ start
¤ addition
¤ deletion
¤ size
¤ levels
¤ animations
¤ surface management.¤ input management
¤ display management
¤ power management
¤ etc.As we know. Most of the system services starts from system server. Similarly window manager service also starts from system server.
3. Package Manager Service :
PMS is one of the key system service that is responsible for managing applications in the OS. It manages package related tasks such installing / uninstalling and updating apps.
The PMS is initialized during android system boot process which can be shown in the below specific diagram :
PMS startup process can be divided into 5 phases :
- PMS start phase
- PMS system scan start phase
- PMS data scan start phase
- PMS scan end phase
- PMS ready phaseKey Functions of Package Manager Service:
- App Installation and Removal
- Package Scanning
- App Permissions
- Component Resolution
- Shared Libraries
- Data Management
- Security
In the next article we’ll see such interesting topics of android internal’s, stay tuned. If you like do share with your friends, You can also write a feedback for further improvements. Happy learning.
Subscribe to my newsletter
Read articles from Faraz Sheikh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Faraz Sheikh
Faraz Sheikh
Hiya 🖐 I’m Faraz Sheikh, a curious & creative software engineer from India. I like to solve complex engineering problems in a simplest possible way, based on learn by doing principle. I also likes to design software system, front-end mockups for personal and commercial projects. Past time includes ✍️ writing technical blogs, 📺 anime, 🏏 cricket and 🗺️ exploring world. And I hope we shall work together on X great ideas. 🤝 Thank You 🤝