The packagemanagerservice of the path of the Android master

Source: Internet
Author: User

SOURCE Location: Frameworks/base/core/java/android/content/pm/packageparser.java

Source file path:Android\frameworks\base\services\java\com\android\server\packagemanagerservice.java

1.packagemanagerservice.java used a very important tool class,Packageparser.java.

Here are some tools and tool methods that assist Packagemanagerservice to complete some functions.

The following analysis of the Packagemanagerservice start process .

There is a static method in 1.PackageManagerService: Main (). Generates a Ipackagemanager interface, which is packagemanagerservice. Below we mainly look at the construction method of Packagemanagerservice.
public static final Ipackagemanager main (context context, Boolean factorytest) {
Packagemanagerservice m = new Packagemanagerservice (context, factorytest);
Servicemanager.addservice ("package", m);
return m;
}

2. in the construction method , some member variables are initialized first, such as Mcontext, Mfactorytest, Mmetrics, msettings, etc.
A. The most important thing is to initialize the Minstaller variable . Installer is a very important class, all of the APK install, Uninstall,move, and so on, all through it.
Installer Installer = new Installer ();
if (installer.ping () && process.supportsprocesses ()) {
Minstaller = installer;
} else {
Minstaller = null;

}

B. Establish a Packagehandler message loop to process the external APK installation request message , such as when the ADB Install,packageinstaller installs the APK when the message is sent
Mhandlerthread.start ();
Mhandler = new Packagehandler (Mhandlerthread.getlooper ());

4. Parse the compiled system/etc/permission XML file (framework/base/data/etc/), including feature for Platform.xml and various hardware modules supported by the system.

Main work:

(1) Establish a mapping between the underlying user IDs and the group IDs with the upper permissions; You can specify a permission that corresponds to several group IDs. When an APK is granted this permission, it also belongs to these groups.
(2) Assign permissions to some of the underlying users, such as giving the shell various permission permissions, and assigning a permission to a UID, which is available when the process is running with this UID.
(3) Library, some applications of the system need link expansion jar library;

(4) feature, the system to add a hardware, the corresponding feature should be added. Put the parsing results in Msystempermissions,msharedlibraries,msettings.mpermissions, Mavailablefeatures and other collections for system query and permission configuration use.

5.Check if/data/system/packages.xml existsThis file was created by Writelp () when parsing the apk., which records the system's permissions, and the name of each APK, Codepath, Flags, TS, version, Uesrid and other information,This information is mainly via APK androidmanifest.xmlParse get, after parsing the APK to write the update information to this file and save to Flash, the next time the boot directly from the inside read related information added to the memory related list. This file will be updated when an APK is upgraded, installed or deleted.

6. Check the jar under Bootclasspath,msharedlibraries and/system/framework
If dexopt is needed, it needs to be optimized by dexopt

7.Start Appdirobserver threadmonitoring/system/framework,/system/app,/data/app,/data/app-private directoryThe events, mainlymonitoring the Add and remove events。 For the bottom of directory monitoring through the inotify mechanism, inotify is a file system change notification mechanism, such as file additions, deletions and other events can be immediately known to the user, it provides a strong support for the changes in the User Configuration monitoring file system.
Call Scanpackageli (File, int, int) to handle when there is an add event;
Call Removepackageli () processing when there is a remove event;


8.for each of the above directories, the APK is solved individuallyAnalysis, the main is to parse each apk androidmanifest.xml file, processing asset/res and other resource files, set up each APK configuration structure information, and add each APK configuration information to the global list for management. Call Installer.install () to install, check if the Dex file in the APK needs to be re-optimized, optimize with the aid dexopt if needed, and add the parsed componet to the corresponding list of pkg;
The APK is signed and the certificate is verified for integrity verification.

9. Save the information for each apk that is parsed to the Packages.xml and packages.list files, Packages.list records the following data: Pkgname,userid,debugflag,datapath (the packet's data path).

The packagemanagerservice of the path of the Android master

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.