Always set FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE on SaveInfo when on compat mode.
Test: atest CtsAutoFillServiceTestCases:VirtualContainerActivityCompatModeTest
Bug: 76027553
Change-Id: I432b4321801ca90a55a24e5e896578d5b2d63014
diff --git a/core/java/android/service/autofill/AutofillService.java b/core/java/android/service/autofill/AutofillService.java
index 41e4181..94cef60 100644
--- a/core/java/android/service/autofill/AutofillService.java
+++ b/core/java/android/service/autofill/AutofillService.java
@@ -527,6 +527,9 @@
* <pre> <autofill-service xmlns:android="http://schemas.android.com/apk/res/android">
* <compatibility-package android:name="foo.bar.baz" android:maxLongVersionCode="1000000000"/>
* </autofill-service></pre>
+ *
+ * <p>When using compatibility mode, the {@link SaveInfo.Builder#setFlags(int) SaveInfo flags}
+ * automatically include {@link SaveInfo#FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE}.
*/
public abstract class AutofillService extends Service {
private static final String TAG = "AutofillService";
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 7f57615..e3fcab9 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -2074,8 +2074,11 @@
if (saveTriggerId != null) {
writeLog(MetricsEvent.AUTOFILL_EXPLICIT_SAVE_TRIGGER_DEFINITION);
}
- saveOnAllViewsInvisible =
- (saveInfo.getFlags() & SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE) != 0;
+ int flags = saveInfo.getFlags();
+ if (mCompatMode) {
+ flags |= SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE;
+ }
+ saveOnAllViewsInvisible = (flags & SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE) != 0;
// We only need to track views if we want to save once they become invisible.
if (saveOnAllViewsInvisible) {