4

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?

frogatto
  • 28,539
  • 11
  • 83
  • 129
Adi GuN
  • 1,244
  • 3
  • 16
  • 38

1 Answers1

2

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

Andrew T.
  • 4,598
  • 4
  • 35
  • 54
  • Thank you for your comments. Now I seem to understand AIDL concept clearly. I wanted to know how an app installs completely in Android. Starting from packageManager I've reached uptil this point where a call goes to PackageManager Service through the above. Could you point me in a right direction from there? – Adi GuN Feb 24 '14 at 18:46
  • 2
    @AdiGuN It's fairly complicated to get into the specifics in PackageManagerService, but it mostly stays in there. installPackage chains into installPackageWithVerificationAndEncryption which sends a INIT_COPY message to mHandler, which adds the install to mPendingInstalls. Then it sends a MCS_BOUND message which gets handled and chains into params.startCopy() which is in HandleParams and that eventually chains to a InstallParams and handleStartCopy() and this is the chain of code that never ends, for it goes on and on my friend. – Andrew T. Feb 24 '14 at 22:09
  • Thank you Andrew for the clarification. I totally agree with you. As a matter of fact I was just doing through the PackageHandler class and I did come across all the elements that you mentioned above. I can be more specific in my question, "I want to know how the permissions are set to an app during installation process in android". How the permissions in the AndroidManifest.xml are transformed to linux uid's or gid's. – Adi GuN Feb 24 '14 at 23:10
  • I can see that in the handleStartCopy(), copyApk() is invoked which sets the permissions using FileUtils.setPermission() but I'm not sure if this is the one related to grabbing app permissions and transforming them into gid's. If so I couldn't find the link. I hope you understand my predicament. – Adi GuN Feb 24 '14 at 23:13
  • @AdiGuN to be honest I am not sure, but it is a good question. I would raise it on Stack Overflow as a seperate question, you might get some better answers that way. – Andrew T. Feb 25 '14 at 07:39
  • Thanks. Appreciate your help! – Adi GuN Feb 25 '14 at 18:52
  • posted this question.! http://stackoverflow.com/questions/22025935/understanding-how-android-app-is-installed-by-packagemanagerservice – Adi GuN Feb 25 '14 at 20:54