From deec8f01752508a65fbbee6ff692d29b6aff4855 Mon Sep 17 00:00:00 2001 From: Feng Cao Date: Tue, 10 Mar 2020 18:14:13 -0700 Subject: [PATCH] Sends click and long click events from the inline suggestion to host app Test: manual, atest InlineSuggestionTest Bug: 151185482 Change-Id: Iafeb4584feca8a1cb1374f81105fa22136eba183 --- .../autofill/IInlineSuggestionUiCallback.aidl | 3 +- .../InlineSuggestionRenderService.java | 13 ++++- .../view/inputmethod/InlineSuggestion.java | 58 +++++++++++++++---- .../view/inline/IInlineContentCallback.aidl | 2 + .../autofill/ui/InlineSuggestionFactory.java | 8 ++- 5 files changed, 70 insertions(+), 14 deletions(-) diff --git a/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl b/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl index 1011651762932..1bcc76bfca445 100644 --- a/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl +++ b/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl @@ -25,7 +25,8 @@ import android.view.SurfaceControlViewHost; * @hide */ oneway interface IInlineSuggestionUiCallback { - void onAutofill(); + void onClick(); + void onLongClick(); void onContent(in SurfaceControlViewHost.SurfacePackage surface); void onError(); void onTransferTouchFocusToImeWindow(in IBinder sourceInputToken, int displayId); diff --git a/core/java/android/service/autofill/InlineSuggestionRenderService.java b/core/java/android/service/autofill/InlineSuggestionRenderService.java index ee15283715ffd..b6cc62dc213e1 100644 --- a/core/java/android/service/autofill/InlineSuggestionRenderService.java +++ b/core/java/android/service/autofill/InlineSuggestionRenderService.java @@ -97,12 +97,21 @@ public abstract class InlineSuggestionRenderService extends Service { host.addView(suggestionRoot, lp); suggestionRoot.setOnClickListener((v) -> { try { - callback.onAutofill(); + callback.onClick(); } catch (RemoteException e) { - Log.w(TAG, "RemoteException calling onAutofill()"); + Log.w(TAG, "RemoteException calling onClick()"); } }); + suggestionRoot.setOnLongClickListener((v) -> { + try { + callback.onLongClick(); + } catch (RemoteException e) { + Log.w(TAG, "RemoteException calling onLongClick()"); + } + return true; + }); + sendResult(callback, host.getSurfacePackage()); } finally { updateDisplay(Display.DEFAULT_DISPLAY); diff --git a/core/java/android/view/inputmethod/InlineSuggestion.java b/core/java/android/view/inputmethod/InlineSuggestion.java index 6500613969927..dd1738a5ff296 100644 --- a/core/java/android/view/inputmethod/InlineSuggestion.java +++ b/core/java/android/view/inputmethod/InlineSuggestion.java @@ -16,6 +16,7 @@ package android.view.inputmethod; +import android.annotation.BinderThread; import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.annotation.Nullable; @@ -94,19 +95,21 @@ public final class InlineSuggestion implements Parcelable { } - /** * Inflates a view with the content of this suggestion at a specific size. * The size must be between the {@link InlinePresentationSpec#getMinSize() min size} * and the {@link InlinePresentationSpec#getMaxSize() max size} of the presentation * spec returned by {@link InlineSuggestionInfo#getPresentationSpec()}. * - * @param context Context in which to inflate the view. - * @param size The size at which to inflate the suggestion. - * @param callback Callback for receiving the inflated view. + *

The caller can attach an {@link View.OnClickListener} and/or an + * {@link View.OnLongClickListener} to the view in the {@code callback} to receive click and + * long click events on the view. * + * @param context Context in which to inflate the view. + * @param size The size at which to inflate the suggestion. + * @param callback Callback for receiving the inflated view. * @throws IllegalArgumentException If an invalid argument is passed. - * @throws IllegalStateException if this method is already called. + * @throws IllegalStateException If this method is already called. */ public void inflate(@NonNull Context context, @NonNull Size size, @NonNull @CallbackExecutor Executor callbackExecutor, @@ -151,12 +154,31 @@ public final class InlineSuggestion implements Parcelable { } @Override + @BinderThread public void onContent(SurfaceControlViewHost.SurfacePackage content) { final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get(); if (callbackImpl != null) { callbackImpl.onContent(content); } } + + @Override + @BinderThread + public void onClick() { + final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get(); + if (callbackImpl != null) { + callbackImpl.onClick(); + } + } + + @Override + @BinderThread + public void onLongClick() { + final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get(); + if (callbackImpl != null) { + callbackImpl.onLongClick(); + } + } } private static final class InlineContentCallbackImpl { @@ -164,6 +186,7 @@ public final class InlineSuggestion implements Parcelable { private final @NonNull Context mContext; private final @NonNull Executor mCallbackExecutor; private final @NonNull Consumer mCallback; + private @Nullable View mView; InlineContentCallbackImpl(@NonNull Context context, @NonNull @CallbackExecutor Executor callbackExecutor, @@ -173,12 +196,27 @@ public final class InlineSuggestion implements Parcelable { mCallback = callback; } + @BinderThread public void onContent(SurfaceControlViewHost.SurfacePackage content) { if (content == null) { mCallbackExecutor.execute(() -> mCallback.accept(/* view */null)); } else { - mCallbackExecutor.execute( - () -> mCallback.accept(new InlineContentView(mContext, content))); + mView = new InlineContentView(mContext, content); + mCallbackExecutor.execute(() -> mCallback.accept(mView)); + } + } + + @BinderThread + public void onClick() { + if (mView != null && mView.hasOnClickListeners()) { + mView.callOnClick(); + } + } + + @BinderThread + public void onLongClick() { + if (mView != null && mView.hasOnLongClickListeners()) { + mView.performLongClick(); } } } @@ -201,7 +239,7 @@ public final class InlineSuggestion implements Parcelable { - // Code below generated by codegen v1.0.14. + // Code below generated by codegen v1.0.15. // // DO NOT MODIFY! // CHECKSTYLE:OFF Generated code @@ -360,8 +398,8 @@ public final class InlineSuggestion implements Parcelable { }; @DataClass.Generated( - time = 1581929285156L, - codegenVersion = "1.0.14", + time = 1583889058241L, + codegenVersion = "1.0.15", sourceFile = "frameworks/base/core/java/android/view/inputmethod/InlineSuggestion.java", inputSignatures = "private static final java.lang.String TAG\nprivate final @android.annotation.NonNull android.view.inputmethod.InlineSuggestionInfo mInfo\nprivate final @android.annotation.Nullable com.android.internal.view.inline.IInlineContentProvider mContentProvider\nprivate @com.android.internal.util.DataClass.ParcelWith(android.view.inputmethod.InlineSuggestion.InlineContentCallbackImplParceling.class) @android.annotation.Nullable android.view.inputmethod.InlineSuggestion.InlineContentCallbackImpl mInlineContentCallback\npublic static @android.annotation.TestApi @android.annotation.NonNull android.view.inputmethod.InlineSuggestion newInlineSuggestion(android.view.inputmethod.InlineSuggestionInfo)\npublic void inflate(android.content.Context,android.util.Size,java.util.concurrent.Executor,java.util.function.Consumer)\nprivate synchronized android.view.inputmethod.InlineSuggestion.InlineContentCallbackImpl getInlineContentCallback(android.content.Context,java.util.concurrent.Executor,java.util.function.Consumer)\nclass InlineSuggestion extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genHiddenConstDefs=true, genHiddenConstructor=true)") @Deprecated diff --git a/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl b/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl index 29bdf5661eafa..feb3f026b806e 100644 --- a/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl +++ b/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl @@ -24,4 +24,6 @@ import android.view.SurfaceControlViewHost; */ oneway interface IInlineContentCallback { void onContent(in SurfaceControlViewHost.SurfacePackage content); + void onClick(); + void onLongClick(); } diff --git a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java index ee59d89b7f159..0ca9dd92877f8 100644 --- a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java +++ b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java @@ -329,8 +329,14 @@ public final class InlineSuggestionFactory { @NonNull Runnable onErrorCallback) { return new IInlineSuggestionUiCallback.Stub() { @Override - public void onAutofill() throws RemoteException { + public void onClick() throws RemoteException { onAutofillCallback.run(); + callback.onClick(); + } + + @Override + public void onLongClick() throws RemoteException { + callback.onLongClick(); } @Override