“怎么样"Android 应用程序(Facebook 等)安装到 android 手机? [英] "How are" Android applications (Facebook etc.) installed to an android phone?

查看:71
本文介绍了“怎么样"Android 应用程序(Facebook 等)安装到 android 手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何将应用程序安装到 Android 设备,例如从 Play-Store 或通过 .apk 文件.但我想了解实际安装过程.

I know how to install an application to an Android device e.g from Play-Store or via an .apk file. But I'd like to understand the actual process of installation.

例如在 Windows 上:

E.g. on Windows:

  • 序列号等放在注册表中
  • 对软件运行很重要的文件放在Program Files文件夹中(.exe)

到目前为止,我对 Android 应用程序安装过程的了解是:

So far, what I do know about the Android application installation process is:

  • Android 应用程序执行后(安装后),新下载的数据放置在以下位置:Android/dataAndroid/obb 等.

如果 Android 开发者明确表示,文件也可以放在其他地方,例如二级存储(存储卡、云存储等)

If specifically expressed by an Android developer, files can also be placed elsewhere e.g. on secondary storage (memory cards, cloud storage etc.)

但除此之外,我对 Android 安装过程的了解非常有限,例如:

But other than that, my knowledge concerning the Android installation process is pretty slim e.g.:

  • 我不知道与 Android 程序执行相关的重要文件放在哪里(在 Windows 的情况下,.exe、相关媒体、库等)

我同样不知道这些文件是如何在 Android 设备上构建的(安装后),例如这些文件是否在如下文件夹中结构化:javaresmenulayout 等.喜欢 Android Studio?

I similarly don't know how these files are structured upon an Android device (post-installation) e.g. are these files structured in folders like: java, res, menu, layout etc. as during development within environments like Android Studio?

我也不知道在安装后(从 android 安装文件或 apk 解压后)用户的设备上存储了哪些应用程序文件类型,例如它们是否存储为 .java 和或 .xml 文件,如在开发过程中等

Neither do I know how what application file-types are stored on a user's device post-installation (after being unpacked from the android installation file or apk) e.g. are they stored as .java and or .xml files, as during development etc.

希望有人能填空,谢谢.

Hopefully someone can fill in the blanks, thank you.

推荐答案

开始

PackageInstaller 调用 InstallAppProgress 活动以接收来自用户的指令.InstallAppProgress 会要求 PackageManager 服务通过 installd 安装包.源代码位于 /packages/apps/PackageInstaller.

PackageInstaller calls InstallAppProgress activity to receives an instruction from the user. InstallAppProgress will ask PackageManager Service to install package via installd. Source code is available at <Android Source>/packages/apps/PackageInstaller.

当我们安装APK文件时,包管理器解析包(APK)文件并显示确认,当用户按下OK按钮时,包管理器调用名为的方法installPackage 带有这四个参数,分别是uriinstallFlags、observer、installPackageName.包管理器启动了一个名为包"的服务,现在所有模糊的事情都发生在这个服务中.您可以在 PackageInstaller 源代码中查看 PackageInstallerActivity.javaInstallAppProgress.java.在 system_service 进程中运行的包管理器服务和作为本机进程运行的安装守护程序 (installd) 都在系统启动时启动.

When we install APK file, Package Manager parse the package(APK) file and display confirmation, When user press OK button, Package Manager call method named installPackage with these four parameters namely uri, installFlags, observer, installPackageName. Package Manager start one service named "package", now all fuzzy things happen in this service. you can check PackageInstallerActivity.java and InstallAppProgress.java in PackageInstaller source code. Package Manager Service running in system_service process and install daemon (installd) that runs as a native process both start at system boot time.

APK 文件在 Android 中的存储位置?

Where APK files stores in Android ?

  1. 预安装(即相机、日历、浏览器等)APK 存储在/system/app/
  2. 用户安装(ApiDemo、Any.do 等)APK 存储在 /data/app/
  3. Package Manager 创建数据目录 /data/data// 用于存储数据库、共享首选项、本机库和缓存数据
  1. Pre-Install (i.e. Camera, Calendar, Browser,etc.) APK stored in /system/app/
  2. User Install (ApiDemo, Any.do, etc.) APK stored in /data/app/
  3. Package Manager create data directory /data/data/<package name>/ to store database, shared preference, native library and cache data

对于同一个APK,你可能会看到apk文件和*.odex文件,ODEX文件是完全不同的讨论和目的.

You might see apk file and *.odex file for same APK, ODEX file is totally different discussion and purpose.

APK 安装过程详细是什么?

以下过程在Package Manager Service中执行.

  • 等待
  • 将一个包添加到安装过程的队列中
  • 确定软件包安装的适当位置
  • 确定安装安装/更新新的
  • 将 apk 文件复制到指定目录
  • 确定应用的 UID
  • 请求安装守护进程
  • 创建应用目录并设置权限
  • 提取dex代码到缓存目录
  • 反映和packages.list /system/data/packages.xml最新状态
  • 广播到系统连同安装完成包的效果Intent.ACTION_PACKAGE_ADDED:如果新的(Intent.ACTION_PACKAGE_REPLACED):更新的情况.
  • Waiting
  • Add a package to the queue for the installation process
  • Determine the appropriate location of the package installation
  • Determine installation Install / Update new
  • A copy of the apk file to a given directory
  • Determine the UID of the app
  • Request to installd daemon process
  • Create the application directory and set permissions
  • Extraction of dex code to the cache directory
  • To reflect and packages.list /system/data/packages.xml the latest status
  • Broadcast to the system along with the name of the effect of the installation is complete package Intent.ACTION_PACKAGE_ADDED: If the new ( Intent.ACTION_PACKAGE_REPLACED): the case of an update.

包管理器如何存储数据?

Package Manager 将应用程序信息存储在三个文件中,位于 /data/system.以下示例摘自 Android 4 ICS 模拟器图像.

Package Manager store application information in three files, located in /data/system. Following sample is extracted from Android 4 ICS emulator image.

packages.xml:此文件包含权限和包/应用程序列表.这个 xml 文件存储两件事 1. 权限 2. 包(应用程序),权限存储在 标签下.每个权限具有三个属性,即名称、包和保护.名称属性具有我们在 AndroidManifest.xml 中使用的权限名称,包属性表示权限属于包,在大多数情况下,android"是值,因为 标签包含默认权限和保护指示安全级别.

packages.xml:This file contain list of permissions and Packages/Applications. This xml file stores two things 1. permissions 2. package (application), permission are store under <permissions> tag. Each Permission has three attributes namely name, package and protection. Name attribute has permission name which we are using in AndroidManifest.xml, package attribute indicate permission belong to package, In majority cases "android" is values because <permission> tag contain default permissions and protection indicate level of security.

packages.list:它是一个简单的文本文件,包含包名、用户 ID、标志和数据目录,我找不到任何完美的描述,但我假设它packages.list 文件可以更快地查找已安装的包,因为它只保留重要信息.

packages.list: It is simple text file contain package name, user id, flag and data directory, I can't find any perfect description but I assume it that packages.list file may provide faster lookup of installed package because it file keep important information only.

com.android.launcher 10013 0 /data/data/com.android.launcher
com.android.quicksearchbox 10033 0 /data/data/com.android.quicksearchbox
com.android.contacts 10001 0 /data/data/com.android.contacts
com.android.inputmethod.latin 10006 0 /data/data/com.android.inputmethod.latin

packages-stoped.xml:此文件包含已停止状态的包列表,Stope 声明应用程序无法接收任何广播.

packages-stoped.xml: This file contain package list which has stopped state, Stope stated applications can not receive any broadcast.

在哪里可以找到包管理器和包安装器的源代码?

包管理器

frameworks/base/services/java/com/android/server/pm/Settings.java
frameworks/base/services/java/com/android/server/pm/PackageManagerService.java
frameworks/base/services/java/com/android/server/pm/IPackageManager.aidl
frameworks/base/services/java/com/android/server/pm/PackageSignatures.java
frameworks/base/services/java/com/android/server/pm/PreferredActivity.java
frameworks/services/java/com/android/server/PreferredComponent.java
frameworks/core/java/android/content/IntentFilter.java
frameworks/base/core/java/android/content/pm/PackageParser.java
frameworks/base/services/java/com/android/server/pm/Installer.java
frameworks/base/core/java/com/android/internal/app/IMediaContainerService.aidl
frameworks/base/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java

软件包安装程序

packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java.

参考链接:链接 1链接 2.

这篇关于“怎么样"Android 应用程序(Facebook 等)安装到 android 手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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