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

Commit 9bbdeaec authored by Dmitry Dementyev's avatar Dmitry Dementyev Committed by Android Build Coastguard Worker
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
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d248c61ef55b0874cd586d6812a9af29ad31e909)
Merged-In: I0f3190e8b284230b5c955b9f43b09c4c291ea73a
Change-Id: I0f3190e8b284230b5c955b9f43b09c4c291ea73a
parent b05cba7d
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;
@@ -1457,8 +1458,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) {
@@ -4460,6 +4461,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);
        }
@@ -4535,7 +4539,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[]{};
        }
@@ -4545,7 +4549,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[]{};
        }