Beginnning
PackageInstaller calls InstallAppProgress activity to receives an instruction from the user. InstallAppProgress will ask PackageManager
Service to install package via installd. Source code is available at <Android Source>/packages/apps/PackageInstaller
.
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.
Where APK
files stores in Android
?
- Pre-Install (i.e. Camera, Calendar, Browser,etc.)
APK
stored in /system/app/
- User Install (ApiDemo, Any.do, etc.) APK stored in
/data/app/
- 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.
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.
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.
packages.xml
:This file contain list of permissions and Packages/Applications.
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.
packages.list
: It is simple text file contain package name, user id, flag and data directory, I can't find any perfect description but I assume it that packages.list
file may provide faster lookup of installed package because it file keep important information only.
com.android.launcher 10013 0 /data/data/com.android.launcher
com.android.quicksearchbox 10033 0 /data/data/com.android.quicksearchbox
com.android.contacts 10001 0 /data/data/com.android.contacts
com.android.inputmethod.latin 10006 0 /data/data/com.android.inputmethod.latin
packages-stoped.xml
: This file contain package list which has stopped state, Stope stated applications can not receive any broadcast.
Where I can find the source code of Package Manager and Package Installer ?
Package Manager
frameworks/base/services/java/com/android/server/pm/Settings.java
frameworks/base/services/java/com/android/server/pm/PackageManagerService.java
frameworks/base/services/java/com/android/server/pm/IPackageManager.aidl
frameworks/base/services/java/com/android/server/pm/PackageSignatures.java
frameworks/base/services/java/com/android/server/pm/PreferredActivity.java
frameworks/services/java/com/android/server/PreferredComponent.java
frameworks/core/java/android/content/IntentFilter.java
frameworks/base/core/java/android/content/pm/PackageParser.java
frameworks/base/services/java/com/android/server/pm/Installer.java
frameworks/base/core/java/com/android/internal/app/IMediaContainerService.aidl
frameworks/base/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
Package Installer
packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java.
Links to refer: link 1 and link 2.
adb shell
. The commands are similar to a unix shell - e.g. you can typecd
andls
. Check out directories like/data/app
. blog.shvetsov.com/2013/02/… – Mattingly