One of the critical elements of Android offering some key functionalities is PackageManager. Several classes being part of the android.content.pm and com.android.server.pm package names serv to deliver such features. The lengthy list of its duties gives a comprehension of how it contributes to the stability and safety of Android. It is important to keep in mind that various modules are engaged in the security, stability, and safety of Android. Nonetheless, a few of them play important roles in between.
PackageManager is part of android.content.pm package while PackageManagerService included in com.android.server.pm. The first one is part of Android SDK providing public API can be used even by user applications. On the other hand PackageManagerService run as important system service can be accessed inly by other system level applications and services.
Dive a bit to the boot process
In order for other services to work, the PackageManagerService must be started as an essential system service in the first stages of the boot process. There are only few system services that provide other system level features are available before it. SystemService starts the critical services categorized to different stages. In the first step startBootstrapServices fires the critical services needed to launch the system. To fulfill the necessary dependencies, these services should be launched. Now it is a bit clear the necessity of PackageManagerService.
The Roles
Speaking the role of PackageManager and PakageManagerServices leads to a long list of different activities bound together to perform important tasks. They consist of different classes and modules including
PackagaeManager
- Installation/Uninstallation/Updating
As implied by its name, Package Manager is in charge of both installing new apps from APK files and uninstalling existing ones. It is necessary to summon other operations in order to complete this assignment. It can be supposed that all of them twisted together as a package/service to make it possible. - Permission Management
Controls the permissions that apps request and are granted. - Component Enable/Disable
Can enable or disable app components (e.g., Activities, Services). - Retrieving App Information
Retrieves metadata about installed apps, such as their permissions, activities, services, etc. - Querying Capabalities
Allows querying for apps based on criteria like permissions, intents they can handle, etc. - Package Verification
Validates the integrity of app packages. - Resolve Intent
Determines the best component (Activity, Service, etc.) to handle a given Intent. - Interacting with App Signing Certificates
Provides access to information about the digital certificates apps are signed with. - Feature Management
Manages features of the device that affect compatibility with applications. - Shared Libraries & User IDs
Handles shared libraries and shared user IDs between apps.
PackageManagerService
- System Boot Management
Starts at system boot and manages application-related tasks. - Data Storage
Stores application information in specific system files (like packages.xml). - Installation and Uninstallation
Manages APK installation and uninstallation processes. - Permission Assignment
Assigns permissions to applications during installation. - Signature Verification
Checks the signature of APKs during installation. - Package Parsing
Parses APK files during installation to retrieve required information. - Managing User IDs
Assigns unique User IDs (UIDs) to each application. - Enforcement of Manifest Declarations
Enforces manifest declarations for apps. - System Updates
Handles system updates and changes to applications. - SELinux Label Assignment
Assigns appropriate SELinux labels to applications
Some of the duties are shared by PackageManager and PackageManagerService, as was previously mentioned. How is it possible? is the question at hand. The relationship between them, which we will explore later, hides the solution. Nonetheless, a rough answer would be that PackageManager handles the low-level jobs and processes, whereas PackageManagerService handles the high-level API and functionalities.
In the next article will try to have look at the inside of these two packages and their relationship.