From 0ed20c5891f51b54c4284661b2b10c1ce5bc008a Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Mon, 17 Jul 2023 15:18:01 -0700 Subject: [PATCH] [pm] fix loading progress race condition during incremental app migration When an incremental app is migrated to non-incremental through an app update, there is a small chance of race conditioning on the loading progress update. The loading progress is stored in PackageSetting. The new app's PackageSetting is created before the old package's loading progress callback is destroyed, which happens when the old directory is deleted. So there's a small chance that the old package's loading progress callback updates the new package's package setting with an outdated loading progress. As a result, as observed in the test, the new package setting should have a loading progress of 1, but there is a 3% chance that it is set to the old loading progress which is 0.3. To prevent this, we add a restriction on the value of loading progress so that it will never go down. BUG: 288323351 Test: atest com.android.tests.loadingprogress.host.IncrementalLoadingProgressTest#testGetLoadingProgressDuringMigration --iterations 100 Change-Id: Ie5a5a56ba4eb211b83db8d1d5dbcb179610eb1d9 --- .../core/java/com/android/server/pm/PackageSetting.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageSetting.java b/services/core/java/com/android/server/pm/PackageSetting.java index 9b926973945c3..494709c17e066 100644 --- a/services/core/java/com/android/server/pm/PackageSetting.java +++ b/services/core/java/com/android/server/pm/PackageSetting.java @@ -1195,8 +1195,11 @@ public class PackageSetting extends SettingBase implements PackageStateInternal } public PackageSetting setLoadingProgress(float progress) { - mLoadingProgress = progress; - onChanged(); + // To prevent race conditions, we don't allow progress to ever go down + if (mLoadingProgress < progress) { + mLoadingProgress = progress; + onChanged(); + } return this; }