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

Commit 1fb0fb38 authored by Dmitry Dementyev's avatar Dmitry Dementyev
Browse files

Prevent crash in AccountManager after profile removal.

When user profile is removed AccountManagerService.purgeUserData may be
called after a delay. Until it happens other methods may try to access
database for a removed profile which causes a crash.

Bug: 281980345
Test: N/A
Change-Id: Idb9840a5b9f9fdc84516149066cbb2a945c083a7
parent 3a317d93
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import android.content.pm.Signature;
import android.content.pm.SigningDetails.CertCapabilities;
import android.content.pm.UserInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteFullException;
import android.database.sqlite.SQLiteStatement;
import android.os.Binder;
@@ -1419,7 +1420,13 @@ public class AccountManagerService
    private void purgeOldGrants(UserAccounts accounts) {
        synchronized (accounts.dbLock) {
            synchronized (accounts.cacheLock) {
                List<Integer> uids = accounts.accountsDb.findAllUidGrants();
                List<Integer> uids;
                try {
                    uids = accounts.accountsDb.findAllUidGrants();
                } catch (SQLiteCantOpenDatabaseException e) {
                    Log.w(TAG, "Could not delete grants for user = " + accounts.userId);
                    return;
                }
                for (int uid : uids) {
                    final boolean packageExists = mPackageManager.getPackagesForUid(uid) != null;
                    if (packageExists) {
@@ -1445,7 +1452,13 @@ public class AccountManagerService
                    mPackageManager.getPackageUidAsUser(packageName, accounts.userId);
                } catch (NameNotFoundException e) {
                    // package does not exist - remove visibility values
                    try {
                        accounts.accountsDb.deleteAccountVisibilityForPackage(packageName);
                    } catch (SQLiteCantOpenDatabaseException sqlException) {
                        Log.w(TAG, "Could not delete account visibility for user = "
                                + accounts.userId, sqlException);
                        continue;
                    }
                    synchronized (accounts.dbLock) {
                        synchronized (accounts.cacheLock) {
                            for (Account account : accounts.visibilityCache.keySet()) {