OSDN Git Service

Added ContentCaptureEvents for session resumed and paused.
authorFelipe Leme <felipeal@google.com>
Fri, 22 Feb 2019 23:10:02 +0000 (15:10 -0800)
committerFelipe Leme <felipeal@google.com>
Sat, 23 Feb 2019 02:10:22 +0000 (18:10 -0800)
Test: atest CtsContentCaptureServiceTestCases # which was updated to listen to the new events
Test: m update-api

Fixes: 125395044

Change-Id: Ie1ed5d9badaa64ff0921226a1c08bd5e3cbf07d8

api/system-current.txt
api/test-current.txt
core/java/android/app/Activity.java
core/java/android/view/View.java
core/java/android/view/ViewRootImpl.java
core/java/android/view/contentcapture/ChildContentCaptureSession.java
core/java/android/view/contentcapture/ContentCaptureEvent.java
core/java/android/view/contentcapture/ContentCaptureManager.java
core/java/android/view/contentcapture/ContentCaptureSession.java
core/java/android/view/contentcapture/MainContentCaptureSession.java
core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java

index e4b2014..c5370bd 100644 (file)
@@ -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 {
index 1981d68..95ab682 100644 (file)
@@ -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 {
index 6ee9e89..de0f2bc 100644 (file)
@@ -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);
     }
 
     /**
index 77aaee4..3d9aab2 100644 (file)
@@ -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);
         }
     }
 
index 33795e5..e41b1b3 100644 (file)
@@ -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()) {
index 03eef5e..b3b0b72 100644 (file)
@@ -84,8 +84,8 @@ final class ChildContentCaptureSession extends ContentCaptureSession {
     }
 
     @Override
-    public void internalNotifyViewHierarchyEvent(boolean started) {
-        getMainCaptureSession().notifyViewHierarchyEvent(mId, started);
+    public void internalNotifyViewTreeEvent(boolean started) {
+        getMainCaptureSession().notifyViewTreeEvent(mId, started);
     }
 
     @Override
index 1dd1bee..2585b74 100644 (file)
@@ -79,8 +79,7 @@ public final class ContentCaptureEvent implements Parcelable {
      * 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
@@ -90,8 +89,7 @@ public final class ContentCaptureEvent implements Parcelable {
      * 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
@@ -101,14 +99,29 @@ public final class ContentCaptureEvent implements Parcelable {
      */
     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{}
@@ -232,8 +245,9 @@ public final class ContentCaptureEvent implements Parcelable {
      * 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;
@@ -413,15 +427,19 @@ public final class ContentCaptureEvent implements Parcelable {
                 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";
index 336d997..1fab0de 100644 (file)
@@ -224,7 +224,7 @@ public final class ContentCaptureManager {
 
     /** @hide */
     @UiThread
-    public void onActivityStarted(@NonNull IBinder applicationToken,
+    public void onActivityCreated(@NonNull IBinder applicationToken,
             @NonNull ComponentName activityComponent, int flags) {
         synchronized (mLock) {
             mFlags |= flags;
@@ -234,7 +234,19 @@ public final class ContentCaptureManager {
 
     /** @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();
     }
 
index 544a4f6..ab8f346 100644 (file)
@@ -134,19 +134,19 @@ public abstract class ContentCaptureSession implements AutoCloseable {
     /** @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{}
@@ -411,7 +411,7 @@ public abstract class ContentCaptureSession implements AutoCloseable {
             @Nullable CharSequence text);
 
     /** @hide */
-    public abstract void internalNotifyViewHierarchyEvent(boolean started);
+    public abstract void internalNotifyViewTreeEvent(boolean started);
 
     /**
      * Creates a {@link ViewStructure} for a "standard" view.
@@ -501,14 +501,14 @@ public abstract class ContentCaptureSession implements AutoCloseable {
         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;
         }
index 14b2b28..dce8ebe 100644 (file)
 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;
@@ -543,8 +545,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
     }
 
     @Override
-    public void internalNotifyViewHierarchyEvent(boolean started) {
-        notifyViewHierarchyEvent(mId, started);
+    public void internalNotifyViewTreeEvent(boolean started) {
+        notifyViewTreeEvent(mId, started);
     }
 
     @Override
@@ -590,12 +592,17 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
     }
 
     /** 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)
index b6717e1..013408e 100644 (file)
@@ -157,7 +157,7 @@ public class ContentCaptureSessionTest {
         }
 
         @Override
-        public void internalNotifyViewHierarchyEvent(boolean started) {
+        public void internalNotifyViewTreeEvent(boolean started) {
             throw new UnsupportedOperationException("should not have been called");
         }