Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51187e18 authored by Sumedh Sen's avatar Sumedh Sen Committed by Android (Google) Code Review
Browse files

Merge "Send PACKAGE_ADDED and PACKAGE_REMOVED broadcasts to installer of static shared libs"

parents 1abfc04d 8ef8dd47
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -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<int[]> newBroadcastAllowList;
                synchronized (mPm.mLock) {
@@ -2650,8 +2664,8 @@ final class InstallPackageHelper {
                        extras, 0 /*flags*/,
                        null /*targetPackage*/, null /*finishedReceiver*/,
                        updateUserIds, instantUserIds, newBroadcastAllowList, null);
                if (installerPackageName != null) {
                // Send to the installer, even if it's not running.
                if (installerPackageName != null) {
                    mPm.sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName,
                            extras, 0 /*flags*/,
                            installerPackageName, null /*finishedReceiver*/,
+12 −11
Original line number Diff line number Diff line
@@ -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);
        if (mRemovedPackage != null) {
            mPackageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED,
                    mRemovedPackage, extras, 0, null /*targetPackage*/, null,
                    mBroadcastUsers, mInstantUserIds, mBroadcastAllowList, null);
            if (mInstallerPackageName != null) {

        // 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);
            mPackageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED_INTERNAL,
                    mRemovedPackage, extras, 0 /*flags*/, PLATFORM_PACKAGE_NAME,
                    null /*finishedReceiver*/, mBroadcastUsers, mInstantUserIds,