Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0da18f3 authored by Felipe Leme's avatar Felipe Leme
Browse files

Added ContentCaptureEvents for session resumed and paused.

Test: atest CtsContentCaptureServiceTestCases # which was updated to listen to the new events
Test: m update-api

Fixes: 125395044

Change-Id: Ie1ed5d9badaa64ff0921226a1c08bd5e3cbf07d8
parent 544b39cb
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -9397,11 +9397,13 @@ package android.view.contentcapture {
    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 {
+4 −2
Original line number Diff line number Diff line
@@ -2773,11 +2773,13 @@ package android.view.contentcapture {
    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 {
+26 −5
Original line number Diff line number Diff line
@@ -1037,11 +1037,15 @@ public class Activity extends ContextThemeWrapper
    }

    /** @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)
@@ -1051,6 +1055,10 @@ public class Activity extends ContextThemeWrapper
        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:
@@ -1077,10 +1085,16 @@ public class Activity extends ContextThemeWrapper
                            & 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);
@@ -1639,6 +1653,8 @@ public class Activity extends ContextThemeWrapper
        }

        mCalled = true;

        notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_START);
    }

    /**
@@ -1682,7 +1698,6 @@ public class Activity extends ContextThemeWrapper
        if (mAutoFillResetNeeded) {
            getAutofillManager().onVisibleForAutofill();
        }
        notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_START);
    }

    /**
@@ -1765,6 +1780,9 @@ public class Activity extends ContextThemeWrapper
                }
            }
        }

        notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_RESUME);

        mCalled = true;
    }

@@ -2181,6 +2199,8 @@ public class Activity extends ContextThemeWrapper
                mAutoFillIgnoreFirstResumePause = false;
            }
        }

        notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_PAUSE);
        mCalled = true;
    }

@@ -2370,7 +2390,6 @@ public class Activity extends ContextThemeWrapper
                getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_CANCEL,
                        mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN));
            }
            notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_STOP);
        }
        mEnterAnimationComplete = false;
    }
@@ -2442,6 +2461,8 @@ public class Activity extends ContextThemeWrapper
        }

        dispatchActivityDestroyed();

        notifyContentCaptureManagerIfNeeded(CONTENT_CAPTURE_STOP);
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -9732,11 +9732,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            return;
        }
        session.internalNotifyViewHierarchyEvent(/* started= */ true);
        session.internalNotifyViewTreeEvent(/* started= */ true);
        try {
            dispatchProvideContentCaptureStructure();
        } finally {
            session.internalNotifyViewHierarchyEvent(/* started= */ false);
            session.internalNotifyViewTreeEvent(/* started= */ false);
        }
    }
+8 −15
Original line number Diff line number Diff line
@@ -2808,14 +2808,10 @@ public final class ViewRootImpl implements ViewParent,
        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++) {
@@ -2842,7 +2838,7 @@ public final class ViewRootImpl implements ViewParent,
                        Log.w(mTag, "invalid content capture event: " + event);
                    }
                }
                mainSession.notifyViewHierarchyEvent(sessionId, /* started = */ false);
                mainSession.notifyViewTreeEvent(sessionId, /* started= */ false);
            }
            mAttachInfo.mContentCaptureEvents = null;
        } finally {
@@ -2980,12 +2976,12 @@ public final class ViewRootImpl implements ViewParent,
            }
        }
        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();
        }
    }

@@ -3613,11 +3609,9 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    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 "
@@ -3628,16 +3622,15 @@ public final class ViewRootImpl implements ViewParent,

            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()) {
Loading