PackageManagerservice, mindmanager android

Source: Internet
Author: User

PackageManagerservice, mindmanager android

Source code: 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 uses a very important tool class,PackageParser. java.

Here are someTools and methodsTo assist PackageManagerService to complete some functions.

The following is an analysisHow to start PackageManagerService.

 

1. PackageManagerService hasStatic Method: main (). Generate an IPackageManager interface, that is, PackageManagerService. The following describes 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.ConstructorFirst, initialize some member variables, such as mContext, mFactoryTest, metrics RICS, and mSettings.
A. The most important thing is to initialize the mInstaller variable.. Installer is a very important class. All operations such as install, uninstall, and move on the apk are carried out through it.
Installer installer = new Installer ();
If (installer. ping () & Process. supportsProcesses ()){
MInstaller = installer;
} Else {
MInstaller = null;

}

 

B. Create a PackageHandler message loop,Used to process external apk installation request messages,For example, adb install, packageinstaller will send a message when installing apk
MHandlerThread. start ();
MHandler = new PackageHandler (mHandlerThread. getLooper ());

4. parse the xml file (Framework/base/data/etc/), Including platform. xml and feature of various hardware modules supported by the system.

Main Tasks:

(1) establishes a ing between the underlying user ids and group ids. 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 underlying users, for example, assign various permission permissions to shell, and assign a permission to a UID. When a process uses this UID to run, it has this permission.
(3) library. Some Applications added by the system must be linked to the extended jar library;

(4) feature: each time a hardware is added to the system, the corresponding feature must be added. put the parsing result in mSystemPermissions, mSharedLibraries, and mSettings. mPermissions, mAvailableFeatures, and other sets are used for system query and permission configuration.

 

5.Check whether/data/system/packages. xml exists,This file is created by writeLP () when parsing the apkWhich records the permissions of the system and the name, codePath, flags, ts, version, uesrid, and other information of each apk,This information is mainly used in the AndroidManifest. xml file of apk.After the apk is parsed, the updated information is written to this file and saved to flash. After the apk is parsed, relevant information is read from the file and added to the memory list at the next boot. This file is updated when an apk is upgraded, installed, or deleted.

6. Check the jar files in BootClassPath, mSharedLibraries, And/system/framework.
Whether dexopt is required. If so, dexopt is used for optimization.

7.Start the AppDirObserver thread Monitoring/system/framework,/system/app,/data/app,/data/app-private directoryEvents, mainlyListen to add and remove events. Inotify is a file system change notification mechanism for the underlying directory listening through the inotify mechanism. Events such as file addition and deletion can be immediately known to users, it provides powerful support for user State monitoring of file system changes.
ScanPackageLI (File, int, int) is called when an add event exists;
Call removePackageLI () for processing when a remove event exists;


8.For the apk under the above directories one by oneAnalysis, mainly to parse the AndroidManifest of each apk. process Resource files such as asset and res, create configuration structure information for each apk, and add configuration information for each apk to the global list for management. Call installer. install () to check whether the dex file in the apk needs to be optimized. If optimization is required, use the auxiliary tool dexopt for optimization; add the parsed componet to the corresponding pkg list;
Perform signature and certificate verification on the apk for integrity verification.

9. save the parsed apk information to packages. xml and packages. in the list file, packages. the list records the following data: pkgName, userId, debugFlag, and dataPath ).


How to find the specific implementation of the PackageManager class in the android source code?

Frameworks \ base \ core \ java \ android \ app \ ApplicationPackageManager. java
This file defines the ApplicationPackageManager class and inherits and implements interfaces in PackageManager;
ApplicationPackageManager uses the mPM variable, which is the client (IBinder object) of PackageManagerService and calls the method in the mPM object, actually, frameworks \ base \ services \ java \ com \ android \ server \ pm \ PackageManagerService is called. java File
.
This is the usage of the Binder in the Java layer.
The implementation of PackageManager can be found through grep-rnsw "extends PackageManager. You often need to use the grep command in Linux to find files.

Android PackageManagerhasSystemFeature () method is not used

Can it be specific?
Alt +/There is no way in the prompt: You have to set Automatic Filling
If the prompt "create" is displayed, you can use the hide method.
You can use Android Tools> fix project properties.


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.