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

Commit b1fcb76c authored by John Wu's avatar John Wu
Browse files

Send the new UID along with ACTION_PACKAGE_REMOVED broadcast

Follow up of ag/16417696

Pass the new UID in the broadcast via a new Intent extra with the name
Intent.EXTRA_NEW_UID. This is necessary for many system components to
migrate data structures linked with the old UID to the new one.

Test: SharedUserMigrationTest#testDataMigration
Bug: 217762162
Change-Id: I24f6707cf0fa0ed5acf6836cb803ce96df6f78fc
parent c523daa4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10387,6 +10387,7 @@ package android.content {
    field public static final String EXTRA_LOCAL_ONLY = "android.intent.extra.LOCAL_ONLY";
    field public static final String EXTRA_LOCUS_ID = "android.intent.extra.LOCUS_ID";
    field public static final String EXTRA_MIME_TYPES = "android.intent.extra.MIME_TYPES";
    field public static final String EXTRA_NEW_UID = "android.intent.extra.NEW_UID";
    field public static final String EXTRA_NOT_UNKNOWN_SOURCE = "android.intent.extra.NOT_UNKNOWN_SOURCE";
    field public static final String EXTRA_ORIGINATING_URI = "android.intent.extra.ORIGINATING_URI";
    field public static final String EXTRA_PACKAGE_NAME = "android.intent.extra.PACKAGE_NAME";
+8 −0
Original line number Diff line number Diff line
@@ -5975,6 +5975,14 @@ public class Intent implements Parcelable, Cloneable {
     */
    public static final String EXTRA_PREVIOUS_UID = "android.intent.extra.PREVIOUS_UID";

    /**
     * Used as an optional int extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
     * intents to supply the new uid the package will be assigned.
     * This would only be set when a package is leaving sharedUserId in an upgrade, or when a
     * system app upgrade that had left sharedUserId is getting uninstalled.
     */
    public static final String EXTRA_NEW_UID = "android.intent.extra.NEW_UID";

    /**
     * @hide String array of package names.
     */
+15 −10
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public final class BroadcastHelper {
            int flags, String targetPkg, IIntentReceiver finishedReceiver,
            int[] userIds, boolean isInstantApp, @Nullable SparseArray<int[]> broadcastAllowList,
            @Nullable Bundle bOptions) {
        for (int id : userIds) {
        for (int userId : userIds) {
            final Intent intent = new Intent(action,
                    pkg != null ? Uri.fromParts(PACKAGE_SCHEME, pkg, null) : null);
            final String[] requiredPermissions =
@@ -119,27 +119,32 @@ public final class BroadcastHelper {
                intent.setPackage(targetPkg);
            }
            // Modify the UID when posting to other users
            int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
            if (uid > 0 && UserHandle.getUserId(uid) != id) {
                uid = UserHandle.getUid(id, UserHandle.getAppId(uid));
                intent.putExtra(Intent.EXTRA_UID, uid);
            final String[] uidExtraNames =
                    { Intent.EXTRA_UID, Intent.EXTRA_PREVIOUS_UID, Intent.EXTRA_NEW_UID };
            for (String name : uidExtraNames) {
                int uid = intent.getIntExtra(name, -1);
                if (uid >= 0 && UserHandle.getUserId(uid) != userId) {
                    uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
                    intent.putExtra(name, uid);
                }
            }
            if (broadcastAllowList != null && PLATFORM_PACKAGE_NAME.equals(targetPkg)) {
                intent.putExtra(Intent.EXTRA_VISIBILITY_ALLOW_LIST, broadcastAllowList.get(id));
                intent.putExtra(Intent.EXTRA_VISIBILITY_ALLOW_LIST,
                         broadcastAllowList.get(userId));
            }
            intent.putExtra(Intent.EXTRA_USER_HANDLE, id);
            intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | flags);
            if (DEBUG_BROADCASTS) {
                RuntimeException here = new RuntimeException("here");
                here.fillInStackTrace();
                Slog.d(TAG, "Sending to user " + id + ": "
                Slog.d(TAG, "Sending to user " + userId + ": "
                        + intent.toShortString(false, true, false, false)
                        + " " + intent.getExtras(), here);
            }
            mAmInternal.broadcastIntent(
                    intent, finishedReceiver, requiredPermissions,
                    finishedReceiver != null, id,
                    broadcastAllowList == null ? null : broadcastAllowList.get(id),
                    finishedReceiver != null, userId,
                    broadcastAllowList == null ? null : broadcastAllowList.get(userId),
                    bOptions);
        }
    }
+3 −1
Original line number Diff line number Diff line
@@ -591,7 +591,9 @@ final class DeletePackageHelper {
        if (outInfo != null) {
            // Delete the updated package
            outInfo.mIsRemovedPackageSystemUpdate = true;
            outInfo.mAppIdChanging = disabledPs.getAppId() != deletedPs.getAppId();
            if (disabledPs.getAppId() != deletedPs.getAppId()) {
                outInfo.mNewAppId = disabledPs.getAppId();
            }
        }

        if (disabledPs.getVersionCode() < deletedPs.getVersionCode()
+5 −4
Original line number Diff line number Diff line
@@ -930,9 +930,6 @@ final class InstallPackageHelper {
                                        + " in multi-package install request.");
                        return;
                    }
                    if (result.needsNewAppId()) {
                        request.mInstallResult.mRemovedInfo.mAppIdChanging = true;
                    }
                    if (!checkNoAppStorageIsConsistent(
                            result.mRequest.mOldPkg, result.mPkgSetting.getPkg())) {
                        // TODO: INSTALL_FAILED_UPDATE_INCOMPATIBLE is about incomptabible
@@ -946,6 +943,10 @@ final class InstallPackageHelper {
                    createdAppId.put(packageName, optimisticallyRegisterAppId(result));
                    versionInfos.put(result.mPkgSetting.getPkg().getPackageName(),
                            mPm.getSettingsVersionForPackage(result.mPkgSetting.getPkg()));
                    if (result.needsNewAppId()) {
                        request.mInstallResult.mRemovedInfo.mNewAppId =
                                result.mPkgSetting.getAppId();
                    }
                } catch (PackageManagerException e) {
                    request.mInstallResult.setError("Scanning Failed.", e);
                    return;
@@ -2573,7 +2574,7 @@ final class InstallPackageHelper {
        final int dataLoaderType = installArgs.mDataLoaderType;
        final boolean succeeded = res.mReturnCode == PackageManager.INSTALL_SUCCEEDED;
        final boolean update = res.mRemovedInfo != null && res.mRemovedInfo.mRemovedPackage != null;
        final int previousAppId = (res.mRemovedInfo != null && res.mRemovedInfo.mAppIdChanging)
        final int previousAppId = (res.mRemovedInfo != null && res.mRemovedInfo.mNewAppId >= 0)
                ? res.mRemovedInfo.mUid : Process.INVALID_UID;
        final String packageName = res.mName;
        final PackageStateInternal pkgSetting =
Loading