diff options
| author | 2023-11-02 10:25:37 +0000 | |
|---|---|---|
| committer | 2023-11-08 01:59:09 +0000 | |
| commit | 1e7589afb39cfe04f9f13a87e77a0ec479604a3f (patch) | |
| tree | 4c0044c26dc222d1c91896d59e19338c4916228d | |
| parent | 5ea095ca58eac7f5ae1011793f054ac2bebd81f8 (diff) | |
Fix deadlock between PackageManager and DisplayManager
UpdateOwnershipHelper#readUpdateOwnerDenyList calls getResources()
that will call getDisplayMetrics. In DisplayMetrics() that needs to
access a lock in DisplayManagerGlobal. When calling this method
inside mPm.mLock, it may trigger the deadlock between PackageManager
and DisplayManager.
To fix this issue, try to get the denylist in the handler thread and
outside the mPm.mLock.
Bug: 305615356
Test: manual. Add logs to make sure getResources() doesn't be called
inside mPm.mLock
Change-Id: I3dea7b1df6f115d7c1cffda6a9d51070a5d7dd80
| -rw-r--r-- | services/core/java/com/android/server/pm/InstallPackageHelper.java | 28 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/UpdateOwnershipHelper.java | 2 |
2 files changed, 20 insertions, 10 deletions
diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index a52870e17b16..f8d27f1bad1c 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -476,20 +476,30 @@ final class InstallPackageHelper { pkgSetting.setLoadingProgress(1f); } + // TODO: passes the package name as an argument in a message to the handler for V+ + // so we don't need to rely on creating lambda objects so frequently. + if (UpdateOwnershipHelper.hasValidOwnershipDenyList(pkgSetting)) { + mPm.mHandler.post(() -> handleUpdateOwnerDenyList(pkgSetting)); + } + return pkg; + } + + private void handleUpdateOwnerDenyList(PackageSetting pkgSetting) { ArraySet<String> listItems = mUpdateOwnershipHelper.readUpdateOwnerDenyList(pkgSetting); if (listItems != null && !listItems.isEmpty()) { - mUpdateOwnershipHelper.addToUpdateOwnerDenyList(pkgSetting.getPackageName(), listItems); - for (String unownedPackage : listItems) { - PackageSetting unownedSetting = mPm.mSettings.getPackageLPr(unownedPackage); - SystemConfig config = SystemConfig.getInstance(); - if (unownedSetting != null - && config.getSystemAppUpdateOwnerPackageName(unownedPackage) == null) { - unownedSetting.setUpdateOwnerPackage(null); + mUpdateOwnershipHelper.addToUpdateOwnerDenyList(pkgSetting.getPackageName(), + listItems); + SystemConfig config = SystemConfig.getInstance(); + synchronized (mPm.mLock) { + for (String unownedPackage : listItems) { + PackageSetting unownedSetting = mPm.mSettings.getPackageLPr(unownedPackage); + if (unownedSetting != null + && config.getSystemAppUpdateOwnerPackageName(unownedPackage) == null) { + unownedSetting.setUpdateOwnerPackage(null); + } } } } - - return pkg; } /** diff --git a/services/core/java/com/android/server/pm/UpdateOwnershipHelper.java b/services/core/java/com/android/server/pm/UpdateOwnershipHelper.java index 43752f31a1a2..adac68b25749 100644 --- a/services/core/java/com/android/server/pm/UpdateOwnershipHelper.java +++ b/services/core/java/com/android/server/pm/UpdateOwnershipHelper.java @@ -48,7 +48,7 @@ public class UpdateOwnershipHelper { private final Object mLock = new Object(); - private static boolean hasValidOwnershipDenyList(PackageSetting pkgSetting) { + static boolean hasValidOwnershipDenyList(PackageSetting pkgSetting) { AndroidPackage pkg = pkgSetting.getPkg(); // we're checking for uses-permission for these priv permissions instead of grant as we're // only considering system apps to begin with, so presumed to be granted. |