Loading core/java/android/inputmethodservice/InlineSuggestionSession.java +20 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import com.android.internal.view.IInlineSuggestionsResponseCallback; import com.android.internal.view.InlineSuggestionsRequestInfo; import java.lang.ref.WeakReference; import java.util.Collections; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; Loading @@ -58,6 +59,9 @@ import java.util.function.Supplier; class InlineSuggestionSession { private static final String TAG = "ImsInlineSuggestionSession"; static final InlineSuggestionsResponse EMPTY_RESPONSE = new InlineSuggestionsResponse( Collections.emptyList()); @NonNull private final Handler mMainThreadHandler; @NonNull Loading @@ -72,6 +76,10 @@ class InlineSuggestionSession { private final Supplier<IBinder> mHostInputTokenSupplier; @NonNull private final Consumer<InlineSuggestionsResponse> mResponseConsumer; // Indicate whether the previous call to the mResponseConsumer is empty or not. If it hasn't // been called yet, the value would be null. @Nullable private Boolean mPreviousResponseIsEmpty; /** Loading Loading @@ -142,6 +150,7 @@ class InlineSuggestionSession { @MainThread void invalidate() { if (mResponseCallback != null) { consumeInlineSuggestionsResponse(EMPTY_RESPONSE); mResponseCallback.invalidate(); mResponseCallback = null; } Loading Loading @@ -188,6 +197,17 @@ class InlineSuggestionSession { if (DEBUG) { Log.d(TAG, "IME receives response: " + response.getInlineSuggestions().size()); } consumeInlineSuggestionsResponse(response); } @MainThread void consumeInlineSuggestionsResponse(@NonNull InlineSuggestionsResponse response) { boolean isResponseEmpty = response.getInlineSuggestions().isEmpty(); if (isResponseEmpty && Boolean.TRUE.equals(mPreviousResponseIsEmpty)) { // No-op if both the previous response and current response are empty. return; } mPreviousResponseIsEmpty = isResponseEmpty; mResponseConsumer.accept(response); } Loading core/java/android/inputmethodservice/InlineSuggestionSessionController.java +1 −0 Original line number Diff line number Diff line Loading @@ -213,6 +213,7 @@ class InlineSuggestionSessionController { mImeInputViewStarted = false; mImeInputStarted = false; if (mSession != null && mSession.shouldSendImeStatus()) { mSession.consumeInlineSuggestionsResponse(InlineSuggestionSession.EMPTY_RESPONSE); try { mSession.getRequestCallback().onInputMethodFinishInput(); } catch (RemoteException e) { Loading Loading
core/java/android/inputmethodservice/InlineSuggestionSession.java +20 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import com.android.internal.view.IInlineSuggestionsResponseCallback; import com.android.internal.view.InlineSuggestionsRequestInfo; import java.lang.ref.WeakReference; import java.util.Collections; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; Loading @@ -58,6 +59,9 @@ import java.util.function.Supplier; class InlineSuggestionSession { private static final String TAG = "ImsInlineSuggestionSession"; static final InlineSuggestionsResponse EMPTY_RESPONSE = new InlineSuggestionsResponse( Collections.emptyList()); @NonNull private final Handler mMainThreadHandler; @NonNull Loading @@ -72,6 +76,10 @@ class InlineSuggestionSession { private final Supplier<IBinder> mHostInputTokenSupplier; @NonNull private final Consumer<InlineSuggestionsResponse> mResponseConsumer; // Indicate whether the previous call to the mResponseConsumer is empty or not. If it hasn't // been called yet, the value would be null. @Nullable private Boolean mPreviousResponseIsEmpty; /** Loading Loading @@ -142,6 +150,7 @@ class InlineSuggestionSession { @MainThread void invalidate() { if (mResponseCallback != null) { consumeInlineSuggestionsResponse(EMPTY_RESPONSE); mResponseCallback.invalidate(); mResponseCallback = null; } Loading Loading @@ -188,6 +197,17 @@ class InlineSuggestionSession { if (DEBUG) { Log.d(TAG, "IME receives response: " + response.getInlineSuggestions().size()); } consumeInlineSuggestionsResponse(response); } @MainThread void consumeInlineSuggestionsResponse(@NonNull InlineSuggestionsResponse response) { boolean isResponseEmpty = response.getInlineSuggestions().isEmpty(); if (isResponseEmpty && Boolean.TRUE.equals(mPreviousResponseIsEmpty)) { // No-op if both the previous response and current response are empty. return; } mPreviousResponseIsEmpty = isResponseEmpty; mResponseConsumer.accept(response); } Loading
core/java/android/inputmethodservice/InlineSuggestionSessionController.java +1 −0 Original line number Diff line number Diff line Loading @@ -213,6 +213,7 @@ class InlineSuggestionSessionController { mImeInputViewStarted = false; mImeInputStarted = false; if (mSession != null && mSession.shouldSendImeStatus()) { mSession.consumeInlineSuggestionsResponse(InlineSuggestionSession.EMPTY_RESPONSE); try { mSession.getRequestCallback().onInputMethodFinishInput(); } catch (RemoteException e) { Loading