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

Commit 358acd58 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ignore ContentCapture events after the activity stopped."

parents 2e425c6f bef744c4
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import dalvik.system.CloseGuard;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Session used to notify a system-provided Content Capture service about events associated with
@@ -90,6 +91,12 @@ public abstract class ContentCaptureSession implements AutoCloseable {

    private final CloseGuard mCloseGuard = CloseGuard.get();

    /**
     * Guard use to ignore events after it's destroyed.
     */
    @NonNull
    private final AtomicBoolean mDestroyed = new AtomicBoolean();

    /** @hide */
    @Nullable
    protected final String mId = UUID.randomUUID().toString();
@@ -157,10 +164,10 @@ public abstract class ContentCaptureSession implements AutoCloseable {
     * <p>Once destroyed, any new notification will be dropped.
     */
    public final void destroy() {
        //TODO(b/111276913): mark it as destroyed so other methods are ignored (and test on CTS)

        //TODO(b/111276913): probably shouldn't check for it
        if (!isContentCaptureEnabled()) return;
        if (!mDestroyed.compareAndSet(false, true)) {
            Log.e(mTag, "destroy(): already destroyed");
            return;
        }

        mCloseGuard.close();

@@ -298,10 +305,13 @@ public abstract class ContentCaptureSession implements AutoCloseable {
        return new ViewNode.ViewStructureImpl(parentId, virtualId);
    }

    abstract boolean isContentCaptureEnabled();
    boolean isContentCaptureEnabled() {
        return !mDestroyed.get();
    }

    @CallSuper
    void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
        pw.print(prefix); pw.print("destroyed: "); pw.println(mDestroyed.get());
        if (mChildren != null && !mChildren.isEmpty()) {
            final String prefix2 = prefix + "  ";
            final int numberChildren = mChildren.size();
+3 −2
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
    /**
     * Callback from {@code system_server} after call to
     * {@link IContentCaptureManager#startSession(int, IBinder, ComponentName, String,
     * ContentCaptureContext, int, IResultReceiver)}.
     * int, IResultReceiver)}.
     *
     * @param resultCode session state
     * @param binder handle to {@code IContentCaptureDirectManager}
@@ -425,7 +425,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession {

    @Override
    boolean isContentCaptureEnabled() {
        return mSystemServerInterface != null && !mDisabled.get();
        return super.isContentCaptureEnabled() && mSystemServerInterface != null
                && !mDisabled.get();
    }

    // TODO(b/121033016): refactor "notifyXXXX" methods below to a common "Buffer" object that is