[Stability][Bugfix] Catch DeadObjectException in TCMS.

The disconnection of TextClassificationService may be unhandled
when binder call comes, which causes RuntimeException. Since the
disconnection will be handled later, we just catch the exception
here.

Bug: 210711405
Test: CtsTextClassifierService
Change-Id: I1745f2b40c84115f745a7424c1d329cc1b357831
This commit is contained in:
qinyige1
2021-11-29 14:28:19 +08:00
parent 27c03c7f68
commit 72a6d56d84

View File

@@ -527,12 +527,13 @@ public final class TextClassificationManagerService extends ITextClassifierServi
callback.onFailure();
return;
}
textClassifierServiceConsumer.accept(serviceState.mService);
consumeServiceNoExceptLocked(textClassifierServiceConsumer, serviceState.mService);
} else {
serviceState.mPendingRequests.add(
new PendingRequest(
methodName,
() -> textClassifierServiceConsumer.accept(serviceState.mService),
() -> consumeServiceNoExceptLocked(
textClassifierServiceConsumer, serviceState.mService),
callback::onFailure, callback.asBinder(),
this,
serviceState,
@@ -541,6 +542,16 @@ public final class TextClassificationManagerService extends ITextClassifierServi
}
}
private static void consumeServiceNoExceptLocked(
@NonNull ThrowingConsumer<ITextClassifierService> textClassifierServiceConsumer,
@Nullable ITextClassifierService service) {
try {
textClassifierServiceConsumer.accept(service);
} catch (RuntimeException | Error e) {
Slog.e(LOG_TAG, "Exception when consume textClassifierService: " + e);
}
}
private static ITextClassifierCallback wrap(ITextClassifierCallback orig) {
return new CallbackWrapper(orig);
}