"android App development"-(9) Application safety loading principle

Source: Internet
Author: User
<span id="Label3"></p><p><p>This article in bold part from the network of an article, has not known the source, know the inform, thank the original author Here. Before the principle of loading and unloading is introduced, a simple loading and unloading application function is implemented First. The article is a blog I wrote earlier, here is not in the narrative, only add a few points:</p></p><p><p>1, because the code used in the Packageinstallobserver,packageinstallobserver in Eclipse is not callable, you must compile the system in a Linux environment to compile the Application.</p></p><p><p>2, Android4.0 installed API and 2.3 different, a number of Parameters. Interested in where you can see the code in Packageinstaller or view the Api.</p></p><p><p>-----------------------------split line--------------------------------------</p></p><p><p><strong>Application installation is the main feature of the intelligent machine, that is, users can install various applications (such as games, Etc.) to the mobile phone, and can be uninstalled and other management Operations. APK is the abbreviation for Android package, which is the Android Installer. APK is a file format similar to Symbian SIS or sisx. Install the APK file by uploading it directly to the Android emulator or Android Phone.</strong></p></p><p><p><strong>Android apps are installed in four different ways</strong></p></p><p><p><strong>1. System Application Installation-complete on boot, no Installation interface</strong></p></p><p><p><strong>2. Network Download Application installation-completed through Market application, No installation Interface</strong></p></p><p><p><strong>3.ADB Tool Installation – no installation Interface.</strong></p></p><p><p><strong>4. Third-party Application Installation-through The APK file installed in the SD card, there is an installation interface, the interface for the installation and uninstallation process is handled by the packageinstaller.apk Application.</strong></p></p><p><p><strong>Application installation process and the path, the application installation involves the following several directories:</strong></p></p><p><p><strong>1.system/app system comes with an application that cannot be deleted</strong></p></p><p><p><strong>2.data/app User program installs the directory, has the delete Permission. Copy the apk file to this directory during installation</strong></p></p><p><p><strong>3.data/data storing data for an application</strong></p></p><p><p><strong>4.data/dalvik-cache installs 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)</strong></p></p><p><p><strong>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.</strong></p></p><p><p><strong>Uninstall process: delete files and directories created in the above three directories during Installation.</strong></p></p><p><p><strong>first, the System Application Installation:</strong></p></p><p><p><strong>Packagemanagerservice handles the installation, uninstallation, management of various applications, and starts the service by Systemserver when booting</strong></p></p><p><p><strong>(source file Path: Android\frameworks\base\services\java\com\android\server\packagemanagerservice.java)</strong></p></p><p><p><strong>Packagemanagerservice Service Start Process:</strong></p></p><p><p><strong>1. First scan the jar package installed in the "system\framework" directory</strong></p></p><p><p><strong>1. Scandirli (mframeworkdir,packageparser.parse_is_system,scanmode | scan_no_dex);</strong></p></p><p><p><strong>2. The second step scan installs each system application under the "system\app" directory</strong></p></p><p><p><strong>Scandirli (msystemappdir,packageparser.parse_is_system, scanmode);</strong></p></p><p><p><strong>3. The third step scans the "data\app" directory, which is a user-installed third-party app</strong></p></p><p><p><strong>Scandirli (mappinstalldir, 0, scanmode);</strong></p></p><p><p><strong>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).</strong></p></p><p><p><strong>Scandirli (mdrmappprivateinstalldir,0, Scanmode | scan_forward_locked);</strong></p></p><p><p><strong>Procedures for installing Apps</strong></p></p><p><p><strong>1.scanDirLI (filedir, int flags, int Scanmode) traverse the installation of files in the specified directory</strong></p></p><p><p><strong>2.scanPackageLI (filescanfile, file destcodefile, filedestresourcefile, int parseflags,int scanmode) Install the package file</strong></p></p><p><p><strong>3.scanPackageLI (file scanfile, file destcodefile, filedestresourcefile, packageparser.package pkg, intparseflags, int Scanmode)</strong></p></p><p><p><strong>Obtain the information structure of the installation package by parsing the installation package Parsepackage</strong></p></p><p><p><strong>4.minstaller.install (pkgname,pkg.applicationinfo.uid,pkg.applicationinfo.uid); Implementing the installation process for file replication</strong></p></p><p><p><strong>(source file Path: Frameworks\base\cmds\installd\installd.install)</strong></p></p><p><p><strong>second, Download the application from the Market:</strong></p></p><p><p><strong>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:</strong></p></p><p><p><strong>Public voidinstallpackage (final Uri packageuri, final ipackageinstallobserver observer,final int Flags)</strong></p></p><p><p><strong>Final Uri packageuri: path saved after file download is complete</strong></p></p><p><p><strong>Final Ipackageinstallobserver observer: handling returned installation results</strong></p></p><p><p><strong>Final int flags: installed parameters, applications downloaded from the market, installation parameters Of-r (replace)</strong></p></p><p><p><strong>InstallPackage the installation process of the interface function:</strong></p></p><p><p><strong>1.public voidinstallpackage (final Uri packageuri, final ipackageinstallobserverobserver, final int flags,final String Installerpackagename)</strong></p></p><p><p><strong>Final String installerpackagename: This name is saved in Settings after the installation is complete, usually null, not a key parameter</strong></p></p><p><p><strong>2.FiletmpPackageFile = Copytempinstallfile (packageuri, res);</strong></p></p><p><p><strong>Copy the apk file to a temporary file in the temp directory</strong></p></p><p><p><strong>3.private Voidinstallpackageli (Uri ppackageuri,</strong></p></p><p><p><strong>int pflags, Boolean newinstall,string installerpackagename,</strong></p></p><p><p><strong>File tmppackagefile, Packageinstalledinfo res)</strong></p></p><p><p><strong>Parse temporary file, get app package name Pkgname = Packageparser.parsepackagename (</strong></p></p><p><p><strong>Tmppackagefile.getabsolutepath (), 0);</strong></p></p><p><p><strong>4. Determine if the parameter install_replace_existing is called Replacepackageli (pkgname, tmppackagefile, destfilepath,destpackagefile, destresourcefilepkg, forwardlocked,newinstall, installerpackagename, res)</strong></p></p><p><p><strong>5. If not, call Installnewpackageli (pkgname,tmppackagefile, destfilepath,destpackagefile, destresourcefile, pkg, forwardlocked, newinstall, installerpackagename, res);</strong></p></p><p><p><strong>6.privatepackageparser.package scanpackageli (file scanfile, file destcodefile, filedestresourcefile, Packageparser.package pkg, intparseflags, int Scanmode)</strong></p></p><p><p><strong>The Scanpackageli process is the same as the application installation process at boot Time.</strong></p></p><p><p><strong>Iii. Installing from ADB tools</strong></p></p><p><p><strong>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)</strong></p></p><p><p><strong>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"</strong></p></p><p><p><strong>function Runinstall () to determine the parameters</strong></p></p><p><p><strong>"-l" ――install_forward_lock</strong></p></p><p><p><strong>"-r"--install_replace_existing</strong></p></p><p><p><strong>"-i"--installerpackagename</strong></p></p><p><p><strong>"-t"--install_allow_test</strong></p></p><p><p><strong>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.</strong></p></p><p><p><strong>Runinstall and the market call the same interface to complete the application Installation.</strong></p></p><p><p><strong>Public voidinstallpackage (android.net.Uri packageuri,android.content.pm.ipackageinstallobserver observer, int Flags , Java.lang.String Installerpackagename)</strong></p></p><p><p><strong>Iv. third-party application Installation-install via apk file in SD card</strong></p></p><p><p><strong>To protect 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 in this way the installation and uninstall interface process,</strong></p></p><p><p><strong>Packageinstalleractivity is responsible for parsing the package to determine if the APK file is available</strong></p></p><p><p><strong>Create temporary installation files/data/data/com.android.packageinstaller/files/apidemos.apk</strong></p></p><p><p><strong>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.</strong></p></p><p><p><strong>After confirming the installation, start installappprogress and call the installation interface to complete the Installation.</strong></p></p><p><p><strong>Pm.installpackage (mpackageuri,observer, installflags);</strong></p></p><p><p><strong>Other:</strong></p></p><p><p><strong>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.</strong></p></p><p><p><strong>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.</strong></p></p><p><p>"android App development"-(9) Application safety loading principle</p></p></span>

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.