Android application installation process and principles

Source: Internet
Author: User

#标签: Read the Blog



I laughed when I saw a lap, but the final installation was back to the PMS call.

:)

This article was reproduced from: http://www.miui.com/thread-759958-1-1.html

The process and path for Android app installation:

Application installation involves the following directories:

System/app system comes with an application that cannot be deleted

Data/app User program installs the directory, has the delete permission. Copy the apk file to this directory during installation

data/data Storing data for an application

Data/dalvik-cache Install the Dex file in the APK into the Dalvik-cache directory (the Dex file is the executable file for the Dalvik virtual machine, which is approximately one-fourth of the original apk file size)

Installation process:

Copy the APK installation package into the Data/app directory, unzip and scan the installation package, save the Dex file (Dalvik bytecode) to the Dalvik-cache directory, and create the corresponding application Data directory in the Data/data directory.

Uninstall process:

Delete the files and directories created in the above three directories during the installation process.

Four ways to install Android apps:

1. System Application Installation: Complete at boot time, no installation interface

Packagemanagerservice handles the installation, uninstallation, management of various applications, and starts the service by Systemserver when booting

(source file path: Android\frameworks\base\services\java\com\android\server\packagemanagerservice.java)

Packagemanagerservice Service START Process:

1. First scan the jar package installed in the "System\framework" directory

1. Scandirli (Mframeworkdir,packageparser.parse_is_system,

Scanmode | Scan_no_dex);


2. The second step scan installs each system application under the "System\app" directory

Scandirli (Msystemappdir,packageparser.parse_is_system, Scanmode);


3. The third step scans the "Data\app" directory, which is a user-installed third-party app

Scandirli (mappinstalldir, 0, Scanmode);


4. The fourth step is to scan the "data\app-private" directory, that is, install the DRM-protected apk file (no such applications are currently encountered).

Scandirli (mdrmappprivateinstalldir,0, Scanmode | scan_forward_locked);


Procedures for installing Apps

1.scanDirLI (filedir, int flags, int scanmode) traverse the installation of files in the specified directory

2.scanPackageLI (Filescanfile,

File destcodefile, filedestresourcefile, int parseflags,

int Scanmode) Install the package file

3.scanPackageLI (

File Scanfile, file Destcodefile, Filedestresourcefile,

Packageparser.package pkg, intparseflags, int scanmode)

Obtain the information structure of the installation package by parsing the installation package Parsepackage

4.minstaller.install (Pkgname,pkg.applicationinfo.uid,

PKG.APPLICATIONINFO.UID); Implementing the installation process for file replication

(source file path: Frameworks\base\cmds\installd\installd.install)

Network Download Application installation: Completed via market application, no Installation interface

Google Market app needs to use Gmail account login to use, select an app, start to download the installation package, the process, in the phone's signal area there is a progress bar prompt, after the download is complete, will automatically call Packagemanager interface installation, the calling interface is as follows:

Public Voidinstallpackage (Final Uri Packageuri, final ipackageinstallobserver observer,final int flags)

Final Uri Packageuri: path saved after file download is complete

Final Ipackageinstallobserver Observer: Handling returned installation results

Final int flags: installed parameters, applications downloaded from the market, installation parameters of-R (replace)

InstallPackage the installation process of the interface function:

1.public Voidinstallpackage (

Final Uri Packageuri, final ipackageinstallobserverobserver, final int flags,

Final String Installerpackagename)

Final Stringinstallerpackagename: This name is saved in Settings after the installation is complete, usually null, not a key parameter

2.FiletmpPackageFile = Copytempinstallfile (Packageuri, RES);

Copy the apk file to a temporary file in the temp directory

3.private Voidinstallpackageli (Uri Ppackageuri,

int Pflags, Boolean newinstall,string installerpackagename,

File Tmppackagefile, Packageinstalledinfo Res)

Parse temporary file, get app package name Pkgname = Packageparser.parsepackagename (

Tmppackagefile.getabsolutepath (), 0);

4. Determine if the parameter install_replace_existing is called Replacepackageli (Pkgname,

Tmppackagefile,

Destfilepath,destpackagefile, Destresourcefile,

Pkg, Forwardlocked,newinstall, Installerpackagename,

Res

5. If not, call Installnewpackageli (Pkgname,

Tmppackagefile,

Destfilepath,destpackagefile, Destresourcefile,

Pkg,forwardlocked, Newinstall, Installerpackagename,

RES);

6.privatepackageparser.package Scanpackageli (

File Scanfile, file Destcodefile, Filedestresourcefile,

Packageparser.package pkg, intparseflags, int scanmode)

The Scanpackageli process is the same as the application installation process at boot time.

ADB Tool Installation: No installation interface.

Android Debug Bridge (ADB) is a tool for the SDK's own management device, which can also be installed for mobile phones or emulators via the ADB command line, with the entry function source file Pm.java

(source file path: Android\frameworks\base\cmds\pm\src\com\android\commands\pm\pm.java)

ADB command line in the form of adb install <path_to_apk>, can also be equipped with installation parameters such as: "-L" "-r" "-I" "-t"

function Runinstall () to determine the parameters

"-L" ――install_forward_lock

"-R"--install_replace_existing

"-I"--installerpackagename

"-T"--install_allow_test

Our commonly used parameter is-r, which means that an app with the same name installed on the installed phone is overwritten. Applications that are downloaded from the market are also directly passed into this parameter installation.

Runinstall and the market call the same interface to complete the application installation.

Public Voidinstallpackage (ANDROID.NET.URI packageuri,android.content.pm.ipackageinstallobserver Observer, int flags , java.lang.String Installerpackagename)

4. Third-party app installation: Install via APK file in SD card, install interface, interface of installation and uninstall process by packageinstaller.apk application.

To keep the APK installation package in the SD card, from the phone to access the SD card in the APK installation package, click to start the installation interface, the system Application packageinstaller.apk processing this way under the installation and uninstall interface process, such as:


Packageinstalleractivity is responsible for parsing the package to determine if the APK file is available

Create temporary installation files/data/data/com.android.packageinstaller/files/apidemos.apk

and launch the installation confirmation interface startinstallconfirm, list the resolved application basic information. If an app with the same name is already installed on your phone, you will need to confirm that you want to replace the installation.

After confirming the installation, start installappprogress and call the installation interface to complete the installation.

Pm.installpackage (Mpackageuri,observer, installflags);

Other:

1. Packagemanagerservice.java's internal class Appdirobserver implements the ability to listen to the app directory: when you drag an apk into the app directory, you can call Scanpackageli to complete the installation.

2. The Mobile Data area directory "Data/system/packages.xml" file contains basic information about all installed apps on the phone, such as installation path, requested permission, etc.



What's the meaning of installation?

1. Integration of component information into PMS management

2. Copy the apk file to the specified directory (intermediate may go through temporary directory/data/local/tmp or/sdcard/tmp), and dexopt files are placed in the/data/dalvik-cache directory

3. Copy also set up the data directory


Make sure the process is clear, the code is the manual, when it is used, or when it is needed, check the manual. -----my boss said so.


Merlin

2015/10/22



Android application installation process and principles

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.