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

Commit 43af15ea authored by Joanne's avatar Joanne
Browse files

Report ActivityId in Content capture ActivityEvent

Currently, the ActivityEvent only reports ComponentName and the event
type. It may be a problem when launching the split mode for tablet.
If the Activity launch mode is standard or singleTop, system allows
to launch the same Activity in split mode. The ContentCaptureService
cannot identify two different Activities instances in the split mode.

To resolve this problem, the system will also report ActivityId in
ActivityEvent to help ContentCaptureService to identify the Activity.

Bug: 245023463
Test: atest CtsContentCaptureServiceTestCases
Change-Id: I8a79633a8ff0e5a99dc154bb4002a418b2e98219
parent d08eb3f9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11159,6 +11159,7 @@ package android.service.contentcapture {
  public final class ActivityEvent implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.app.assist.ActivityId getActivityId();
    method @NonNull public android.content.ComponentName getComponentName();
    method public int getEventType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
+2 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager.ProcessCapability;
import android.app.ActivityManager.RestrictionLevel;
import android.app.assist.ActivityId;
import android.content.ComponentName;
import android.content.IIntentReceiver;
import android.content.IIntentSender;
@@ -343,7 +344,7 @@ public abstract class ActivityManagerInternal {
     */
    public abstract void updateActivityUsageStats(
            ComponentName activity, @UserIdInt int userId, int event, IBinder appToken,
            ComponentName taskRoot);
            ComponentName taskRoot, ActivityId activityId);
    public abstract void updateForegroundTimeIfOnBattery(
            String packageName, int uid, long cpuTimeDiff);
    public abstract void sendForegroundProfileChanged(@UserIdInt int userId);
+20 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.service.contentcapture;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.assist.ActivityId;
import android.app.usage.UsageEvents.Event;
import android.content.ComponentName;
import android.os.Parcel;
@@ -80,13 +81,24 @@ public final class ActivityEvent implements Parcelable {

    private final @NonNull ComponentName mComponentName;
    private final @ActivityEventType int mType;
    private final @NonNull ActivityId mActivityId;

    /** @hide */
    public ActivityEvent(@NonNull ComponentName componentName, @ActivityEventType int type) {
    public ActivityEvent(@NonNull ActivityId activityId,
            @NonNull ComponentName componentName, @ActivityEventType int type) {
        mActivityId = activityId;
        mComponentName = componentName;
        mType = type;
    }

    /**
     * Gets the ActivityId of the activity associated with the event.
     */
    @NonNull
    public ActivityId getActivityId() {
        return mActivityId;
    }

    /**
     * Gests the {@link ComponentName} of the activity associated with the event.
     */
@@ -129,6 +141,7 @@ public final class ActivityEvent implements Parcelable {
    @Override
    public String toString() {
        return new StringBuilder("ActivityEvent[").append(mComponentName.toShortString())
                .append(", ActivityId: ").append(mActivityId)
                .append("]:").append(getTypeAsString(mType)).toString();
    }

@@ -141,6 +154,7 @@ public final class ActivityEvent implements Parcelable {
    public void writeToParcel(@NonNull Parcel parcel, int flags) {
        parcel.writeParcelable(mComponentName, flags);
        parcel.writeInt(mType);
        parcel.writeParcelable(mActivityId, flags);
    }

    public static final @android.annotation.NonNull Creator<ActivityEvent> CREATOR =
@@ -149,9 +163,12 @@ public final class ActivityEvent implements Parcelable {
        @Override
        @NonNull
        public ActivityEvent createFromParcel(@NonNull Parcel parcel) {
            final ComponentName componentName = parcel.readParcelable(null, android.content.ComponentName.class);
            final ComponentName componentName =
                    parcel.readParcelable(null, ComponentName.class);
            final int eventType = parcel.readInt();
            return new ActivityEvent(componentName, eventType);
            final ActivityId activityId =
                    parcel.readParcelable(null, ActivityId.class);
            return new ActivityEvent(activityId, componentName, eventType);
        }

        @Override
+6 −2
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManagerInternal;
import android.app.ActivityThread;
import android.app.assist.ActivityId;
import android.content.ComponentName;
import android.content.ContentCaptureOptions;
import android.content.ContentResolver;
@@ -916,13 +917,16 @@ public final class ContentCaptureManagerService extends
            return mGlobalContentCaptureOptions.getOptions(userId, packageName);
        }

        // ErrorProne says ContentCaptureManagerService.this.mLock needs to be guarded by
        // 'service.mLock', which is the same as mLock.
        @SuppressWarnings("GuardedBy")
        @Override
        public void notifyActivityEvent(int userId, @NonNull ComponentName activityComponent,
                @ActivityEventType int eventType) {
                @ActivityEventType int eventType, @NonNull ActivityId activityId) {
            synchronized (mLock) {
                final ContentCapturePerUserService service = peekServiceForUserLocked(userId);
                if (service != null) {
                    service.onActivityEventLocked(activityComponent, eventType);
                    service.onActivityEventLocked(activityId, activityComponent, eventType);
                }
            }
        }
+3 −2
Original line number Diff line number Diff line
@@ -548,12 +548,13 @@ final class ContentCapturePerUserService
    }

    @GuardedBy("mLock")
    void onActivityEventLocked(@NonNull ComponentName componentName, @ActivityEventType int type) {
    void onActivityEventLocked(@NonNull ActivityId activityId,
            @NonNull ComponentName componentName, @ActivityEventType int type) {
        if (mRemoteService == null) {
            if (mMaster.debug) Slog.d(mTag, "onActivityEvent(): no remote service");
            return;
        }
        final ActivityEvent event = new ActivityEvent(componentName, type);
        final ActivityEvent event = new ActivityEvent(activityId, componentName, type);

        if (mMaster.verbose) Slog.v(mTag, "onActivityEvent(): " + event);

Loading