有人可以解释或指出我可以阅读Android应用程序升级如何在操作系统细节级别上实际工作的资源吗?
3 回答
从包管理器日志中,似乎采取了以下步骤进行升级:
1)在临时位置下载包。
act=android.intent.action.PACKAGE_NEEDS_VERIFICATION dat=file:///data/app/vmdl1854135520.tmp typ=application/vnd.android.package-archive
2)做包装验证。
06-30 17:59:02.751 3701 3751 D PackageManager:[MSG] PACKAGE_VERIFIED:观察者{237546897}
3)重命名包。
06-30 17:59:03.361 3701 3751 D PackageManager:将 /data/app/vmdl1854135520.tmp 重命名为 /data/app/com.vzw.hss.myverizon-1
4)杀死现有的应用程序
06-30 17:59:03.361 3701 3751 D PackageManager: !@killApplicatoin: 10031, 替换 sys pkg
5) Dexopt apk
06-30 17:59:03.381 3701 3751 D PackageManager:在:/data/app/com.vzw.hss.myverizon-1/base.apk pkg=com.vzw.hss.myverizon isa=arm64 vmSafeMode=false 上运行 dexopt只解释=假
**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}
我找不到好的资源,但这是我对这个过程的理解。
APK 在安装时会存储在手机上的私有目录中。发生升级时,会从商店下载新的 APK,然后用新的 APK 替换旧的 APK。解析和安装新的 AndroidManifest,就好像它是新安装一样,并检查版本、签名密钥等以确保允许升级。实际的应用程序数据存储在单独的位置,并且在升级过程中不会被触及。如果您更改数据库架构或其他内容,则需要在首次启动时迁移数据。
来源:http: //java.dzone.com/articles/depth-android-package-manager
我不太确定这是否是你所追求的,但我能找到的最好的就是这个。
Package Manager API 负责管理安装、卸载和升级 APK 文件。
它使用“uri”、“installFlags”、“observer”和“InstallPackageName”参数调用方法“InstallPackage”,然后启动名为“package”的服务,该服务将实际安装/升级它。
包管理器服务在 system_service 进程中运行,安装守护进程(installd)作为本机进程运行。两者都在系统启动时启动。
流程概述:
- 等待;
- 将包添加到安装过程的队列中;
- 确定包安装的合适位置;
- 确定安装安装/更新新
- 将APK文件复制到给定目录;
- 确定应用的UID;
- 请求安装的守护进程;
- 创建应用目录并设置权限;
- 提取dex代码到缓存目录;
- 反映 packages.list /system/data/packages.xml 最新包状态;
- 将安装效果连同包名一起广播到系统;
- Intent.ACTION_PACKAGE_ADDED: 如果包是新的 // (Intent.ACTION_PACKAGE_REPLACED) 如果包是更新的
包管理器将应用程序信息存储在三个文件中,位于 /data/system :
- packages.xml - 具有属于包的权限
- packages.list - 它是一个简单的文本文件,包含包名、用户 ID、标志和数据目录
- packages-stopped.xml :此文件包含已停止状态的包列表。停止状态的应用程序无法接收任何广播。
包管理器(和包安装程序)的相关源代码的链接如下:
包安装程序