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
This commit is contained in:
Joanne Chung
2021-06-18 18:35:14 +08:00
parent 44e18a7ab7
commit cdcf3a8339
2 changed files with 26 additions and 2 deletions

View File

@@ -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.
*
* <p>There are some reason, ACTIVITY_START cannot be added into UsageStats. We don't depend on
* UsageEvents for Activity start.
* </p>
*
* @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;
}

View File

@@ -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);