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

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

Merge "No more flush for view tree events." into main

parents 38b97132 c6518724
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -881,8 +881,15 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        final boolean forceFlush = disableFlush ? !started : FORCE_FLUSH;
        final boolean forceFlush = disableFlush ? !started : FORCE_FLUSH;


        final ContentCaptureEvent event = new ContentCaptureEvent(sessionId, type);
        final ContentCaptureEvent event = new ContentCaptureEvent(sessionId, type);

        if (Flags.reduceBinderTransactionEnabled()) {
            // Don't force a flush for view tree events. A dedicated flush event will be sent
            // after the entire view tree is processed, reducing binder transactions.
            enqueueEvent(event);
        } else {
            enqueueEvent(event, forceFlush);
            enqueueEvent(event, forceFlush);
        }
        }
    }


    @Override
    @Override
    public void internalNotifySessionResumed() {
    public void internalNotifySessionResumed() {
@@ -1074,10 +1081,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
                    }
                    }
                }
                }
                internalNotifyViewTreeEvent(sessionId, /* started= */ false);
                internalNotifyViewTreeEvent(sessionId, /* started= */ false);
                if (Flags.flushAfterEachFrame()) {
                internalNotifySessionFlushEvent(sessionId);
                internalNotifySessionFlushEvent(sessionId);
            }
            }
            }
        } finally {
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_VIEW);
            Trace.traceEnd(Trace.TRACE_TAG_VIEW);
        }
        }
+37 −29
Original line number Original line Diff line number Diff line
@@ -413,35 +413,6 @@ public class MainContentCaptureSessionTest {
    }
    }


    @Test
    @Test
    @DisableFlags(Flags.FLAG_FLUSH_AFTER_EACH_FRAME)
    @SuppressWarnings("GuardedBy")
    public void notifyContentCaptureEvents_started_ContentCaptureEnabled_ProtectionEnabled()
            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());
        // Other than the five view events, there will be two additional tree appearing events.
        verify(mMockContentProtectionEventProcessor, times(7)).processEvent(any());
        assertThat(session.mEvents).isEmpty();
    }

    @Test
    @EnableFlags(Flags.FLAG_FLUSH_AFTER_EACH_FRAME)
    @SuppressWarnings("GuardedBy")
    @SuppressWarnings("GuardedBy")
    public void notifyContentCaptureEvents_started_ContentCaptureEnabled_ProtectionEnabled_Flush()
    public void notifyContentCaptureEvents_started_ContentCaptureEnabled_ProtectionEnabled_Flush()
            throws RemoteException {
            throws RemoteException {
@@ -534,6 +505,43 @@ public class MainContentCaptureSessionTest {
        assertThat(session.mEventProcessQueue).hasSize(1);
        assertThat(session.mEventProcessQueue).hasSize(1);
    }
    }


    @Test
    @DisableFlags(Flags.FLAG_REDUCE_BINDER_TRANSACTION_ENABLED)
    public void notifyViewsAppeared_reducedBinderTransactionDisabled() throws RemoteException {
        ContentCaptureOptions options =
                createOptions(
                        /* enableContentCaptureReceiver= */ true,
                        /* enableContentProtectionReceiver= */ false);
        MainContentCaptureSession session = createSession(options);
        session.mDirectServiceInterface = mMockContentCaptureDirectManager;
        session.onSessionStarted(0x2, null);
        View view = prepareView(session);

        session.notifyViewsAppeared(List.of(session.newViewStructure(view)));
        mTestableLooper.processAllMessages();

        verify(mMockContentCaptureDirectManager, times(2)).sendEvents(any(), anyInt(), any());
    }

    @Test
    @EnableFlags(Flags.FLAG_REDUCE_BINDER_TRANSACTION_ENABLED)
    public void notifyViewsAppeared_reducedBinderTransactionEnabled() throws RemoteException {
        ContentCaptureOptions options =
                createOptions(
                        /* enableContentCaptureReceiver= */ true,
                        /* enableContentProtectionReceiver= */ false);
        MainContentCaptureSession session = createSession(options);
        session.mDirectServiceInterface = mMockContentCaptureDirectManager;
        session.onSessionStarted(0x2, null);
        View view = prepareView(session);

        session.notifyViewsAppeared(List.of(session.newViewStructure(view)));
        mTestableLooper.processAllMessages();

        // No events should be sent to the service.
        verifyNoMoreInteractions(mMockContentCaptureDirectManager);
    }

    /** Simulates the regular content capture events sequence. */
    /** Simulates the regular content capture events sequence. */
    private void notifyContentCaptureEvents(final MainContentCaptureSession session) {
    private void notifyContentCaptureEvents(final MainContentCaptureSession session) {
        final ArrayList<Object> events = new ArrayList<>(
        final ArrayList<Object> events = new ArrayList<>(