summaryrefslogtreecommitdiff
path: root/services/backup/java
diff options
context:
space:
mode:
authorRuslan Tkhakokhov <rthakohov@google.com>2019-12-27 09:36:55 +0000
committerRuslan Tkhakokhov <rthakohov@google.com>2020-01-06 10:23:31 +0000
commite9388dacfe48f03db76b40e0bf0f345b3c249c7b (patch)
treeaed87e8f18cbead64fe22fb2aee65e68f79539d3 /services/backup/java
parentf472e23be5bdb04d2e4c78b9decaca443190b362 (diff)
Handle uncaught exceptions in BackupHandler
Bug: 144431410 Test: 1. atest BackupHandlerTest 2. Manual (with and without the fix): 1) Locally create a host-side CTS test that extends BaseMultiUserBackupHostSideTest 2) Modify the test so that it creates a user, starts backup init and removes the user 3) Add log in BackupHandler to indicate when an exception is suppressed. 3) If the fix is applied, verify the crash doesn't happen and the log message from 3) is present. If the fix isn't applied verify that the crash happens. After backup service for a user is stopped, leftover work on the corresponding BackupHandler can throw exceptions. If uncaught, they can crash the system process. Catch all uncaught BackupHandler exceptions after the backup service has entered the stopping state, to allow any leftover work to finish harmlessly. Change-Id: I8c233ad0e117ec0ae65599a762d87f15f8a3cec2
Diffstat (limited to 'services/backup/java')
-rw-r--r--services/backup/java/com/android/server/backup/internal/BackupHandler.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/services/backup/java/com/android/server/backup/internal/BackupHandler.java b/services/backup/java/com/android/server/backup/internal/BackupHandler.java
index 0964b3194e60..eb6262094849 100644
--- a/services/backup/java/com/android/server/backup/internal/BackupHandler.java
+++ b/services/backup/java/com/android/server/backup/internal/BackupHandler.java
@@ -31,6 +31,7 @@ import android.util.EventLog;
import android.util.Pair;
import android.util.Slog;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.backup.IBackupTransport;
import com.android.server.EventLogTags;
import com.android.server.backup.BackupAgentTimeoutParameters;
@@ -91,7 +92,9 @@ public class BackupHandler extends Handler {
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
private final HandlerThread mBackupThread;
- private volatile boolean mIsStopping = false;
+
+ @VisibleForTesting
+ volatile boolean mIsStopping = false;
public BackupHandler(
UserBackupManagerService backupManagerService, HandlerThread backupThread) {
@@ -113,6 +116,24 @@ public class BackupHandler extends Handler {
sendMessage(obtainMessage(BackupHandler.MSG_STOP));
}
+ @Override
+ public void dispatchMessage(Message message) {
+ try {
+ dispatchMessageInternal(message);
+ } catch (Exception e) {
+ // If the backup service is stopping, we'll suppress all exceptions to avoid crashes
+ // caused by code still running after the current user has become unavailable.
+ if (!mIsStopping) {
+ throw e;
+ }
+ }
+ }
+
+ @VisibleForTesting
+ void dispatchMessageInternal(Message message) {
+ super.dispatchMessage(message);
+ }
+
public void handleMessage(Message msg) {
if (msg.what == MSG_STOP) {
Slog.v(TAG, "Stopping backup handler");
@@ -414,7 +435,7 @@ public class BackupHandler extends Handler {
try {
params.observer.onTimeout();
} catch (RemoteException e) {
- /* don't care if the app has gone away */
+ /* don't care if the app has gone away */
}
}
} else {