Handle CancellationException in BackupTransportClient
Logic added in ag/16968183 can produce a CancellationException which is
not currently caught, resulting in system server crashes (see attached
bug). Catch the exception and update tests accordingly.
Bug: 224777563
Test: atest BackupTransportClientTest
Merged-In: Ibee991dbc9673c7b6b4d0051f09b4e8862ad6af4
Change-Id: Ibee991dbc9673c7b6b4d0051f09b4e8862ad6af4
(cherry picked from commit d0c42dc678)
This commit is contained in:
@@ -34,6 +34,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -374,7 +375,8 @@ public class BackupTransportClient {
|
||||
private <T> T getFutureResult(AndroidFuture<T> future) {
|
||||
try {
|
||||
return future.get(600, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException
|
||||
| CancellationException e) {
|
||||
Slog.w(TAG, "Failed to get result from transport:", e);
|
||||
return null;
|
||||
} finally {
|
||||
@@ -403,7 +405,11 @@ public class BackupTransportClient {
|
||||
void cancelActiveFutures() {
|
||||
synchronized (mActiveFuturesLock) {
|
||||
for (AndroidFuture<?> future : mActiveFutures) {
|
||||
future.cancel(true);
|
||||
try {
|
||||
future.cancel(true);
|
||||
} catch (CancellationException ignored) {
|
||||
// This is expected, so ignore the exception.
|
||||
}
|
||||
}
|
||||
mActiveFutures.clear();
|
||||
}
|
||||
|
||||
@@ -110,10 +110,7 @@ public class BackupTransportClientTest {
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
/*String name =*/ client.transportDirName();
|
||||
fail("transportDirName should be cancelled");
|
||||
} catch (CancellationException ex) {
|
||||
// This is expected.
|
||||
assertThat(client.transportDirName()).isNull();
|
||||
} catch (Exception ex) {
|
||||
fail("unexpected Exception: " + ex.getClass().getCanonicalName());
|
||||
}
|
||||
@@ -189,7 +186,7 @@ public class BackupTransportClientTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFinishBackup_canceledBeforeCompletion_throwsException() throws Exception {
|
||||
public void testFinishBackup_canceledBeforeCompletion_returnsError() throws Exception {
|
||||
TestCallbacksFakeTransportBinder binder = new TestCallbacksFakeTransportBinder();
|
||||
BackupTransportClient client = new BackupTransportClient(binder);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user