OSDN Git Service

Fix: AccountManagerService crashed by accessing closed db
authorTetsutoki Shiozawa <tetsutoki.shiozawa@sony.com>
Tue, 24 Oct 2017 09:44:00 +0000 (18:44 +0900)
committerShunta Sato <shunta.sato@sony.com>
Fri, 27 Oct 2017 02:24:38 +0000 (02:24 +0000)
Symptom:
When a current user was switched, AccountManagerService crashed with
IllegalStateException.

Root cause:
accountsDb was closed when user was stopped. AccountManagerService
tried to insert a log record to the closed db and it failed.

Solution:
It catches the exception if it's failed to insert a log record.

Bug: 68233592
Change-Id: I97b63e4777bf7f8a1d38d96e494f6a21847d374b

services/core/java/com/android/server/accounts/AccountManagerService.java

index d6a010f..f007eb4 100644 (file)
@@ -5082,8 +5082,16 @@ public class AccountManagerService
                 logStatement.bindLong(4, callingUid);
                 logStatement.bindString(5, tableName);
                 logStatement.bindLong(6, userDebugDbInsertionPoint);
-                logStatement.execute();
-                logStatement.clearBindings();
+                try {
+                    logStatement.execute();
+                } catch (IllegalStateException e) {
+                    // Guard against crash, DB can already be closed
+                    // since this statement is executed on a handler thread
+                    Slog.w(TAG, "Failed to insert a log record. accountId=" + accountId
+                            + " action=" + action + " tableName=" + tableName + " Error: " + e);
+                } finally {
+                    logStatement.clearBindings();
+                }
             }
         }