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

Commit cdcf3a83 authored by Joanne Chung's avatar Joanne Chung
Browse files

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
parent 44e18a7a
Loading
Loading
Loading
Loading
+18 −2
Original line number Original line Diff line number Diff line
@@ -55,12 +55,25 @@ public final class ActivityEvent implements Parcelable {
     */
     */
    public static final int TYPE_ACTIVITY_DESTROYED = Event.ACTIVITY_DESTROYED;
    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 */
    /** @hide */
    @IntDef(prefix = { "TYPE_" }, value = {
    @IntDef(prefix = { "TYPE_" }, value = {
            TYPE_ACTIVITY_RESUMED,
            TYPE_ACTIVITY_RESUMED,
            TYPE_ACTIVITY_PAUSED,
            TYPE_ACTIVITY_PAUSED,
            TYPE_ACTIVITY_STOPPED,
            TYPE_ACTIVITY_STOPPED,
            TYPE_ACTIVITY_DESTROYED
            TYPE_ACTIVITY_DESTROYED,
            TYPE_ACTIVITY_STARTED
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface ActivityEventType{}
    public @interface ActivityEventType{}
@@ -86,7 +99,8 @@ public final class ActivityEvent implements Parcelable {
     * Gets the event type.
     * Gets the event type.
     *
     *
     * @return either {@link #TYPE_ACTIVITY_RESUMED}, {@value #TYPE_ACTIVITY_PAUSED},
     * @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
    @ActivityEventType
    public int getEventType() {
    public int getEventType() {
@@ -104,6 +118,8 @@ public final class ActivityEvent implements Parcelable {
                return "ACTIVITY_STOPPED";
                return "ACTIVITY_STOPPED";
            case TYPE_ACTIVITY_DESTROYED:
            case TYPE_ACTIVITY_DESTROYED:
                return "ACTIVITY_DESTROYED";
                return "ACTIVITY_DESTROYED";
            case TYPE_ACTIVITY_STARTED:
                return "ACTIVITY_STARTED";
            default:
            default:
                return "UKNOWN_TYPE: " + type;
                return "UKNOWN_TYPE: " + type;
        }
        }
+8 −0
Original line number Original line Diff line number Diff line
@@ -277,6 +277,7 @@ import android.os.SystemClock;
import android.os.Trace;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.os.storage.StorageManager;
import android.service.contentcapture.ActivityEvent;
import android.service.dreams.DreamActivity;
import android.service.dreams.DreamActivity;
import android.service.dreams.DreamManagerInternal;
import android.service.dreams.DreamManagerInternal;
import android.service.voice.IVoiceInteractionSession;
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.LocalServices;
import com.android.server.am.AppTimeTracker;
import com.android.server.am.AppTimeTracker;
import com.android.server.am.PendingIntentRecord;
import com.android.server.am.PendingIntentRecord;
import com.android.server.contentcapture.ContentCaptureManagerInternal;
import com.android.server.display.color.ColorDisplayService;
import com.android.server.display.color.ColorDisplayService;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.uri.NeededUriGrants;
import com.android.server.uri.NeededUriGrants;
@@ -4835,6 +4837,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                            true /* activityChange */, true /* updateOomAdj */,
                            true /* activityChange */, true /* updateOomAdj */,
                            true /* addPendingTopUid */);
                            true /* addPendingTopUid */);
                }
                }
                final ContentCaptureManagerInternal contentCaptureService =
                        LocalServices.getService(ContentCaptureManagerInternal.class);
                if (contentCaptureService != null) {
                    contentCaptureService.notifyActivityEvent(mUserId, mActivityComponent,
                            ActivityEvent.TYPE_ACTIVITY_STARTED);
                }
                break;
                break;
            case PAUSED:
            case PAUSED:
                mAtmService.updateBatteryStats(this, false);
                mAtmService.updateBatteryStats(this, false);