PackageManager

PackageManager: Driving Android’s App Ecosystem (Part I)

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

  1. 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.
  2. Permission Management
    Controls the permissions that apps request and are granted.
  3. Component Enable/Disable
    Can enable or disable app components (e.g., Activities, Services).
  4. Retrieving App Information
    Retrieves metadata about installed apps, such as their permissions, activities, services, etc.
  5. Querying Capabalities
    Allows querying for apps based on criteria like permissions, intents they can handle, etc.
  6. Package Verification
    Validates the integrity of app packages.
  7. Resolve Intent
    Determines the best component (Activity, Service, etc.) to handle a given Intent.
  8. Interacting with App Signing Certificates
    Provides access to information about the digital certificates apps are signed with.
  9. Feature Management
    Manages features of the device that affect compatibility with applications.
  10. Shared Libraries & User IDs
    Handles shared libraries and shared user IDs between apps.

PackageManagerService

  1. System Boot Management
    Starts at system boot and manages application-related tasks.
  2. Data Storage
    Stores application information in specific system files (like packages.xml).
  3. Installation and Uninstallation
    Manages APK installation and uninstallation processes.
  4. Permission Assignment
    Assigns permissions to applications during installation.
  5. Signature Verification
    Checks the signature of APKs during installation.
  6. Package Parsing
    Parses APK files during installation to retrieve required information.
  7. Managing User IDs
    Assigns unique User IDs (UIDs) to each application.
  8. Enforcement of Manifest Declarations
    Enforces manifest declarations for apps.
  9. System Updates
    Handles system updates and changes to applications.
  10. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *