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

Commit 518fb624 authored by Felipe Leme's avatar Felipe Leme
Browse files

Changed ContentCapture session lifecycle so session is kept alive when service died.

This is useful for long-lived activities (like a browser), so child session can still be reported
after the service is restarted after dying.

Test: manual verification (cannot be tested using CTS because it would kill the test process)
Test: atest FrameworksCoreTests:android.view.contentcapture.ContentCaptureEventTest
Test: m update-api

Bug: 128466656

Change-Id: I9310263e897e929189d323d31853592a374dc6e0
parent 9699ac5e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9530,6 +9530,7 @@ package android.view.contentcapture {
    method public int getTaskId();
    field public static final int FLAG_DISABLED_BY_APP = 1; // 0x1
    field public static final int FLAG_DISABLED_BY_FLAG_SECURE = 2; // 0x2
    field public static final int FLAG_RECONNECTED = 4; // 0x4
  }
  public final class ContentCaptureEvent implements android.os.Parcelable {
+1 −0
Original line number Diff line number Diff line
@@ -3056,6 +3056,7 @@ package android.view.contentcapture {
    method public int getTaskId();
    field public static final int FLAG_DISABLED_BY_APP = 1; // 0x1
    field public static final int FLAG_DISABLED_BY_FLAG_SECURE = 2; // 0x2
    field public static final int FLAG_RECONNECTED = 4; // 0x4
  }

  public final class ContentCaptureEvent implements android.os.Parcelable {
+5 −4
Original line number Diff line number Diff line
@@ -102,9 +102,10 @@ public abstract class ContentCaptureService extends Service {

        @Override
        public void onSessionStarted(ContentCaptureContext context, String sessionId, int uid,
                IResultReceiver clientReceiver) {
                IResultReceiver clientReceiver, int initialState) {
            mHandler.sendMessage(obtainMessage(ContentCaptureService::handleOnCreateSession,
                    ContentCaptureService.this, context, sessionId, uid, clientReceiver));
                    ContentCaptureService.this, context, sessionId, uid, clientReceiver,
                    initialState));
        }

        @Override
@@ -335,7 +336,7 @@ public abstract class ContentCaptureService extends Service {
    // so we don't need to create a temporary InteractionSessionId for each event.

    private void handleOnCreateSession(@NonNull ContentCaptureContext context,
            @NonNull String sessionId, int uid, IResultReceiver clientReceiver) {
            @NonNull String sessionId, int uid, IResultReceiver clientReceiver, int initialState) {
        mSessionUids.put(sessionId, uid);
        onCreateContentCaptureSession(context, new ContentCaptureSessionId(sessionId));

@@ -348,7 +349,7 @@ public abstract class ContentCaptureService extends Service {
            stateFlags |= ContentCaptureSession.STATE_BY_APP;
        }
        if (stateFlags == 0) {
            stateFlags = ContentCaptureSession.STATE_ACTIVE;
            stateFlags = initialState;
        } else {
            stateFlags |= ContentCaptureSession.STATE_DISABLED;

+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ oneway interface IContentCaptureService {
    void onConnected(IBinder callback, boolean verbose, boolean debug);
    void onDisconnected();
    void onSessionStarted(in ContentCaptureContext context, String sessionId, int uid,
                          in IResultReceiver clientReceiver);
                          in IResultReceiver clientReceiver, int initialState);
    void onSessionFinished(String sessionId);
    void onActivitySnapshot(String sessionId, in SnapshotData snapshotData);
    void onUserDataRemovalRequest(in UserDataRemovalRequest request);
+25 −3
Original line number Diff line number Diff line
@@ -71,10 +71,21 @@ public final class ContentCaptureContext implements Parcelable {
    @TestApi
    public static final int FLAG_DISABLED_BY_FLAG_SECURE = 0x2;

    /**
     * Flag used when the event is sent because the Android System reconnected to the service (for
     * example, after its process died).
     *
     * @hide
     */
    @SystemApi
    @TestApi
    public static final int FLAG_RECONNECTED = 0x4;

    /** @hide */
    @IntDef(flag = true, prefix = { "FLAG_" }, value = {
            FLAG_DISABLED_BY_APP,
            FLAG_DISABLED_BY_FLAG_SECURE
            FLAG_DISABLED_BY_FLAG_SECURE,
            FLAG_RECONNECTED
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface ContextCreationFlags{}
@@ -126,6 +137,17 @@ public final class ContentCaptureContext implements Parcelable {
        mDisplayId = Display.INVALID_DISPLAY;
    }

    /** @hide */
    public ContentCaptureContext(@Nullable ContentCaptureContext original, int extraFlags) {
        mHasClientContext = original.mHasClientContext;
        mExtras = original.mExtras;
        mId = original.mId;
        mComponentName = original.mComponentName;
        mTaskId = original.mTaskId;
        mFlags = original.mFlags | extraFlags;
        mDisplayId = original.mDisplayId;
    }

    /**
     * Gets the (optional) extras set by the app (through {@link Builder#setExtras(Bundle)}).
     *
@@ -199,8 +221,8 @@ public final class ContentCaptureContext implements Parcelable {
    /**
     * Gets the flags associated with this context.
     *
     * @return any combination of {@link #FLAG_DISABLED_BY_FLAG_SECURE} and
     * {@link #FLAG_DISABLED_BY_APP}.
     * @return any combination of {@link #FLAG_DISABLED_BY_FLAG_SECURE},
     * {@link #FLAG_DISABLED_BY_APP} and {@link #FLAG_RECONNECTED}.
     *
     * @hide
     */
Loading