From 185bdbb637941cc1ae50669a3a13c0e06d8bc2a7 Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Thu, 23 Jun 2022 18:13:07 -0700 Subject: [PATCH] [Android Autofill] Don't set autofillHints to an empty array when there's no autofillhints (flutter/engine#34203) --- .../android/io/flutter/plugin/editing/TextInputPlugin.java | 6 +++++- .../test/io/flutter/plugin/editing/TextInputPluginTest.java | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 7382cd49e3..444d0360cf 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -766,7 +766,11 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch structure.addChildCount(1); final ViewStructure child = structure.newChild(i); child.setAutofillId(parentId, autofillId); - child.setAutofillHints(autofill.hints); + // Don't set hints when there's none. + // See https://github.com/flutter/flutter/issues/98505. + if (autofill.hints.length > 0) { + child.setAutofillHints(autofill.hints); + } child.setAutofillType(View.AUTOFILL_TYPE_TEXT); child.setVisibility(View.VISIBLE); if (autofill.hintText != null) { diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 8ec751164d..0fde5814ab 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -12,6 +12,7 @@ import static org.mockito.Mockito.eq; import static org.mockito.Mockito.isNotNull; import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -1337,7 +1338,8 @@ public class TextInputPluginTest { verify(viewStructure).newChild(0); verify(children[0]).setAutofillId(any(), eq("1".hashCode())); - verify(children[0]).setAutofillHints(aryEq(new String[] {})); + // The flutter application sends an empty hint list, don't set hints. + verify(children[0], never()).setAutofillHints(aryEq(new String[] {})); verify(children[0]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), gt(0), gt(0)); } @@ -1507,7 +1509,7 @@ public class TextInputPluginTest { } @Test - public void autofill_onProvideVirtualViewStructure_single() { + public void autofill_onProvideVirtualViewStructure_singular_textfield() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; }