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

Commit c6518724 authored by Kai Li's avatar Kai Li
Browse files

No more flush for view tree events.

Background: after API B, there is a dedicated flush event after the traversal. No need to flush the view tree events anymore.

This can help to reduce the binder transactions of `IContentCaptureDirectManager#sendEvents`.

Also cleaned up the launched flag `flush_after_each_frame`.

Bug: 433614684
Flag: android.view.contentcapture.flags.reduce_binder_transaction_enabled
Test: atest FrameworksCoreTests:android.view.contentcapture.MainContentCaptureSessionTest

Change-Id: I11f5ee4c54b8c96399a0355f0e0f8f354adcebca
parent ee1c6f49
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -881,8 +881,15 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        final boolean forceFlush = disableFlush ? !started : FORCE_FLUSH;

        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);
        }
    }

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

    @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")
    public void notifyContentCaptureEvents_started_ContentCaptureEnabled_ProtectionEnabled_Flush()
            throws RemoteException {
@@ -534,6 +505,43 @@ public class MainContentCaptureSessionTest {
        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. */
    private void notifyContentCaptureEvents(final MainContentCaptureSession session) {
        final ArrayList<Object> events = new ArrayList<>(