blob: 2c08420af42d528a2162902c35b6e04b76267657 [file] [log] [blame]
Jeff Brown64a55af2012-08-26 02:47:39 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.display;
18
Adrian Roos30f53212018-01-05 16:14:34 +010019import android.app.ActivityThread;
Jeff Brown64a55af2012-08-26 02:47:39 -070020import android.content.Context;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080021import android.content.res.Resources;
Chris Phoenixbc839a32017-10-21 14:46:15 -070022import android.hardware.sidekick.SidekickInternal;
Griff Hazend3c454d2016-03-25 07:30:34 -070023import android.os.Build;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070024import android.os.Handler;
Jeff Brown64a55af2012-08-26 02:47:39 -070025import android.os.IBinder;
Jeff Browne87bf032012-09-20 18:30:13 -070026import android.os.Looper;
Jeff Brown5d6443b2015-04-10 20:15:01 -070027import android.os.PowerManager;
Jeff Brown27f1d672012-10-17 18:32:34 -070028import android.os.SystemProperties;
Jeff Brown3edf5272014-08-14 19:25:14 -070029import android.os.Trace;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080030import android.util.LongSparseArray;
Dan Stoza00101052014-05-02 15:23:40 -070031import android.util.Slog;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070032import android.util.SparseArray;
Santos Cordon4505e5e2020-01-17 15:18:10 +000033import android.util.Spline;
Jeff Brown92130f62012-10-24 21:28:33 -070034import android.view.Display;
Dominik Laskowskidb845962019-01-27 21:20:00 -080035import android.view.DisplayAddress;
Adrian Roos1cf585052018-01-03 18:43:27 +010036import android.view.DisplayCutout;
Jeff Browne87bf032012-09-20 18:30:13 -070037import android.view.DisplayEventReceiver;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080038import android.view.SurfaceControl;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080039
Fiona Campbelld4eb2952019-11-04 17:19:56 +000040import com.android.internal.BrightnessSynchronizer;
Santos Cordon4505e5e2020-01-17 15:18:10 +000041import com.android.internal.os.BackgroundThread;
Riddle Hsu8b37bc02019-11-23 00:39:14 +080042import com.android.internal.util.function.pooled.PooledLambda;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080043import com.android.server.LocalServices;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080044import com.android.server.lights.LightsManager;
Ivailo Karamanolevf773e102020-01-16 16:10:42 +010045import com.android.server.lights.LogicalLight;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080046
Jeff Brown4ed8fe72012-08-30 18:18:29 -070047import java.io.PrintWriter;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070048import java.util.ArrayList;
Michael Wright58e829f2015-09-15 00:13:26 +010049import java.util.Arrays;
Michael Wright1c9977b2016-07-12 13:30:10 -070050import java.util.Collections;
51import java.util.List;
Marin Shalamanov677d3a72020-01-07 13:45:55 +010052import java.util.Objects;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070053
Jeff Brown64a55af2012-08-26 02:47:39 -070054/**
Dominik Laskowski26290bb2020-01-15 16:09:55 -080055 * A display adapter for the local displays managed by SurfaceFlinger.
Jeff Brownbd6e1502012-08-28 03:27:37 -070056 * <p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070057 * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock.
Jeff Brownbd6e1502012-08-28 03:27:37 -070058 * </p>
Jeff Brown64a55af2012-08-26 02:47:39 -070059 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070060final class LocalDisplayAdapter extends DisplayAdapter {
Jeff Brownbd6e1502012-08-28 03:27:37 -070061 private static final String TAG = "LocalDisplayAdapter";
Jeff Brown5d6443b2015-04-10 20:15:01 -070062 private static final boolean DEBUG = false;
Jeff Brown64a55af2012-08-26 02:47:39 -070063
Wale Ogunwale361ca212014-11-20 11:42:38 -080064 private static final String UNIQUE_ID_PREFIX = "local:";
65
Adam Powell01f280d2015-05-18 16:07:42 -070066 private static final String PROPERTY_EMULATOR_CIRCULAR = "ro.emulator.circular";
67
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +010068 private static final int NO_DISPLAY_MODE_ID = 0;
69
70 private final LongSparseArray<LocalDisplayDevice> mDevices = new LongSparseArray<>();
Jeff Brown4ed8fe72012-08-30 18:18:29 -070071
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070072 @SuppressWarnings("unused") // Becomes active at instantiation time.
Ady Abrahama5a21f72019-02-13 16:41:59 -080073 private PhysicalDisplayEventReceiver mPhysicalDisplayEventReceiver;
74
Jeff Brown4ed8fe72012-08-30 18:18:29 -070075
Jeff Brown66692502012-10-18 16:13:44 -070076 // Called with SyncRoot lock held.
Jeff Brown4ed8fe72012-08-30 18:18:29 -070077 public LocalDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
78 Context context, Handler handler, Listener listener) {
79 super(syncRoot, context, handler, listener, TAG);
Jeff Brown64a55af2012-08-26 02:47:39 -070080 }
81
82 @Override
Jeff Brown4ed8fe72012-08-30 18:18:29 -070083 public void registerLocked() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -070084 super.registerLocked();
Jeff Brown66692502012-10-18 16:13:44 -070085
Ady Abrahama5a21f72019-02-13 16:41:59 -080086 mPhysicalDisplayEventReceiver = new PhysicalDisplayEventReceiver(getHandler().getLooper());
Jesse Halle244db42012-11-08 11:55:14 -080087
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080088 for (long physicalDisplayId : SurfaceControl.getPhysicalDisplayIds()) {
89 tryConnectDisplayLocked(physicalDisplayId);
Jesse Halle244db42012-11-08 11:55:14 -080090 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -070091 }
92
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080093 private void tryConnectDisplayLocked(long physicalDisplayId) {
94 final IBinder displayToken = SurfaceControl.getPhysicalDisplayToken(physicalDisplayId);
Dan Stoza00101052014-05-02 15:23:40 -070095 if (displayToken != null) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -080096 SurfaceControl.DisplayInfo info = SurfaceControl.getDisplayInfo(displayToken);
97 if (info == null) {
98 Slog.w(TAG, "No valid info found for display device " + physicalDisplayId);
99 return;
100 }
101 SurfaceControl.DisplayConfig[] configs = SurfaceControl.getDisplayConfigs(displayToken);
Dan Stoza00101052014-05-02 15:23:40 -0700102 if (configs == null) {
103 // There are no valid configs for this device, so we can't use it
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800104 Slog.w(TAG, "No valid configs found for display device " + physicalDisplayId);
Dan Stoza00101052014-05-02 15:23:40 -0700105 return;
106 }
107 int activeConfig = SurfaceControl.getActiveConfig(displayToken);
108 if (activeConfig < 0) {
109 // There is no active config, and for now we don't have the
110 // policy to set one.
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800111 Slog.w(TAG, "No active config found for display device " + physicalDisplayId);
Dan Stoza00101052014-05-02 15:23:40 -0700112 return;
113 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700114 int activeColorMode = SurfaceControl.getActiveColorMode(displayToken);
115 if (activeColorMode < 0) {
116 // We failed to get the active color mode. We don't bail out here since on the next
117 // configuration pass we'll go ahead and set it to whatever it was set to last (or
118 // COLOR_MODE_NATIVE if this is the first configuration).
119 Slog.w(TAG, "Unable to get active color mode for display device " +
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800120 physicalDisplayId);
Michael Wright1c9977b2016-07-12 13:30:10 -0700121 activeColorMode = Display.COLOR_MODE_INVALID;
122 }
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800123 SurfaceControl.DesiredDisplayConfigSpecs configSpecs =
Ana Kruleca74a8642019-11-14 00:51:00 +0100124 SurfaceControl.getDesiredDisplayConfigSpecs(displayToken);
Marin Shalamanov677d3a72020-01-07 13:45:55 +0100125 int[] colorModes = SurfaceControl.getDisplayColorModes(displayToken);
126 Display.HdrCapabilities hdrCapabilities =
127 SurfaceControl.getHdrCapabilities(displayToken);
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800128 LocalDisplayDevice device = mDevices.get(physicalDisplayId);
Jesse Halle244db42012-11-08 11:55:14 -0800129 if (device == null) {
130 // Display was added.
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800131 final boolean isDefaultDisplay = mDevices.size() == 0;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800132 device = new LocalDisplayDevice(displayToken, physicalDisplayId, info,
133 configs, activeConfig, configSpecs, colorModes, activeColorMode,
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800134 hdrCapabilities, isDefaultDisplay);
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800135 mDevices.put(physicalDisplayId, device);
Jesse Halle244db42012-11-08 11:55:14 -0800136 sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED);
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100137 } else if (device.updateDisplayProperties(configs, activeConfig,
138 configSpecs, colorModes, activeColorMode, hdrCapabilities)) {
139 sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_CHANGED);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700140 }
Jesse Halle244db42012-11-08 11:55:14 -0800141 } else {
142 // The display is no longer available. Ignore the attempt to add it.
143 // If it was connected but has already been disconnected, we'll get a
144 // disconnect event that will remove it from mDevices.
145 }
146 }
147
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800148 private void tryDisconnectDisplayLocked(long physicalDisplayId) {
149 LocalDisplayDevice device = mDevices.get(physicalDisplayId);
Jesse Halle244db42012-11-08 11:55:14 -0800150 if (device != null) {
151 // Display was removed.
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800152 mDevices.remove(physicalDisplayId);
Jesse Halle244db42012-11-08 11:55:14 -0800153 sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700154 }
Jeff Brown64a55af2012-08-26 02:47:39 -0700155 }
156
Prashant Malanic55929a2014-05-25 01:59:21 -0700157 static int getPowerModeForState(int state) {
158 switch (state) {
159 case Display.STATE_OFF:
160 return SurfaceControl.POWER_MODE_OFF;
Jeff Brown5dc21912014-07-17 18:50:18 -0700161 case Display.STATE_DOZE:
Prashant Malanic55929a2014-05-25 01:59:21 -0700162 return SurfaceControl.POWER_MODE_DOZE;
Jeff Brown5dc21912014-07-17 18:50:18 -0700163 case Display.STATE_DOZE_SUSPEND:
164 return SurfaceControl.POWER_MODE_DOZE_SUSPEND;
Chris Phoenix10a4a642017-09-25 13:21:00 -0700165 case Display.STATE_ON_SUSPEND:
166 return SurfaceControl.POWER_MODE_ON_SUSPEND;
Prashant Malanic55929a2014-05-25 01:59:21 -0700167 default:
168 return SurfaceControl.POWER_MODE_NORMAL;
169 }
Jeff Brown44b1f762014-04-22 18:07:24 -0700170 }
171
Jeff Brown64a55af2012-08-26 02:47:39 -0700172 private final class LocalDisplayDevice extends DisplayDevice {
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800173 private final long mPhysicalDisplayId;
Ivailo Karamanolevf773e102020-01-16 16:10:42 +0100174 private final LogicalLight mBacklight;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700175 private final SparseArray<DisplayModeRecord> mSupportedModes = new SparseArray<>();
Michael Wright1c9977b2016-07-12 13:30:10 -0700176 private final ArrayList<Integer> mSupportedColorModes = new ArrayList<>();
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800177 private final boolean mIsDefaultDisplay;
Jeff Brown64a55af2012-08-26 02:47:39 -0700178
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700179 private DisplayDeviceInfo mInfo;
180 private boolean mHavePendingChanges;
Jeff Brown037c33e2014-04-09 00:31:55 -0700181 private int mState = Display.STATE_UNKNOWN;
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000182 private float mBrightnessState = PowerManager.BRIGHTNESS_INVALID_FLOAT;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700183 private int mDefaultModeId;
Ady Abraham8a5e3912020-02-18 17:28:26 -0800184 private int mDefaultConfigGroup;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700185 private int mActiveModeId;
186 private boolean mActiveModeInvalid;
Ana Kruleca74a8642019-11-14 00:51:00 +0100187 private DisplayModeDirector.DesiredDisplayModeSpecs mDisplayModeSpecs =
188 new DisplayModeDirector.DesiredDisplayModeSpecs();
189 private boolean mDisplayModeSpecsInvalid;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800190 private int mActiveConfigId;
Michael Wright1c9977b2016-07-12 13:30:10 -0700191 private int mActiveColorMode;
192 private boolean mActiveColorModeInvalid;
Michael Wright9ff94c02016-03-30 18:05:40 -0700193 private Display.HdrCapabilities mHdrCapabilities;
Galia Peycheva056b3ee2019-06-26 14:05:12 +0200194 private boolean mAllmSupported;
195 private boolean mGameContentTypeSupported;
196 private boolean mAllmRequested;
197 private boolean mGameContentTypeRequested;
Chris Phoenixbc839a32017-10-21 14:46:15 -0700198 private boolean mSidekickActive;
199 private SidekickInternal mSidekickInternal;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800200 private SurfaceControl.DisplayInfo mDisplayInfo;
201 private SurfaceControl.DisplayConfig[] mDisplayConfigs;
Santos Cordon4505e5e2020-01-17 15:18:10 +0000202 private Spline mSystemBrightnessToNits;
203 private Spline mNitsToHalBrightness;
Jeff Brown5d6443b2015-04-10 20:15:01 -0700204
Fiona Campbell172fd4a2020-03-13 16:34:30 +0000205 private DisplayDeviceConfig mDisplayDeviceConfig;
206
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800207 LocalDisplayDevice(IBinder displayToken, long physicalDisplayId,
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800208 SurfaceControl.DisplayInfo info, SurfaceControl.DisplayConfig[] configs,
209 int activeConfigId, SurfaceControl.DesiredDisplayConfigSpecs configSpecs,
Marin Shalamanov677d3a72020-01-07 13:45:55 +0100210 int[] colorModes, int activeColorMode, Display.HdrCapabilities hdrCapabilities,
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800211 boolean isDefaultDisplay) {
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800212 super(LocalDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + physicalDisplayId);
213 mPhysicalDisplayId = physicalDisplayId;
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800214 mIsDefaultDisplay = isDefaultDisplay;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800215 mDisplayInfo = info;
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100216 updateDisplayProperties(configs, activeConfigId, configSpecs, colorModes,
217 activeColorMode, hdrCapabilities);
Chris Phoenixbc839a32017-10-21 14:46:15 -0700218 mSidekickInternal = LocalServices.getService(SidekickInternal.class);
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800219 if (mIsDefaultDisplay) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700220 LightsManager lights = LocalServices.getService(LightsManager.class);
221 mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT);
222 } else {
223 mBacklight = null;
224 }
Galia Peycheva056b3ee2019-06-26 14:05:12 +0200225 mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken);
226 mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken);
Fiona Campbell172fd4a2020-03-13 16:34:30 +0000227 mDisplayDeviceConfig = null;
Santos Cordon4505e5e2020-01-17 15:18:10 +0000228 // Defer configuration file loading
229 BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage(
230 LocalDisplayDevice::loadDisplayConfigurationBrightnessMapping, this));
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700231 }
232
Michael Wright1c9977b2016-07-12 13:30:10 -0700233 @Override
234 public boolean hasStableUniqueId() {
235 return true;
236 }
237
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100238 /**
239 * Returns true if there is a change.
240 **/
241 public boolean updateDisplayProperties(SurfaceControl.DisplayConfig[] configs,
242 int activeConfigId, SurfaceControl.DesiredDisplayConfigSpecs configSpecs,
243 int[] colorModes, int activeColorMode, Display.HdrCapabilities hdrCapabilities) {
244 boolean changed = updateDisplayConfigsLocked(configs, activeConfigId, configSpecs);
245 changed |= updateColorModesLocked(colorModes, activeColorMode);
246 changed |= updateHdrCapabilitiesLocked(hdrCapabilities);
247 return changed;
248 }
249
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800250 public boolean updateDisplayConfigsLocked(
251 SurfaceControl.DisplayConfig[] configs, int activeConfigId,
Marin Shalamanov677d3a72020-01-07 13:45:55 +0100252 SurfaceControl.DesiredDisplayConfigSpecs configSpecs) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800253 mDisplayConfigs = Arrays.copyOf(configs, configs.length);
254 mActiveConfigId = activeConfigId;
Michael Wright58e829f2015-09-15 00:13:26 +0100255 // Build an updated list of all existing modes.
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100256 ArrayList<DisplayModeRecord> records = new ArrayList<>();
Michael Wright58e829f2015-09-15 00:13:26 +0100257 boolean modesAdded = false;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800258 for (int i = 0; i < configs.length; i++) {
259 SurfaceControl.DisplayConfig config = configs[i];
Michael Wright58e829f2015-09-15 00:13:26 +0100260 // First, check to see if we've already added a matching mode. Since not all
261 // configuration options are exposed via Display.Mode, it's possible that we have
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800262 // multiple DisplayConfigs that would generate the same Display.Mode.
Michael Wright58e829f2015-09-15 00:13:26 +0100263 boolean existingMode = false;
264 for (int j = 0; j < records.size(); j++) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800265 if (records.get(j).hasMatchingMode(config)) {
Michael Wright58e829f2015-09-15 00:13:26 +0100266 existingMode = true;
267 break;
268 }
269 }
270 if (existingMode) {
271 continue;
272 }
273 // If we haven't already added a mode for this configuration to the new set of
274 // supported modes then check to see if we have one in the prior set of supported
275 // modes to reuse.
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800276 DisplayModeRecord record = findDisplayModeRecord(config);
Michael Wright58e829f2015-09-15 00:13:26 +0100277 if (record == null) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800278 record = new DisplayModeRecord(config);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700279 modesAdded = true;
280 }
281 records.add(record);
Michael Wright58e829f2015-09-15 00:13:26 +0100282 }
283
284 // Get the currently active mode
285 DisplayModeRecord activeRecord = null;
286 for (int i = 0; i < records.size(); i++) {
287 DisplayModeRecord record = records.get(i);
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800288 if (record.hasMatchingMode(configs[activeConfigId])) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700289 activeRecord = record;
Michael Wright58e829f2015-09-15 00:13:26 +0100290 break;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700291 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700292 }
Michael Wrighta3dab232019-02-22 16:54:21 +0000293
294 // Check whether surface flinger spontaneously changed modes out from under us.
295 // Schedule traversals to ensure that the correct state is reapplied if necessary.
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100296 if (mActiveModeId != NO_DISPLAY_MODE_ID
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700297 && mActiveModeId != activeRecord.mMode.getModeId()) {
298 mActiveModeInvalid = true;
299 sendTraversalRequestLocked();
300 }
Michael Wright58e829f2015-09-15 00:13:26 +0100301
Ana Kruleca74a8642019-11-14 00:51:00 +0100302 // Check whether surface flinger spontaneously changed display config specs out from
303 // under us. If so, schedule a traversal to reapply our display config specs.
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100304 if (mDisplayModeSpecs.baseModeId != NO_DISPLAY_MODE_ID) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800305 int activeBaseMode = findMatchingModeIdLocked(configSpecs.defaultConfig);
Ana Kruleca74a8642019-11-14 00:51:00 +0100306 // If we can't map the defaultConfig index to a mode, then the physical display
307 // configs must have changed, and the code below for handling changes to the
308 // list of available modes will take care of updating display config specs.
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100309 if (activeBaseMode != NO_DISPLAY_MODE_ID) {
Steven Thomasec161942020-01-03 12:46:28 -0800310 if (mDisplayModeSpecs.baseModeId != activeBaseMode
Steven Thomas305a57c2020-04-17 12:28:36 -0700311 || mDisplayModeSpecs.primaryRefreshRateRange.min
312 != configSpecs.primaryRefreshRateMin
313 || mDisplayModeSpecs.primaryRefreshRateRange.max
314 != configSpecs.primaryRefreshRateMax
315 || mDisplayModeSpecs.appRequestRefreshRateRange.min
316 != configSpecs.appRequestRefreshRateMin
317 || mDisplayModeSpecs.appRequestRefreshRateRange.max
318 != configSpecs.appRequestRefreshRateMax) {
Ana Kruleca74a8642019-11-14 00:51:00 +0100319 mDisplayModeSpecsInvalid = true;
320 sendTraversalRequestLocked();
321 }
322 }
323 }
324
Michael Wright58e829f2015-09-15 00:13:26 +0100325 boolean recordsChanged = records.size() != mSupportedModes.size() || modesAdded;
Michael Wright1c9977b2016-07-12 13:30:10 -0700326 // If the records haven't changed then we're done here.
327 if (!recordsChanged) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700328 return false;
329 }
330 // Update the index of modes.
331 mHavePendingChanges = true;
Michael Wright58e829f2015-09-15 00:13:26 +0100332
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700333 mSupportedModes.clear();
334 for (DisplayModeRecord record : records) {
335 mSupportedModes.put(record.mMode.getModeId(), record);
336 }
Michael Wrighta3dab232019-02-22 16:54:21 +0000337
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100338 // For a new display, we need to initialize the default mode ID.
339 if (mDefaultModeId == NO_DISPLAY_MODE_ID) {
340 mDefaultModeId = activeRecord.mMode.getModeId();
Ady Abraham8a5e3912020-02-18 17:28:26 -0800341 mDefaultConfigGroup = configs[activeConfigId].configGroup;
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100342 } else if (modesAdded && mActiveModeId != activeRecord.mMode.getModeId()) {
343 Slog.d(TAG, "New display modes are added and the active mode has changed, "
344 + "use active mode as default mode.");
345 mActiveModeId = activeRecord.mMode.getModeId();
346 mDefaultModeId = activeRecord.mMode.getModeId();
Ady Abraham8a5e3912020-02-18 17:28:26 -0800347 mDefaultConfigGroup = configs[activeConfigId].configGroup;
348 } else if (findDisplayConfigIdLocked(mDefaultModeId, mDefaultConfigGroup) < 0) {
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100349 Slog.w(TAG, "Default display mode no longer available, using currently"
350 + " active mode as default.");
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700351 mDefaultModeId = activeRecord.mMode.getModeId();
Ady Abraham8a5e3912020-02-18 17:28:26 -0800352 mDefaultConfigGroup = configs[activeConfigId].configGroup;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700353 }
Michael Wrighta3dab232019-02-22 16:54:21 +0000354
Steven Thomasec161942020-01-03 12:46:28 -0800355 // Determine whether the display mode specs' base mode is still there.
356 if (mSupportedModes.indexOfKey(mDisplayModeSpecs.baseModeId) < 0) {
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100357 if (mDisplayModeSpecs.baseModeId != NO_DISPLAY_MODE_ID) {
Ana Kruleca74a8642019-11-14 00:51:00 +0100358 Slog.w(TAG,
Steven Thomasec161942020-01-03 12:46:28 -0800359 "DisplayModeSpecs base mode no longer available, using currently"
360 + " active mode.");
Ana Kruleca74a8642019-11-14 00:51:00 +0100361 }
Steven Thomasec161942020-01-03 12:46:28 -0800362 mDisplayModeSpecs.baseModeId = activeRecord.mMode.getModeId();
Ana Kruleca74a8642019-11-14 00:51:00 +0100363 mDisplayModeSpecsInvalid = true;
364 }
365
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700366 // Determine whether the active mode is still there.
367 if (mSupportedModes.indexOfKey(mActiveModeId) < 0) {
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100368 if (mActiveModeId != NO_DISPLAY_MODE_ID) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700369 Slog.w(TAG, "Active display mode no longer available, reverting to default"
370 + " mode.");
371 }
372 mActiveModeId = mDefaultModeId;
373 mActiveModeInvalid = true;
374 }
Michael Wright58e829f2015-09-15 00:13:26 +0100375
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700376 // Schedule traversals so that we apply pending changes.
377 sendTraversalRequestLocked();
378 return true;
379 }
380
Fiona Campbell172fd4a2020-03-13 16:34:30 +0000381 @Override
382 public DisplayDeviceConfig getDisplayDeviceConfig() {
383 return mDisplayDeviceConfig;
384 }
385
Santos Cordon4505e5e2020-01-17 15:18:10 +0000386 private void loadDisplayConfigurationBrightnessMapping() {
387 Spline nitsToHal = null;
388 Spline sysToNits = null;
389
390 // Load the mapping from nits to HAL brightness range (display-device-config.xml)
391 DisplayDeviceConfig config = DisplayDeviceConfig.create(mPhysicalDisplayId);
Fiona Campbell172fd4a2020-03-13 16:34:30 +0000392 mDisplayDeviceConfig = config;
Santos Cordon4505e5e2020-01-17 15:18:10 +0000393 if (config == null) {
394 return;
395 }
Fiona Campbell172fd4a2020-03-13 16:34:30 +0000396 final float[] halNits = mDisplayDeviceConfig.getNits();
397 final float[] halBrightness = mDisplayDeviceConfig.getBrightness();
Santos Cordon4505e5e2020-01-17 15:18:10 +0000398 if (halNits == null || halBrightness == null) {
399 return;
400 }
401 nitsToHal = Spline.createSpline(halNits, halBrightness);
402
403 // Load the mapping from system brightness range to nits (config.xml)
404 final Resources res = getOverlayContext().getResources();
405 final float[] sysNits = BrightnessMappingStrategy.getFloatArray(res.obtainTypedArray(
406 com.android.internal.R.array.config_screenBrightnessNits));
407 final int[] sysBrightness = res.getIntArray(
408 com.android.internal.R.array.config_screenBrightnessBacklight);
409 if (sysNits.length == 0 || sysBrightness.length != sysNits.length) {
410 return;
411 }
412 final float[] sysBrightnessFloat = new float[sysBrightness.length];
413 for (int i = 0; i < sysBrightness.length; i++) {
414 sysBrightnessFloat[i] = sysBrightness[i];
415 }
416 sysToNits = Spline.createSpline(sysBrightnessFloat, sysNits);
417
418 mNitsToHalBrightness = nitsToHal;
419 mSystemBrightnessToNits = sysToNits;
420 }
421
Marin Shalamanov677d3a72020-01-07 13:45:55 +0100422 private boolean updateColorModesLocked(int[] colorModes, int activeColorMode) {
423 if (colorModes == null) {
424 return false;
425 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700426
Marin Shalamanov677d3a72020-01-07 13:45:55 +0100427 List<Integer> pendingColorModes = new ArrayList<>();
Michael Wright1c9977b2016-07-12 13:30:10 -0700428 // Build an updated list of all existing color modes.
429 boolean colorModesAdded = false;
Marin Shalamanov677d3a72020-01-07 13:45:55 +0100430 for (int colorMode : colorModes) {
Michael Wright1c9977b2016-07-12 13:30:10 -0700431 if (!mSupportedColorModes.contains(colorMode)) {
432 colorModesAdded = true;
433 }
434 pendingColorModes.add(colorMode);
435 }
436
437 boolean colorModesChanged =
438 pendingColorModes.size() != mSupportedColorModes.size()
439 || colorModesAdded;
440
441 // If the supported color modes haven't changed then we're done here.
442 if (!colorModesChanged) {
443 return false;
444 }
445
446 mHavePendingChanges = true;
447
448 mSupportedColorModes.clear();
449 mSupportedColorModes.addAll(pendingColorModes);
450 Collections.sort(mSupportedColorModes);
451
452 // Determine whether the active color mode is still there.
453 if (!mSupportedColorModes.contains(mActiveColorMode)) {
454 if (mActiveColorMode != 0) {
455 Slog.w(TAG, "Active color mode no longer available, reverting"
456 + " to default mode.");
457 mActiveColorMode = Display.COLOR_MODE_DEFAULT;
458 mActiveColorModeInvalid = true;
459 } else {
460 if (!mSupportedColorModes.isEmpty()) {
461 // This should never happen.
462 Slog.e(TAG, "Default and active color mode is no longer available!"
463 + " Reverting to first available mode.");
464 mActiveColorMode = mSupportedColorModes.get(0);
465 mActiveColorModeInvalid = true;
466 } else {
467 // This should really never happen.
468 Slog.e(TAG, "No color modes available!");
469 }
470 }
471 }
472 return true;
473 }
474
Marin Shalamanov677d3a72020-01-07 13:45:55 +0100475 private boolean updateHdrCapabilitiesLocked(Display.HdrCapabilities newHdrCapabilities) {
476 // If the HDR capabilities haven't changed, then we're done here.
477 if (Objects.equals(mHdrCapabilities, newHdrCapabilities)) {
478 return false;
479 }
480 mHdrCapabilities = newHdrCapabilities;
481 return true;
482 }
483
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800484 private DisplayModeRecord findDisplayModeRecord(SurfaceControl.DisplayConfig config) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700485 for (int i = 0; i < mSupportedModes.size(); i++) {
486 DisplayModeRecord record = mSupportedModes.valueAt(i);
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800487 if (record.hasMatchingMode(config)) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700488 return record;
489 }
490 }
491 return null;
Jeff Brown64a55af2012-08-26 02:47:39 -0700492 }
493
494 @Override
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700495 public void applyPendingDisplayDeviceInfoChangesLocked() {
496 if (mHavePendingChanges) {
497 mInfo = null;
498 mHavePendingChanges = false;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700499 }
Jeff Brown64a55af2012-08-26 02:47:39 -0700500 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700501
502 @Override
503 public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
504 if (mInfo == null) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800505 SurfaceControl.DisplayConfig config = mDisplayConfigs[mActiveConfigId];
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700506 mInfo = new DisplayDeviceInfo();
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800507 mInfo.width = config.width;
508 mInfo.height = config.height;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700509 mInfo.modeId = mActiveModeId;
510 mInfo.defaultModeId = mDefaultModeId;
Michael Wrighta3dab232019-02-22 16:54:21 +0000511 mInfo.supportedModes = getDisplayModes(mSupportedModes);
Michael Wright1c9977b2016-07-12 13:30:10 -0700512 mInfo.colorMode = mActiveColorMode;
Galia Peycheva056b3ee2019-06-26 14:05:12 +0200513 mInfo.allmSupported = mAllmSupported;
514 mInfo.gameContentTypeSupported = mGameContentTypeSupported;
Michael Wright1c9977b2016-07-12 13:30:10 -0700515 mInfo.supportedColorModes =
516 new int[mSupportedColorModes.size()];
517 for (int i = 0; i < mSupportedColorModes.size(); i++) {
518 mInfo.supportedColorModes[i] = mSupportedColorModes.get(i);
Michael Wright58e829f2015-09-15 00:13:26 +0100519 }
Michael Wright9ff94c02016-03-30 18:05:40 -0700520 mInfo.hdrCapabilities = mHdrCapabilities;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800521 mInfo.appVsyncOffsetNanos = config.appVsyncOffsetNanos;
522 mInfo.presentationDeadlineNanos = config.presentationDeadlineNanos;
Jeff Brown037c33e2014-04-09 00:31:55 -0700523 mInfo.state = mState;
Wale Ogunwale361ca212014-11-20 11:42:38 -0800524 mInfo.uniqueId = getUniqueId();
Keun young Parkabf38e32019-04-23 19:18:34 -0700525 final DisplayAddress.Physical physicalAddress =
526 DisplayAddress.fromPhysicalDisplayId(mPhysicalDisplayId);
527 mInfo.address = physicalAddress;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800528 mInfo.densityDpi = (int) (mDisplayInfo.density * 160 + 0.5f);
529 mInfo.xDpi = config.xDpi;
530 mInfo.yDpi = config.yDpi;
Marin Shalamanov98af1592019-10-08 10:48:08 +0200531 mInfo.deviceProductInfo = mDisplayInfo.deviceProductInfo;
Jeff Brown77aebfd2012-10-01 21:07:03 -0700532
Jeff Brownf0681b32012-10-23 17:35:57 -0700533 // Assume that all built-in displays that have secure output (eg. HDCP) also
Jeff Brown77aebfd2012-10-01 21:07:03 -0700534 // support compositing from gralloc protected buffers.
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800535 if (mDisplayInfo.secure) {
Jeff Brownf0681b32012-10-23 17:35:57 -0700536 mInfo.flags = DisplayDeviceInfo.FLAG_SECURE
537 | DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS;
538 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700539
Adrian Roos30f53212018-01-05 16:14:34 +0100540 final Resources res = getOverlayContext().getResources();
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800541
542 if (mIsDefaultDisplay) {
543 mInfo.flags |= DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY;
544
Adam Powell01f280d2015-05-18 16:07:42 -0700545 if (res.getBoolean(com.android.internal.R.bool.config_mainBuiltInDisplayIsRound)
Griff Hazend3c454d2016-03-25 07:30:34 -0700546 || (Build.IS_EMULATOR
Adam Powell01f280d2015-05-18 16:07:42 -0700547 && SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) {
Adam Powell49e7ff92015-05-14 16:18:53 -0700548 mInfo.flags |= DisplayDeviceInfo.FLAG_ROUND;
549 }
Adrian Roos8c28c7c2018-08-20 13:43:38 +0200550 if (res.getBoolean(
551 com.android.internal.R.bool.config_maskMainBuiltInDisplayCutout)) {
552 mInfo.flags |= DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT;
553 }
Jorim Jaggi60640512018-06-29 01:14:31 +0200554 mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res,
555 mInfo.width, mInfo.height);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700556 } else {
Michael Wright4b0fa172016-03-11 17:15:24 -0800557 if (!res.getBoolean(
558 com.android.internal.R.bool.config_localDisplaysMirrorContent)) {
559 mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY;
560 }
Pavel Maltseva6fec7b2018-04-04 10:14:55 -0700561
Keun young Parkabf38e32019-04-23 19:18:34 -0700562 if (isDisplayPrivate(physicalAddress)) {
Pavel Maltseva6fec7b2018-04-04 10:14:55 -0700563 mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE;
564 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700565 }
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800566
567 if (mDisplayInfo.isInternal) {
568 mInfo.type = Display.TYPE_INTERNAL;
569 mInfo.touch = DisplayDeviceInfo.TOUCH_INTERNAL;
570 mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT;
571 mInfo.name = res.getString(
572 com.android.internal.R.string.display_manager_built_in_display_name);
573 } else {
574 mInfo.type = Display.TYPE_EXTERNAL;
575 mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL;
576 mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION;
577 mInfo.name = getContext().getResources().getString(
578 com.android.internal.R.string.display_manager_hdmi_display_name);
579 }
Charles Chenb28fb722020-05-21 17:19:32 +0800580 // The display is trusted since it is created by system.
581 mInfo.flags |= DisplayDeviceInfo.FLAG_TRUSTED;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700582 }
583 return mInfo;
584 }
585
586 @Override
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000587 public Runnable requestDisplayStateLocked(final int state, final float brightnessState) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700588 // Assume that the brightness is off if the display is being turned off.
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000589 assert state != Display.STATE_OFF || BrightnessSynchronizer.floatEquals(
590 brightnessState, PowerManager.BRIGHTNESS_OFF_FLOAT);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700591 final boolean stateChanged = (mState != state);
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000592 final boolean brightnessChanged = (!BrightnessSynchronizer.floatEquals(
593 mBrightnessState, brightnessState))
594 && mBacklight != null;
Jeff Brown5d6443b2015-04-10 20:15:01 -0700595 if (stateChanged || brightnessChanged) {
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800596 final long physicalDisplayId = mPhysicalDisplayId;
Jeff Browne75926d2014-09-18 15:24:49 -0700597 final IBinder token = getDisplayTokenLocked();
Jeff Brown5d6443b2015-04-10 20:15:01 -0700598 final int oldState = mState;
Jeff Browne75926d2014-09-18 15:24:49 -0700599
Jeff Brown5d6443b2015-04-10 20:15:01 -0700600 if (stateChanged) {
601 mState = state;
602 updateDeviceInfoLocked();
603 }
604
605 if (brightnessChanged) {
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000606 mBrightnessState = brightnessState;
Jeff Brown5d6443b2015-04-10 20:15:01 -0700607 }
608
609 // Defer actually setting the display state until after we have exited
Jeff Browne75926d2014-09-18 15:24:49 -0700610 // the critical section since it can take hundreds of milliseconds
611 // to complete.
612 return new Runnable() {
613 @Override
614 public void run() {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700615 // Exit a suspended state before making any changes.
616 int currentState = oldState;
617 if (Display.isSuspendedState(oldState)
618 || oldState == Display.STATE_UNKNOWN) {
619 if (!Display.isSuspendedState(state)) {
620 setDisplayState(state);
621 currentState = state;
622 } else if (state == Display.STATE_DOZE_SUSPEND
623 || oldState == Display.STATE_DOZE_SUSPEND) {
624 setDisplayState(Display.STATE_DOZE);
625 currentState = Display.STATE_DOZE;
Chris Phoenix10a4a642017-09-25 13:21:00 -0700626 } else if (state == Display.STATE_ON_SUSPEND
627 || oldState == Display.STATE_ON_SUSPEND) {
628 setDisplayState(Display.STATE_ON);
629 currentState = Display.STATE_ON;
Jeff Brown5d6443b2015-04-10 20:15:01 -0700630 } else {
631 return; // old state and new state is off
632 }
633 }
634
Santos Cordond6a56602016-09-20 15:50:35 -0700635 // If the state change was from or to VR, then we need to tell the light
Karthik Ravi Shankar66855312017-10-04 13:30:13 -0700636 // so that it can apply appropriate VR brightness settings. Also, update the
637 // brightness so the state is propogated to light.
638 boolean vrModeChange = false;
Santos Cordond6a56602016-09-20 15:50:35 -0700639 if ((state == Display.STATE_VR || currentState == Display.STATE_VR) &&
640 currentState != state) {
641 setVrMode(state == Display.STATE_VR);
Karthik Ravi Shankar66855312017-10-04 13:30:13 -0700642 vrModeChange = true;
Santos Cordond6a56602016-09-20 15:50:35 -0700643 }
644
Jeff Brown5d6443b2015-04-10 20:15:01 -0700645 // Apply brightness changes given that we are in a non-suspended state.
Karthik Ravi Shankar66855312017-10-04 13:30:13 -0700646 if (brightnessChanged || vrModeChange) {
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000647 setDisplayBrightness(brightnessState);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700648 }
649
650 // Enter the final desired state, possibly suspended.
651 if (state != currentState) {
652 setDisplayState(state);
653 }
654 }
655
Santos Cordond6a56602016-09-20 15:50:35 -0700656 private void setVrMode(boolean isVrEnabled) {
657 if (DEBUG) {
658 Slog.d(TAG, "setVrMode("
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800659 + "id=" + physicalDisplayId
Santos Cordond6a56602016-09-20 15:50:35 -0700660 + ", state=" + Display.stateToString(state) + ")");
661 }
Robin Leeb9e44e52020-02-07 04:18:20 +0100662 if (mBacklight != null) {
663 mBacklight.setVrMode(isVrEnabled);
664 }
Santos Cordond6a56602016-09-20 15:50:35 -0700665 }
666
Jeff Brown5d6443b2015-04-10 20:15:01 -0700667 private void setDisplayState(int state) {
668 if (DEBUG) {
669 Slog.d(TAG, "setDisplayState("
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800670 + "id=" + physicalDisplayId
Jeff Brown5d6443b2015-04-10 20:15:01 -0700671 + ", state=" + Display.stateToString(state) + ")");
672 }
673
Chris Phoenixbc839a32017-10-21 14:46:15 -0700674 // We must tell sidekick to stop controlling the display before we
675 // can change its power mode, so do that first.
676 if (mSidekickActive) {
677 Trace.traceBegin(Trace.TRACE_TAG_POWER,
678 "SidekickInternal#endDisplayControl");
679 try {
680 mSidekickInternal.endDisplayControl();
681 } finally {
682 Trace.traceEnd(Trace.TRACE_TAG_POWER);
683 }
684 mSidekickActive = false;
685 }
686 final int mode = getPowerModeForState(state);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700687 Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState("
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800688 + "id=" + physicalDisplayId
Jeff Brown5d6443b2015-04-10 20:15:01 -0700689 + ", state=" + Display.stateToString(state) + ")");
Jeff Browne75926d2014-09-18 15:24:49 -0700690 try {
691 SurfaceControl.setDisplayPowerMode(token, mode);
Michael Wrightc3e6af82017-07-25 22:31:03 +0100692 Trace.traceCounter(Trace.TRACE_TAG_POWER, "DisplayPowerMode", mode);
Jeff Browne75926d2014-09-18 15:24:49 -0700693 } finally {
694 Trace.traceEnd(Trace.TRACE_TAG_POWER);
695 }
Chris Phoenixbc839a32017-10-21 14:46:15 -0700696 // If we're entering a suspended (but not OFF) power state and we
697 // have a sidekick available, tell it now that it can take control.
698 if (Display.isSuspendedState(state) && state != Display.STATE_OFF
699 && mSidekickInternal != null && !mSidekickActive) {
700 Trace.traceBegin(Trace.TRACE_TAG_POWER,
701 "SidekickInternal#startDisplayControl");
702 try {
703 mSidekickActive = mSidekickInternal.startDisplayControl(state);
704 } finally {
705 Trace.traceEnd(Trace.TRACE_TAG_POWER);
706 }
707 }
Jeff Browne75926d2014-09-18 15:24:49 -0700708 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700709
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000710 private void setDisplayBrightness(float brightness) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700711 if (DEBUG) {
712 Slog.d(TAG, "setDisplayBrightness("
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800713 + "id=" + physicalDisplayId
714 + ", brightness=" + brightness + ")");
Jeff Brown5d6443b2015-04-10 20:15:01 -0700715 }
716
717 Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness("
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800718 + "id=" + physicalDisplayId + ", brightness=" + brightness + ")");
Jeff Brown5d6443b2015-04-10 20:15:01 -0700719 try {
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000720 if (isHalBrightnessRangeSpecified()) {
721 brightness = displayBrightnessToHalBrightness(
Santos Cordoned5a8fe2020-05-13 18:25:21 +0100722 BrightnessSynchronizer.brightnessFloatToIntRange(
723 getContext(), brightness));
Santos Cordon4505e5e2020-01-17 15:18:10 +0000724 }
Robin Leeb9e44e52020-02-07 04:18:20 +0100725 if (mBacklight != null) {
726 mBacklight.setBrightness(brightness);
727 }
Michael Wrightc3e6af82017-07-25 22:31:03 +0100728 Trace.traceCounter(Trace.TRACE_TAG_POWER,
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000729 "ScreenBrightness",
730 BrightnessSynchronizer.brightnessFloatToInt(
731 getContext(), brightness));
Jeff Brown5d6443b2015-04-10 20:15:01 -0700732 } finally {
733 Trace.traceEnd(Trace.TRACE_TAG_POWER);
734 }
735 }
Santos Cordon4505e5e2020-01-17 15:18:10 +0000736
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000737 private boolean isHalBrightnessRangeSpecified() {
738 return !(mSystemBrightnessToNits == null || mNitsToHalBrightness == null);
739 }
740
Santos Cordon4505e5e2020-01-17 15:18:10 +0000741 /**
742 * Converts brightness range from the framework's brightness space to the
743 * Hal brightness space if the HAL brightness space has been provided via
744 * a display device configuration file.
745 */
Santos Cordoned5a8fe2020-05-13 18:25:21 +0100746 private float displayBrightnessToHalBrightness(float brightness) {
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000747 if (!isHalBrightnessRangeSpecified()) {
Santos Cordon4505e5e2020-01-17 15:18:10 +0000748 return PowerManager.BRIGHTNESS_INVALID_FLOAT;
749 }
750
Santos Cordoned5a8fe2020-05-13 18:25:21 +0100751 if (BrightnessSynchronizer.floatEquals(
752 brightness, PowerManager.BRIGHTNESS_OFF)) {
Santos Cordon4505e5e2020-01-17 15:18:10 +0000753 return PowerManager.BRIGHTNESS_OFF_FLOAT;
754 }
755
756 final float nits = mSystemBrightnessToNits.interpolate(brightness);
757 final float halBrightness = mNitsToHalBrightness.interpolate(nits);
758 return halBrightness;
759 }
Jeff Browne75926d2014-09-18 15:24:49 -0700760 };
Jeff Brown037c33e2014-04-09 00:31:55 -0700761 }
Jeff Browne75926d2014-09-18 15:24:49 -0700762 return null;
Jeff Brown9e316a12012-10-08 19:17:06 -0700763 }
764
765 @Override
Michael Wrighta3dab232019-02-22 16:54:21 +0000766 public void setRequestedColorModeLocked(int colorMode) {
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800767 requestColorModeLocked(colorMode);
Michael Wright1c9977b2016-07-12 13:30:10 -0700768 }
769
Adrian Roos898ec382018-01-17 12:54:50 +0100770 @Override
Ana Kruleca74a8642019-11-14 00:51:00 +0100771 public void setDesiredDisplayModeSpecsLocked(
772 DisplayModeDirector.DesiredDisplayModeSpecs displayModeSpecs) {
Steven Thomasec161942020-01-03 12:46:28 -0800773 if (displayModeSpecs.baseModeId == 0) {
Ana Kruleca74a8642019-11-14 00:51:00 +0100774 // Bail if the caller is requesting a null mode. We'll get called again shortly with
775 // a valid mode.
776 return;
777 }
Ady Abraham8a5e3912020-02-18 17:28:26 -0800778
779 // Find the config Id based on the desired mode specs. In case there is more than one
780 // config matching the mode spec, prefer the one that is in the default config group.
781 // For now the default config group is taken from the active config when we got the
782 // hotplug event for the display. In the future we might want to change the default
783 // config based on vendor requirements.
784 // Note: We prefer the default config group over the current one as this is the config
785 // group the vendor prefers.
786 int baseConfigId = findDisplayConfigIdLocked(displayModeSpecs.baseModeId,
787 mDefaultConfigGroup);
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800788 if (baseConfigId < 0) {
Ana Kruleca74a8642019-11-14 00:51:00 +0100789 // When a display is hotplugged, it's possible for a mode to be removed that was
790 // previously valid. Because of the way display changes are propagated through the
791 // framework, and the caching of the display mode specs in LogicalDisplay, it's
792 // possible we'll get called with a stale mode id that no longer represents a valid
793 // mode. This should only happen in extremely rare cases. A followup call will
794 // contain a valid mode id.
795 Slog.w(TAG,
Steven Thomasec161942020-01-03 12:46:28 -0800796 "Ignoring request for invalid base mode id " + displayModeSpecs.baseModeId);
Ana Kruleca74a8642019-11-14 00:51:00 +0100797 updateDeviceInfoLocked();
798 return;
799 }
800 if (mDisplayModeSpecsInvalid || !displayModeSpecs.equals(mDisplayModeSpecs)) {
801 mDisplayModeSpecsInvalid = false;
802 mDisplayModeSpecs.copyFrom(displayModeSpecs);
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800803 getHandler().sendMessage(PooledLambda.obtainMessage(
804 LocalDisplayDevice::setDesiredDisplayModeSpecsAsync, this,
805 getDisplayTokenLocked(),
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800806 new SurfaceControl.DesiredDisplayConfigSpecs(baseConfigId,
Steven Thomas305a57c2020-04-17 12:28:36 -0700807 mDisplayModeSpecs.primaryRefreshRateRange.min,
808 mDisplayModeSpecs.primaryRefreshRateRange.max,
809 mDisplayModeSpecs.appRequestRefreshRateRange.min,
810 mDisplayModeSpecs.appRequestRefreshRateRange.max)));
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800811 }
812 }
813
814 private void setDesiredDisplayModeSpecsAsync(IBinder displayToken,
815 SurfaceControl.DesiredDisplayConfigSpecs configSpecs) {
816 // Do not lock when calling these SurfaceControl methods because they are sync
817 // operations that may block for a while when setting display power mode.
818 SurfaceControl.setDesiredDisplayConfigSpecs(displayToken, configSpecs);
819 final int activePhysIndex = SurfaceControl.getActiveConfig(displayToken);
820 synchronized (getSyncRoot()) {
Ana Kruleca74a8642019-11-14 00:51:00 +0100821 if (updateActiveModeLocked(activePhysIndex)) {
822 updateDeviceInfoLocked();
823 }
824 }
Michael Wrighta3dab232019-02-22 16:54:21 +0000825 }
826
827 @Override
Adrian Roos898ec382018-01-17 12:54:50 +0100828 public void onOverlayChangedLocked() {
829 updateDeviceInfoLocked();
830 }
831
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800832 public void onActiveDisplayConfigChangedLocked(int configId) {
833 if (updateActiveModeLocked(configId)) {
Michael Wrighta3dab232019-02-22 16:54:21 +0000834 updateDeviceInfoLocked();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700835 }
Michael Wrighta3dab232019-02-22 16:54:21 +0000836 }
Michael Wright58e829f2015-09-15 00:13:26 +0100837
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800838 public boolean updateActiveModeLocked(int activeConfigId) {
839 if (mActiveConfigId == activeConfigId) {
Michael Wright1c9977b2016-07-12 13:30:10 -0700840 return false;
Michael Wright3f145a22014-07-22 19:46:03 -0700841 }
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800842 mActiveConfigId = activeConfigId;
843 mActiveModeId = findMatchingModeIdLocked(activeConfigId);
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100844 mActiveModeInvalid = mActiveModeId == NO_DISPLAY_MODE_ID;
Michael Wrighta3dab232019-02-22 16:54:21 +0000845 if (mActiveModeInvalid) {
846 Slog.w(TAG, "In unknown mode after setting allowed configs"
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800847 + ", activeConfigId=" + mActiveConfigId);
Michael Wrighta3dab232019-02-22 16:54:21 +0000848 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700849 return true;
850 }
851
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800852 public void requestColorModeLocked(int colorMode) {
Michael Wright1c9977b2016-07-12 13:30:10 -0700853 if (mActiveColorMode == colorMode) {
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800854 return;
Michael Wright1c9977b2016-07-12 13:30:10 -0700855 }
856 if (!mSupportedColorModes.contains(colorMode)) {
857 Slog.w(TAG, "Unable to find color mode " + colorMode
858 + ", ignoring request.");
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800859 return;
Michael Wright1c9977b2016-07-12 13:30:10 -0700860 }
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800861
Michael Wright1c9977b2016-07-12 13:30:10 -0700862 mActiveColorMode = colorMode;
863 mActiveColorModeInvalid = false;
Riddle Hsu8b37bc02019-11-23 00:39:14 +0800864 getHandler().sendMessage(PooledLambda.obtainMessage(
865 LocalDisplayDevice::requestColorModeAsync, this,
866 getDisplayTokenLocked(), colorMode));
867 }
868
869 private void requestColorModeAsync(IBinder displayToken, int colorMode) {
870 // Do not lock when calling this SurfaceControl method because it is a sync operation
871 // that may block for a while when setting display power mode.
872 SurfaceControl.setActiveColorMode(displayToken, colorMode);
873 synchronized (getSyncRoot()) {
874 updateDeviceInfoLocked();
875 }
Michael Wright3f145a22014-07-22 19:46:03 -0700876 }
877
878 @Override
Galia Peycheva056b3ee2019-06-26 14:05:12 +0200879 public void setAutoLowLatencyModeLocked(boolean on) {
880 if (mAllmRequested == on) {
881 return;
882 }
883
884 mAllmRequested = on;
885
886 if (!mAllmSupported) {
887 Slog.d(TAG, "Unable to set ALLM because the connected display "
888 + "does not support ALLM.");
889 return;
890 }
891
892 SurfaceControl.setAutoLowLatencyMode(getDisplayTokenLocked(), on);
893 }
894
895 @Override
896 public void setGameContentTypeLocked(boolean on) {
897 if (mGameContentTypeRequested == on) {
898 return;
899 }
900
901 mGameContentTypeRequested = on;
902
903 if (!mGameContentTypeSupported) {
904 Slog.d(TAG, "Unable to set game content type because the connected "
905 + "display does not support game content type.");
906 return;
907 }
908
909 SurfaceControl.setGameContentType(getDisplayTokenLocked(), on);
910 }
911
912 @Override
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700913 public void dumpLocked(PrintWriter pw) {
914 super.dumpLocked(pw);
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800915 pw.println("mPhysicalDisplayId=" + mPhysicalDisplayId);
Ana Kruleca74a8642019-11-14 00:51:00 +0100916 pw.println("mDisplayModeSpecs={" + mDisplayModeSpecs + "}");
917 pw.println("mDisplayModeSpecsInvalid=" + mDisplayModeSpecsInvalid);
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800918 pw.println("mActiveConfigId=" + mActiveConfigId);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700919 pw.println("mActiveModeId=" + mActiveModeId);
Michael Wright1c9977b2016-07-12 13:30:10 -0700920 pw.println("mActiveColorMode=" + mActiveColorMode);
Michael Wrighta3dab232019-02-22 16:54:21 +0000921 pw.println("mDefaultModeId=" + mDefaultModeId);
Jeff Brown037c33e2014-04-09 00:31:55 -0700922 pw.println("mState=" + Display.stateToString(mState));
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000923 pw.println("mBrightnessState=" + mBrightnessState);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700924 pw.println("mBacklight=" + mBacklight);
Galia Peycheva056b3ee2019-06-26 14:05:12 +0200925 pw.println("mAllmSupported=" + mAllmSupported);
926 pw.println("mAllmRequested=" + mAllmRequested);
Marin Shalamanov98af1592019-10-08 10:48:08 +0200927 pw.println("mGameContentTypeSupported=" + mGameContentTypeSupported);
928 pw.println("mGameContentTypeRequested=" + mGameContentTypeRequested);
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800929 pw.println("mDisplayInfo=" + mDisplayInfo);
930 pw.println("mDisplayConfigs=");
931 for (int i = 0; i < mDisplayConfigs.length; i++) {
932 pw.println(" " + mDisplayConfigs[i]);
Michael Wright58e829f2015-09-15 00:13:26 +0100933 }
934 pw.println("mSupportedModes=");
935 for (int i = 0; i < mSupportedModes.size(); i++) {
936 pw.println(" " + mSupportedModes.valueAt(i));
937 }
Marin Shalamanov98af1592019-10-08 10:48:08 +0200938 pw.print("mSupportedColorModes=" + mSupportedColorModes.toString());
Michael Wright58e829f2015-09-15 00:13:26 +0100939 }
940
Ady Abraham8a5e3912020-02-18 17:28:26 -0800941 private int findDisplayConfigIdLocked(int modeId, int configGroup) {
942 int matchingConfigId = SurfaceControl.DisplayConfig.INVALID_DISPLAY_CONFIG_ID;
Michael Wright58e829f2015-09-15 00:13:26 +0100943 DisplayModeRecord record = mSupportedModes.get(modeId);
Michael Wright1c9977b2016-07-12 13:30:10 -0700944 if (record != null) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800945 for (int i = 0; i < mDisplayConfigs.length; i++) {
946 SurfaceControl.DisplayConfig config = mDisplayConfigs[i];
947 if (record.hasMatchingMode(config)) {
Ady Abraham8a5e3912020-02-18 17:28:26 -0800948 if (matchingConfigId
949 == SurfaceControl.DisplayConfig.INVALID_DISPLAY_CONFIG_ID) {
950 matchingConfigId = i;
951 }
952
953 // Prefer to return a config that matches the configGroup
954 if (config.configGroup == configGroup) {
955 return i;
956 }
Michael Wright58e829f2015-09-15 00:13:26 +0100957 }
958 }
959 }
Ady Abraham8a5e3912020-02-18 17:28:26 -0800960 return matchingConfigId;
Jeff Brown037c33e2014-04-09 00:31:55 -0700961 }
962
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800963 private int findMatchingModeIdLocked(int configId) {
964 SurfaceControl.DisplayConfig config = mDisplayConfigs[configId];
Michael Wrighta3dab232019-02-22 16:54:21 +0000965 for (int i = 0; i < mSupportedModes.size(); i++) {
966 DisplayModeRecord record = mSupportedModes.valueAt(i);
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800967 if (record.hasMatchingMode(config)) {
Michael Wrighta3dab232019-02-22 16:54:21 +0000968 return record.mMode.getModeId();
969 }
970 }
Marin Shalamanovcdf7bb62020-01-07 14:19:50 +0100971 return NO_DISPLAY_MODE_ID;
Michael Wrighta3dab232019-02-22 16:54:21 +0000972 }
973
Jeff Brown037c33e2014-04-09 00:31:55 -0700974 private void updateDeviceInfoLocked() {
975 mInfo = null;
976 sendDisplayDeviceEventLocked(this, DISPLAY_DEVICE_EVENT_CHANGED);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700977 }
Michael Wrighta3dab232019-02-22 16:54:21 +0000978
979 private Display.Mode[] getDisplayModes(SparseArray<DisplayModeRecord> records) {
980 final int size = records.size();
981 Display.Mode[] modes = new Display.Mode[size];
982 for (int i = 0; i < size; i++) {
983 DisplayModeRecord record = records.valueAt(i);
984 modes[i] = record.mMode;
985 }
986 return modes;
987 }
Keun young Parkabf38e32019-04-23 19:18:34 -0700988
989 private boolean isDisplayPrivate(DisplayAddress.Physical physicalAddress) {
990 if (physicalAddress == null) {
991 return false;
992 }
993 final Resources res = getOverlayContext().getResources();
994 int[] ports = res.getIntArray(
995 com.android.internal.R.array.config_localPrivateDisplayPorts);
996 if (ports != null) {
Dominik Laskowski67cc7f82019-11-08 17:09:29 -0800997 int port = Byte.toUnsignedInt(physicalAddress.getPort());
Keun young Parkabf38e32019-04-23 19:18:34 -0700998 for (int p : ports) {
999 if (p == port) {
1000 return true;
1001 }
1002 }
1003 }
1004 return false;
1005 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001006 }
Michael Wright3f145a22014-07-22 19:46:03 -07001007
Adrian Roos30f53212018-01-05 16:14:34 +01001008 /** Supplies a context whose Resources apply runtime-overlays */
1009 Context getOverlayContext() {
1010 return ActivityThread.currentActivityThread().getSystemUiContext();
1011 }
1012
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001013 /**
1014 * Keeps track of a display configuration.
1015 */
1016 private static final class DisplayModeRecord {
1017 public final Display.Mode mMode;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001018
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001019 DisplayModeRecord(SurfaceControl.DisplayConfig config) {
1020 mMode = createMode(config.width, config.height, config.refreshRate);
Michael Wright58e829f2015-09-15 00:13:26 +01001021 }
1022
1023 /**
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001024 * Returns whether the mode generated by the given DisplayConfig matches the mode
Michael Wright58e829f2015-09-15 00:13:26 +01001025 * contained by the record modulo mode ID.
1026 *
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001027 * Note that this doesn't necessarily mean that the DisplayConfigs are identical, just
Michael Wright58e829f2015-09-15 00:13:26 +01001028 * that they generate identical modes.
1029 */
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001030 public boolean hasMatchingMode(SurfaceControl.DisplayConfig config) {
Michael Wright58e829f2015-09-15 00:13:26 +01001031 int modeRefreshRate = Float.floatToIntBits(mMode.getRefreshRate());
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001032 int configRefreshRate = Float.floatToIntBits(config.refreshRate);
1033 return mMode.getPhysicalWidth() == config.width
1034 && mMode.getPhysicalHeight() == config.height
1035 && modeRefreshRate == configRefreshRate;
Michael Wright58e829f2015-09-15 00:13:26 +01001036 }
1037
1038 public String toString() {
1039 return "DisplayModeRecord{mMode=" + mMode + "}";
Michael Wright3f145a22014-07-22 19:46:03 -07001040 }
Jeff Brown64a55af2012-08-26 02:47:39 -07001041 }
Jeff Browne87bf032012-09-20 18:30:13 -07001042
Ady Abrahama5a21f72019-02-13 16:41:59 -08001043 private final class PhysicalDisplayEventReceiver extends DisplayEventReceiver {
1044 PhysicalDisplayEventReceiver(Looper looper) {
Ady Abraham9c501aa2019-06-04 16:07:44 -07001045 super(looper, VSYNC_SOURCE_APP, CONFIG_CHANGED_EVENT_DISPATCH);
Jeff Browne87bf032012-09-20 18:30:13 -07001046 }
1047
1048 @Override
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001049 public void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected) {
Jeff Browne87bf032012-09-20 18:30:13 -07001050 synchronized (getSyncRoot()) {
Jesse Halle244db42012-11-08 11:55:14 -08001051 if (connected) {
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001052 tryConnectDisplayLocked(physicalDisplayId);
Jesse Halle244db42012-11-08 11:55:14 -08001053 } else {
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001054 tryDisconnectDisplayLocked(physicalDisplayId);
Jesse Halle244db42012-11-08 11:55:14 -08001055 }
Jeff Browne87bf032012-09-20 18:30:13 -07001056 }
1057 }
Ady Abrahama5a21f72019-02-13 16:41:59 -08001058
1059 @Override
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001060 public void onConfigChanged(long timestampNanos, long physicalDisplayId, int configId) {
Ady Abrahama5a21f72019-02-13 16:41:59 -08001061 if (DEBUG) {
1062 Slog.d(TAG, "onConfigChanged("
1063 + "timestampNanos=" + timestampNanos
Michael Wrighta3dab232019-02-22 16:54:21 +00001064 + ", physicalDisplayId=" + physicalDisplayId
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001065 + ", configId=" + configId + ")");
Michael Wrighta3dab232019-02-22 16:54:21 +00001066 }
1067 synchronized (getSyncRoot()) {
1068 LocalDisplayDevice device = mDevices.get(physicalDisplayId);
1069 if (device == null) {
1070 if (DEBUG) {
1071 Slog.d(TAG, "Received config change for unhandled physical display: "
1072 + "physicalDisplayId=" + physicalDisplayId);
1073 }
1074 return;
1075 }
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001076 device.onActiveDisplayConfigChangedLocked(configId);
Ady Abrahama5a21f72019-02-13 16:41:59 -08001077 }
1078 }
Jeff Browne87bf032012-09-20 18:30:13 -07001079 }
Dan Stoza00101052014-05-02 15:23:40 -07001080}