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

Commit bcf1d66f authored by Danae Savvidi's avatar Danae Savvidi
Browse files

Add DisplayInfo details logging for DisplayInfoChanged atom

Get more information for the EVENT_TYPE_BASIC_CHANGED event specifically which field in DisplayInfo changed, because currently we only get the type of event not the details.

Bug: 435146856
Bug: 431149632
Flag: com.android.server.display.feature.flags.enable_logging_for_display_events
Test: atest DisplayEventOccurredStatsTests
Test: atest DisplayManagerServiceTest
Change-Id: I34943d1eb43acfc496a0781d2aa0deb9f8c04aca
parent dcbcebda
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.server.display;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerGlobal;
import android.util.SparseIntArray;
import android.view.DisplayInfo;
import android.view.DisplayInfo.DisplayInfoGroup;

import com.android.internal.util.FrameworkStatsLog;

@@ -34,6 +36,36 @@ public final class DisplayFrameworkStatsLogger {
                notifiedUids.size());
    }

    /** Logs DisplayInfoChanged push atom */
    public void logDisplayInfoChanged(int changedGroups,
            DisplayInfo.DisplayInfoChangeSource source) {
        FrameworkStatsLog.write(
                FrameworkStatsLog.DISPLAY_INFO_CHANGED,
                Integer.bitCount(changedGroups),
                (changedGroups & DisplayInfoGroup.BASIC_PROPERTIES.getMask()) > 0 ? 1 : 0,
                (changedGroups & DisplayInfoGroup.DIMENSIONS_AND_SHAPES.getMask()) > 0 ? 1 : 0,
                (changedGroups
                        & DisplayInfoGroup.ORIENTATION_AND_ROTATION.getMask()) > 0 ? 1 : 0,
                (changedGroups & DisplayInfoGroup.REFRESH_RATE_AND_MODE.getMask()) > 0 ? 1 : 0,
                (changedGroups & DisplayInfoGroup.COLOR_AND_BRIGHTNESS.getMask()) > 0 ? 1 : 0,
                (changedGroups & DisplayInfoGroup.STATE.getMask()) > 0 ? 1 : 0,
                toProtoEventSource(source));
    }

    /** Maps DisplayInfoChangeSource to atom */
    private int toProtoEventSource(DisplayInfo.DisplayInfoChangeSource source) {
        return switch (source) {
            case DISPLAY_MANAGER ->
                FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_DISPLAY_MANAGER;
            case WINDOW_MANAGER ->
                FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_WINDOW_MANAGER;
            case DISPLAY_SWAP ->
                FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_DISPLAY_SWAP;
            case OTHER -> FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_OTHER;
            default -> FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_UNKNOWN;
        };
    }

    /**
     * Maps DisplayEvent to atom. Default case "unknown" is required when defining an atom.
     * Currently private display events {@link DisplayManager.PrivateEventType} are marked as
+29 −6
Original line number Diff line number Diff line
@@ -2605,11 +2605,10 @@ public final class DisplayManagerService extends SystemService {

    private void handleLogicalDisplayFrameRateOverridesChangedLocked(
            @NonNull LogicalDisplay display) {
        final int displayId = display.getDisplayIdLocked();
        // We don't bother invalidating the display info caches here because any changes to the
        // display info will trigger a cache invalidation inside of LogicalDisplay before we hit
        // this point.
        sendDisplayEventFrameRateOverrideLocked(displayId);
        sendDisplayEventFrameRateOverrideLocked(display);
        scheduleTraversalLocked(false);
    }

@@ -3698,6 +3697,11 @@ public final class DisplayManagerService extends SystemService {
    private void sendDisplayEventLocked(@NonNull LogicalDisplay display, @DisplayEvent int event) {
        int displayId = display.getDisplayIdLocked();
        Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
        if (mFlags.isDisplayEventsLoggingEnabled()
                && event == DisplayManagerGlobal.EVENT_DISPLAY_BASIC_CHANGED) {
            msg.obj = new DisplayInfoChangedFields(display.getDisplayInfoGroupsChangedLocked(),
                    display.getDisplayInfoChangeSource());
        }
        if (mExtraDisplayEventLogging) {
            Slog.i(TAG, "Deliver Display Event on Handler: " + event);
        }
@@ -3709,12 +3713,18 @@ public final class DisplayManagerService extends SystemService {
        mHandler.sendMessage(msg);
    }

    private void sendDisplayEventFrameRateOverrideLocked(int displayId) {
    private void sendDisplayEventFrameRateOverrideLocked(LogicalDisplay display) {
        int event = (mFlags.isFramerateOverrideTriggersRrCallbacksEnabled())
                ? DisplayManagerGlobal.EVENT_DISPLAY_REFRESH_RATE_CHANGED
                : DisplayManagerGlobal.EVENT_DISPLAY_BASIC_CHANGED;
        int displayId = display.getDisplayIdLocked();
        Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT_FRAME_RATE_OVERRIDE,
                displayId, event);
        if (mFlags.isDisplayEventsLoggingEnabled()
                && event == DisplayManagerGlobal.EVENT_DISPLAY_BASIC_CHANGED) {
            msg.obj = new DisplayInfoChangedFields(display.getDisplayInfoGroupsChangedLocked(),
                    display.getDisplayInfoChangeSource());
        }
        mHandler.sendMessage(msg);
    }

@@ -3732,7 +3742,7 @@ public final class DisplayManagerService extends SystemService {
    // Runs on Handler thread.
    // Delivers display event notifications to callbacks.
    private void deliverDisplayEvent(int displayId, ArraySet<Integer> uids,
            @DisplayEvent int event) {
            @DisplayEvent int event, DisplayInfoChangedFields displayInfoChangedFields) {
        if (DEBUG || mExtraDisplayEventLogging) {
            Slog.d(TAG, "Delivering display event: displayId="
                    + displayId + ", event=" + event
@@ -3769,7 +3779,14 @@ public final class DisplayManagerService extends SystemService {
        }

        if (mFlags.isDisplayEventsLoggingEnabled()) {
            // Log DisplayEventCallbackOccurred atom
            mStatsLogger.logDisplayEvent(event, notifiedUids);

            // Log DisplayInfoChanged atom
            if (event == DisplayManagerGlobal.EVENT_DISPLAY_BASIC_CHANGED) {
                mStatsLogger.logDisplayInfoChanged(displayInfoChangedFields.changedGroups(),
                        displayInfoChangedFields.source());
            }
        }

        mTempCallbacks.clear();
@@ -4308,7 +4325,8 @@ public final class DisplayManagerService extends SystemService {
                    break;

                case MSG_DELIVER_DISPLAY_EVENT:
                    deliverDisplayEvent(msg.arg1, null, msg.arg2);
                    deliverDisplayEvent(msg.arg1, null, msg.arg2,
                            (DisplayInfoChangedFields) msg.obj);
                    break;

                case MSG_REQUEST_TRAVERSAL:
@@ -4352,7 +4370,8 @@ public final class DisplayManagerService extends SystemService {
                        uids = display.getPendingFrameRateOverrideUids();
                        display.clearPendingFrameRateOverrideUids();
                    }
                    deliverDisplayEvent(msg.arg1, uids, msg.arg2);
                    deliverDisplayEvent(msg.arg1, uids, msg.arg2,
                            (DisplayInfoChangedFields) msg.obj);
                    break;

                case MSG_DELIVER_DISPLAY_GROUP_EVENT:
@@ -6575,4 +6594,8 @@ public final class DisplayManagerService extends SystemService {
        @Nullable
        DisplayInfo get(int displayId);
    }

    private record DisplayInfoChangedFields(int changedGroups,
                                            DisplayInfo.DisplayInfoChangeSource source) {}

}
+60 −0
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@

package com.android.server.display;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.hardware.display.DisplayManagerGlobal;
import android.util.SparseIntArray;
import android.view.DisplayInfo;
import android.view.DisplayInfo.DisplayInfoGroup;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -115,4 +119,60 @@ public class DisplayFrameworkStatsLoggerTest {
                        expectedProtoType,
                        uidMap.copyKeys(), 1);
    }

    @Test
    public void logDisplayInfoChanged_singleChange() {
        int changedGroups = DisplayInfoGroup.COLOR_AND_BRIGHTNESS.getMask();

        mLogger.logDisplayInfoChanged(changedGroups,
                DisplayInfo.DisplayInfoChangeSource.DISPLAY_SWAP);

        int expectedSource =
                FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_DISPLAY_SWAP;
        verify(mFrameworkStatsLogMock)
                .write(FrameworkStatsLog.DISPLAY_INFO_CHANGED,
                    1, 0, 0, 0, 0, 1, 0, expectedSource);
    }

    @Test
    public void logDisplayInfoChanged_multipleChanges() {
        int changedGroups = DisplayInfoGroup.BASIC_PROPERTIES.getMask()
                | DisplayInfoGroup.STATE.getMask()
                | DisplayInfoGroup.ORIENTATION_AND_ROTATION.getMask();

        mLogger.logDisplayInfoChanged(changedGroups,
                DisplayInfo.DisplayInfoChangeSource.DISPLAY_MANAGER);

        int expectedSource =
                FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_DISPLAY_MANAGER;
        verify(mFrameworkStatsLogMock)
                .write(FrameworkStatsLog.DISPLAY_INFO_CHANGED,
                        3, 1, 0, 1, 0, 0, 1, expectedSource);
    }

    @Test
    public void logDisplayInfoChanged_allChanges() {
        int changedGroupsMask = 0;
        for (DisplayInfoGroup group : DisplayInfoGroup.values()) {
            changedGroupsMask |= group.getMask();
        }

        mLogger.logDisplayInfoChanged(changedGroupsMask, DisplayInfo.DisplayInfoChangeSource.OTHER);

        int expectedSource =
                FrameworkStatsLog.DISPLAY_INFO_CHANGED__EVENT_SOURCE__EVENT_SOURCE_OTHER;
        verify(mFrameworkStatsLogMock)
                .write(FrameworkStatsLog.DISPLAY_INFO_CHANGED,
                        6, 1, 1, 1, 1, 1, 1, expectedSource);
    }

    @Test
    public void testDisplayInfoChanged_zeroInput_doesNotLog() {
        mLogger.logDisplayInfoChanged(0, DisplayInfo.DisplayInfoChangeSource.WINDOW_MANAGER);

        verify(mFrameworkStatsLogMock, never())
                .write(anyInt(), anyInt(), anyInt(), anyInt(),
                        anyInt(), anyInt(), anyInt(), anyInt(), anyInt());
    }

}