Merge "Remove onError from translationResultCallback." into sc-dev

This commit is contained in:
Adam He
2021-04-21 00:26:34 +00:00
committed by Android (Google) Code Review
5 changed files with 8 additions and 35 deletions

View File

@@ -10410,7 +10410,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

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

View File

@@ -379,24 +379,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);
}
}
}
}
}