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

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

Support leaving sharedUserId in PackageManagerService

This is part 2 of ag/15290670

- Return the proper error code when sharedUserId mismatches
- Update Settings.updatePackageSetting(...) to also handle the case when
  a package is leaving a shared UID group
- In Settings.updatePackageSetting(...), update PackageSettings with new
  SharedUserSetting so changes will be picked up during the commit stage
- Introduce new CTS test: CtsSharedUserMigrationTestCases

Test: atest CtsSharedUserMigrationTestCases
Bug: 179284822
Change-Id: Iaf984eed7fd45238b42020789b3b14e2dc4415be
parent 74217efd
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -28,8 +28,8 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
import static android.content.pm.PackageManager.INSTALL_FAILED_SESSION_INVALID;
import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE;
import static android.content.pm.PackageManager.INSTALL_FAILED_TEST_ONLY;
import static android.content.pm.PackageManager.INSTALL_FAILED_UID_CHANGED;
import static android.content.pm.PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE;
import static android.content.pm.PackageManager.INSTALL_REASON_DEVICE_RESTORE;
import static android.content.pm.PackageManager.INSTALL_REASON_DEVICE_SETUP;
@@ -1202,19 +1202,17 @@ final class InstallParams extends HandlerParams {
                    }

                    // Check for shared user id changes
                    String invalidPackageName = null;
                    if (!Objects.equals(oldPackage.getSharedUserId(),
                            parsedPackage.getSharedUserId())
                            // Don't mark as invalid if the app is trying to
                            // leave a sharedUserId
                            && parsedPackage.getSharedUserId() != null) {
                        invalidPackageName = parsedPackage.getPackageName();
                    }

                    if (invalidPackageName != null) {
                        throw new PrepareFailure(INSTALL_FAILED_SHARED_USER_INCOMPATIBLE,
                                "Package " + invalidPackageName + " tried to change user "
                                        + oldPackage.getSharedUserId());
                        throw new PrepareFailure(INSTALL_FAILED_UID_CHANGED,
                                "Package " + parsedPackage.getPackageName()
                                        + " shared user changed from "
                                        + (oldPackage.getSharedUserId() != null
                                        ? oldPackage.getSharedUserId() : "<nothing>")
                                        + " to " + parsedPackage.getSharedUserId());
                    }

                    // In case of rollback, remember per-user/profile install state
+5 −4
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE;
import static android.content.pm.PackageManager.INSTALL_FAILED_UID_CHANGED;
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
import static android.content.pm.PackageManager.UNINSTALL_REASON_UNKNOWN;
import static android.content.pm.PackageManager.UNINSTALL_REASON_USER_TYPE;
@@ -1040,14 +1040,15 @@ public final class Settings implements Watchable, Snappable {
            @Nullable Set<String> mimeGroupNames, @NonNull UUID domainSetId)
                    throws PackageManagerException {
        final String pkgName = pkgSetting.name;
        if (pkgSetting.sharedUser != sharedUser) {
        if (!Objects.equals(pkgSetting.sharedUser, sharedUser) && sharedUser != null) {
            PackageManagerService.reportSettingsProblem(Log.WARN,
                    "Package " + pkgName + " shared user changed from "
                    + (pkgSetting.sharedUser != null ? pkgSetting.sharedUser.name : "<nothing>")
                    + " to " + (sharedUser != null ? sharedUser.name : "<nothing>"));
            throw new PackageManagerException(INSTALL_FAILED_SHARED_USER_INCOMPATIBLE,
                    + " to " + sharedUser.name);
            throw new PackageManagerException(INSTALL_FAILED_UID_CHANGED,
                    "Updating application package " + pkgName + " failed");
        }
        pkgSetting.sharedUser = sharedUser;

        if (!pkgSetting.getPath().equals(codePath)) {
            final boolean isSystem = pkgSetting.isSystem();