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

Commit 539a7ef5 authored by Alexandra Gherghina's avatar Alexandra Gherghina
Browse files

Removes cross profile package information when removing an user

This makes sure that if the user id gets reassigned without restarting the phone,
we do not have old information from the preexisting profile.

Also renames method which needs write locks.

Bug: 15928463
Change-Id: I30b0f85cf90d3e0c289a37bcbaec8da63499a170
parent 4143bc5f
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -13025,7 +13025,7 @@ public class PackageManagerService extends IPackageManager.Stub {
    /** Called by UserManagerService */
    /** Called by UserManagerService */
    void cleanUpUserLILPw(int userHandle) {
    void cleanUpUserLILPw(int userHandle) {
        mDirtyUsers.remove(userHandle);
        mDirtyUsers.remove(userHandle);
        mSettings.removeUserLPr(userHandle);
        mSettings.removeUserLPw(userHandle);
        mPendingBroadcasts.remove(userHandle);
        mPendingBroadcasts.remove(userHandle);
        if (mInstaller != null) {
        if (mInstaller != null) {
            // Technically, we shouldn't be doing this with the package lock
            // Technically, we shouldn't be doing this with the package lock
+23 −1
Original line number Original line Diff line number Diff line
@@ -3112,7 +3112,7 @@ final class Settings {
        writePackageRestrictionsLPr(userHandle);
        writePackageRestrictionsLPr(userHandle);
    }
    }


    void removeUserLPr(int userId) {
    void removeUserLPw(int userId) {
        Set<Entry<String, PackageSetting>> entries = mPackages.entrySet();
        Set<Entry<String, PackageSetting>> entries = mPackages.entrySet();
        for (Entry<String, PackageSetting> entry : entries) {
        for (Entry<String, PackageSetting> entry : entries) {
            entry.getValue().removeUser(userId);
            entry.getValue().removeUser(userId);
@@ -3123,6 +3123,7 @@ final class Settings {
        file = getUserPackagesStateBackupFile(userId);
        file = getUserPackagesStateBackupFile(userId);
        file.delete();
        file.delete();
        removeCrossProfileIntentFiltersToUserLPr(userId);
        removeCrossProfileIntentFiltersToUserLPr(userId);
        removeCrossProfilePackagesLPw(userId);
    }
    }


    void removeCrossProfileIntentFiltersToUserLPr(int targetUserId) {
    void removeCrossProfileIntentFiltersToUserLPr(int targetUserId) {
@@ -3144,6 +3145,27 @@ final class Settings {
        }
        }
    }
    }


    public void removeCrossProfilePackagesLPw(int userId) {
        synchronized(mCrossProfilePackageInfo) {
            // userId is the source user
            if (mCrossProfilePackageInfo.get(userId) != null) {
                mCrossProfilePackageInfo.remove(userId);
                writePackageRestrictionsLPr(userId);
            }
            // userId is the target user
            int count = mCrossProfilePackageInfo.size();
            for (int i = 0; i < count; i++) {
                int sourceUserId = mCrossProfilePackageInfo.keyAt(i);
                SparseArray<ArrayList<String>> sourceForwardingInfo =
                        mCrossProfilePackageInfo.valueAt(i);
                if (sourceForwardingInfo.get(userId) != null) {
                    sourceForwardingInfo.remove(userId);
                    writePackageRestrictionsLPr(sourceUserId);
                }
            }
        }
    }

    // This should be called (at least) whenever an application is removed
    // This should be called (at least) whenever an application is removed
    private void setFirstAvailableUid(int uid) {
    private void setFirstAvailableUid(int uid) {
        if (uid > mFirstAvailableUid) {
        if (uid > mFirstAvailableUid) {