From 713af5fdd39a2b56efe89d1125d6864f92c6298f Mon Sep 17 00:00:00 2001 From: Yabin Huang Date: Wed, 10 Jun 2020 15:37:59 -0700 Subject: [PATCH 1/3] Update FocusFinder Don't return the current view when finding the next or previous view. Bug: 158492287 Test: atest cts/tests/tests/view/src/android/view/cts/FocusFinderTest.java atest frameworks/base/core/tests/coretests/src/android/view/FocusFinderTest.java Change-Id: Ib5c1854d1a13b9469ca55dfbf0be61bead47e29e --- core/java/android/view/FocusFinder.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index 713cfb48c95f1..064bc6947fc43 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -311,6 +311,9 @@ public class FocusFinder { } final int count = focusables.size(); + if (count < 2) { + return null; + } switch (direction) { case View.FOCUS_FORWARD: return getNextFocusable(focused, focusables, count); @@ -373,29 +376,29 @@ public class FocusFinder { } private static View getNextFocusable(View focused, ArrayList focusables, int count) { + if (count < 2) { + return null; + } if (focused != null) { int position = focusables.lastIndexOf(focused); if (position >= 0 && position + 1 < count) { return focusables.get(position + 1); } } - if (!focusables.isEmpty()) { - return focusables.get(0); - } - return null; + return focusables.get(0); } private static View getPreviousFocusable(View focused, ArrayList focusables, int count) { + if (count < 2) { + return null; + } if (focused != null) { int position = focusables.indexOf(focused); if (position > 0) { return focusables.get(position - 1); } } - if (!focusables.isEmpty()) { - return focusables.get(count - 1); - } - return null; + return focusables.get(count - 1); } private static View getNextKeyboardNavigationCluster( From 5f74d605ce2d2237a78d7e259e8adaa70e6683bf Mon Sep 17 00:00:00 2001 From: Joanne Chung Date: Wed, 3 Jun 2020 15:36:08 +0800 Subject: [PATCH 2/3] Made AutofillId.withoutSession is testable. We add new test in stage-aosp-rvc-ts-dev for R2, we need make this API testable. Bug: 156408900 Test: atest android.autofillservice.cts.inline.\ InlineAugmentedWebViewActivityTest Change-Id: I27d1227f858aac83b3de1cb8ef719edf177524dc Merged-In: I27d1227f858aac83b3de1cb8ef719edf177524dc --- api/test-current.txt | 1 + core/java/android/view/autofill/AutofillId.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/api/test-current.txt b/api/test-current.txt index ed4c9b13dacd5..6f3c9ee2df37e 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -5136,6 +5136,7 @@ package android.view.autofill { ctor public AutofillId(int, int); ctor public AutofillId(@NonNull android.view.autofill.AutofillId, long, int); method public boolean equalsIgnoreSession(@Nullable android.view.autofill.AutofillId); + method @NonNull public static android.view.autofill.AutofillId withoutSession(@NonNull android.view.autofill.AutofillId); } public final class AutofillManager { diff --git a/core/java/android/view/autofill/AutofillId.java b/core/java/android/view/autofill/AutofillId.java index b387a68dd8a34..9cdaba599d94a 100644 --- a/core/java/android/view/autofill/AutofillId.java +++ b/core/java/android/view/autofill/AutofillId.java @@ -73,6 +73,8 @@ public final class AutofillId implements Parcelable { } /** @hide */ + @NonNull + @TestApi public static AutofillId withoutSession(@NonNull AutofillId id) { final int flags = id.mFlags & ~FLAG_HAS_SESSION; return new AutofillId(flags, id.mViewId, id.mVirtualLongId, NO_SESSION); From 6c01bf5f87c0572b7ef872438fc0d0dfe6a03753 Mon Sep 17 00:00:00 2001 From: Yabin Huang Date: Thu, 23 Jul 2020 17:39:45 +0000 Subject: [PATCH 3/3] Revert "Update FocusFinder" Revert submission 11830696-b/158492287-stage-aosp-rvc-ts-dev Reason for revert: It's too late to merge this CL to rvc-dev. Let's revert it and merge it to rvc-qpr-dev. Reverted Changes: Ib5c1854d1:Update FocusFinder Change-Id: I5f50166322b662b457e1b79b2ce62c622ddd1013 --- core/java/android/view/FocusFinder.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index 064bc6947fc43..713cfb48c95f1 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -311,9 +311,6 @@ public class FocusFinder { } final int count = focusables.size(); - if (count < 2) { - return null; - } switch (direction) { case View.FOCUS_FORWARD: return getNextFocusable(focused, focusables, count); @@ -376,29 +373,29 @@ public class FocusFinder { } private static View getNextFocusable(View focused, ArrayList focusables, int count) { - if (count < 2) { - return null; - } if (focused != null) { int position = focusables.lastIndexOf(focused); if (position >= 0 && position + 1 < count) { return focusables.get(position + 1); } } - return focusables.get(0); + if (!focusables.isEmpty()) { + return focusables.get(0); + } + return null; } private static View getPreviousFocusable(View focused, ArrayList focusables, int count) { - if (count < 2) { - return null; - } if (focused != null) { int position = focusables.indexOf(focused); if (position > 0) { return focusables.get(position - 1); } } - return focusables.get(count - 1); + if (!focusables.isEmpty()) { + return focusables.get(count - 1); + } + return null; } private static View getNextKeyboardNavigationCluster(