Android framework -- packagemanager framework

Source: Internet
Author: User

1. Next, let's talk about the activitymanager framework mentioned above. Next, let's talk about another important system framework, packagermanager.
Let's take a look at the static class structure:

In most cases, we use the getpackagemanager method in the activity to obtain an applicationpackagemanager object. applicationpackagemanager actually encapsulates an ipackagemanager. stub. Proxy object.
The ipackagemanager. stub. Proxy proxy executes packagemanager-related operations. The actual proxy of ipackagemanager. stub. Proxy is packagemanagerservice,
2. After reading the above, you may be dizzy. Let's repeat it:
The ipackagemanager is generated through the ipackagemanager. aidl file, and the ipackagemanager. stub is generated, and the proxy class is ipackagemanager. stub. Proxy.
This is the basic framework for packagemanager process communication. As I mentioned in the previous blog, I will not add more details.
Then packagemanagerservice inherits ipackagemanager. stub, which is the actual executor of packagemanager action and exists in system_process.
The applicationpackagemanager in our user application first describes how it is obtained:
Contextimpl. Java has a method:
Public packagemanager getpackagemanager (){
If (mpackagemanager! = NULL ){
Return mpackagemanager;
}

Ipackagemanager PM = activitythread. getpackagemanager ();
If (PM! = NULL ){
// Doesn' t matter if we make more than one instance.
Return (mpackagemanager = new applicationpackagemanager (this, PM ));
}

Return NULL;
}
Applicationpackagemanager actually wraps an ipackagemanager object (ipackagemanager. stub. Proxy). When we call queryintentactivities, we actually execute it through the proxy object:
Public list <resolveinfo> queryintentactivities (intent,
Int flags ){
Try {
Return MPM. queryintentactivities (// MPM is the ipackagemanager. stub. Proxy object
Intent,
Intent. resolvetypeifneeded (mcontext. getcontentresolver ()),
Flags );
} Catch (RemoteException e ){
Throw new runtimeexception ("Package Manager has died", e );
}
}
After Process Communication, perform the following operations on packagemanagerservice:
3. Build and obtain packagemanagerservice
-- Build packagemanagerservice: When the system_process process is loaded, packagemanagerservice is built. The following code is contained in systemserver. serverthread. Run, which loads packagemanagerservice:
Slog. I (TAG, "Package Manager ");
PM = packagemanagerservice. Main (context,
Factorytest! = Systemserver. factory_test_off); // start packagemanagerservice
/// // /// Packagemanagerservice //////////////// //////////////////////////////////////// ///////////////////
Public static final ipackagemanager main (context, Boolean factorytest ){
Packagemanagerservice M = new packagemanagerservice (context, factorytest );
Servicemanager. addservice ("package", M );
Return m;
}
-- Obtain packagemanagerservice:
First look at the previous section in contextimpl. Java-> getpackagermanager:
Ipackagemanager PM = activitythread. getpackagemanager ();
/// // Activitythread ////////////////
Public static ipackagemanager getpackagemanager (){
If (spackagemanager! = NULL ){
// Slog. V ("packagemanager", "returning cur default =" + spackagemanager );
Return spackagemanager;
}
Ibinder B = servicemanager. getservice ("package ");
// Slog. V ("packagemanager", "default service binder =" + B );
Spackagemanager = ipackagemanager. stub. asinterface (B );
// Slog. V ("packagemanager", "default service =" + spackagemanager );
Return spackagemanager;
}
The service pakager obtained from servicemanager. The service is registered in servicemanager during the construction of. packagemanagerservice. The servicemanager mechanism has not been further understood.

Original article: http://blog.csdn.net/stonecao/article/details/6591454

Related Article

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.