Merge "Create HighBrightnessModeMetadataMapper" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f247d365ed
@@ -119,7 +119,6 @@ import android.os.UserManager;
|
|||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
import android.util.IntArray;
|
import android.util.IntArray;
|
||||||
@@ -298,11 +297,10 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
mDisplayWindowPolicyControllers = new SparseArray<>();
|
mDisplayWindowPolicyControllers = new SparseArray<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of every internal primary display device {@link HighBrightnessModeMetadata}s indexed by
|
* Provides {@link HighBrightnessModeMetadata}s for {@link DisplayDevice}s.
|
||||||
* {@link DisplayDevice#mUniqueId}.
|
|
||||||
*/
|
*/
|
||||||
public final ArrayMap<String, HighBrightnessModeMetadata> mHighBrightnessModeMetadataMap =
|
private final HighBrightnessModeMetadataMapper mHighBrightnessModeMetadataMapper =
|
||||||
new ArrayMap<>();
|
new HighBrightnessModeMetadataMapper();
|
||||||
|
|
||||||
// List of all currently registered display adapters.
|
// List of all currently registered display adapters.
|
||||||
private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
|
private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
|
||||||
@@ -1823,19 +1821,14 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
|
|
||||||
DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId);
|
DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId);
|
||||||
if (dpc != null) {
|
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();
|
final int leadDisplayId = display.getLeadDisplayIdLocked();
|
||||||
updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId);
|
updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId);
|
||||||
|
|
||||||
final String uniqueId = device.getUniqueId();
|
HighBrightnessModeMetadata hbmMetadata =
|
||||||
HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMap.get(uniqueId);
|
mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display);
|
||||||
dpc.onDisplayChanged(hbmMetadata, leadDisplayId);
|
if (hbmMetadata != null) {
|
||||||
|
dpc.onDisplayChanged(hbmMetadata, leadDisplayId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1922,19 +1915,14 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
final int displayId = display.getDisplayIdLocked();
|
final int displayId = display.getDisplayIdLocked();
|
||||||
final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId);
|
final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId);
|
||||||
if (dpc != null) {
|
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();
|
final int leadDisplayId = display.getLeadDisplayIdLocked();
|
||||||
updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId);
|
updateDisplayPowerControllerLeaderLocked(dpc, leadDisplayId);
|
||||||
|
|
||||||
final String uniqueId = device.getUniqueId();
|
HighBrightnessModeMetadata hbmMetadata =
|
||||||
HighBrightnessModeMetadata hbmMetadata = mHighBrightnessModeMetadataMap.get(uniqueId);
|
mHighBrightnessModeMetadataMapper.getHighBrightnessModeMetadataLocked(display);
|
||||||
dpc.onDisplayChanged(hbmMetadata, leadDisplayId);
|
if (hbmMetadata != null) {
|
||||||
|
dpc.onDisplayChanged(hbmMetadata, leadDisplayId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3073,26 +3061,6 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
mLogicalDisplayMapper.forEachLocked(this::addDisplayPowerControllerLocked);
|
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)
|
@RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG)
|
||||||
private void addDisplayPowerControllerLocked(LogicalDisplay display) {
|
private void addDisplayPowerControllerLocked(LogicalDisplay display) {
|
||||||
if (mPowerHandler == null) {
|
if (mPowerHandler == null) {
|
||||||
@@ -3113,7 +3081,13 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
// We also need to pass a mapping of the HighBrightnessModeTimeInfoMap to
|
// We also need to pass a mapping of the HighBrightnessModeTimeInfoMap to
|
||||||
// displayPowerController, so the hbm info can be correctly associated
|
// displayPowerController, so the hbm info can be correctly associated
|
||||||
// with the corresponding displaydevice.
|
// 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",
|
if (DeviceConfig.getBoolean("display_manager",
|
||||||
"use_newly_structured_display_power_controller", true)) {
|
"use_newly_structured_display_power_controller", true)) {
|
||||||
displayPowerController = new DisplayPowerController2(
|
displayPowerController = new DisplayPowerController2(
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user