Improved how Content Capture events are flushed when activity is resumed / paused.
We were flushing right after the activity resumed, but the relevant events (views added / removed)
were not generated yet, which made such flushes useless.
This CL changes the workflow to flush them after the ViewRoot finishes doing its work.
Test: atest CtsContentCaptureServiceTestCases
Bug: 125395044
Bug: 122315042
Change-Id: I05bf27069b00c285643b2d23ad6708a6ad7bc8f3
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index 1e051a4..49d985c 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -132,9 +132,9 @@
/** @hide */
public static final int FLUSH_REASON_FULL = 1;
/** @hide */
- public static final int FLUSH_REASON_ACTIVITY_PAUSED = 2;
+ public static final int FLUSH_REASON_VIEW_ROOT_ENTERED = 2;
/** @hide */
- public static final int FLUSH_REASON_ACTIVITY_RESUMED = 3;
+ public static final int FLUSH_REASON_POST_VIEW_ROOT_TRAVERSAL = 3;
/** @hide */
public static final int FLUSH_REASON_SESSION_STARTED = 4;
/** @hide */
@@ -145,14 +145,14 @@
/** @hide */
@IntDef(prefix = { "FLUSH_REASON_" }, value = {
FLUSH_REASON_FULL,
- FLUSH_REASON_ACTIVITY_PAUSED,
- FLUSH_REASON_ACTIVITY_RESUMED,
FLUSH_REASON_SESSION_STARTED,
FLUSH_REASON_SESSION_FINISHED,
- FLUSH_REASON_IDLE_TIMEOUT
+ FLUSH_REASON_IDLE_TIMEOUT,
+ FLUSH_REASON_VIEW_ROOT_ENTERED,
+ FLUSH_REASON_POST_VIEW_ROOT_TRAVERSAL
})
@Retention(RetentionPolicy.SOURCE)
- @interface FlushReason{}
+ public @interface FlushReason{}
private final Object mLock = new Object();
@@ -500,20 +500,20 @@
/** @hide */
@NonNull
- static String getflushReasonAsString(@FlushReason int reason) {
+ public static String getFlushReasonAsString(@FlushReason int reason) {
switch (reason) {
case FLUSH_REASON_FULL:
return "FULL";
- case FLUSH_REASON_ACTIVITY_PAUSED:
- return "PAUSED";
- case FLUSH_REASON_ACTIVITY_RESUMED:
- return "RESUMED";
case FLUSH_REASON_SESSION_STARTED:
return "STARTED";
case FLUSH_REASON_SESSION_FINISHED:
return "FINISHED";
case FLUSH_REASON_IDLE_TIMEOUT:
return "IDLE";
+ case FLUSH_REASON_VIEW_ROOT_ENTERED:
+ return "ENTERED";
+ case FLUSH_REASON_POST_VIEW_ROOT_TRAVERSAL:
+ return "TRAVERSAL";
default:
return "UNKOWN-" + reason;
}
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index 0abf689..b55b975 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -451,7 +451,7 @@
}
final int numberEvents = mEvents.size();
- final String reasonString = getflushReasonAsString(reason);
+ final String reasonString = getFlushReasonAsString(reason);
if (sDebug) {
Log.d(TAG, "Flushing " + numberEvents + " event(s) for " + getDebugState(reason));
}
@@ -684,6 +684,6 @@
@NonNull
private String getDebugState(@FlushReason int reason) {
- return getDebugState() + ", reason=" + getflushReasonAsString(reason);
+ return getDebugState() + ", reason=" + getFlushReasonAsString(reason);
}
}