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

Commit ce8a2d50 authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Don't hold mPackages when clearing package state

This change stops locking on mPackages when making calls to
clearPackageForUserLIF to avoid the potential for lock contention and
address error logs emitted by installd.

Test: atest AppSecurityTests
Fixes: 122530620
Change-Id: If3372fc38140ede0c05e49dfafd761d56790df44
parent d81cd262
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -19138,7 +19138,6 @@ public class PackageManagerService extends IPackageManager.Stub
        final UserHandle user = action.user;
        final int flags = action.flags;
        final boolean systemApp = isSystemApp(ps);
        synchronized (mPackages) {
        if (ps.parentPackageName != null
                && (!systemApp || (flags & PackageManager.DELETE_SYSTEM_APP) != 0)) {
@@ -19150,10 +19149,11 @@ public class PackageManagerService extends IPackageManager.Stub
                    : UserHandle.USER_ALL;
            clearPackageStateForUserLIF(ps, removedUserId, outInfo, flags);
            synchronized (mPackages) {
                markPackageUninstalledForUserLPw(ps, user);
                scheduleWritePackageRestrictionsLocked(user);
                return;
            }
            return;
        }
        final int userId = user == null ? UserHandle.USER_ALL : user.getIdentifier();
@@ -19167,6 +19167,7 @@ public class PackageManagerService extends IPackageManager.Stub
            // its data. If this is a system app, we only allow this to happen if
            // they have set the special DELETE_SYSTEM_APP which requests different
            // semantics than normal for uninstalling system apps.
            final boolean clearPackageStateAndReturn;
            synchronized (mPackages) {
                markPackageUninstalledForUserLPw(ps, user);
                if (!systemApp) {
@@ -19177,15 +19178,14 @@ public class PackageManagerService extends IPackageManager.Stub
                        // we need to do is clear this user's data and save that
                        // it is uninstalled.
                        if (DEBUG_REMOVE) Slog.d(TAG, "Still installed by other users");
                        clearPackageStateForUserLIF(ps, userId, outInfo, flags);
                        scheduleWritePackageRestrictionsLocked(user);
                        return;
                        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);
                        mSettings.writeKernelMappingLPr(ps);
                        clearPackageStateAndReturn = false;
                    }
                } else {
                    // This is a system app, so we assume that the
@@ -19193,10 +19193,15 @@ public class PackageManagerService extends IPackageManager.Stub
                    // we need to do is clear this user's data and save that
                    // it is uninstalled.
                    if (DEBUG_REMOVE) Slog.d(TAG, "Deleting system app");
                    clearPackageStateAndReturn = true;
                }
            }
            if (clearPackageStateAndReturn) {
                clearPackageStateForUserLIF(ps, userId, outInfo, flags);
                synchronized (mPackages) {
                    scheduleWritePackageRestrictionsLocked(user);
                    return;
                }
                return;
            }
        }