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

Commit 13dae678 authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] set installed=false after DELETE_KEEP_DATA on single user

BUG: 288142708
Test: atest
android.content.pm.cts.PackageManagerTest#testUninstallWithKeepData

Change-Id: I2f273986e3f19af84e2ed961dfe4c71628db01b5
parent ed44123c
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static android.content.pm.PackageManager.DELETE_KEEP_DATA;
import static android.content.pm.PackageManager.DELETE_SUCCEEDED;
import static android.content.pm.PackageManager.MATCH_KNOWN_PACKAGES;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.PackageManagerService.DEBUG_COMPRESSION;
import static com.android.server.pm.PackageManagerService.DEBUG_REMOVE;
@@ -464,10 +463,7 @@ final class DeletePackageHelper {
                        if (DEBUG_REMOVE) Slog.d(TAG, "Still installed by other users");
                        clearPackageStateAndReturn = true;
                    } else {
                        // We need to set it back to 'installed' so the uninstall
                        // broadcasts will be sent correctly.
                        if (DEBUG_REMOVE) Slog.d(TAG, "Not installed by other users, full delete");
                        ps.setInstalled(true, userId);
                        mPm.mSettings.writeKernelMappingLPr(ps);
                        clearPackageStateAndReturn = false;
                    }
+15 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static android.os.incremental.IncrementalManager.isIncrementalPath;
import static android.os.storage.StorageManager.FLAG_STORAGE_CE;
import static android.os.storage.StorageManager.FLAG_STORAGE_DE;
import static android.os.storage.StorageManager.FLAG_STORAGE_EXTERNAL;

import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
import static com.android.server.pm.PackageManagerService.DEBUG_INSTALL;
import static com.android.server.pm.PackageManagerService.DEBUG_REMOVE;
@@ -400,6 +399,21 @@ final class RemovePackageHelper {
                        changedUsers);
                mPm.postPreferredActivityChangedBroadcast(UserHandle.USER_ALL);
            }
        } else if (!deletedPs.isSystem() && outInfo != null && !outInfo.mIsUpdate
                && outInfo.mRemovedUsers != null) {
            // For non-system uninstalls with DELETE_KEEP_DATA, set the installed state to false
            // for affected users. This does not apply to app updates where the old apk is replaced
            // but the old data remains.
            if (DEBUG_REMOVE) {
                Slog.d(TAG, "Updating installed state to false because of DELETE_KEEP_DATA");
            }
            for (int userId : outInfo.mRemovedUsers) {
                if (DEBUG_REMOVE) {
                    final boolean wasInstalled = deletedPs.getInstalled(userId);
                    Slog.d(TAG, "    user " + userId + ": " + wasInstalled + " => " + false);
                }
                deletedPs.setInstalled(/* installed= */ false, userId);
            }
        }
        // make sure to preserve per-user installed state if this removal was just
        // a downgrade of a system app to the factory package