Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Android app upgrades work technically?

Can someone explain or point out resources where I can read how Android app upgrades actually work on an OS level of detail?

like image 918
Ankit Garg Avatar asked May 14 '15 16:05

Ankit Garg


People also ask

How do Android app updates work?

The developer publishes a new version (4.0). The 90-day period ends, the app is added to the update queue and will be automatically updated according to the default update behavior, once the constraints are met. The constraints are met and therefore the app is updated to the latest available version (4.0).

What happens during app update?

When your users keep your app up to date on their devices, they can try new features, as well as benefit from performance improvements and bug fixes.

Can an app force an update?

Developers can force users to update, say with a full-screen blocking message, force-install the update in the background and restart the app when the download has completed or create their own custom update flows.


3 Answers

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

I'm not so sure if thats what you're after, but the best I could find was this.

The Package Manager API is is the responsible for managing installing, uninstalling, and upgrading APK files.

It calls the method "InstallPackage" with the 'uri', 'installFlags', 'observer', and 'InstallPackageName' parameters, it then starts the service named "package" that will actually install/upgrade it.

Package Manager Service runs in system_service process and install daemon (installd) runs as a native process. Both start at system boot time.

Overview of the process:

  • Waiting;
  • Add a package to the queue for the installation process;
  • Determine the appropriate location of the package installation;
  • Determine installation Install/Update new
  • Copy the APK file to a given directory;
  • Determine the UID of the app;
  • Request the installd daemon process;
  • Create the application directory and set permissions;
  • Extraction of dex code to the cache directory;
  • Reflect packages.list /system / data / packages.xml the latest packages status;
  • Broadcast to the system along with the name of the package the effect of the installation;
  • Intent.ACTION_PACKAGE_ADDED: If the package is new // ( Intent.ACTION_PACKAGE_REPLACED) If the package is updated Overview of the instalation/upgrade process

The package manager stores application information in three files, located in /data/system :

  1. packages.xml - With permissions that belong to the package
  2. packages.list - It is simply text file containing package name, user id, flag and data directory
  3. packages-stopped.xml : This file contains the package list which has stopped state. Stopped state applications cannot receive any broadcast.

The links to relevant source code for the package manager (and the package installer) are below:

Package Manager 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

Package installer

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

like image 148
Waldez Junior Avatar answered Sep 19 '22 00:09

Waldez Junior


From the package manager logs,it seems following steps are taken for upgrade:

1) Download the package at temporary location.

act=android.intent.action.PACKAGE_NEEDS_VERIFICATION dat=file:///data/app/vmdl1854135520.tmp typ=application/vnd.android.package-archive

2) Do package verification.

06-30 17:59:02.751 3701 3751 D PackageManager: [MSG] PACKAGE_VERIFIED: observer{237546897}

3) Rename the package.

06-30 17:59:03.361 3701 3751 D PackageManager: Renaming /data/app/vmdl1854135520.tmp to /data/app/com.vzw.hss.myverizon-1

4) Kill existing app

06-30 17:59:03.361 3701 3751 D PackageManager: !@killApplicatoin: 10031, replace sys pkg

5) Dexopt the apk

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: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}
like image 20
rupesh jain Avatar answered Sep 18 '22 00:09

rupesh jain


I can't find a good resource, but here's what I understand about the process.

APK's are stored in a private directory on the phone when they are installed. When an upgrade happens, the new APK is downloaded from the store, and then the old APK is replaced with the new one. The new AndroidManifest is parsed and installed as if it was a new installation, and checks for version, signing key, and etc. are done to make sure the upgrade is allowed. The actual application data is stored in a separate location and is not touched during the upgrade. If you change your database schema or something, you will need to migrate your data when you first launch.

like image 42
Jschools Avatar answered Sep 18 '22 00:09

Jschools