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

Commit 6761a39c authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] remove mRemovedAppId in PackageRemovedInfo

This CL should be a no-op.

This field is only used to indicate whether we should send
Intent.ACTION_UID_REMOVED broadcast. Its name is confusing and can lead
to misusages where the appId is sent when the UID is supposed to be sent.

Delete this field and replace it with a boolean. Make sure mUid is set
properly which will be used for broadcasts.

BUG: 314207341
Test: atest CtsPackageManagerTest
Test: atest android.content.pm.cts.PackageManagerShellCommandMultiUserTest#testPackageRemovedBroadcastsMultiUser

Change-Id: I63483028d76a7c0a29caff82232b4cd413c10365
parent a13d4326
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -837,13 +837,11 @@ public final class BroadcastHelper {
        }

        final String removedPackage = packageRemovedInfo.mRemovedPackage;
        final int removedAppId = packageRemovedInfo.mRemovedAppId;
        final int uid = packageRemovedInfo.mUid;
        final String installerPackageName = packageRemovedInfo.mInstallerPackageName;
        final SparseArray<int[]> broadcastAllowList = packageRemovedInfo.mBroadcastAllowList;

        Bundle extras = new Bundle(2);
        extras.putInt(Intent.EXTRA_UID, removedAppId >= 0 ? removedAppId : uid);
        extras.putInt(Intent.EXTRA_UID, packageRemovedInfo.mUid);
        extras.putBoolean(Intent.EXTRA_REPLACING, true);
        sendPackageBroadcastAndNotify(Intent.ACTION_PACKAGE_ADDED, removedPackage, extras,
                0, null /*targetPackage*/, null, null, null, broadcastAllowList, null);
@@ -888,8 +886,6 @@ public final class BroadcastHelper {
            boolean removedBySystem,
            boolean isArchived) {
        final String removedPackage = packageRemovedInfo.mRemovedPackage;
        final int removedAppId = packageRemovedInfo.mRemovedAppId;
        final int uid = packageRemovedInfo.mUid;
        final String installerPackageName = packageRemovedInfo.mInstallerPackageName;
        final int[] broadcastUserIds = packageRemovedInfo.mBroadcastUsers;
        final int[] instantUserIds = packageRemovedInfo.mInstantUserIds;
@@ -902,8 +898,7 @@ public final class BroadcastHelper {
        final boolean isStaticSharedLib = packageRemovedInfo.mIsStaticSharedLib;

        Bundle extras = new Bundle();
        final int removedUid = removedAppId >= 0  ? removedAppId : uid;
        extras.putInt(Intent.EXTRA_UID, removedUid);
        extras.putInt(Intent.EXTRA_UID, packageRemovedInfo.mUid);
        extras.putBoolean(Intent.EXTRA_DATA_REMOVED, dataRemoved);
        extras.putBoolean(Intent.EXTRA_SYSTEM_UPDATE_UNINSTALL, isRemovedPackageSystemUpdate);
        extras.putBoolean(Intent.EXTRA_DONT_KILL_APP, !killApp);
@@ -940,10 +935,10 @@ public final class BroadcastHelper {
                sendPackageBroadcastAndNotify(Intent.ACTION_PACKAGE_FULLY_REMOVED,
                        removedPackage, extras, Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND, null,
                        null, broadcastUserIds, instantUserIds, broadcastAllowList, null);
                packageSender.notifyPackageRemoved(removedPackage, removedUid);
                packageSender.notifyPackageRemoved(removedPackage, packageRemovedInfo.mUid);
            }
        }
        if (removedAppId >= 0) {
        if (packageRemovedInfo.mIsAppIdRemoved) {
            // If a system app's updates are uninstalled the UID is not actually removed. Some
            // services need to know the package name affected.
            if (isReplace) {
+5 −1
Original line number Diff line number Diff line
@@ -510,7 +510,10 @@ final class DeletePackageHelper {
            }
            if (clearPackageStateAndReturn) {
                mRemovePackageHelper.clearPackageStateForUserLIF(ps, userId, flags);
                outInfo.mRemovedAppId = ps.getAppId();
                // Legacy behavior to report appId as UID here.
                // The final broadcasts will contain a per-user UID.
                outInfo.mUid = ps.getAppId();
                outInfo.mIsAppIdRemoved = true;
                mPm.scheduleWritePackageRestrictions(user);
                return;
            }
@@ -555,6 +558,7 @@ final class DeletePackageHelper {
            boolean deleteCodeAndResources, int flags, @NonNull int[] allUserHandles,
            @NonNull PackageRemovedInfo outInfo, boolean writeSettings) {
        synchronized (mPm.mLock) {
            // Since the package is being deleted in all users, report appId as the uid
            outInfo.mUid = ps.getAppId();
            outInfo.mBroadcastAllowList = mPm.mAppsFilter.getVisibilityAllowList(
                    mPm.snapshotComputer(), ps, allUserHandles,
+2 −1
Original line number Diff line number Diff line
@@ -2910,7 +2910,8 @@ final class InstallPackageHelper {
                info.mInstallerPackageName = request.getInstallerPackageName();
                info.mRemovedUsers = firstUserIds;
                info.mBroadcastUsers = firstUserIds;
                info.mRemovedAppId = request.getAppId();
                info.mUid = request.getAppId();
                info.mIsAppIdRemoved = true;
                info.mRemovedPackageVersionCode = request.getPkg().getLongVersionCode();
                info.mRemovedForAllUsers = true;

+2 −1
Original line number Diff line number Diff line
@@ -818,7 +818,8 @@ final class InstallRequest {

    public void setRemovedAppId(int appId) {
        if (mRemovedInfo != null) {
            mRemovedInfo.mRemovedAppId = appId;
            mRemovedInfo.mUid = appId;
            mRemovedInfo.mIsAppIdRemoved = true;
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ final class PackageRemovedInfo {
    String mRemovedPackage;
    String mInstallerPackageName;
    int mUid = -1;
    int mRemovedAppId = -1;
    boolean mIsAppIdRemoved = false;
    int[] mOrigUsers;
    int[] mRemovedUsers = null;
    int[] mBroadcastUsers = null;
Loading