Android应用程序升级在技术上是如何工作的?

v8wbuo2f  于 2023-02-11  发布在  Android
关注(0)|答案(3)|浏览(164)

有人能解释或指出我可以阅读Android应用程序升级实际上是如何在操作系统层面上工作的资源吗?

wnvonmuf

wnvonmuf1#

从软件包管理器日志来看,似乎采取了以下步骤进行升级:
1)在临时位置下载程序包。
act=android.意图.操作.包_需要_验证数据=文件:///数据/应用程序/vmdl1854135520.tmp类型=应用程序/vnd.android.包-存档
2)进行 Package 验证。
06-30 17:59:02.751 3701 3751 D Package 经理:[MSG] Package _已验证:观察员{237546897}
3)重命名包。
06-30 17:59:03.361 3701 3751 D Package 经理:将/数据/应用程序/vmdl1854135520.tmp重命名为/数据/应用程序/com.vzw.hss.myverizon-1
4)终止现有应用程序
06-30 17:59:03.361 3701 3751 D Package 经理:!@ kill应用程序:10031,更换系统 Package
5)Dexopt的APK
06-30 17:59:03.381 3701 3751 D Package 经理:运行dexopt:/数据/应用程序/com.vzw.hss.myverizon-1/基础.apk Package =com.vzw.hss.myverizon伊萨= arm 64 vmSafeMode=假仅解释=假

**06-30 17:59:02.741  3701  3751 D PackageManager: [VERIFY] Found 1 verifiers for intent Intent { act=android.intent.action.PACKAGE_NEEDS_VERIFICATION dat=file:///data/app/vmdl1854135520.tmp** typ=application/vnd.android.package-archive flg=0x10000001 } with 0 optional verifiers
06-30 17:59:02.741  3701  3751 D PackageManager: [VERIFY] sendOrderedBroadcastToRequiredVerifier:
06-30 17:59:02.741  3701  3751 D PackageManager: PackageVerificationState{
06-30 17:59:02.741  3701  3751 D PackageManager:     verifier packages=com.android.vending(10034),
06-30 17:59:02.741  3701  3751 D PackageManager:     intent=Intent { act=android.intent.action.PACKAGE_NEEDS_VERIFICATION dat=file:///data/app/vmdl1854135520.tmp typ=application/vnd.android.package-archive flg=0x10000001 (has extras) }
06-30 17:59:02.741  3701  3751 D PackageManager:     others=28, false, false, false, false, false
06-30 17:59:02.741  3701  3751 D PackageManager: }
06-30 17:59:02.741  3701  3751 D PackageManager: remove MCS_UNBIND message and Posting MCS_UNBIND 10 secs later
06-30 17:59:02.751  3701  3701 D PackageManager: [VERIFY] onReceive for RequiredVerifier id=28
06-30 17:59:02.751  3701  3701 D PackageManager: [VERIFY] send delayed message for CHECK_PENDING_VERIFICATION after : 10000
06-30 17:59:02.751  3701  4589 D PackageManager: [VERIFY] verifyPendingInstall(28, VERIFICATION_ALLOW), uid=10034
06-30 17:59:02.751  3701  3751 D PackageManager: [MSG] PACKAGE_VERIFIED: observer{237546897}
06-30 17:59:02.751  3701  3751 D PackageManager: [VERIFY] PACKAGE_VERIFIED: 
06-30 17:59:02.751  3701  3751 D PackageManager: PackageVerificationState{
06-30 17:59:02.751  3701  3751 D PackageManager:     verifier packages=com.android.vending(10034),
06-30 17:59:02.751  3701  3751 D PackageManager:     intent=Intent { act=android.intent.action.PACKAGE_NEEDS_VERIFICATION dat=file:///data/app/vmdl1854135520.tmp typ=application/vnd.android.package-archive flg=0x10000001 cmp=com.android.vending/com.google.android.vending.verifier.PackageVerificationReceiver (has extras) }
06-30 17:59:02.751  3701  3751 D PackageManager:     others=28, false, false, false, false, false
06-30 17:59:02.751  3701  3751 D PackageManager: }
06-30 17:59:02.751  3701  3751 D PackageManager: [VERIFY] broadcastPackageVerified(28, VERIFICATION_ALLOW, file:///data/app/vmdl1854135520.tmp)
06-30 17:59:02.761  3701  3751 D PackageManager: /data/app/vmdl1854135520.tmp already staged; skipping copy
06-30 17:59:02.761  3701  3751 D PackageManager: remove MCS_UNBIND and Posting MCS_UNBIND
06-30 17:59:02.761  3701  3751 D PackageManager: [MSG] PROCESS_PENDING_INSTALL: observer{237546897}
06-30 17:59:02.761  3701  3751 D PackageManager: currentStatus{1}
06-30 17:59:02.761  3701  3751 D PackageManager: installPackageLI: path
06-30 17:59:03.321  3701  3751 W PackageManager: verifying app can be installed or not
**06-30 17:59:03.361  3701  3751 D PackageManager: Renaming /data/app/vmdl1854135520.tmp to /data/app/com.vzw.hss.myverizon-1**
**06-30 17:59:03.361  3701  3751 D PackageManager: replacePackageLI**
**06-30 17:59:03.361  3701  3751 D PackageManager: !@killApplicatoin: 10031, replace sys pkg**
06-30 17:59:03.371  3701  3751 W PackageManager: Trying to update system app code path from /system/priv-app/MyVerizon to /data/app/com.vzw.hss.myverizon-1
06-30 17:59:03.371  3701  3751 I PackageManager: scanFileNewer : com.vzw.hss.myverizon
**06-30 17:59:03.381  3701  3751 D PackageManager: Running dexopt on: /data/app/com.vzw.hss.myverizon-1/base.apk pkg=com.vzw.hss.myverizon isa=arm64 vmSafeMode=false interpret_only=false**
06-30 17:59:06.861  3701  3751 I PackageManager: do mInstaller.dexopt : 0
06-30 17:59:06.861  3701  3751 D PackageManager: Time to dexopt: 3.482 seconds
06-30 17:59:06.861  3701  3751 D PackageManager: !@killApplicatoin: 10031, update pkg
06-30 17:59:06.861  3701  3751 W PackageManager: Code path for pkg : com.vzw.hss.myverizon changing from /system/priv-app/MyVerizon to /data/app/com.vzw.hss.myverizon-1
06-30 17:59:06.861  3701  3751 W PackageManager: Resource path for pkg : com.vzw.hss.myverizon changing from /system/priv-app/MyVerizon to /data/app/com.vzw.hss.myverizon-1
06-30 17:59:06.961  3701  3751 D PackageManager: New package installed
06-30 17:59:06.971  3701  3751 I PackageManager: Un-granting permission android.permission.sec.ENTERPRISE_DEVICE_ADMIN from package com.samsung.mdmtest1 (protectionLevel=2 flags=0x89be44)
06-30 17:59:06.971  3701  3751 I PackageManager: Un-granting permission com.sec.enterprise.knox.permission.KNOX_ENTERPRISE_BILLING from package com.samsung.mdmtest1 (protectionLevel=2 flags=0x89be44)
06-30 17:59:07.141  3701  3751 D PackageManager: doPostInstall for uid{10031}
06-30 17:59:07.151  3701  3751 D PackageManager: [MSG] MCS_UNBIND
06-30 17:59:07.151  3701  3751 D PackageManager: [MSG] POST_INSTALL: observer{237546897}
06-30 17:59:07.151  3701  3751 D PackageManager:           Handling post-install for 29
06-30 17:59:07.661  3701  3751 D PackageManager: result of install: 1{237546897}
s5a0g9ez

s5a0g9ez2#

我找不到一个好的资源,但这里是我对这个过程的理解。
APK在安装时会存储在手机的私人目录中。升级时,会从存储中下载新APK,然后用新APK替换旧APK。新的AndroidManifest会像新安装一样进行解析和安装,并检查版本、签名密钥、和等等,以确保升级是允许的。实际的应用程序数据存储在一个单独的位置,在升级过程中不会被触及。如果您更改了数据库架构或其他内容,您将需要在首次启动时迁移数据。

z0qdvdin

z0qdvdin3#

来源:http://java.dzone.com/articles/depth-android-package-manager

我不知道你是不是在找这个,但我能找到的最好的就是这个。
软件包管理器API负责管理APK文件的安装、卸载和升级。
它使用“uri”、“installFlags”、“observer”和“InstallPackageName”参数调用方法“InstallPackage”,然后启动名为“package”的服务,该服务将实际安装/升级它。
程序包管理器服务在system_server进程中运行,安装守护进程(installd)作为本机进程运行。两者都在系统 Boot 时启动。
流程概述:

  • 等待;
  • 将程序包添加到安装过程的队列中;
  • 确定程序包安装的适当位置;
  • 确定安装安装/更新新
  • 将APK文件复制到给定目录;
  • 确定应用程序的UID;
  • 请求installd守护进程;
  • 创建应用程序目录并设置权限;
  • 将dex代码提取到该高速缓存目录;
  • 反映packages. list/system/data/packages.xml最新的包状态;
  • 将安装的效果与包的名称沿着广播到系统;
  • 意向行动_ Package _添加:如果软件包是新的//(Intent.ACTION_PACKAGE_REPLACED)如果软件包更新x1c 0d1x

软件包管理器将应用程序信息存储在位于/data/system中的三个文件中:

  1. packages.xml -具有属于包的权限
  2. list -它是一个简单的文本文件,包含包名、用户ID、标志和数据目录
  3. packages-stopped.xml -此文件包含已停止状态的包列表。处于停止状态的应用程序无法接收任何广播。
    包管理器(和包安装程序)的相关源代码链接如下:

程序包管理器https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/services/java/com/android/server/pm/Settings.java

https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/services/java/com/android/server/pm/PackageManagerService.java
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/android/content/pm/IPackageManager.aidl
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/services/java/com/android/server/pm/PackageSignatures.java
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/services/java/com/android/server/pm/PreferredActivity.java
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/services/java/com/android/server/PreferredComponent.java
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/android/content/IntentFilter.java
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/android/content/pm/PackageParser.java
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/android/content/pm/IPackageManager.aidl
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/services/java/com/android/server/pm/Installer.java
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/com/android/internal/app/IMediaContainerService.aidl
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java

程序包安装程序

https://android.googlesource.com/platform/packages/apps/PackageInstaller/+/47fe118e0178e9d72c98073ff588ee5cf353258e/src/com/android/packageinstaller/PackageInstallerActivity.java
https://android.googlesource.com/platform/packages/apps/PackageInstaller/+/47fe118e0178e9d72c98073ff588ee5cf353258e/src/com/android/packageinstaller/PackageUtil.java
https://android.googlesource.com/platform/packages/apps/PackageInstaller/+/47fe118e0178e9d72c98073ff588ee5cf353258e/src/com/android/packageinstaller/InstallAppProgress.java

相关问题