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

Commit 731c2307 authored by Ankita Vyas's avatar Ankita Vyas
Browse files

Add check to delete app in child only if present.

Also adds check to delete child package only when it was successfully
deleted in parent.

Bug: 272033649
Test: atest CtsScopedStorageDeviceOnlyTest
Change-Id: I57e936a2f52f12612d1d1095b76b72d495c9b3ec
parent aeba6853
Loading
Loading
Loading
Loading
+27 −17
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.pm;
import static android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
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 android.os.storage.StorageManager.FLAG_STORAGE_CE;
@@ -339,7 +340,7 @@ final class DeletePackageHelper {
            packageInstallerService.onInstallerPackageDeleted(uninstalledPs.getAppId(), removeUser);
        }

        return res ? PackageManager.DELETE_SUCCEEDED : PackageManager.DELETE_FAILED_INTERNAL_ERROR;
        return res ? DELETE_SUCCEEDED : PackageManager.DELETE_FAILED_INTERNAL_ERROR;
    }

    /*
@@ -777,24 +778,33 @@ final class DeletePackageHelper {
                    returnCode = deletePackageX(internalPackageName, versionCode,
                            userId, deleteFlags, false /*removedBySystem*/);

                    // Delete package in child only if successfully deleted in parent.
                    if (returnCode == DELETE_SUCCEEDED && packageState != null) {
                        // Get a list of child user profiles and delete if package is
                        // present in that profile.
                        int[] childUserIds = mUserManagerInternal.getProfileIds(userId, true);
                        int returnCodeOfChild;
                        for (int childId : childUserIds) {
                            if (childId == userId) continue;

                            // If package is not present in child then don't attempt to delete.
                            if (!packageState.getUserStateOrDefault(childId).isInstalled()) {
                                continue;
                            }

                            UserProperties userProperties = mUserManagerInternal
                                    .getUserProperties(childId);
                            if (userProperties != null && userProperties.getDeleteAppWithParent()) {
                                returnCodeOfChild = deletePackageX(internalPackageName, versionCode,
                                        childId, deleteFlags, false /*removedBySystem*/);
                            if (returnCodeOfChild != PackageManager.DELETE_SUCCEEDED) {
                                if (returnCodeOfChild != DELETE_SUCCEEDED) {
                                    Slog.w(TAG, "Package delete failed for user " + childId
                                            + ", returnCode " + returnCodeOfChild);
                                    returnCode = PackageManager.DELETE_FAILED_FOR_CHILD_PROFILE;
                                }
                            }
                        }
                    }
                } else {
                    int[] blockUninstallUserIds = getBlockUninstallForUsers(innerSnapshot,
                            internalPackageName, users);
@@ -809,7 +819,7 @@ final class DeletePackageHelper {
                            if (!ArrayUtils.contains(blockUninstallUserIds, userId1)) {
                                returnCode = deletePackageX(internalPackageName, versionCode,
                                        userId1, userFlags, false /*removedBySystem*/);
                                if (returnCode != PackageManager.DELETE_SUCCEEDED) {
                                if (returnCode != DELETE_SUCCEEDED) {
                                    Slog.w(TAG, "Package delete failed for user " + userId1
                                            + ", returnCode " + returnCode);
                                }