Question

I've been trying to figure out how an android app is installed by browsing AOSP.

The PackageManagerService.java has the gids for the corresponding permissions by parsing the platform.xml file.

PackageInstallerActivity parses and checks for any existing packages and then invokes the InstallAppProgress.

I was able to follow the paths where the package is parsed and validated and PackagerManager.installPackage() method is invoked from InstallAppProgress.initView() to install the package. I know this makes a native call to the JNI library. The corresponding .aidl file is IPackageManager.aidl.

What I want to know is where can I find the implementation of the Stub (or Native code if any) related to this aidl mentioned above?

I'm new to aidl so that is the reason I'm not able to understand its nuances completely. Could somebody kindly point me to the right direction?

Was it helpful?

Solution

So AIDL files are there to define how the service and client talk to each other. They are important for system services because they need to handle multi threading, and there are lots of different apps that may want to talk to it. So IPackageManager.aidl is there to allow clients to communicate to PackageManager.

I took a look at InstallAppProgress.initView() and I don't see a specific call to native code. There is a call to PackageManager here:

pm.installPackageWithVerificationAndEncryption(mPackageURI, observer, installFlags,
                installerPackageName, verificationParams, null);

So to explain how this chain works, InstallAppProgress gets the PackageManager from context, which if you follow that chain leads to ContextImpl.getPackageManager() which you will see actually returns the ApplicationPackageManager which extends the abstract PackageManager class.

ApplicationPackageManager has a reference to the actual PackageManagerService which it calls through an interface, which is defined by the aidl file IPackageManager. The manager here is just controlling access to the service, and defining what is and is not actually accessible to the outside world. Apps can not normally get a handle to the PackageManagerService, IIRC it is possible to do so but you must have system privilleges.

To get a better explanation on what aidl files actually are, check out the page on the android site here: Android Interface Definition Language

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top