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

Commit 81489831 authored by Oleg Blinnikov's avatar Oleg Blinnikov Committed by Android (Google) Code Review
Browse files

Merge "Dont stop external display connection session" into main

parents a6b4065e e06dcc28
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -518,11 +518,16 @@ public final class ExternalDisplayStatsService {
    private void logExternalDisplayIdleStarted() {
        synchronized (mExternalDisplayStates) {
            for (var i = 0; i < mExternalDisplayStates.size(); i++) {
                final int displayId = mExternalDisplayStates.keyAt(i);
                final int state = mExternalDisplayStates.get(displayId, DISCONNECTED_STATE);
                // Don't try to stop "connected" session by keyguard event.
                // There is no purpose to measure how long keyguard is shown while external
                // display is connected but not used for mirroring or extended display.
                // Therefore there no need to log this event.
                if (state != DISCONNECTED_STATE && state != CONNECTED_STATE) {
                    mInjector.writeLog(FrameworkStatsLog.EXTERNAL_DISPLAY_STATE_CHANGED,
                            KEYGUARD, i + 1, mIsExternalDisplayUsedForAudio);
                    if (DEBUG) {
                    final int displayId = mExternalDisplayStates.keyAt(i);
                    final int state = mExternalDisplayStates.get(displayId, DISCONNECTED_STATE);
                        Slog.d(TAG, "logExternalDisplayIdleStarted"
                                            + " displayId=" + displayId
                                            + " currentState=" + state
@@ -534,13 +539,18 @@ public final class ExternalDisplayStatsService {
                }
            }
        }
    }

    private void logExternalDisplayIdleEnded() {
        synchronized (mExternalDisplayStates) {
            for (var i = 0; i < mExternalDisplayStates.size(); i++) {
                final int displayId = mExternalDisplayStates.keyAt(i);
                final int state = mExternalDisplayStates.get(displayId, DISCONNECTED_STATE);
                if (state == DISCONNECTED_STATE) {
                // No need to restart "connected" session after keyguard is stopped.
                // This is because the connection is continuous even if keyguard is shown.
                // In case in the future keyguard needs to be measured also while display
                // is not used, then a 'keyguard finished' event needs to be emitted in this case.
                if (state == DISCONNECTED_STATE || state == CONNECTED_STATE) {
                    return;
                }
                mInjector.writeLog(FrameworkStatsLog.EXTERNAL_DISPLAY_STATE_CHANGED,
+29 −2
Original line number Diff line number Diff line
@@ -151,9 +151,10 @@ public class ExternalDisplayStatsServiceTest {
    }

    @Test
    public void testDisplayInteractivityChanges(
    public void testDisplayInteractivityChangesWhileMirroring(
            @TestParameter final boolean isExternalDisplayUsedForAudio) {
        mExternalDisplayStatsService.onDisplayConnected(mMockedLogicalDisplay);
        mExternalDisplayStatsService.onDisplayAdded(EXTERNAL_DISPLAY_ID);
        mHandler.flush();
        assertThat(mInteractivityReceiver).isNotNull();

@@ -180,11 +181,37 @@ public class ExternalDisplayStatsServiceTest {
        mInteractivityReceiver.onReceive(null, null);
        assertThat(mExternalDisplayStatsService.isInteractiveExternalDisplays()).isTrue();
        verify(mMockedInjector).writeLog(FrameworkStatsLog.EXTERNAL_DISPLAY_STATE_CHANGED,
                FrameworkStatsLog.EXTERNAL_DISPLAY_STATE_CHANGED__STATE__CONNECTED,
                FrameworkStatsLog.EXTERNAL_DISPLAY_STATE_CHANGED__STATE__MIRRORING,
                /*numberOfDisplays=*/ 1,
                isExternalDisplayUsedForAudio);
    }

    @Test
    public void testDisplayInteractivityChangesWhileConnected() {
        mExternalDisplayStatsService.onDisplayConnected(mMockedLogicalDisplay);
        mHandler.flush();
        assertThat(mInteractivityReceiver).isNotNull();
        clearInvocations(mMockedInjector);

        // Default is 'interactive', so no log should be written.
        mInteractivityReceiver.onReceive(null, null);
        assertThat(mExternalDisplayStatsService.isInteractiveExternalDisplays()).isTrue();
        verify(mMockedInjector, never()).writeLog(anyInt(), anyInt(), anyInt(), anyBoolean());

        // Change to non-interactive should not produce log
        when(mMockedInjector.isInteractive(eq(EXTERNAL_DISPLAY_ID))).thenReturn(false);
        mInteractivityReceiver.onReceive(null, null);
        assertThat(mExternalDisplayStatsService.isInteractiveExternalDisplays()).isFalse();
        verify(mMockedInjector, never()).writeLog(anyInt(), anyInt(), anyInt(), anyBoolean());
        clearInvocations(mMockedInjector);

        // Change back to interactive should not produce log
        when(mMockedInjector.isInteractive(eq(EXTERNAL_DISPLAY_ID))).thenReturn(true);
        mInteractivityReceiver.onReceive(null, null);
        assertThat(mExternalDisplayStatsService.isInteractiveExternalDisplays()).isTrue();
        verify(mMockedInjector, never()).writeLog(anyInt(), anyInt(), anyInt(), anyBoolean());
    }

    @Test
    public void testAudioPlaybackChanges() {
        mExternalDisplayStatsService.onDisplayConnected(mMockedLogicalDisplay);