diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index 2a0b44d43bd7d..70bd24ce20a22 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -2619,11 +2619,29 @@ final class InstallPackageHelper { } } + Bundle extras = new Bundle(); + extras.putInt(Intent.EXTRA_UID, request.getUid()); + if (update) { + extras.putBoolean(Intent.EXTRA_REPLACING, true); + } + extras.putInt(PackageInstaller.EXTRA_DATA_LOADER_TYPE, dataLoaderType); + + // If a package is a static shared library, then only the installer of the package + // should get the broadcast. + if (installerPackageName != null + && request.getPkg().getStaticSharedLibraryName() != null) { + mPm.sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName, + extras, 0 /*flags*/, + installerPackageName, null /*finishedReceiver*/, + request.getNewUsers(), null /* instantUserIds*/, + null /* broadcastAllowList */, null); + } + // Send installed broadcasts if the package is not a static shared lib. if (request.getPkg().getStaticSharedLibraryName() == null) { mPm.mProcessLoggingHandler.invalidateBaseApkHash(request.getPkg().getBaseApkPath()); - // Send added for users that see the package for the first time + // Send PACKAGE_ADDED broadcast for users that see the package for the first time // sendPackageAddedForNewUsers also deals with system apps int appId = UserHandle.getAppId(request.getUid()); boolean isSystem = request.getPkg().isSystem(); @@ -2631,13 +2649,9 @@ final class InstallPackageHelper { isSystem || virtualPreload, virtualPreload /*startReceiver*/, appId, firstUserIds, firstInstantUserIds, dataLoaderType); - // Send added for users that don't see the package for the first time - Bundle extras = new Bundle(); - extras.putInt(Intent.EXTRA_UID, request.getUid()); - if (update) { - extras.putBoolean(Intent.EXTRA_REPLACING, true); - } - extras.putInt(PackageInstaller.EXTRA_DATA_LOADER_TYPE, dataLoaderType); + // Send PACKAGE_ADDED broadcast for users that don't see + // the package for the first time + // Send to all running apps. final SparseArray newBroadcastAllowList; synchronized (mPm.mLock) { @@ -2650,8 +2664,8 @@ final class InstallPackageHelper { extras, 0 /*flags*/, null /*targetPackage*/, null /*finishedReceiver*/, updateUserIds, instantUserIds, newBroadcastAllowList, null); + // Send to the installer, even if it's not running. if (installerPackageName != null) { - // Send to the installer, even if it's not running. mPm.sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName, extras, 0 /*flags*/, installerPackageName, null /*finishedReceiver*/, diff --git a/services/core/java/com/android/server/pm/PackageRemovedInfo.java b/services/core/java/com/android/server/pm/PackageRemovedInfo.java index 3c863d080d79b..4cac1151136d8 100644 --- a/services/core/java/com/android/server/pm/PackageRemovedInfo.java +++ b/services/core/java/com/android/server/pm/PackageRemovedInfo.java @@ -111,12 +111,6 @@ final class PackageRemovedInfo { } private void sendPackageRemovedBroadcastInternal(boolean killApp, boolean removedBySystem) { - // Don't send static shared library removal broadcasts as these - // libs are visible only the apps that depend on them an one - // cannot remove the library if it has a dependency. - if (mIsStaticSharedLib) { - return; - } Bundle extras = new Bundle(); final int removedUid = mRemovedAppId >= 0 ? mRemovedAppId : mUid; extras.putInt(Intent.EXTRA_UID, removedUid); @@ -128,15 +122,22 @@ final class PackageRemovedInfo { extras.putBoolean(Intent.EXTRA_REPLACING, true); } extras.putBoolean(Intent.EXTRA_REMOVED_FOR_ALL_USERS, mRemovedForAllUsers); + + // Send PACKAGE_REMOVED broadcast to the respective installer. + if (mRemovedPackage != null && mInstallerPackageName != null) { + mPackageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, + mRemovedPackage, extras, 0 /*flags*/, + mInstallerPackageName, null, mBroadcastUsers, mInstantUserIds, null, null); + } + if (mIsStaticSharedLib) { + // When uninstalling static shared libraries, only the package's installer needs to be + // sent a PACKAGE_REMOVED broadcast. There are no other intended recipients. + return; + } if (mRemovedPackage != null) { mPackageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, mRemovedPackage, extras, 0, null /*targetPackage*/, null, mBroadcastUsers, mInstantUserIds, mBroadcastAllowList, null); - if (mInstallerPackageName != null) { - mPackageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, - mRemovedPackage, extras, 0 /*flags*/, - mInstallerPackageName, null, mBroadcastUsers, mInstantUserIds, null, null); - } mPackageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED_INTERNAL, mRemovedPackage, extras, 0 /*flags*/, PLATFORM_PACKAGE_NAME, null /*finishedReceiver*/, mBroadcastUsers, mInstantUserIds,