method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.view.contentcapture.ContentCaptureEvent> CREATOR;
field public static final int TYPE_CONTEXT_UPDATED = 6; // 0x6
- field public static final int TYPE_INITIAL_VIEW_TREE_APPEARED = 5; // 0x5
- field public static final int TYPE_INITIAL_VIEW_TREE_APPEARING = 4; // 0x4
+ field public static final int TYPE_SESSION_PAUSED = 8; // 0x8
+ field public static final int TYPE_SESSION_RESUMED = 7; // 0x7
field public static final int TYPE_VIEW_APPEARED = 1; // 0x1
field public static final int TYPE_VIEW_DISAPPEARED = 2; // 0x2
field public static final int TYPE_VIEW_TEXT_CHANGED = 3; // 0x3
+ field public static final int TYPE_VIEW_TREE_APPEARED = 5; // 0x5
+ field public static final int TYPE_VIEW_TREE_APPEARING = 4; // 0x4
}
public final class ContentCaptureManager {
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.view.contentcapture.ContentCaptureEvent> CREATOR;
field public static final int TYPE_CONTEXT_UPDATED = 6; // 0x6
- field public static final int TYPE_INITIAL_VIEW_TREE_APPEARED = 5; // 0x5
- field public static final int TYPE_INITIAL_VIEW_TREE_APPEARING = 4; // 0x4
+ field public static final int TYPE_SESSION_PAUSED = 8; // 0x8
+ field public static final int TYPE_SESSION_RESUMED = 7; // 0x7
field public static final int TYPE_VIEW_APPEARED = 1; // 0x1
field public static final int TYPE_VIEW_DISAPPEARED = 2; // 0x2
field public static final int TYPE_VIEW_TEXT_CHANGED = 3; // 0x3
+ field public static final int TYPE_VIEW_TREE_APPEARED = 5; // 0x5
+ field public static final int TYPE_VIEW_TREE_APPEARING = 4; // 0x4
}
public final class ContentCaptureManager {
}
/** @hide */ private static final int CONTENT_CAPTURE_START = 1;
- /** @hide */ private static final int CONTENT_CAPTURE_STOP = 2;
+ /** @hide */ private static final int CONTENT_CAPTURE_RESUME = 2;
+ /** @hide */ private static final int CONTENT_CAPTURE_PAUSE = 3;
+ /** @hide */ private static final int CONTENT_CAPTURE_STOP = 4;
/** @hide */
@IntDef(prefix = { "CONTENT_CAPTURE_" }, value = {
CONTENT_CAPTURE_START,
+ CONTENT_CAPTURE_RESUME,
+ CONTENT_CAPTURE_PAUSE,
CONTENT_CAPTURE_STOP
})
@Retention(RetentionPolicy.SOURCE)
switch (type) {
case CONTENT_CAPTURE_START:
return "START";
+ case CONTENT_CAPTURE_RESUME:
+ return "RESUME";
+ case CONTENT_CAPTURE_PAUSE:
+ return "PAUSE";
case CONTENT_CAPTURE_STOP:
return "STOP";
default:
& WindowManager.LayoutParams.FLAG_SECURE) != 0) {
flags |= ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE;
}
- cm.onActivityStarted(mToken, getComponentName(), flags);
+ cm.onActivityCreated(mToken, getComponentName(), flags);
+ break;
+ case CONTENT_CAPTURE_RESUME:
+ cm.onActivityResumed();
+ break;
+ case CONTENT_CAPTURE_PAUSE:
+ cm.onActivityPaused();
break;
case CONTENT_CAPTURE_STOP:
- cm.onActivityStopped();
+ cm.onActivityDestroyed();
break;
default:
Log.wtf(TAG, "Invalid @ContentCaptureNotificationType: " + type);
}
mCalled = true;
+
+ notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_START);
}
/**
if (mAutoFillResetNeeded) {
getAutofillManager().onVisibleForAutofill();
}
- notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_START);
}
/**
}
}
}
+
+ notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_RESUME);
+
mCalled = true;
}
mAutoFillIgnoreFirstResumePause = false;
}
}
+
+ notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_PAUSE);
mCalled = true;
}
getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_CANCEL,
mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN));
}
- notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_STOP);
}
mEnterAnimationComplete = false;
}
}
dispatchActivityDestroyed();
+
+ notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_STOP);
}
/**
return;
}
- session.internalNotifyViewHierarchyEvent(/* started= */ true);
+ session.internalNotifyViewTreeEvent(/* started= */ true);
try {
dispatchProvideContentCaptureStructure();
} finally {
- session.internalNotifyViewHierarchyEvent(/* started= */ false);
+ session.internalNotifyViewTreeEvent(/* started= */ false);
}
}
try {
MainContentCaptureSession mainSession = mAttachInfo.mContentCaptureManager
.getMainContentCaptureSession();
- if (mainSession == null) {
- Log.w(mTag, "no MainContentCaptureSession on AttachInfo");
- return;
- }
for (int i = 0; i < mAttachInfo.mContentCaptureEvents.size(); i++) {
String sessionId = mAttachInfo.mContentCaptureEvents
.keyAt(i);
- mainSession.notifyViewHierarchyEvent(sessionId, /* started = */ true);
+ mainSession.notifyViewTreeEvent(sessionId, /* started= */ true);
ArrayList<Object> events = mAttachInfo.mContentCaptureEvents
.valueAt(i);
for_each_event: for (int j = 0; j < events.size(); j++) {
Log.w(mTag, "invalid content capture event: " + event);
}
}
- mainSession.notifyViewHierarchyEvent(sessionId, /* started = */ false);
+ mainSession.notifyViewTreeEvent(sessionId, /* started= */ false);
}
mAttachInfo.mContentCaptureEvents = null;
} finally {
}
}
mFirstInputStage.onWindowFocusChanged(hasWindowFocus);
+
// NOTE: there's no view visibility (appeared / disapparead) events when the windows focus
// is lost, so we don't need to to force a flush - there might be other events such as
// text changes, but these should be flushed independently.
if (hasWindowFocus) {
- performContentCaptureFlushIfNecessary(
- ContentCaptureSession.FLUSH_REASON_VIEW_ROOT_ENTERED);
+ handleContentCaptureFlush();
}
}
}
}
- private void performContentCaptureFlushIfNecessary(
- @ContentCaptureSession.FlushReason int flushReason) {
+ private void handleContentCaptureFlush() {
if (DEBUG_CONTENT_CAPTURE) {
- Log.v(mTag, "performContentCaptureFlushIfNecessary("
- + ContentCaptureSession.getFlushReasonAsString(flushReason) + ")");
+ Log.v(mTag, "handleContentCaptureFlush()");
}
if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) {
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "flushContentCapture for "
final ContentCaptureManager ccm = mAttachInfo.mContentCaptureManager;
if (ccm == null) {
- Log.w(TAG, "flush content capture: no ContentCapture on AttachInfo");
+ Log.w(TAG, "No ContentCapture on AttachInfo");
return;
}
- ccm.flush(flushReason);
+ ccm.flush(ContentCaptureSession.FLUSH_REASON_VIEW_ROOT_ENTERED);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
}
}
-
private boolean draw(boolean fullRedrawNeeded) {
Surface surface = mSurface;
if (!surface.isValid()) {
}
@Override
- public void internalNotifyViewHierarchyEvent(boolean started) {
- getMainCaptureSession().notifyViewHierarchyEvent(mId, started);
+ public void internalNotifyViewTreeEvent(boolean started) {
+ getMainCaptureSession().notifyViewTreeEvent(mId, started);
}
@Override
* if the initial view hierarchy doesn't initially have any view that's important for content
* capture.
*/
- // TODO(b/125395044): change to TYPE_VIEW_TREE_APPEARING
- public static final int TYPE_INITIAL_VIEW_TREE_APPEARING = 4;
+ public static final int TYPE_VIEW_TREE_APPEARING = 4;
/**
* Called after events (such as {@link #TYPE_VIEW_APPEARED} and/or
* if the initial view hierarchy doesn't initially have any view that's important for content
* capture.
*/
- // TODO(b/125395044): change to TYPE_VIEW_TREE_APPEARED
- public static final int TYPE_INITIAL_VIEW_TREE_APPEARED = 5;
+ public static final int TYPE_VIEW_TREE_APPEARED = 5;
/**
* Called after a call to
*/
public static final int TYPE_CONTEXT_UPDATED = 6;
+ /**
+ * Called after the session is ready, typically after the activity resumed and the
+ * initial views appeared
+ */
+ public static final int TYPE_SESSION_RESUMED = 7;
+
+ /**
+ * Called after the session is paused, typically after the activity paused and the
+ * views disappeared.
+ */
+ public static final int TYPE_SESSION_PAUSED = 8;
+
+
/** @hide */
@IntDef(prefix = { "TYPE_" }, value = {
TYPE_VIEW_APPEARED,
TYPE_VIEW_DISAPPEARED,
TYPE_VIEW_TEXT_CHANGED,
- TYPE_INITIAL_VIEW_TREE_APPEARING,
- TYPE_INITIAL_VIEW_TREE_APPEARED,
- TYPE_CONTEXT_UPDATED
+ TYPE_VIEW_TREE_APPEARING,
+ TYPE_VIEW_TREE_APPEARED,
+ TYPE_CONTEXT_UPDATED,
+ TYPE_SESSION_PAUSED,
+ TYPE_SESSION_RESUMED
})
@Retention(RetentionPolicy.SOURCE)
public @interface EventType{}
* Gets the type of the event.
*
* @return one of {@link #TYPE_VIEW_APPEARED}, {@link #TYPE_VIEW_DISAPPEARED},
- * {@link #TYPE_VIEW_TEXT_CHANGED}, {@link #TYPE_INITIAL_VIEW_TREE_APPEARING},
- * {@link #TYPE_INITIAL_VIEW_TREE_APPEARED}, or {@link #TYPE_CONTEXT_UPDATED}.
+ * {@link #TYPE_VIEW_TEXT_CHANGED}, {@link #TYPE_VIEW_TREE_APPEARING},
+ * {@link #TYPE_VIEW_TREE_APPEARED}, {@link #TYPE_CONTEXT_UPDATED},
+ * {@link #TYPE_SESSION_RESUMED}, or {@link #TYPE_SESSION_PAUSED}.
*/
public @EventType int getType() {
return mType;
return "SESSION_STARTED";
case TYPE_SESSION_FINISHED:
return "SESSION_FINISHED";
+ case TYPE_SESSION_RESUMED:
+ return "SESSION_RESUMED";
+ case TYPE_SESSION_PAUSED:
+ return "SESSION_PAUSED";
case TYPE_VIEW_APPEARED:
return "VIEW_APPEARED";
case TYPE_VIEW_DISAPPEARED:
return "VIEW_DISAPPEARED";
case TYPE_VIEW_TEXT_CHANGED:
return "VIEW_TEXT_CHANGED";
- case TYPE_INITIAL_VIEW_TREE_APPEARING:
+ case TYPE_VIEW_TREE_APPEARING:
return "VIEW_TREE_APPEARING";
- case TYPE_INITIAL_VIEW_TREE_APPEARED:
+ case TYPE_VIEW_TREE_APPEARED:
return "VIEW_TREE_APPEARED";
case TYPE_CONTEXT_UPDATED:
return "CONTEXT_UPDATED";
/** @hide */
@UiThread
- public void onActivityStarted(@NonNull IBinder applicationToken,
+ public void onActivityCreated(@NonNull IBinder applicationToken,
@NonNull ComponentName activityComponent, int flags) {
synchronized (mLock) {
mFlags |= flags;
/** @hide */
@UiThread
- public void onActivityStopped() {
+ public void onActivityResumed() {
+ getMainContentCaptureSession().notifySessionLifecycle(/* started= */ true);
+ }
+
+ /** @hide */
+ @UiThread
+ public void onActivityPaused() {
+ getMainContentCaptureSession().notifySessionLifecycle(/* started= */ false);
+ }
+
+ /** @hide */
+ @UiThread
+ public void onActivityDestroyed() {
getMainContentCaptureSession().destroy();
}
/** @hide */
public static final int FLUSH_REASON_VIEW_ROOT_ENTERED = 2;
/** @hide */
- public static final int FLUSH_REASON_SESSION_STARTED = 4;
+ public static final int FLUSH_REASON_SESSION_STARTED = 3;
/** @hide */
- public static final int FLUSH_REASON_SESSION_FINISHED = 5;
+ public static final int FLUSH_REASON_SESSION_FINISHED = 4;
/** @hide */
- public static final int FLUSH_REASON_IDLE_TIMEOUT = 6;
+ public static final int FLUSH_REASON_IDLE_TIMEOUT = 5;
/** @hide */
@IntDef(prefix = { "FLUSH_REASON_" }, value = {
FLUSH_REASON_FULL,
+ FLUSH_REASON_VIEW_ROOT_ENTERED,
FLUSH_REASON_SESSION_STARTED,
FLUSH_REASON_SESSION_FINISHED,
- FLUSH_REASON_IDLE_TIMEOUT,
- FLUSH_REASON_VIEW_ROOT_ENTERED,
+ FLUSH_REASON_IDLE_TIMEOUT
})
@Retention(RetentionPolicy.SOURCE)
public @interface FlushReason{}
@Nullable CharSequence text);
/** @hide */
- public abstract void internalNotifyViewHierarchyEvent(boolean started);
+ public abstract void internalNotifyViewTreeEvent(boolean started);
/**
* Creates a {@link ViewStructure} for a "standard" view.
switch (reason) {
case FLUSH_REASON_FULL:
return "FULL";
+ case FLUSH_REASON_VIEW_ROOT_ENTERED:
+ return "VIEW_ROOT";
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";
default:
return "UNKOWN-" + reason;
}
package android.view.contentcapture;
import static android.view.contentcapture.ContentCaptureEvent.TYPE_CONTEXT_UPDATED;
-import static android.view.contentcapture.ContentCaptureEvent.TYPE_INITIAL_VIEW_TREE_APPEARED;
-import static android.view.contentcapture.ContentCaptureEvent.TYPE_INITIAL_VIEW_TREE_APPEARING;
import static android.view.contentcapture.ContentCaptureEvent.TYPE_SESSION_FINISHED;
+import static android.view.contentcapture.ContentCaptureEvent.TYPE_SESSION_PAUSED;
+import static android.view.contentcapture.ContentCaptureEvent.TYPE_SESSION_RESUMED;
import static android.view.contentcapture.ContentCaptureEvent.TYPE_SESSION_STARTED;
import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_APPEARED;
import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_DISAPPEARED;
import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_TEXT_CHANGED;
+import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_TREE_APPEARED;
+import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_TREE_APPEARING;
import static android.view.contentcapture.ContentCaptureHelper.getSanitizedString;
import static android.view.contentcapture.ContentCaptureHelper.sDebug;
import static android.view.contentcapture.ContentCaptureHelper.sVerbose;
}
@Override
- public void internalNotifyViewHierarchyEvent(boolean started) {
- notifyViewHierarchyEvent(mId, started);
+ public void internalNotifyViewTreeEvent(boolean started) {
+ notifyViewTreeEvent(mId, started);
}
@Override
}
/** Public because is also used by ViewRootImpl */
- public void notifyViewHierarchyEvent(@NonNull String sessionId, boolean started) {
- final int type = started ? TYPE_INITIAL_VIEW_TREE_APPEARING
- : TYPE_INITIAL_VIEW_TREE_APPEARED;
+ public void notifyViewTreeEvent(@NonNull String sessionId, boolean started) {
+ final int type = started ? TYPE_VIEW_TREE_APPEARING : TYPE_VIEW_TREE_APPEARED;
sendEvent(new ContentCaptureEvent(sessionId, type), FORCE_FLUSH);
}
+ /** Public because is also used by ViewRootImpl */
+ public void notifySessionLifecycle(boolean started) {
+ final int type = started ? TYPE_SESSION_RESUMED : TYPE_SESSION_PAUSED;
+ sendEvent(new ContentCaptureEvent(mId, type), FORCE_FLUSH);
+ }
+
void notifyContextUpdated(@NonNull String sessionId,
@Nullable ContentCaptureContext context) {
sendEvent(new ContentCaptureEvent(sessionId, TYPE_CONTEXT_UPDATED)
}
@Override
- public void internalNotifyViewHierarchyEvent(boolean started) {
+ public void internalNotifyViewTreeEvent(boolean started) {
throw new UnsupportedOperationException("should not have been called");
}