Loading services/core/java/com/android/server/display/DisplayFrameworkStatsLogger.java +32 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading services/core/java/com/android/server/display/DisplayManagerService.java +29 −6 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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); } Loading @@ -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); } Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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: Loading Loading @@ -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: Loading Loading @@ -6575,4 +6594,8 @@ public final class DisplayManagerService extends SystemService { @Nullable DisplayInfo get(int displayId); } private record DisplayInfoChangedFields(int changedGroups, DisplayInfo.DisplayInfoChangeSource source) {} } services/tests/displayservicetests/src/com/android/server/display/DisplayFrameworkStatsLoggerTest.java +60 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); } } Loading
services/core/java/com/android/server/display/DisplayFrameworkStatsLogger.java +32 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading
services/core/java/com/android/server/display/DisplayManagerService.java +29 −6 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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); } Loading @@ -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); } Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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: Loading Loading @@ -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: Loading Loading @@ -6575,4 +6594,8 @@ public final class DisplayManagerService extends SystemService { @Nullable DisplayInfo get(int displayId); } private record DisplayInfoChangedFields(int changedGroups, DisplayInfo.DisplayInfoChangeSource source) {} }
services/tests/displayservicetests/src/com/android/server/display/DisplayFrameworkStatsLoggerTest.java +60 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); } }