AF: Clear the existing response for the partition on a new request.

Once a new Request is in flight, we probably don't want to display the
old responses.

This prevents a VIEW_ENTERED flow from displaying the suggestions
(either as a dropdown or as inline chips) if there is a pending request
for the same partition. Thus fixing a bug where the suggestions may be
rendered twice - once from the VIEW_ENTERED update and again from the
Fill Request succeeding (see http://b/152620157#comment7). An example of
how this may occur:
1. User taps on a View that previously showed suggestions.
2. App manually triggers autofill, which issues a new fill request.
3. The Session is updated with VIEW_ENTERED (due to (1)).
Session#requestShowInlineSuggestionsLocked returns false because of the
pending request. The system fallsback to drawing the dropdown UI.
4. FillRequest from (2) completes. This hides the dropdown and shows
inline chips.

An alternative is to exit the VIEW_ENTERED flow when there's a pending
request for the same view. This should also fix the bug, but is no
longer necessary with the current fix. The advantage of the current
approach is that the VIEW_ENTERED update logic and the request logic are
less coupled.

Fix: 152620157
Test: manual
Test: atest android.autofillservice.cts
Change-Id: Id15887ffdf28d0a3ea32e1f68ffd81f994f93187
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 4b2e3b2..1290569 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -657,13 +657,21 @@
     }
 
     /**
-     * Reads a new structure and then request a new fill response from the fill service.
+     * Clears the existing response for the partition, reads a new structure, and then requests a
+     * new fill response from the fill service.
      *
      * <p> Also asks the IME to make an inline suggestions request if it's enabled.
      */
     @GuardedBy("mLock")
     private void requestNewFillResponseLocked(@NonNull ViewState viewState, int newState,
             int flags) {
+        final FillResponse existingResponse = viewState.getResponse();
+        if (existingResponse != null) {
+            setViewStatesLocked(
+                    existingResponse,
+                    ViewState.STATE_INITIAL,
+                    /* clearResponse= */ true);
+        }
         mExpiredResponse = false;
         if (mForAugmentedAutofillOnly || mRemoteFillService == null) {
             if (sVerbose) {