Loading services/core/java/com/android/server/display/DisplayManagerService.java +20 −46 Original line number Diff line number Diff line Loading @@ -119,7 +119,6 @@ import android.os.UserManager; import android.provider.DeviceConfig; import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.EventLog; import android.util.IntArray; Loading Loading @@ -298,11 +297,10 @@ public final class DisplayManagerService extends SystemService { mDisplayWindowPolicyControllers = new SparseArray<>(); /** * Map of every internal primary display device {@link HighBrightnessModeMetadata}s indexed by * {@link DisplayDevice#mUniqueId}. * Provides {@link HighBrightnessModeMetadata}s for {@link DisplayDevice}s. */ public final ArrayMap<String, HighBrightnessModeMetadata> mHighBrightnessModeMetadataMap = new ArrayMap<>(); private final HighBrightnessModeMetadataMapper mHighBrightnessModeMetadataMapper = new HighBrightnessModeMetadataMapper(); // List of all currently registered display adapters. private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>(); Loading Loading @@ -1823,21 +1821,16 @@ public final class DisplayManagerService extends SystemService { DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId); if (dpc != null) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayManagerService for display: " + display.getDisplayIdLocked()); return; } final int leadDisplayId = display.getLeadDisplayIdLocked(); updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId); final String uniqueId = device.getUniqueId(); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMap.get(uniqueId); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); if (hbmMetadata != null) { dpc.onDisplayChanged(hbmMetadata, leadDisplayId); } } } private void updateDisplayPowerControllerLeaderLocked(DisplayPowerControllerInterface dpc, int leadDisplayId) { Loading Loading @@ -1922,21 +1915,16 @@ public final class DisplayManagerService extends SystemService { final int displayId = display.getDisplayIdLocked(); final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId); if (dpc != null) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayManagerService for display: " + display.getDisplayIdLocked()); return; } final int leadDisplayId = display.getLeadDisplayIdLocked(); updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId); final String uniqueId = device.getUniqueId(); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMap.get(uniqueId); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); if (hbmMetadata != null) { dpc.onDisplayChanged(hbmMetadata, leadDisplayId); } } } private Runnable updateDisplayStateLocked(DisplayDevice device) { // Blank or unblank the display immediately to match the state requested Loading Loading @@ -3073,26 +3061,6 @@ public final class DisplayManagerService extends SystemService { mLogicalDisplayMapper.forEachLocked(this::addDisplayPowerControllerLocked); } private HighBrightnessModeMetadata getHighBrightnessModeMetadata(LogicalDisplay display) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayPowerController for display: " + display.getDisplayIdLocked()); return null; } final String uniqueId = device.getUniqueId(); if (mHighBrightnessModeMetadataMap.containsKey(uniqueId)) { return mHighBrightnessModeMetadataMap.get(uniqueId); } // HBM Time info not present. Create a new one for this physical display. HighBrightnessModeMetadata hbmInfo = new HighBrightnessModeMetadata(); mHighBrightnessModeMetadataMap.put(uniqueId, hbmInfo); return hbmInfo; } @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG) private void addDisplayPowerControllerLocked(LogicalDisplay display) { if (mPowerHandler == null) { Loading @@ -3113,7 +3081,13 @@ public final class DisplayManagerService extends SystemService { // We also need to pass a mapping of the HighBrightnessModeTimeInfoMap to // displayPowerController, so the hbm info can be correctly associated // with the corresponding displaydevice. HighBrightnessModeMetadata hbmMetadata = getHighBrightnessModeMetadata(display); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); if (hbmMetadata == null) { Slog.wtf(TAG, "High Brightness Mode Metadata is null in DisplayManagerService for " + "display: " + display.getDisplayIdLocked()); return; } if (DeviceConfig.getBoolean("display_manager", "use_newly_structured_display_power_controller", true)) { displayPowerController = new DisplayPowerController2( Loading services/core/java/com/android/server/display/HighBrightnessModeMetadataMapper.java 0 → 100644 +56 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.display; import android.util.ArrayMap; import android.util.Slog; /** * Provides {@link HighBrightnessModeMetadata}s for {@link DisplayDevice}s. This class should only * be accessed from the display thread. */ class HighBrightnessModeMetadataMapper { private static final String TAG = "HighBrightnessModeMetadataMapper"; /** * Map of every internal primary display device {@link HighBrightnessModeMetadata}s indexed by * {@link DisplayDevice#mUniqueId}. */ private final ArrayMap<String, HighBrightnessModeMetadata> mHighBrightnessModeMetadataMap = new ArrayMap<>(); HighBrightnessModeMetadata getHighBrightnessModeMetadataLocked(LogicalDisplay display) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayPowerController for display: " + display.getDisplayIdLocked()); return null; } final String uniqueId = device.getUniqueId(); if (mHighBrightnessModeMetadataMap.containsKey(uniqueId)) { return mHighBrightnessModeMetadataMap.get(uniqueId); } // HBM Time info not present. Create a new one for this physical display. HighBrightnessModeMetadata hbmInfo = new HighBrightnessModeMetadata(); mHighBrightnessModeMetadataMap.put(uniqueId, hbmInfo); return hbmInfo; } } services/tests/mockingservicestests/src/com/android/server/display/HighBrightnessModeMetadataMapperTest.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.display; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Before; import org.junit.Test; public class HighBrightnessModeMetadataMapperTest { private HighBrightnessModeMetadataMapper mHighBrightnessModeMetadataMapper; @Before public void setUp() { mHighBrightnessModeMetadataMapper = new HighBrightnessModeMetadataMapper(); } @Test public void testGetHighBrightnessModeMetadata() { // Display device is null final LogicalDisplay display = mock(LogicalDisplay.class); when(display.getPrimaryDisplayDeviceLocked()).thenReturn(null); assertNull(mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display)); // No HBM metadata stored for this display yet final DisplayDevice device = mock(DisplayDevice.class); when(display.getPrimaryDisplayDeviceLocked()).thenReturn(device); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); assertTrue(hbmMetadata.getHbmEventQueue().isEmpty()); assertTrue(hbmMetadata.getRunningStartTimeMillis() < 0); // Modify the metadata long startTimeMillis = 100; long endTimeMillis = 200; long setTime = 300; hbmMetadata.addHbmEvent(new HbmEvent(startTimeMillis, endTimeMillis)); hbmMetadata.setRunningStartTimeMillis(setTime); hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); assertEquals(1, hbmMetadata.getHbmEventQueue().size()); assertEquals(startTimeMillis, hbmMetadata.getHbmEventQueue().getFirst().getStartTimeMillis()); assertEquals(endTimeMillis, hbmMetadata.getHbmEventQueue().getFirst().getEndTimeMillis()); assertEquals(setTime, hbmMetadata.getRunningStartTimeMillis()); } } Loading
services/core/java/com/android/server/display/DisplayManagerService.java +20 −46 Original line number Diff line number Diff line Loading @@ -119,7 +119,6 @@ import android.os.UserManager; import android.provider.DeviceConfig; import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.EventLog; import android.util.IntArray; Loading Loading @@ -298,11 +297,10 @@ public final class DisplayManagerService extends SystemService { mDisplayWindowPolicyControllers = new SparseArray<>(); /** * Map of every internal primary display device {@link HighBrightnessModeMetadata}s indexed by * {@link DisplayDevice#mUniqueId}. * Provides {@link HighBrightnessModeMetadata}s for {@link DisplayDevice}s. */ public final ArrayMap<String, HighBrightnessModeMetadata> mHighBrightnessModeMetadataMap = new ArrayMap<>(); private final HighBrightnessModeMetadataMapper mHighBrightnessModeMetadataMapper = new HighBrightnessModeMetadataMapper(); // List of all currently registered display adapters. private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>(); Loading Loading @@ -1823,21 +1821,16 @@ public final class DisplayManagerService extends SystemService { DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId); if (dpc != null) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayManagerService for display: " + display.getDisplayIdLocked()); return; } final int leadDisplayId = display.getLeadDisplayIdLocked(); updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId); final String uniqueId = device.getUniqueId(); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMap.get(uniqueId); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); if (hbmMetadata != null) { dpc.onDisplayChanged(hbmMetadata, leadDisplayId); } } } private void updateDisplayPowerControllerLeaderLocked(DisplayPowerControllerInterface dpc, int leadDisplayId) { Loading Loading @@ -1922,21 +1915,16 @@ public final class DisplayManagerService extends SystemService { final int displayId = display.getDisplayIdLocked(); final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId); if (dpc != null) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayManagerService for display: " + display.getDisplayIdLocked()); return; } final int leadDisplayId = display.getLeadDisplayIdLocked(); updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId); final String uniqueId = device.getUniqueId(); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMap.get(uniqueId); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); if (hbmMetadata != null) { dpc.onDisplayChanged(hbmMetadata, leadDisplayId); } } } private Runnable updateDisplayStateLocked(DisplayDevice device) { // Blank or unblank the display immediately to match the state requested Loading Loading @@ -3073,26 +3061,6 @@ public final class DisplayManagerService extends SystemService { mLogicalDisplayMapper.forEachLocked(this::addDisplayPowerControllerLocked); } private HighBrightnessModeMetadata getHighBrightnessModeMetadata(LogicalDisplay display) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayPowerController for display: " + display.getDisplayIdLocked()); return null; } final String uniqueId = device.getUniqueId(); if (mHighBrightnessModeMetadataMap.containsKey(uniqueId)) { return mHighBrightnessModeMetadataMap.get(uniqueId); } // HBM Time info not present. Create a new one for this physical display. HighBrightnessModeMetadata hbmInfo = new HighBrightnessModeMetadata(); mHighBrightnessModeMetadataMap.put(uniqueId, hbmInfo); return hbmInfo; } @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG) private void addDisplayPowerControllerLocked(LogicalDisplay display) { if (mPowerHandler == null) { Loading @@ -3113,7 +3081,13 @@ public final class DisplayManagerService extends SystemService { // We also need to pass a mapping of the HighBrightnessModeTimeInfoMap to // displayPowerController, so the hbm info can be correctly associated // with the corresponding displaydevice. HighBrightnessModeMetadata hbmMetadata = getHighBrightnessModeMetadata(display); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); if (hbmMetadata == null) { Slog.wtf(TAG, "High Brightness Mode Metadata is null in DisplayManagerService for " + "display: " + display.getDisplayIdLocked()); return; } if (DeviceConfig.getBoolean("display_manager", "use_newly_structured_display_power_controller", true)) { displayPowerController = new DisplayPowerController2( Loading
services/core/java/com/android/server/display/HighBrightnessModeMetadataMapper.java 0 → 100644 +56 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.display; import android.util.ArrayMap; import android.util.Slog; /** * Provides {@link HighBrightnessModeMetadata}s for {@link DisplayDevice}s. This class should only * be accessed from the display thread. */ class HighBrightnessModeMetadataMapper { private static final String TAG = "HighBrightnessModeMetadataMapper"; /** * Map of every internal primary display device {@link HighBrightnessModeMetadata}s indexed by * {@link DisplayDevice#mUniqueId}. */ private final ArrayMap<String, HighBrightnessModeMetadata> mHighBrightnessModeMetadataMap = new ArrayMap<>(); HighBrightnessModeMetadata getHighBrightnessModeMetadataLocked(LogicalDisplay display) { final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); if (device == null) { Slog.wtf(TAG, "Display Device is null in DisplayPowerController for display: " + display.getDisplayIdLocked()); return null; } final String uniqueId = device.getUniqueId(); if (mHighBrightnessModeMetadataMap.containsKey(uniqueId)) { return mHighBrightnessModeMetadataMap.get(uniqueId); } // HBM Time info not present. Create a new one for this physical display. HighBrightnessModeMetadata hbmInfo = new HighBrightnessModeMetadata(); mHighBrightnessModeMetadataMap.put(uniqueId, hbmInfo); return hbmInfo; } }
services/tests/mockingservicestests/src/com/android/server/display/HighBrightnessModeMetadataMapperTest.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.display; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Before; import org.junit.Test; public class HighBrightnessModeMetadataMapperTest { private HighBrightnessModeMetadataMapper mHighBrightnessModeMetadataMapper; @Before public void setUp() { mHighBrightnessModeMetadataMapper = new HighBrightnessModeMetadataMapper(); } @Test public void testGetHighBrightnessModeMetadata() { // Display device is null final LogicalDisplay display = mock(LogicalDisplay.class); when(display.getPrimaryDisplayDeviceLocked()).thenReturn(null); assertNull(mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display)); // No HBM metadata stored for this display yet final DisplayDevice device = mock(DisplayDevice.class); when(display.getPrimaryDisplayDeviceLocked()).thenReturn(device); HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); assertTrue(hbmMetadata.getHbmEventQueue().isEmpty()); assertTrue(hbmMetadata.getRunningStartTimeMillis() < 0); // Modify the metadata long startTimeMillis = 100; long endTimeMillis = 200; long setTime = 300; hbmMetadata.addHbmEvent(new HbmEvent(startTimeMillis, endTimeMillis)); hbmMetadata.setRunningStartTimeMillis(setTime); hbmMetadata = mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display); assertEquals(1, hbmMetadata.getHbmEventQueue().size()); assertEquals(startTimeMillis, hbmMetadata.getHbmEventQueue().getFirst().getStartTimeMillis()); assertEquals(endTimeMillis, hbmMetadata.getHbmEventQueue().getFirst().getEndTimeMillis()); assertEquals(setTime, hbmMetadata.getRunningStartTimeMillis()); } }