Remove onError from translationResultCallback.

*onError is not needed, error code is embedded in the
TranslationResponse itself.

Bug: 176208267
Test: atest CtsTranslationTestCases
Change-Id: I67f42ae900cbac1d697de7ecae1bbffabd921c4a
This commit is contained in:
Adam He
2021-03-30 14:33:19 -07:00
parent c93faeed3b
commit 7e6f9ea49b
5 changed files with 8 additions and 35 deletions

View File

@@ -10323,7 +10323,7 @@ package android.service.translation {
}
public static interface TranslationService.OnTranslationResultCallback {
method public void onError();
method @Deprecated public void onError();
method public void onTranslationSuccess(@NonNull android.view.translation.TranslationResponse);
}

View File

@@ -25,5 +25,4 @@ import android.view.translation.TranslationResponse;
*/
oneway interface ITranslationCallback {
void onTranslationResponse(in TranslationResponse translationResponse);
void onError();
}

View File

@@ -66,22 +66,13 @@ final class OnTranslationResultCallbackWrapper implements
}
}
/**
* @deprecated use {@link #onTranslationSuccess} with error response instead.
*/
@Override
@Deprecated
public void onError() {
assertNotCalled();
if (mCalled.getAndSet(true)) {
throw new IllegalStateException("Already called");
}
try {
mCallback.onError();
} catch (RemoteException e) {
if (e instanceof DeadObjectException) {
Log.w(TAG, "Process is dead, ignore.");
return;
}
throw e.rethrowAsRuntimeException();
}
// no-op.
}
private void assertNotCalled() {

View File

@@ -140,7 +140,9 @@ public abstract class TranslationService extends Service {
/**
* TODO: implement javadoc
* @deprecated use {@link #onTranslationSuccess} with an error response instead.
*/
@Deprecated
void onError();
}

View File

@@ -329,24 +329,5 @@ public class Translator {
}
}
}
@Override
public void onError() throws RemoteException {
final Consumer<TranslationResponse> callback = mCallback.get();
final Runnable runnable = () -> callback.accept(
new TranslationResponse.Builder(
TranslationResponse.TRANSLATION_STATUS_UNKNOWN_ERROR)
.build());
if (callback != null) {
final Executor executor = mExecutor.get();
final long token = Binder.clearCallingIdentity();
try {
executor.execute(runnable);
} finally {
restoreCallingIdentity(token);
}
}
}
}
}