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

Commit 8c6b48a9 authored by Kai Li's avatar Kai Li Committed by Android (Google) Code Review
Browse files

Merge "Send a FLUSH event after each frame." into main

parents 80f15bd5 bbeb46cd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.view.View;
import android.view.ViewStructure;
import android.view.autofill.AutofillId;
import android.view.contentcapture.ViewNode.ViewStructureImpl;
import android.view.contentcapture.flags.Flags;
import android.view.contentprotection.ContentProtectionEventProcessor;
import android.view.inputmethod.BaseInputConnection;

@@ -1008,6 +1009,9 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
                    }
                }
                internalNotifyViewTreeEvent(sessionId, /* started= */ false);
                if (Flags.flushAfterEachFrame()) {
                    internalNotifySessionFlushEvent(sessionId);
                }
            }
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_VIEW);
+11 −0
Original line number Diff line number Diff line
@@ -15,3 +15,14 @@ flag {
    bug: "380381249"
    is_exported: true
}

flag {
    name: "flush_after_each_frame"
    namespace: "pixel_state_server"
    description: "Feature flag to send a flush event after each frame"
    bug: "380381249"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+35 −0
Original line number Diff line number Diff line
@@ -36,11 +36,15 @@ import android.content.pm.ParceledListSlice;
import android.graphics.Insets;
import android.os.Handler;
import android.os.RemoteException;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.SparseArray;
import android.view.View;
import android.view.autofill.AutofillId;
import android.view.contentcapture.flags.Flags;
import android.view.contentprotection.ContentProtectionEventProcessor;

import androidx.test.core.app.ApplicationProvider;
@@ -90,6 +94,8 @@ public class MainContentCaptureSessionTest {

    @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Mock private IContentCaptureManager mMockSystemServerInterface;

    @Mock private ContentProtectionEventProcessor mMockContentProtectionEventProcessor;
@@ -407,6 +413,7 @@ public class MainContentCaptureSessionTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_FLUSH_AFTER_EACH_FRAME)
    @SuppressWarnings("GuardedBy")
    public void notifyContentCaptureEvents_started_ContentCaptureEnabled_ProtectionEnabled()
            throws RemoteException {
@@ -433,6 +440,34 @@ public class MainContentCaptureSessionTest {
        assertThat(session.mEvents).isEmpty();
    }

    @Test
    @EnableFlags(Flags.FLAG_FLUSH_AFTER_EACH_FRAME)
    @SuppressWarnings("GuardedBy")
    public void notifyContentCaptureEvents_started_ContentCaptureEnabled_ProtectionEnabled_Flush()
            throws RemoteException {
        ContentCaptureOptions options =
                createOptions(
                        /* enableContentCaptureReceiver= */ true,
                        /* enableContentProtectionReceiver= */ true);
        MainContentCaptureSession session = createSession(options);
        session.mDirectServiceInterface = mMockContentCaptureDirectManager;

        session.onSessionStarted(0x2, null);
        // Override the processor for interaction verification.
        session.mContentProtectionEventProcessor = mMockContentProtectionEventProcessor;
        notifyContentCaptureEvents(session);
        mTestableLooper.processAllMessages();

        // Force flush will happen twice.
        verify(mMockContentCaptureDirectManager, times(1))
                .sendEvents(any(), eq(FLUSH_REASON_VIEW_TREE_APPEARING), any());
        verify(mMockContentCaptureDirectManager, times(1))
                .sendEvents(any(), eq(FLUSH_REASON_VIEW_TREE_APPEARED), any());
        // 5 view events + 2 view tree events + 1 flush event
        verify(mMockContentProtectionEventProcessor, times(8)).processEvent(any());
        assertThat(session.mEvents).isEmpty();
    }

    @Test
    public void notifyViewAppearedBelowMaximumBufferSize() throws RemoteException {
        ContentCaptureOptions options =