Merge "Clear inline suggestions before onFinishInput" into rvc-dev am: e11fa9a741

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11920284

Change-Id: If49aa26ead8225934190414193b96e5ea85114cd
This commit is contained in:
TreeHugger Robot
2020-06-23 17:51:36 +00:00
committed by Automerger Merge Worker
2 changed files with 21 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ import com.android.internal.view.IInlineSuggestionsResponseCallback;
import com.android.internal.view.InlineSuggestionsRequestInfo; import com.android.internal.view.InlineSuggestionsRequestInfo;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
@@ -58,6 +59,9 @@ import java.util.function.Supplier;
class InlineSuggestionSession { class InlineSuggestionSession {
private static final String TAG = "ImsInlineSuggestionSession"; private static final String TAG = "ImsInlineSuggestionSession";
static final InlineSuggestionsResponse EMPTY_RESPONSE = new InlineSuggestionsResponse(
Collections.emptyList());
@NonNull @NonNull
private final Handler mMainThreadHandler; private final Handler mMainThreadHandler;
@NonNull @NonNull
@@ -72,6 +76,10 @@ class InlineSuggestionSession {
private final Supplier<IBinder> mHostInputTokenSupplier; private final Supplier<IBinder> mHostInputTokenSupplier;
@NonNull @NonNull
private final Consumer<InlineSuggestionsResponse> mResponseConsumer; 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;
/** /**
@@ -142,6 +150,7 @@ class InlineSuggestionSession {
@MainThread @MainThread
void invalidate() { void invalidate() {
if (mResponseCallback != null) { if (mResponseCallback != null) {
consumeInlineSuggestionsResponse(EMPTY_RESPONSE);
mResponseCallback.invalidate(); mResponseCallback.invalidate();
mResponseCallback = null; mResponseCallback = null;
} }
@@ -188,6 +197,17 @@ class InlineSuggestionSession {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "IME receives response: " + response.getInlineSuggestions().size()); 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); mResponseConsumer.accept(response);
} }

View File

@@ -213,6 +213,7 @@ class InlineSuggestionSessionController {
mImeInputViewStarted = false; mImeInputViewStarted = false;
mImeInputStarted = false; mImeInputStarted = false;
if (mSession != null && mSession.shouldSendImeStatus()) { if (mSession != null && mSession.shouldSendImeStatus()) {
mSession.consumeInlineSuggestionsResponse(InlineSuggestionSession.EMPTY_RESPONSE);
try { try {
mSession.getRequestCallback().onInputMethodFinishInput(); mSession.getRequestCallback().onInputMethodFinishInput();
} catch (RemoteException e) { } catch (RemoteException e) {