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

Commit 435736d3 authored by Adam He's avatar Adam He Committed by Android (Google) Code Review
Browse files

Merge changes from topics "nested_sessions", "fix_flush_sessions"

* changes:
  Implemented nested Content Capture sessions.
  Fixed how session created / removed events are generated.
parents cf82717c 4bc0f6be
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import java.util.List;
@SystemApi
@Deprecated
public final class ContentCaptureEventsRequest implements Parcelable {
// TODO(b/121033016): remove .java and .aidl once service implementation doesn't use it anymore
// TODO(b/121051220): remove .java and .aidl once service implementation doesn't use it anymore

    private final ContentCaptureEvent mEvent;

+15 −12
Original line number Diff line number Diff line
@@ -123,12 +123,12 @@ public abstract class ContentCaptureService extends Service {
    };

    /**
     * List of sessions per UID.
     * UIDs associated with each session.
     *
     * <p>This map is populated when an session is started, which is called by the system server
     * and can be trusted. Then subsequent calls made by the app are verified against this map.
     */
    private final ArrayMap<String, Integer> mSessionsByUid = new ArrayMap<>();
    private final ArrayMap<String, Integer> mSessionUids = new ArrayMap<>();

    @CallSuper
    @Override
@@ -285,13 +285,13 @@ public abstract class ContentCaptureService extends Service {
    @Override
    @CallSuper
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        final int size = mSessionsByUid.size();
        final int size = mSessionUids.size();
        pw.print("Number sessions: "); pw.println(size);
        if (size > 0) {
            final String prefix = "  ";
            for (int i = 0; i < size; i++) {
                pw.print(prefix); pw.print(mSessionsByUid.keyAt(i));
                pw.print(": uid="); pw.println(mSessionsByUid.valueAt(i));
                pw.print(prefix); pw.print(mSessionUids.keyAt(i));
                pw.print(": uid="); pw.println(mSessionUids.valueAt(i));
            }
        }
    }
@@ -309,7 +309,7 @@ public abstract class ContentCaptureService extends Service {

    private void handleOnCreateSession(@NonNull ContentCaptureContext context,
            @NonNull String sessionId, int uid, IResultReceiver clientReceiver) {
        mSessionsByUid.put(sessionId, uid);
        mSessionUids.put(sessionId, uid);
        onCreateContentCaptureSession(context, new ContentCaptureSessionId(sessionId));
        setClientState(clientReceiver, ContentCaptureSession.STATE_ACTIVE,
                mClientInterface.asBinder());
@@ -336,11 +336,11 @@ public abstract class ContentCaptureService extends Service {
                case ContentCaptureEvent.TYPE_SESSION_STARTED:
                    final ContentCaptureContext clientContext = event.getClientContext();
                    clientContext.setParentSessionId(event.getParentSessionId());
                    mSessionsByUid.put(sessionIdString, uid);
                    mSessionUids.put(sessionIdString, uid);
                    onCreateContentCaptureSession(clientContext, sessionId);
                    break;
                case ContentCaptureEvent.TYPE_SESSION_FINISHED:
                    mSessionsByUid.remove(sessionIdString);
                    mSessionUids.remove(sessionIdString);
                    onDestroyContentCaptureSession(sessionId);
                    break;
                default:
@@ -355,7 +355,7 @@ public abstract class ContentCaptureService extends Service {
    }

    private void handleFinishSession(@NonNull String sessionId) {
        mSessionsByUid.remove(sessionId);
        mSessionUids.remove(sessionId);
        onDestroyContentCaptureSession(new ContentCaptureSessionId(sessionId));
    }

@@ -372,10 +372,13 @@ public abstract class ContentCaptureService extends Service {
            default:
                sessionId = event.getSessionId();
        }
        final Integer rightUid = mSessionsByUid.get(sessionId);
        final Integer rightUid = mSessionUids.get(sessionId);
        if (rightUid == null) {
            if (VERBOSE) Log.v(TAG, "No session for " + sessionId);
            // Just ignore, as the session could have finished
            if (DEBUG) {
                Log.d(TAG, "handleIsRightCallerFor(" + event + "): no session for " + sessionId
                        + ": " + mSessionUids);
            }
            // Just ignore, as the session could have been finished already
            return false;
        }
        if (rightUid != uid) {
+19 −10
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import java.io.PrintWriter;
final class ChildContentCaptureSession extends ContentCaptureSession {

    @NonNull
    private final MainContentCaptureSession mParent;
    private final ContentCaptureSession mParent;

    /**
     * {@link ContentCaptureContext} set by client, or {@code null} when it's the
@@ -46,16 +46,25 @@ final class ChildContentCaptureSession extends ContentCaptureSession {
    private final ContentCaptureContext mClientContext;

    /** @hide */
    protected ChildContentCaptureSession(@NonNull MainContentCaptureSession parent,
    protected ChildContentCaptureSession(@NonNull ContentCaptureSession parent,
            @NonNull ContentCaptureContext clientContext) {
        mParent = parent;
        mClientContext = Preconditions.checkNotNull(clientContext);
    }

    @Override
    ContentCaptureSession newChild(@NonNull ContentCaptureContext context) {
        // TODO(b/121033016): implement it
        throw new UnsupportedOperationException("grand-children not implemented yet");
    MainContentCaptureSession getMainCaptureSession() {
        if (mParent instanceof MainContentCaptureSession) {
            return (MainContentCaptureSession) mParent;
        }
        return mParent.getMainCaptureSession();
    }

    @Override
    ContentCaptureSession newChild(@NonNull ContentCaptureContext clientContext) {
        final ContentCaptureSession child = new ChildContentCaptureSession(this, clientContext);
        getMainCaptureSession().notifyChildSessionStarted(mId, child.mId, clientContext);
        return child;
    }

    @Override
@@ -65,27 +74,27 @@ final class ChildContentCaptureSession extends ContentCaptureSession {

    @Override
    void onDestroy() {
        mParent.notifyChildSessionFinished(mParent.mId, mId);
        getMainCaptureSession().notifyChildSessionFinished(mParent.mId, mId);
    }

    @Override
    void internalNotifyViewAppeared(@NonNull ViewStructureImpl node) {
        mParent.notifyViewAppeared(mId, node);
        getMainCaptureSession().notifyViewAppeared(mId, node);
    }

    @Override
    void internalNotifyViewDisappeared(@NonNull AutofillId id) {
        mParent.notifyViewDisappeared(mId, id);
        getMainCaptureSession().notifyViewDisappeared(mId, id);
    }

    @Override
    void internalNotifyViewTextChanged(@NonNull AutofillId id, @Nullable CharSequence text,
            int flags) {
        mParent.notifyViewTextChanged(mId, id, text, flags);
        getMainCaptureSession().notifyViewTextChanged(mId, id, text, flags);
    }
    @Override
    boolean isContentCaptureEnabled() {
        return mParent.isContentCaptureEnabled();
        return getMainCaptureSession().isContentCaptureEnabled();
    }

    @Override
+4 −0
Original line number Diff line number Diff line
@@ -251,6 +251,10 @@ public final class ContentCaptureEvent implements Parcelable {
    public String toString() {
        final StringBuilder string = new StringBuilder("ContentCaptureEvent[type=")
                .append(getTypeAsString(mType));
        string.append(", session=").append(mSessionId);
        if (mType == TYPE_SESSION_STARTED && mParentSessionId != null) {
            string.append(", parent=").append(mParentSessionId);
        }
        if (mFlags > 0) {
            string.append(", flags=").append(mFlags);
        }
+0 −3
Original line number Diff line number Diff line
@@ -117,13 +117,11 @@ public final class ContentCaptureManager {
    /** @hide */
    public void onActivityStarted(@NonNull IBinder applicationToken,
            @NonNull ComponentName activityComponent) {
        // TODO(b/121033016): must start all sessions
        getMainContentCaptureSession().start(applicationToken, activityComponent);
    }

    /** @hide */
    public void onActivityStopped() {
        // TODO(b/121033016): must finish all sessions
        getMainContentCaptureSession().destroy();
    }

@@ -135,7 +133,6 @@ public final class ContentCaptureManager {
     * @hide
     */
    public void flush() {
        // TODO(b/121033016): must flush all sessions
        getMainContentCaptureSession().flush();
    }

Loading