如何理解Android应用被安装PackageManagerService [英] Understanding how android app is installed by PackageManagerService

本文介绍了如何理解Android应用被安装PackageManagerService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直四处AOSP试图找出如何安装一个Android应用程序。到目前为止,这是我在哪里:

So I've been digging around AOSP trying to figure out how an android app is installed. So far this is where I'm at:

APK文件将从PackageInstallerActivity发送到InstallAppProgress它调用软件包管理系统方法的 installPackage()。

The apk File will be sent from PackageInstallerActivity to InstallAppProgress where it invokes the PackageManager method installPackage().

在previous调用软件包管理系统被定向到PackageManagerService,与AIDL的魔力(花了一些时间让我明白这一点)。

The previous call to PackageManager gets directed to the PackageManagerService, with the magic of AIDL (took some time for me to understand this).

在核心方法的 installPackageWithVerification()的PackageHandler的一个实例被创建和消息传递发生在一个可靠的方法与一群身份codeS一样INIT_COPY,PACKAGE_VERIFIED的用法等等。

In the core method installPackageWithVerification() an instance of the PackageHandler gets created and the message passing takes place in a robust way with the usage of a bunch of status codes like INIT_COPY, PACKAGE_VERIFIED etc.

根据状态$ C $在处理程序接收的消息的CS的OPS发生。若要启动 INIT_COPY - 增加了包挂起安装列表和code调用消息 MCS_BOUND

Based on the status codes of the messages received in the Handler the ops takes place. To start of with INIT_COPY - adds the package to the list of pending installs and invokes message with code MCS_BOUND.

这将复制类似的数据文件中的APK文件中提取的基本文件。

This copies the basic files extracted from the apk files like the data files.

和在车道某处带有标志消息的 CHECK_PENDING_VERIFICATION ,这需要包从待定名单解析条目,尤其是AndroidManifest文件。检查和确认的东西像包签名的packageName等等等等。

And somewhere down in the lane come the message with flag CHECK_PENDING_VERIFICATION, which takes the package from the pending list parses the entries, especially the AndroidManifest file. Verifies and validates stuff like package signature, packageName etc etc.

然后呼叫为 updateSettingLI()发这反过来又使3更重要的功能最终调用

Then a call is made to updateSettingLI() which in turn makes 3 more important function calls eventually.


  • moveDexFilesL​​I()

  • setPermissionsLI() - 提取DIR RES /文件,resources.arsc,的Manifest.xml

  • updatePermissionsLPw() - 电话grantPermissionLPw - 并增加了从清单文件解析的权限的组识别

  • moveDexFilesLI()
  • setPermissionsLI() - extracts dir res/ files, resources.arsc, Manifest.xml
  • updatePermissionsLPw() - calls grantPermissionLPw - and adds the groupids of the permissions parsed from the manifest file

在这一点上的时间包对象具有各自的组识别所以一直到现在我能找出权限被基本上如何转变为组识别。原谅我的言论,我想这可能是有人dubugging PackageManagerService,尤其是scanPackageLI方法很容易迷失在code有用。

At this point of time the Package object has the respective groupids so until now I was able to figure out basically how Permissions gets transformed into groupids. Pardon my rant, I thought this might be useful for someone dubugging PackageManagerService, especially the scanPackageLI method it is easy to get lost in code.

现在的实际问题,我象征性地在android系统知道每个应用程序是什么,但有自己的UID和GID控制Linux进程。我们拥有的GID从上面我想知道如何从PackageManagerService这个被转换到Linux的过程。

Now the actual question, I know figuratively in android each app is nothing but a linux process controlled with its own uid and gids. We have the gids from the above I want to know how from the PackageManagerService this gets transformed to a linux process.

我知道INSTALLD也起着在安装过程中的关键作用。 但是我无法找到那里的权限或访问权限(根据Linux的teminology)设置为包的链接(在Linux进程)正在安装?

I know "installd" also plays a crucial role in the install process. But I was unable to find the link where the permissions or access rights (according to linux teminology) is set for the package (process in linux) being installed?

请帮助我。

推荐答案

非常好的问题。但要找到回答你的问题,你需要考虑小幅另一个方向,即过程将开始。正如你可能知道的Andr​​oid有一个叫合子特殊工艺。这是一个pre-回暖过程中(即在内存中,已经有一些装载库),并从这个过程中所有Android进程分叉了。

Very good question. But to find the answer to your question you need to look into slightly another direction, namely start of processes. As you may know in Android there is a special process called Zygote. This is a pre-warmed process (meaning that in its memory there are already some libraries loaded) and from this process all Android processes are forked off.

当你启动应用程序,Android系统通过套接字发送命令到受精卵创建一个新的进程。在这个命令也被分配给基于权限的应用程序的GID被发送。受精卵创造了一个新的进程后,它setgid程序传递导报。因此,派生进程接收其UID和GID。但这个过程只对权限,它们映射到相关的GID

When you start an application, Android system sends a command through a socket to Zygote to create a new process. Within this command also a set of gids assigned to the application based on permissions is sent. After Zygote has created a new process it setgid the passed gids. Thus, the forked process receives its uid and gids. But this process only relevant for permissions, which are mapped onto gids.

这篇关于如何理解Android应用被安装PackageManagerService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆