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

Commit 88ef6ed2 authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] stop sending broadcast from commitPackagesLocked()

Calling activity manager to send a broadcast from inside mPm.mLock can cause a deadlock.
We can postpone the broadcast till after the installation.

BUG: 210167312
Test: builds; will monitor TV CTS dashboard
Change-Id: Ia42d1db24d4f0f98b1fc6523a5a3a859bf7fdff5
parent 09076f0a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -508,6 +508,7 @@ final class DeletePackageHelper {
            outInfo.mRemovedAppId = ps.getAppId();
            outInfo.mRemovedUsers = userIds;
            outInfo.mBroadcastUsers = userIds;
            outInfo.mIsExternal = ps.isExternalStorage();
        }
    }

+12 −15
Original line number Diff line number Diff line
@@ -1663,6 +1663,7 @@ final class InstallPackageHelper {
                    final int userId = uninstalledUsers[i];
                    res.mRemovedInfo.mUninstallReasons.put(userId, ps.getUninstallReason(userId));
                }
                res.mRemovedInfo.mIsExternal = oldPackage.isExternalStorage();

                sysPkg = oldPackage.isSystem();
                if (sysPkg) {
@@ -1937,21 +1938,6 @@ final class InstallPackageHelper {
                        }
                    }
                    // Successfully deleted the old package; proceed with replace.

                    // If deleted package lived in a container, give users a chance to
                    // relinquish resources before killing.
                    if (oldPackage.isExternalStorage()) {
                        if (DEBUG_INSTALL) {
                            Slog.i(TAG, "upgrading pkg " + oldPackage
                                    + " is ASEC-hosted -> UNAVAILABLE");
                        }
                        final int[] uidArray = new int[]{oldPackage.getUid()};
                        final ArrayList<String> pkgList = new ArrayList<>(1);
                        pkgList.add(oldPackage.getPackageName());
                        mBroadcastHelper.sendResourcesChangedBroadcast(
                                false, true, pkgList, uidArray, null);
                    }

                    // Update the in-memory copy of the previous code paths.
                    PackageSetting ps1 = mPm.mSettings.getPackageLPr(
                            reconciledPkg.mPrepareResult.mExistingPackage.getPackageName());
@@ -2647,6 +2633,17 @@ final class InstallPackageHelper {

            // Send the removed broadcasts
            if (res.mRemovedInfo != null) {
                if (res.mRemovedInfo.mIsExternal) {
                    if (DEBUG_INSTALL) {
                        Slog.i(TAG, "upgrading pkg " + res.mRemovedInfo.mRemovedPackage
                                + " is ASEC-hosted -> UNAVAILABLE");
                    }
                    final int[] uidArray = new int[]{res.mRemovedInfo.mUid};
                    final ArrayList<String> pkgList = new ArrayList<>(1);
                    pkgList.add(res.mRemovedInfo.mRemovedPackage);
                    mBroadcastHelper.sendResourcesChangedBroadcast(
                            false, true, pkgList, uidArray, null);
                }
                res.mRemovedInfo.sendPackageRemovedBroadcasts(killApp, false /*removedBySystem*/);
            }

+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ final class PackageRemovedInfo {
    boolean mDataRemoved;
    boolean mRemovedForAllUsers;
    boolean mIsStaticSharedLib;
    boolean mIsExternal;
    // a two dimensional array mapping userId to the set of appIds that can receive notice
    // of package changes
    SparseArray<int[]> mBroadcastAllowList;
+1 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ final class RemovePackageHelper {
                    && deletedPkg.getStaticSharedLibName() != null;
            outInfo.populateUsers(deletedPs.queryInstalledUsers(
                    mUserManagerInternal.getUserIds(), true), deletedPs);
            outInfo.mIsExternal = deletedPs.isExternalStorage();
        }

        removePackageLI(deletedPs.getPackageName(), (flags & PackageManager.DELETE_CHATTY) != 0);