Merge "[Autofill Brute Force] Do no show suggestion after user entered 4 or more characters" into main
diff --git a/core/java/android/service/autofill/Dataset.java b/core/java/android/service/autofill/Dataset.java
index d04ff8e..115894f 100644
--- a/core/java/android/service/autofill/Dataset.java
+++ b/core/java/android/service/autofill/Dataset.java
@@ -115,6 +115,8 @@
  * with the lower case value of the view's text are shown.
  *   <li>All other datasets are hidden.
  * </ol>
+ * <p>Note: If user enters four or more characters, all datasets will be hidden</p>
+ *
  */
 public final class Dataset implements Parcelable {
     /**
diff --git a/services/autofill/java/com/android/server/autofill/ui/FillUi.java b/services/autofill/java/com/android/server/autofill/ui/FillUi.java
index cdd9ef4..0a8fe62 100644
--- a/services/autofill/java/com/android/server/autofill/ui/FillUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/FillUi.java
@@ -426,12 +426,18 @@
             if (mDestroyed) {
                 return;
             }
+            final int size = mFilterText == null ? 0 : mFilterText.length();
             if (count <= 0) {
                 if (sDebug) {
-                    final int size = mFilterText == null ? 0 : mFilterText.length();
                     Slog.d(TAG, "No dataset matches filter with " + size + " chars");
                 }
                 mCallback.requestHideFillUi();
+            } else if (size > 3) {
+                // Do not show suggestion if user entered four or more characters
+                if (sDebug) {
+                    Slog.d(TAG, "Not showing fill UI because user entered more than 3 characters");
+                }
+                mCallback.requestHideFillUi();
             } else {
                 if (updateContentSize()) {
                     requestShowFillUi();
diff --git a/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java b/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java
index ac8d962..24eab0b 100644
--- a/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java
@@ -216,6 +216,16 @@
             }
             return new InlineSuggestionsResponse(inlineSuggestions);
         }
+
+        // Do not show suggestion if user entered four or more characters
+        if (!TextUtils.isEmpty(mFilterText) && mFilterText.length() > 3) {
+            if (sVerbose) {
+                Slog.v(TAG, "Not showing inline suggestion because user entered more than 3 "
+                        + "characters");
+            }
+            return new InlineSuggestionsResponse(inlineSuggestions);
+        }
+
         for (int i = 0; i < size; i++) {
             final Dataset dataset = mDatasets.get(i);
             final int fieldIndex = dataset.getFieldIds().indexOf(mAutofillId);