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

Commit d248c61e authored by Dmitry Dementyev's avatar Dmitry Dementyev
Browse files

Prevent system service crash after SQL error in AccountManagerService.

Catch broader exception instead of SQLiteCantOpenDatabaseException since
current one ignores some errors during database update.

Return empty list if error happened during getAccountsAsUser call used by SyncManager.

Bug: 354764198
Test: manual
Flag: EXEMPT bugfix
Change-Id: I0f3190e8b284230b5c955b9f43b09c4c291ea73a
parent 06483f83
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.content.pm.SigningDetails.CertCapabilities;
import android.content.pm.UserInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteFullException;
import android.database.sqlite.SQLiteStatement;
import android.os.Binder;
@@ -1461,8 +1462,8 @@ public class AccountManagerService
                List<Integer> uids;
                try {
                    uids = accounts.accountsDb.findAllUidGrants();
                } catch (SQLiteCantOpenDatabaseException e) {
                    Log.w(TAG, "Could not delete grants for user = " + accounts.userId);
                } catch (SQLiteException e) {
                    Log.w(TAG, "Could not delete grants for user = " + accounts.userId, e);
                    return;
                }
                for (int uid : uids) {
@@ -4464,6 +4465,9 @@ public class AccountManagerService
                    opPackageName,
                    visibleAccountTypes,
                    false /* includeUserManagedNotVisible */);
        } catch (SQLiteException e) {
            Log.w(TAG, "Could not get accounts for user " + userId, e);
            return new Account[]{};
        } finally {
            restoreCallingIdentity(identityToken);
        }
@@ -4539,7 +4543,7 @@ public class AccountManagerService
        try {
            return getAccountsAsUserForPackage(type, userId, opPackageName /* callingPackage */, -1,
                    opPackageName, false /* includeUserManagedNotVisible */);
        } catch (SQLiteCantOpenDatabaseException e) {
        } catch (SQLiteException e) {
            Log.e(TAG, "Could not get accounts for user " + userId, e);
            return new Account[]{};
        }
@@ -4549,7 +4553,7 @@ public class AccountManagerService
    private Account[] getAccountsOrEmptyArray(String type, int userId, String opPackageName) {
        try {
            return getAccountsAsUser(type, userId, opPackageName);
        } catch (SQLiteCantOpenDatabaseException e) {
        } catch (SQLiteException e) {
            Log.w(TAG, "Could not get accounts for user " + userId, e);
            return new Account[]{};
        }