Android APK Installation Process Introduction

Source: Internet
Author: User

Project path: Click Apply from MyFile to install, to install, process analysis

Method of thinking: In the study of Preloadinstaller, we directly from the entire APK file structure, from the overall to the part of the analysis, but now the whole PMS is very large. We take hold of a function point analysis, from point to face, until we control all


Directory
Phenomenon 1
Log Analysis 3
Extraction of Packageinstaller Functions 4
Packageinstaller/androidmanifest.xml 4
Packageinstalleractivity.java 4
Installappprogress.java 4
Packagemanager.java Analysis 5
1. Installpackagewithverificationandencryption 5
2. Pm.installexistingpackage 5
Pm/apm/pms's Relationship 5
APK Installation Flowchart Master 6
Applicationpackagemanager Analysis 6
Packagemanagerservice Analysis 8
InstallPackage 8
Installpackageasuser 8

Phenomenon
Guo Bao three. apk

Log analysis
Activitymanager:   START u0 {act=android.intent.action.view dat=file:///storage/emulated/0/guo Bao three. apk typ= Application/vnd.android.package-archive cmp=com.android.packageinstaller/. Packageinstalleractivity (have extras)} from UID 10037 pid 7437 on display 0ActivityManager:   Start proc Com.android.pac Kageinstaller for Activity com.android.packageinstaller/. packageinstalleractivity:pid=8691 uid=10095 gids={50095, 9997, 1028} abi=armeabi-v7a

To install Apk,activitymanager based on intent filtering open Packageinstaller

Packageinstaller:launching settings packagemanager:failed to GENERATEPACKAGEINFOFROMSETTINGSLPW, There isnt package Setting object forCom.centurysoft.fruityrobo packagemanager:start_package_install:observer{532627611} packagemanager:originpath{/storage/emulated/0/Guo Bao tri. apk} packagemanager:flag{0} packagemanager:request From{null} packagemanager:verificationparams{verificationparams{,moriginatinguid=1000,mmanifestdigest=manifestdigest { MDIGEST=60,E1,A0,C0,72,EF,1C,21,4C,B9,A3,D8,BD,AF,0E,AF,05,8C,16,5B,CE,65,6A,AB,AC,45,D5,F9,66,8E,91,FA,}, minstalleruid=10095}} Packagemanager: [MSG] init_copy:observer{532627611} packagemanager:idx{0} packagemanager:for_user{userhandle{0}} Packagemanager: [MSG] mcs_bound:observer{532627611} packagemanager:for_user{userhandle{0}} packagemanager:remove Mcs_unbind message and Posting Mcs_unbind 10secs later Packagemanager: [MSG] process_pending_install:observer{532627611} packagemanager:currentstatus{1} packagemanager:installpackageli:path=/data/app/Vmdl679148838.tmp packagemanager:verifying app can be installed or not packagemanager:renaming/data/app/vmdl679148838. TMP to/data/app/com.centurysoft.fruityrobo-1Packagemanager:installnewpackageli:package{1af2bbac Com.centurysoft.fruityrobo} packagemanager:scanfilenewer: Com.centurysoft.fruityrobo packagemanager:resolved nativelibraryroot for Com.centurysoft.fruityrobo to root=/data/ App/com.centurysoft.fruityrobo-1/lib, Isa=truePackagemanager:abis for Package[com.centurysoft.fruityrobo] is Primary=armeabi secondary=nullPackagemanager:running dexopt on:/data/app/com.centurysoft.fruityrobo-1/base.apk Pkg=com.centurysoft.fruityrobo Isa=arm Vmsafemode=false Interpret_only=falsePackagemanager:do minstaller.dexopt:0Packagemanager:time to Dexopt com.centurysoft.fruityrobo:4.943Seconds Packagemanager:new Package Installed In/data/app/com.centurysoft.fruityrobo-1 packagemanager:not granting permission Android.permission.MOUNT_UNMOUNT_FILESYSTEMS to package Com.centurysoft.fruityrobo (protectionlevel=18 flags=0x8be44 ) packagemanager:unknown permission Com.android.launcher3.permission.READ_SETTINGS in package  Com.centurysoft.fruityrobo Packagemanager:unknown Permission Com.android.launcher2.permission.READ_SETTINGS in Package  Com.centurysoft.fruityrobo Packagemanager:dopostinstall for uid{10156 } Packagemanager:token one-to-BM for  possible restore Packagemanage R:BM Finishing Package install for one  packagemanager: [MSG] post_install:observer{532627611 } packagemanager : Handling post-install for one  Launcher.PackageChangeReceiver:onReceive = Intent {act= Android.intent.action.PACKAGE_ADDED Dat=package:com.centurysoft.fruityrobo flg=0x4000010  (has extras)} Packagemanager:result of install:1{532627611}          

Packageinstaller to implement the installation process by invoking PMS after a series of checks

Packagemanager:result of install:1{532627611} indicates successful installation and if other return values indicate an unsuccessful installation

Extraction of Packageinstaller function

Packageinstaller/androidmanifest.xml

The log just now reads as follows:

Act=android.intent.action.view

dat=file:///storage/emulated/0/Guo Bao three. apk

Typ=application/vnd.android.package-archive

Packageinstalleractivity.java

Packageinstaller/src/com/android/packageinstaller/packageinstalleractivity.java

Find the construction method and OnCreate method

Construction Method: None

OnCreate method:

Installappprogress.java

Packageinstaller/src/com/android/packageinstaller/installappprogress.java

Search the keyword "PM." About two places to install

Search for "PM =" to see Methods in dependent Packagemanager

Packagemanager.java Analysis 1. installpackagewithverificationandencryption
public abstract void installpackagewithverificationandencryption (Uri Packageuri,        ipackageinstallobserver Observer, int flags, String installerpackagename,        verificationparams verificationparams, Containerencryptionparams encryptionparams);p ublic abstract void installpackagewithverificationandencryption ( Uri Packageuri,        packageinstallobserver Observer, int flags, String installerpackagename,        Verificationparams Verificationparams, Containerencryptionparams encryptionparams); InstallerPackageName where does the Setup program come from, Which program is installed   
2. Pm.installexistingpackage

Because this is the first installation, so do not go this path

APK Installation Flowchart Master

Applicationpackagemanager Analysis

Installpackagewithverificationandencryption

Installcommon

Packagemanagerservice is the implementation class of Ipackagemanager

Packagemanagerservice Analysis InstallPackage

Installpackageasuser

Is it legal to judge UserID and Callinguid?

Determine where the installation request comes from ADB or other programs

Determine whether to install for all users or only for the current user

Enterprisedevicemanager to judge a request

Various checks complete, start to enter the installation phase

Typing the APK information to install

Knox feature, force apk to install to SD card

Get the APK default installation path

Get the APK in an untrusted way to determine the path to install (internal memory, external memory)

Encapsulates an asynchronous message init_copy, sending (meaning: initiating replication)

/android/frameworks/base/packages/defaultcontainerservice/src/com/android/defcontainer/ Defaultcontainerservice.java

The imediacontainerservice.stub is implemented in the Defaultcontainerservice

The MCS service sends Mcs_bound asynchronous messages when a connection is created

Handling Mcs_bound Asynchronous messages

From the above analysis, the code actually calls the Installparams

The Installparams.handlestartcopy flowchart is as follows:

Fileinstallargs

int copyapk (Imediacontainerservice IMCs, Boolean temp) throws RemoteException

Asecinstallargs

int copyapk (Imediacontainerservice IMCs, Boolean temp) throws RemoteException

/android/frameworks/base/packages/defaultcontainerservice/src/com/android/defcontainer/ Defaultcontainerservice.java

Android APK Installation Process Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.