Merge "Remove onError from translationResultCallback." into sc-dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,5 +25,4 @@ import android.view.translation.TranslationResponse;
|
||||
*/
|
||||
oneway interface ITranslationCallback {
|
||||
void onTranslationResponse(in TranslationResponse translationResponse);
|
||||
void onError();
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user