1. What is Package Manager and Package Installer ?
2. Where APK files stores in Android ?
3. What is APK installation process in detail ?
4. How Package Manager store data ?
5. Where I can find source code of Package Manager and Package Installer ?
1. What is Package Manager and Package Installer ?
PackageInstaller is the default application for Android to install interactively normal package. PackateInstaller provide user interface to manage applications/package. PackageInstaller calls InstallAppProgress activity to receives an instruction from the user. InstallAppProgress will ask Package Manager Service to install package via indalld. Source code is available at <Android Source>/packages/apps/PackageInstaller.
Package Manage is API which actually manage application install, uninstall, upgrade.When we install APK file, Package Manager parse the package(APK) file and display confirmation, When user press OK button, Package Manager call method named "installPackage" with these four parameters namely uri, installFlags, observer, installPackageName. Package Manager start one service named "package", now all fuzzy things happen in this service. you can check "PackageInstallerActivity.java" and "InstallAppProgress.java" in PackageInstaller source code. Package Manager Service running in system_service process and install daemon (installd) that runs as a native process both start at system boot time.
2. Where APK files stores in Android ?
1. Pre-Install (i.e. Camera, Calendar, Browser,etc.) APK stored in /system/app/
2. User Install (ApiDemo, Any.do, etc.) APK stored in /data/app/
3. Package Manager create data directory /data/data/<package name>/ to store database, shared preference, native library and cache data
You might see apk file and *.odex file for same APK, ODEX file is totally different discussion and purpose.
3. What is APK installation process in detail ?
Following process execute in Package Manager Service.
- Waiting
- Add a package to the queue for the installation process
- Determine the appropriate location of the package installation
- Determine installation Install / Update new
- A copy of the apk file to a given directory
- Determine the UID of the app
- Request to installd daemon process
- Create the application directory and set permissions
- Extraction of dex code to the cache directory
- To reflect and packages.list / system / data / packages.xml the latest status
- Broadcast to the system along with the name of the effect of the installation is complete package
Intent.ACTION_PACKAGE_ADDED: If the new ( Intent.ACTION_PACKAGE_REPLACED): the case of an update
4. How Package Manager store data ?
Package Manager store application information in three files, located in /data/system. Following sample is extracted from Android 4 ICS emulator image.
1. packages.xml :This file contain list of permissions and Packages/Applications.
02 | < last-platform-version external = "15" internal = "15" > |
05 | < item name = "android.permission.CHANGE_WIFI_MULTICAST_STATE" package = "android" protection = "1" > |
06 | < item name = "android.permission.CLEAR_APP_USER_DATA" package = "android" protection = "2" > |
11 | </ item ></ item ></ permissions > |
13 | < package codepath = "/system/app/Contacts.apk" flags = "1" ft = "136567b3990" it = "136567b3990" name = "com.android.contacts" nativelibrarypath = "/data/data/com.android.contacts/lib" shareduserid = "10001" ut = "136567b3990" version = "15" > |
22 | < package codepath = "/data/app/com.project.t2i-2.apk" flags = "0" ft = "13a837c2068" it = "13a83704ea3" name = "com.project.t2i" nativelibrarypath = "/data/data/com.project.t2i/lib" userid = "10040" ut = "13a837c2ecb" version = "1" > |
24 | < cert index = "3" key="308201e53082014ea0030201020204506825ae300d06092a86 |
25 | 4886f70d01010505003037310b30090603550406130255533110300e060355040a13074 |
26 | 16e64726f6964311630140603550403130d416e64726f6964204465627567301e170d31 |
27 | 32303933303130353735305a170d3432303932333130353735305a3037310b300906035 |
28 | 50406130255533110300e060355040a1307416e64726f6964311630140603550403130d |
29 | 416e64726f696420446562756730819f300d06092a864886f70d010101050003818d003 |
30 | 08189028181009ce1c5fd64db794fd787887e8a2dccf6798ddd2fd6e1d8ab04cd8cdd9e |
31 | bf721fb3ed6be1d67c55ce729b1e1d32b200cbcfc91c798ef056bc9b2cbc66a396aed6b |
32 | a3629a18e4839353314252811412202500f11a11c3bf4eb41b2a8747c3c791c89391443 |
33 | 39036345b15b5e080469ac5f536fd9edffcd52dcbdf88cf43c580abd0203010001300d0 |
34 | 6092a864886f70d01010505000381810071fa013b4560f16640ed261262f32085a51fca |
35 | 63fa6c5c46fde9a862b56b6d6f17dd49643086a39a06314426ba9a38b784601197246f8 |
36 | d568e349a93bc6af315455de7a8923f40d4051a51e1658ee34aca41494ab94ce978ae38 |
37 | 609803dfb3004806634e6e78dd0be26fe75843958711935ffc85f9fcf81523ce23c86bc |
41 | < item name = "android.permission.WRITE_EXTERNAL_STORAGE" > |
49 | </ permission-trees ></ last-platform-version ></ packages > |
This xml file stores two things 1. permissions 2. package (application), permission are store under <permissions> tag. Each Permission has three attributes namely name, package and protection. Name attribute has permission name which we are using in AndroidManifest.xml, package attribute indicate permission belong to package, In majority cases "android" is values because <permission> tag contain default permissions and protection indicate level of security.
package tag contain 10 attributes and few sub tags.