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

Commit 0c19bf52 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Avoid deadlock between mUsers and cacheLock

Should fix the occasional deadlock that ends up killing the system process via
Watchdog.

Bug: 11033281

Change-Id: Ie9cec0b6e2bd44bb03848b04aec5f9bd04ee74d6
parent d585f954
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -293,8 +293,8 @@ public class AccountManagerService
        return mUserManager;
    }

    private UserAccounts initUser(int userId) {
        synchronized (mUsers) {
    /* Caller should lock mUsers */
    private UserAccounts initUserLocked(int userId) {
        UserAccounts accounts = mUsers.get(userId);
        if (accounts == null) {
            accounts = new UserAccounts(mContext, userId);
@@ -304,7 +304,6 @@ public class AccountManagerService
        }
        return accounts;
    }
    }

    private void purgeOldGrantsAll() {
        synchronized (mUsers) {
@@ -427,7 +426,7 @@ public class AccountManagerService
        synchronized (mUsers) {
            UserAccounts accounts = mUsers.get(userId);
            if (accounts == null) {
                accounts = initUser(userId);
                accounts = initUserLocked(userId);
                mUsers.append(userId, accounts);
            }
            return accounts;
@@ -1798,7 +1797,6 @@ public class AccountManagerService

    private AccountAndUser[] getAccounts(int[] userIds) {
        final ArrayList<AccountAndUser> runningAccounts = Lists.newArrayList();
        synchronized (mUsers) {
        for (int userId : userIds) {
            UserAccounts userAccounts = getUserAccounts(userId);
            if (userAccounts == null) continue;
@@ -1810,7 +1808,6 @@ public class AccountManagerService
                }
            }
        }
        }

        AccountAndUser[] accountsArray = new AccountAndUser[runningAccounts.size()];
        return runningAccounts.toArray(accountsArray);
@@ -2858,7 +2855,8 @@ public class AccountManagerService
                || callingUid == Process.myUid()) {
            return unfiltered;
        }
        if (mUserManager.getUserInfo(userAccounts.userId).isRestricted()) {
        UserInfo user = mUserManager.getUserInfo(userAccounts.userId);
        if (user != null && user.isRestricted()) {
            String[] packages = mPackageManager.getPackagesForUid(callingUid);
            // If any of the packages is a white listed package, return the full set,
            // otherwise return non-shared accounts only.