Understanding the Core Principles of APK Installation on Android
This article explains how Android parses the AndroidManifest, assigns UID and updates permissions during APK installation, covering system boot installation, PMS‑driven third‑party, ADB and Market installations, and provides code snippets to illustrate the underlying mechanisms.
The article analyzes the core principles of APK installation on Android, describing four typical scenarios and two main installation pathways: system boot installation and PMS‑driven installation, aiming to clarify the essential steps and underlying logic.
Core installation steps include: (1) parsing AndroidManifest.xml to extract application, component and permission information (e.g., PackageParser.parseBaseApkCommon()); (2) assigning a UID to the app and recording its package information in the PackageManagerService (e.g., PMS.scanPackageDirtyLI(), Setting.addUserIdLPw()); (3) updating the app’s permission state according to the declared uses‑permission entries (e.g., PMS.grantPermissionsLPw()).
System‑boot installation starts with PackageManagerService initialization during the boot process, scanning directories such as /data/app, /system/app, /vendor/app, restoring previous UID assignments from package.xml, and sequentially installing each APK while finally refreshing all permissions.
PMS‑driven installation (used by third‑party apps, ADB, and Market) begins when the PackageInstaller sends an INIT_COPY signal to DefaultContainerService. A Binder/AIDL connection ( IMediaContainerService) is established, and a HandlerParams queue processes installation requests. The startCopy() method copies the APK to the appropriate location, after which handleReturnCode() triggers the core install logic (e.g., installPackageTracedLI()).
Code examples illustrate key points:
public final static class Activity extends Component<ActivityIntentInfo> implements Parcelable adb shell ps | grep packageName adb install packagePathIn summary, APK installation consists of parsing the manifest, assigning a UID, and updating permissions; these steps are executed either during system boot or via PMS‑driven mechanisms for user‑initiated installations.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
