Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c3372f3 authored by Adam He's avatar Adam He Committed by Android (Google) Code Review
Browse files

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

parents 8aaa2bc1 7e6f9ea4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
  }
+0 −1
Original line number Diff line number Diff line
@@ -25,5 +25,4 @@ import android.view.translation.TranslationResponse;
 */
oneway interface ITranslationCallback {
    void onTranslationResponse(in TranslationResponse translationResponse);
    void onError();
}
+5 −14
Original line number Diff line number Diff line
@@ -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() {
+2 −0
Original line number Diff line number Diff line
@@ -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();
    }

+0 −19
Original line number Diff line number Diff line
@@ -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);
                }
            }
        }
    }
}