From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Ivan Chiang Date: Mon, 18 Mar 2024 02:46:56 +0000 Subject: [PATCH] Send ACTION_PACKAGE_CHANGED when mimeGroups are changed Test: atest CtsPackageManagerTestCases:PackageManagerShellCommandMultiUserTest Test: atest CtsPackageManagerTestCases:PackageManagerTest Bug: 297517712 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:2c0dff90d63674ee0d098219b88f2e01a0ab4612) Merged-In: I271a3526ea4555249e3a2797605269257330e0e9 Change-Id: I271a3526ea4555249e3a2797605269257330e0e9 --- .../server/pm/PackageManagerService.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 1f6c113969c0..819a1437a4f1 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -25877,10 +25877,20 @@ public class PackageManagerService extends IPackageManager.Stub } } - private void applyMimeGroupChanges(String packageName, String mimeGroup) { + private void applyMimeGroupChanges(String packageName, String mimeGroup, + List packageUids) { if (mComponentResolver.updateMimeGroup(packageName, mimeGroup)) { - Binder.withCleanCallingIdentity(() -> - clearPackagePreferredActivities(packageName, UserHandle.USER_ALL)); + Binder.withCleanCallingIdentity(() -> { + clearPackagePreferredActivities(packageName, UserHandle.USER_ALL); + // Send the ACTION_PACKAGE_CHANGED when the mimeGroup has changes + final ArrayList components = new ArrayList<>( + Collections.singletonList(packageName)); + final String reason = "The mimeGroup is changed"; + for (int i = 0; i < packageUids.size(); i++) { + sendPackageChangedBroadcast(packageName, true /* dontKillApp */, + components, packageUids.get(i), reason); + } + }); } mPmInternal.writeSettings(false); @@ -25891,8 +25901,20 @@ public class PackageManagerService extends IPackageManager.Stub boolean changed = mSettings.mPackages.get(packageName) .setMimeGroup(mimeGroup, mimeTypes); + final List packageUids = new ArrayList(); + final PackageSetting ps = mSettings.getPackageLPr(packageName); + if (changed) { + final int appId = ps.appId; + final int[] userIds = resolveUserIds(UserHandle.USER_ALL); + for (int i = 0; i < userIds.length; i++) { + final int userId = userIds[i]; + if (ps.getInstalled(userId)) { + packageUids.add(UserHandle.getUid(userId, appId)); + } + } + } if (changed) { - applyMimeGroupChanges(packageName, mimeGroup); + applyMimeGroupChanges(packageName, mimeGroup, packageUids); } }