From cdcf3a83398e944bc5dfe16058802f0d2e08081e Mon Sep 17 00:00:00 2001 From: Joanne Chung Date: Fri, 18 Jun 2021 18:35:14 +0800 Subject: [PATCH] Add hidden TYPE_ACTIVITY_STARTED to allow notify activity start event. The current launcher implementation, the resumed Activity doesn't enter paused state when entering overview. The launcher will have a start activity event when entering overview but we don't provide start event now. We are not allowed to add new APIs now, we add new hidden constant constants in ActivityEvent and send the event when the activity is started. Bug: 189968849 Test: manual. Checks if the activity start events are received by ContentCaptureService Test: atest ActivityRecordTests Change-Id: I8e4f8b7ac8f24c66ccad9f7e884cac9e20ce3cc6 --- .../service/contentcapture/ActivityEvent.java | 20 +++++++++++++++++-- .../com/android/server/wm/ActivityRecord.java | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/core/java/android/service/contentcapture/ActivityEvent.java b/core/java/android/service/contentcapture/ActivityEvent.java index 1188a3f1021ed..74a7355181201 100644 --- a/core/java/android/service/contentcapture/ActivityEvent.java +++ b/core/java/android/service/contentcapture/ActivityEvent.java @@ -55,12 +55,25 @@ public final class ActivityEvent implements Parcelable { */ public static final int TYPE_ACTIVITY_DESTROYED = Event.ACTIVITY_DESTROYED; + /** + * TODO: change to public field. + * The activity was started. + * + *

There are some reason, ACTIVITY_START cannot be added into UsageStats. We don't depend on + * UsageEvents for Activity start. + *

+ * + * @hide + */ + public static final int TYPE_ACTIVITY_STARTED = 10000; + /** @hide */ @IntDef(prefix = { "TYPE_" }, value = { TYPE_ACTIVITY_RESUMED, TYPE_ACTIVITY_PAUSED, TYPE_ACTIVITY_STOPPED, - TYPE_ACTIVITY_DESTROYED + TYPE_ACTIVITY_DESTROYED, + TYPE_ACTIVITY_STARTED }) @Retention(RetentionPolicy.SOURCE) public @interface ActivityEventType{} @@ -86,7 +99,8 @@ public final class ActivityEvent implements Parcelable { * Gets the event type. * * @return either {@link #TYPE_ACTIVITY_RESUMED}, {@value #TYPE_ACTIVITY_PAUSED}, - * {@value #TYPE_ACTIVITY_STOPPED}, or {@value #TYPE_ACTIVITY_DESTROYED}. + * {@value #TYPE_ACTIVITY_STOPPED}, {@value #TYPE_ACTIVITY_DESTROYED} or 10000 if the Activity + * was started. */ @ActivityEventType public int getEventType() { @@ -104,6 +118,8 @@ public final class ActivityEvent implements Parcelable { return "ACTIVITY_STOPPED"; case TYPE_ACTIVITY_DESTROYED: return "ACTIVITY_DESTROYED"; + case TYPE_ACTIVITY_STARTED: + return "ACTIVITY_STARTED"; default: return "UKNOWN_TYPE: " + type; } diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 45da45aafabaf..f3a99dec22a2c 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -277,6 +277,7 @@ import android.os.SystemClock; import android.os.Trace; import android.os.UserHandle; import android.os.storage.StorageManager; +import android.service.contentcapture.ActivityEvent; import android.service.dreams.DreamActivity; import android.service.dreams.DreamManagerInternal; import android.service.voice.IVoiceInteractionSession; @@ -326,6 +327,7 @@ import com.android.internal.util.function.pooled.PooledLambda; import com.android.server.LocalServices; import com.android.server.am.AppTimeTracker; import com.android.server.am.PendingIntentRecord; +import com.android.server.contentcapture.ContentCaptureManagerInternal; import com.android.server.display.color.ColorDisplayService; import com.android.server.policy.WindowManagerPolicy; import com.android.server.uri.NeededUriGrants; @@ -4835,6 +4837,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A true /* activityChange */, true /* updateOomAdj */, true /* addPendingTopUid */); } + final ContentCaptureManagerInternal contentCaptureService = + LocalServices.getService(ContentCaptureManagerInternal.class); + if (contentCaptureService != null) { + contentCaptureService.notifyActivityEvent(mUserId, mActivityComponent, + ActivityEvent.TYPE_ACTIVITY_STARTED); + } break; case PAUSED: mAtmService.updateBatteryStats(this, false);