summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Haoran Zhang <haoranzhang@google.com> 2024-10-02 20:47:25 +0000
committer Haoran Zhang <haoranzhang@google.com> 2024-10-02 20:47:25 +0000
commitad25f42cd12d940a18e90e5e21562958b0ad711b (patch)
treedeba7a52aa362ed17f0de0073aa4249763ebef29
parent276222e0b85ecef024fda4e32241503ef6796471 (diff)
Post onProvideAutofillStructure in Augment Autofill flow to UI thread
This is to fix the issue that onProvideAutofillStructure is called on the binder thread causing CtsInputMethodTestCases FocusHandlingTest#testOnCheckIsTextEditorRunOnUIThreadWithInputMethodManagerIsActive to fail. Bug: b/362908997 Change-Id: Ic68dca1e0baef2e5b00c248c4417b8891749cdcf Test: atest CtsAutoFillServiceTestCases:android.autofillservice.cts.augmented Flag: EXEMPT bugfix
-rw-r--r--core/java/android/view/autofill/AutofillManager.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java
index 79ecfe1e9141..1a45939f65b6 100644
--- a/core/java/android/view/autofill/AutofillManager.java
+++ b/core/java/android/view/autofill/AutofillManager.java
@@ -117,6 +117,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import sun.misc.Cleaner;
@@ -4914,7 +4916,22 @@ public final class AutofillManager {
&& (root.getWindowFlags() & WindowManager.LayoutParams.FLAG_SECURE) == 0) {
ViewNodeBuilder viewStructure = new ViewNodeBuilder();
viewStructure.setAutofillId(view.getAutofillId());
- view.onProvideAutofillStructure(viewStructure, /* flags= */ 0);
+
+ // Post onProvideAutofillStructure to the UI thread
+ final CountDownLatch latch = new CountDownLatch(1);
+ afm.post(
+ () -> {
+ view.onProvideAutofillStructure(viewStructure, /* flags= */ 0);
+ latch.countDown();
+ }
+ );
+ try {
+ latch.await(5000, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return null;
+ }
+
// TODO(b/141703532): We don't call View#onProvideAutofillVirtualStructure for
// efficiency reason. But this also means we will return null for virtual views
// for now. We will add a new API to fetch the view node info of the virtual