summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/contentcapture/ContentCaptureSession.java7
-rw-r--r--core/java/android/view/contentcapture/MainContentCaptureSession.java52
2 files changed, 52 insertions, 7 deletions
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index 4129e52dcdf3..6d41b289460a 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -153,6 +153,8 @@ public abstract class ContentCaptureSession implements AutoCloseable {
public static final int FLUSH_REASON_SESSION_FINISHED = 4;
/** @hide */
public static final int FLUSH_REASON_IDLE_TIMEOUT = 5;
+ /** @hide */
+ public static final int FLUSH_REASON_TEXT_CHANGE_TIMEOUT = 6;
/** @hide */
@IntDef(prefix = { "FLUSH_REASON_" }, value = {
@@ -160,7 +162,8 @@ public abstract class ContentCaptureSession implements AutoCloseable {
FLUSH_REASON_VIEW_ROOT_ENTERED,
FLUSH_REASON_SESSION_STARTED,
FLUSH_REASON_SESSION_FINISHED,
- FLUSH_REASON_IDLE_TIMEOUT
+ FLUSH_REASON_IDLE_TIMEOUT,
+ FLUSH_REASON_TEXT_CHANGE_TIMEOUT
})
@Retention(RetentionPolicy.SOURCE)
public @interface FlushReason{}
@@ -525,6 +528,8 @@ public abstract class ContentCaptureSession implements AutoCloseable {
return "FINISHED";
case FLUSH_REASON_IDLE_TIMEOUT:
return "IDLE";
+ case FLUSH_REASON_TEXT_CHANGE_TIMEOUT:
+ return "TEXT_CHANGE";
default:
return "UNKOWN-" + reason;
}
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index f9fd0c6ffe00..666af5968f69 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -125,6 +125,11 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
// Used just for debugging purposes (on dump)
private long mNextFlush;
+ /**
+ * Whether the next buffer flush is queued by a text changed event.
+ */
+ private boolean mNextFlushForTextChanged = false;
+
@Nullable
private final LocalLog mFlushHistory;
@@ -331,7 +336,21 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
final boolean bufferEvent = numberEvents < maxBufferSize;
if (bufferEvent && !forceFlush) {
- scheduleFlush(FLUSH_REASON_IDLE_TIMEOUT, /* checkExisting= */ true);
+ final int flushReason;
+ if (eventType == TYPE_VIEW_TEXT_CHANGED) {
+ mNextFlushForTextChanged = true;
+ flushReason = FLUSH_REASON_TEXT_CHANGE_TIMEOUT;
+ } else {
+ if (mNextFlushForTextChanged) {
+ if (sVerbose) {
+ Log.i(TAG, "Not scheduling flush because next flush is for text changed");
+ }
+ return;
+ }
+
+ flushReason = FLUSH_REASON_IDLE_TIMEOUT;
+ }
+ scheduleFlush(flushReason, /* checkExisting= */ true);
return;
}
@@ -392,14 +411,25 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
// "Renew" the flush message by removing the previous one
mHandler.removeMessages(MSG_FLUSH);
}
- final int idleFlushingFrequencyMs = mManager.mOptions.idleFlushingFrequencyMs;
- mNextFlush = System.currentTimeMillis() + idleFlushingFrequencyMs;
+
+ final int flushFrequencyMs;
+ if (reason == FLUSH_REASON_IDLE_TIMEOUT) {
+ flushFrequencyMs = mManager.mOptions.idleFlushingFrequencyMs;
+ } else if (reason == FLUSH_REASON_TEXT_CHANGE_TIMEOUT) {
+ flushFrequencyMs = mManager.mOptions.textChangeFlushingFrequencyMs;
+ } else {
+ Log.e(TAG, "handleScheduleFlush(" + getDebugState(reason) + "): not called with a "
+ + "timeout reason.");
+ return;
+ }
+
+ mNextFlush = System.currentTimeMillis() + flushFrequencyMs;
if (sVerbose) {
Log.v(TAG, "handleScheduleFlush(): scheduled to flush in "
- + idleFlushingFrequencyMs + "ms: " + TimeUtils.logTimeOfDay(mNextFlush));
+ + flushFrequencyMs + "ms: " + TimeUtils.logTimeOfDay(mNextFlush));
}
// Post using a Runnable directly to trim a few μs from PooledLambda.obtainMessage()
- mHandler.postDelayed(() -> flushIfNeeded(reason), MSG_FLUSH, idleFlushingFrequencyMs);
+ mHandler.postDelayed(() -> flushIfNeeded(reason), MSG_FLUSH, flushFrequencyMs);
}
@UiThread
@@ -448,6 +478,10 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
try {
mHandler.removeMessages(MSG_FLUSH);
+ if (reason == FLUSH_REASON_TEXT_CHANGE_TIMEOUT) {
+ mNextFlushForTextChanged = false;
+ }
+
final ParceledListSlice<ContentCaptureEvent> events = clearEvents();
mDirectServiceInterface.sendEvents(events);
} catch (RemoteException e) {
@@ -625,8 +659,14 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
pw.println();
}
}
+ pw.print(prefix); pw.print("mNextFlushForTextChanged: ");
+ pw.println(mNextFlushForTextChanged);
pw.print(prefix); pw.print("flush frequency: ");
- pw.println(mManager.mOptions.idleFlushingFrequencyMs);
+ if (mNextFlushForTextChanged) {
+ pw.println(mManager.mOptions.textChangeFlushingFrequencyMs);
+ } else {
+ pw.println(mManager.mOptions.idleFlushingFrequencyMs);
+ }
pw.print(prefix); pw.print("next flush: ");
TimeUtils.formatDuration(mNextFlush - System.currentTimeMillis(), pw);
pw.print(" ("); pw.print(TimeUtils.logTimeOfDay(mNextFlush)); pw.println(")");