Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.display; |
| 18 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 19 | import android.app.ActivityThread; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 21 | import android.content.res.Resources; |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 22 | import android.hardware.sidekick.SidekickInternal; |
Griff Hazen | d3c454d | 2016-03-25 07:30:34 -0700 | [diff] [blame] | 23 | import android.os.Build; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 25 | import android.os.IBinder; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 26 | import android.os.Looper; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 27 | import android.os.PowerManager; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 28 | import android.os.SystemProperties; |
Jeff Brown | 3edf527 | 2014-08-14 19:25:14 -0700 | [diff] [blame] | 29 | import android.os.Trace; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 30 | import android.util.LongSparseArray; |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 31 | import android.util.Slog; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 32 | import android.util.SparseArray; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 33 | import android.view.Display; |
Dominik Laskowski | db84596 | 2019-01-27 21:20:00 -0800 | [diff] [blame] | 34 | import android.view.DisplayAddress; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 35 | import android.view.DisplayCutout; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 36 | import android.view.DisplayEventReceiver; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 37 | import android.view.Surface; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 38 | import android.view.SurfaceControl; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 39 | |
| 40 | import com.android.server.LocalServices; |
| 41 | import com.android.server.lights.Light; |
| 42 | import com.android.server.lights.LightsManager; |
| 43 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 44 | import java.io.PrintWriter; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 45 | import java.util.ArrayList; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 46 | import java.util.Arrays; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 47 | import java.util.Collections; |
| 48 | import java.util.List; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 49 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 50 | /** |
| 51 | * A display adapter for the local displays managed by Surface Flinger. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 52 | * <p> |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 53 | * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 54 | * </p> |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 55 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 56 | final class LocalDisplayAdapter extends DisplayAdapter { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 57 | private static final String TAG = "LocalDisplayAdapter"; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 58 | private static final boolean DEBUG = false; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 59 | |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 60 | private static final String UNIQUE_ID_PREFIX = "local:"; |
| 61 | |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 62 | private static final String PROPERTY_EMULATOR_CIRCULAR = "ro.emulator.circular"; |
| 63 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 64 | private final LongSparseArray<LocalDisplayDevice> mDevices = |
| 65 | new LongSparseArray<LocalDisplayDevice>(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 66 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 67 | @SuppressWarnings("unused") // Becomes active at instantiation time. |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 68 | private PhysicalDisplayEventReceiver mPhysicalDisplayEventReceiver; |
| 69 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 70 | |
Jeff Brown | 6669250 | 2012-10-18 16:13:44 -0700 | [diff] [blame] | 71 | // Called with SyncRoot lock held. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 72 | public LocalDisplayAdapter(DisplayManagerService.SyncRoot syncRoot, |
| 73 | Context context, Handler handler, Listener listener) { |
| 74 | super(syncRoot, context, handler, listener, TAG); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 78 | public void registerLocked() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 79 | super.registerLocked(); |
Jeff Brown | 6669250 | 2012-10-18 16:13:44 -0700 | [diff] [blame] | 80 | |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 81 | mPhysicalDisplayEventReceiver = new PhysicalDisplayEventReceiver(getHandler().getLooper()); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 82 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 83 | for (long physicalDisplayId : SurfaceControl.getPhysicalDisplayIds()) { |
| 84 | tryConnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 85 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 88 | private void tryConnectDisplayLocked(long physicalDisplayId) { |
| 89 | final IBinder displayToken = SurfaceControl.getPhysicalDisplayToken(physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 90 | if (displayToken != null) { |
| 91 | SurfaceControl.PhysicalDisplayInfo[] configs = |
| 92 | SurfaceControl.getDisplayConfigs(displayToken); |
| 93 | if (configs == null) { |
| 94 | // There are no valid configs for this device, so we can't use it |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 95 | Slog.w(TAG, "No valid configs found for display device " + physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 96 | return; |
| 97 | } |
| 98 | int activeConfig = SurfaceControl.getActiveConfig(displayToken); |
| 99 | if (activeConfig < 0) { |
| 100 | // There is no active config, and for now we don't have the |
| 101 | // policy to set one. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 102 | Slog.w(TAG, "No active config found for display device " + physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 103 | return; |
| 104 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 105 | int activeColorMode = SurfaceControl.getActiveColorMode(displayToken); |
| 106 | if (activeColorMode < 0) { |
| 107 | // We failed to get the active color mode. We don't bail out here since on the next |
| 108 | // configuration pass we'll go ahead and set it to whatever it was set to last (or |
| 109 | // COLOR_MODE_NATIVE if this is the first configuration). |
| 110 | Slog.w(TAG, "Unable to get active color mode for display device " + |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 111 | physicalDisplayId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 112 | activeColorMode = Display.COLOR_MODE_INVALID; |
| 113 | } |
| 114 | int[] colorModes = SurfaceControl.getDisplayColorModes(displayToken); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 115 | int[] allowedConfigs = SurfaceControl.getAllowedDisplayConfigs(displayToken); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 116 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 117 | if (device == null) { |
| 118 | // Display was added. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 119 | final boolean isInternal = mDevices.size() == 0; |
| 120 | device = new LocalDisplayDevice(displayToken, physicalDisplayId, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 121 | configs, activeConfig, allowedConfigs, colorModes, activeColorMode, |
| 122 | isInternal); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 123 | mDevices.put(physicalDisplayId, device); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 124 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 125 | } else if (device.updatePhysicalDisplayInfoLocked(configs, activeConfig, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 126 | allowedConfigs, colorModes, activeColorMode)) { |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 127 | // Display properties changed. |
| 128 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_CHANGED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 129 | } |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 130 | } else { |
| 131 | // The display is no longer available. Ignore the attempt to add it. |
| 132 | // If it was connected but has already been disconnected, we'll get a |
| 133 | // disconnect event that will remove it from mDevices. |
| 134 | } |
| 135 | } |
| 136 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 137 | private void tryDisconnectDisplayLocked(long physicalDisplayId) { |
| 138 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 139 | if (device != null) { |
| 140 | // Display was removed. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 141 | mDevices.remove(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 142 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 143 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 146 | static int getPowerModeForState(int state) { |
| 147 | switch (state) { |
| 148 | case Display.STATE_OFF: |
| 149 | return SurfaceControl.POWER_MODE_OFF; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 150 | case Display.STATE_DOZE: |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 151 | return SurfaceControl.POWER_MODE_DOZE; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 152 | case Display.STATE_DOZE_SUSPEND: |
| 153 | return SurfaceControl.POWER_MODE_DOZE_SUSPEND; |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 154 | case Display.STATE_ON_SUSPEND: |
| 155 | return SurfaceControl.POWER_MODE_ON_SUSPEND; |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 156 | default: |
| 157 | return SurfaceControl.POWER_MODE_NORMAL; |
| 158 | } |
Jeff Brown | 44b1f76 | 2014-04-22 18:07:24 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 161 | private final class LocalDisplayDevice extends DisplayDevice { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 162 | private final long mPhysicalDisplayId; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 163 | private final Light mBacklight; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 164 | private final SparseArray<DisplayModeRecord> mSupportedModes = new SparseArray<>(); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 165 | private final ArrayList<Integer> mSupportedColorModes = new ArrayList<>(); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 166 | private final boolean mIsInternal; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 167 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 168 | private DisplayDeviceInfo mInfo; |
| 169 | private boolean mHavePendingChanges; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 170 | private int mState = Display.STATE_UNKNOWN; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 171 | private int mBrightness = PowerManager.BRIGHTNESS_DEFAULT; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 172 | private int mDefaultModeId; |
| 173 | private int mActiveModeId; |
| 174 | private boolean mActiveModeInvalid; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 175 | private int[] mAllowedModeIds; |
| 176 | private boolean mAllowedModeIdsInvalid; |
| 177 | private int mActivePhysIndex; |
| 178 | private int[] mAllowedPhysIndexes; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 179 | private int mActiveColorMode; |
| 180 | private boolean mActiveColorModeInvalid; |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 181 | private Display.HdrCapabilities mHdrCapabilities; |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 182 | private boolean mSidekickActive; |
| 183 | private SidekickInternal mSidekickInternal; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 184 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 185 | private SurfaceControl.PhysicalDisplayInfo[] mDisplayInfos; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 186 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 187 | LocalDisplayDevice(IBinder displayToken, long physicalDisplayId, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 188 | SurfaceControl.PhysicalDisplayInfo[] physicalDisplayInfos, int activeDisplayInfo, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 189 | int[] allowedDisplayInfos, int[] colorModes, int activeColorMode, |
| 190 | boolean isInternal) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 191 | super(LocalDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + physicalDisplayId); |
| 192 | mPhysicalDisplayId = physicalDisplayId; |
| 193 | mIsInternal = isInternal; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 194 | updatePhysicalDisplayInfoLocked(physicalDisplayInfos, activeDisplayInfo, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 195 | allowedDisplayInfos, colorModes, activeColorMode); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 196 | updateColorModesLocked(colorModes, activeColorMode); |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 197 | mSidekickInternal = LocalServices.getService(SidekickInternal.class); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 198 | if (mIsInternal) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 199 | LightsManager lights = LocalServices.getService(LightsManager.class); |
| 200 | mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT); |
| 201 | } else { |
| 202 | mBacklight = null; |
| 203 | } |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 204 | mHdrCapabilities = SurfaceControl.getHdrCapabilities(displayToken); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public boolean hasStableUniqueId() { |
| 209 | return true; |
| 210 | } |
| 211 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 212 | public boolean updatePhysicalDisplayInfoLocked( |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 213 | SurfaceControl.PhysicalDisplayInfo[] physicalDisplayInfos, int activeDisplayInfo, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 214 | int[] allowedDisplayInfos, int[] colorModes, int activeColorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 215 | mDisplayInfos = Arrays.copyOf(physicalDisplayInfos, physicalDisplayInfos.length); |
| 216 | mActivePhysIndex = activeDisplayInfo; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 217 | mAllowedPhysIndexes = Arrays.copyOf(allowedDisplayInfos, allowedDisplayInfos.length); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 218 | // Build an updated list of all existing modes. |
| 219 | ArrayList<DisplayModeRecord> records = new ArrayList<DisplayModeRecord>(); |
| 220 | boolean modesAdded = false; |
| 221 | for (int i = 0; i < physicalDisplayInfos.length; i++) { |
| 222 | SurfaceControl.PhysicalDisplayInfo info = physicalDisplayInfos[i]; |
| 223 | // First, check to see if we've already added a matching mode. Since not all |
| 224 | // configuration options are exposed via Display.Mode, it's possible that we have |
| 225 | // multiple PhysicalDisplayInfos that would generate the same Display.Mode. |
| 226 | boolean existingMode = false; |
| 227 | for (int j = 0; j < records.size(); j++) { |
| 228 | if (records.get(j).hasMatchingMode(info)) { |
| 229 | existingMode = true; |
| 230 | break; |
| 231 | } |
| 232 | } |
| 233 | if (existingMode) { |
| 234 | continue; |
| 235 | } |
| 236 | // If we haven't already added a mode for this configuration to the new set of |
| 237 | // supported modes then check to see if we have one in the prior set of supported |
| 238 | // modes to reuse. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 239 | DisplayModeRecord record = findDisplayModeRecord(info); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 240 | if (record == null) { |
| 241 | record = new DisplayModeRecord(info); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 242 | modesAdded = true; |
| 243 | } |
| 244 | records.add(record); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | // Get the currently active mode |
| 248 | DisplayModeRecord activeRecord = null; |
| 249 | for (int i = 0; i < records.size(); i++) { |
| 250 | DisplayModeRecord record = records.get(i); |
| 251 | if (record.hasMatchingMode(physicalDisplayInfos[activeDisplayInfo])){ |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 252 | activeRecord = record; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 253 | break; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 254 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 255 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 256 | |
| 257 | // Check whether surface flinger spontaneously changed modes out from under us. |
| 258 | // Schedule traversals to ensure that the correct state is reapplied if necessary. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 259 | if (mActiveModeId != 0 |
| 260 | && mActiveModeId != activeRecord.mMode.getModeId()) { |
| 261 | mActiveModeInvalid = true; |
| 262 | sendTraversalRequestLocked(); |
| 263 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 264 | |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 265 | boolean recordsChanged = records.size() != mSupportedModes.size() || modesAdded; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 266 | // If the records haven't changed then we're done here. |
| 267 | if (!recordsChanged) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 268 | return false; |
| 269 | } |
| 270 | // Update the index of modes. |
| 271 | mHavePendingChanges = true; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 272 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 273 | mSupportedModes.clear(); |
| 274 | for (DisplayModeRecord record : records) { |
| 275 | mSupportedModes.put(record.mMode.getModeId(), record); |
| 276 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 277 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 278 | // Update the default mode, if needed. |
| 279 | if (findDisplayInfoIndexLocked(mDefaultModeId) < 0) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 280 | if (mDefaultModeId != 0) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 281 | Slog.w(TAG, "Default display mode no longer available, using currently" |
| 282 | + " active mode as default."); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 283 | } |
| 284 | mDefaultModeId = activeRecord.mMode.getModeId(); |
| 285 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 286 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 287 | // Determine whether the active mode is still there. |
| 288 | if (mSupportedModes.indexOfKey(mActiveModeId) < 0) { |
| 289 | if (mActiveModeId != 0) { |
| 290 | Slog.w(TAG, "Active display mode no longer available, reverting to default" |
| 291 | + " mode."); |
| 292 | } |
| 293 | mActiveModeId = mDefaultModeId; |
| 294 | mActiveModeInvalid = true; |
| 295 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 296 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 297 | // Determine what the currently allowed modes are |
| 298 | mAllowedModeIds = new int[] { mActiveModeId }; |
| 299 | int[] allowedModeIds = new int[mAllowedPhysIndexes.length]; |
| 300 | int size = 0; |
| 301 | for (int physIndex : mAllowedPhysIndexes) { |
| 302 | int modeId = findMatchingModeIdLocked(physIndex); |
| 303 | if (modeId > 0) { |
| 304 | allowedModeIds[size++] = modeId; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // If this is different from our desired allowed modes, then mark our current set as |
| 309 | // invalid so we correct this on the next traversal. |
| 310 | mAllowedModeIdsInvalid = !Arrays.equals(allowedModeIds, mAllowedModeIds); |
| 311 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 312 | // Schedule traversals so that we apply pending changes. |
| 313 | sendTraversalRequestLocked(); |
| 314 | return true; |
| 315 | } |
| 316 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 317 | private boolean updateColorModesLocked(int[] colorModes, |
| 318 | int activeColorMode) { |
| 319 | List<Integer> pendingColorModes = new ArrayList<>(); |
| 320 | |
thecrazyskull | b34c8104 | 2016-12-18 12:48:20 -0500 | [diff] [blame] | 321 | if (colorModes == null) return false; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 322 | // Build an updated list of all existing color modes. |
| 323 | boolean colorModesAdded = false; |
| 324 | for (int colorMode: colorModes) { |
| 325 | if (!mSupportedColorModes.contains(colorMode)) { |
| 326 | colorModesAdded = true; |
| 327 | } |
| 328 | pendingColorModes.add(colorMode); |
| 329 | } |
| 330 | |
| 331 | boolean colorModesChanged = |
| 332 | pendingColorModes.size() != mSupportedColorModes.size() |
| 333 | || colorModesAdded; |
| 334 | |
| 335 | // If the supported color modes haven't changed then we're done here. |
| 336 | if (!colorModesChanged) { |
| 337 | return false; |
| 338 | } |
| 339 | |
| 340 | mHavePendingChanges = true; |
| 341 | |
| 342 | mSupportedColorModes.clear(); |
| 343 | mSupportedColorModes.addAll(pendingColorModes); |
| 344 | Collections.sort(mSupportedColorModes); |
| 345 | |
| 346 | // Determine whether the active color mode is still there. |
| 347 | if (!mSupportedColorModes.contains(mActiveColorMode)) { |
| 348 | if (mActiveColorMode != 0) { |
| 349 | Slog.w(TAG, "Active color mode no longer available, reverting" |
| 350 | + " to default mode."); |
| 351 | mActiveColorMode = Display.COLOR_MODE_DEFAULT; |
| 352 | mActiveColorModeInvalid = true; |
| 353 | } else { |
| 354 | if (!mSupportedColorModes.isEmpty()) { |
| 355 | // This should never happen. |
| 356 | Slog.e(TAG, "Default and active color mode is no longer available!" |
| 357 | + " Reverting to first available mode."); |
| 358 | mActiveColorMode = mSupportedColorModes.get(0); |
| 359 | mActiveColorModeInvalid = true; |
| 360 | } else { |
| 361 | // This should really never happen. |
| 362 | Slog.e(TAG, "No color modes available!"); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | return true; |
| 367 | } |
| 368 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 369 | private DisplayModeRecord findDisplayModeRecord(SurfaceControl.PhysicalDisplayInfo info) { |
| 370 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 371 | DisplayModeRecord record = mSupportedModes.valueAt(i); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 372 | if (record.hasMatchingMode(info)) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 373 | return record; |
| 374 | } |
| 375 | } |
| 376 | return null; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 380 | public void applyPendingDisplayDeviceInfoChangesLocked() { |
| 381 | if (mHavePendingChanges) { |
| 382 | mInfo = null; |
| 383 | mHavePendingChanges = false; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 384 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 385 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 386 | |
| 387 | @Override |
| 388 | public DisplayDeviceInfo getDisplayDeviceInfoLocked() { |
| 389 | if (mInfo == null) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 390 | SurfaceControl.PhysicalDisplayInfo phys = mDisplayInfos[mActivePhysIndex]; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 391 | mInfo = new DisplayDeviceInfo(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 392 | mInfo.width = phys.width; |
| 393 | mInfo.height = phys.height; |
| 394 | mInfo.modeId = mActiveModeId; |
| 395 | mInfo.defaultModeId = mDefaultModeId; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 396 | mInfo.supportedModes = getDisplayModes(mSupportedModes); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 397 | mInfo.colorMode = mActiveColorMode; |
| 398 | mInfo.supportedColorModes = |
| 399 | new int[mSupportedColorModes.size()]; |
| 400 | for (int i = 0; i < mSupportedColorModes.size(); i++) { |
| 401 | mInfo.supportedColorModes[i] = mSupportedColorModes.get(i); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 402 | } |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 403 | mInfo.hdrCapabilities = mHdrCapabilities; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 404 | mInfo.appVsyncOffsetNanos = phys.appVsyncOffsetNanos; |
| 405 | mInfo.presentationDeadlineNanos = phys.presentationDeadlineNanos; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 406 | mInfo.state = mState; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 407 | mInfo.uniqueId = getUniqueId(); |
Dominik Laskowski | db84596 | 2019-01-27 21:20:00 -0800 | [diff] [blame] | 408 | mInfo.address = DisplayAddress.fromPhysicalDisplayId(mPhysicalDisplayId); |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 409 | |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 410 | // Assume that all built-in displays that have secure output (eg. HDCP) also |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 411 | // support compositing from gralloc protected buffers. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 412 | if (phys.secure) { |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 413 | mInfo.flags = DisplayDeviceInfo.FLAG_SECURE |
| 414 | | DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS; |
| 415 | } |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 416 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 417 | final Resources res = getOverlayContext().getResources(); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 418 | if (mIsInternal) { |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 419 | mInfo.name = res.getString( |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 420 | com.android.internal.R.string.display_manager_built_in_display_name); |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 421 | mInfo.flags |= DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 422 | | DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT; |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 423 | if (res.getBoolean(com.android.internal.R.bool.config_mainBuiltInDisplayIsRound) |
Griff Hazen | d3c454d | 2016-03-25 07:30:34 -0700 | [diff] [blame] | 424 | || (Build.IS_EMULATOR |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 425 | && SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) { |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 426 | mInfo.flags |= DisplayDeviceInfo.FLAG_ROUND; |
| 427 | } |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 428 | if (res.getBoolean( |
| 429 | com.android.internal.R.bool.config_maskMainBuiltInDisplayCutout)) { |
| 430 | mInfo.flags |= DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT; |
| 431 | } |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 432 | mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res, |
| 433 | mInfo.width, mInfo.height); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 434 | mInfo.type = Display.TYPE_BUILT_IN; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 435 | mInfo.densityDpi = (int)(phys.density * 160 + 0.5f); |
| 436 | mInfo.xDpi = phys.xDpi; |
| 437 | mInfo.yDpi = phys.yDpi; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 438 | mInfo.touch = DisplayDeviceInfo.TOUCH_INTERNAL; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 439 | } else { |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 440 | mInfo.displayCutout = null; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 441 | mInfo.type = Display.TYPE_HDMI; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 442 | mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 443 | mInfo.name = getContext().getResources().getString( |
| 444 | com.android.internal.R.string.display_manager_hdmi_display_name); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 445 | mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 446 | mInfo.setAssumedDensityForExternalDisplay(phys.width, phys.height); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 447 | |
| 448 | // For demonstration purposes, allow rotation of the external display. |
| 449 | // In the future we might allow the user to configure this directly. |
| 450 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
| 451 | mInfo.rotation = Surface.ROTATION_270; |
| 452 | } |
Scott Anderson | 8786ed9 | 2013-11-01 13:27:39 -0700 | [diff] [blame] | 453 | |
| 454 | // For demonstration purposes, allow rotation of the external display |
| 455 | // to follow the built-in display. |
| 456 | if (SystemProperties.getBoolean("persist.demo.hdmirotates", false)) { |
| 457 | mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT; |
| 458 | } |
Michael Wright | 4b0fa17 | 2016-03-11 17:15:24 -0800 | [diff] [blame] | 459 | |
| 460 | if (!res.getBoolean( |
| 461 | com.android.internal.R.bool.config_localDisplaysMirrorContent)) { |
| 462 | mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY; |
| 463 | } |
Pavel Maltsev | a6fec7b | 2018-04-04 10:14:55 -0700 | [diff] [blame] | 464 | |
| 465 | if (res.getBoolean(com.android.internal.R.bool.config_localDisplaysPrivate)) { |
| 466 | mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE; |
| 467 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | return mInfo; |
| 471 | } |
| 472 | |
| 473 | @Override |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 474 | public Runnable requestDisplayStateLocked(final int state, final int brightness) { |
| 475 | // Assume that the brightness is off if the display is being turned off. |
| 476 | assert state != Display.STATE_OFF || brightness == PowerManager.BRIGHTNESS_OFF; |
| 477 | |
| 478 | final boolean stateChanged = (mState != state); |
| 479 | final boolean brightnessChanged = (mBrightness != brightness) && mBacklight != null; |
| 480 | if (stateChanged || brightnessChanged) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 481 | final long physicalDisplayId = mPhysicalDisplayId; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 482 | final IBinder token = getDisplayTokenLocked(); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 483 | final int oldState = mState; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 484 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 485 | if (stateChanged) { |
| 486 | mState = state; |
| 487 | updateDeviceInfoLocked(); |
| 488 | } |
| 489 | |
| 490 | if (brightnessChanged) { |
| 491 | mBrightness = brightness; |
| 492 | } |
| 493 | |
| 494 | // Defer actually setting the display state until after we have exited |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 495 | // the critical section since it can take hundreds of milliseconds |
| 496 | // to complete. |
| 497 | return new Runnable() { |
| 498 | @Override |
| 499 | public void run() { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 500 | // Exit a suspended state before making any changes. |
| 501 | int currentState = oldState; |
| 502 | if (Display.isSuspendedState(oldState) |
| 503 | || oldState == Display.STATE_UNKNOWN) { |
| 504 | if (!Display.isSuspendedState(state)) { |
| 505 | setDisplayState(state); |
| 506 | currentState = state; |
| 507 | } else if (state == Display.STATE_DOZE_SUSPEND |
| 508 | || oldState == Display.STATE_DOZE_SUSPEND) { |
| 509 | setDisplayState(Display.STATE_DOZE); |
| 510 | currentState = Display.STATE_DOZE; |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 511 | } else if (state == Display.STATE_ON_SUSPEND |
| 512 | || oldState == Display.STATE_ON_SUSPEND) { |
| 513 | setDisplayState(Display.STATE_ON); |
| 514 | currentState = Display.STATE_ON; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 515 | } else { |
| 516 | return; // old state and new state is off |
| 517 | } |
| 518 | } |
| 519 | |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 520 | // If the state change was from or to VR, then we need to tell the light |
Karthik Ravi Shankar | 6685531 | 2017-10-04 13:30:13 -0700 | [diff] [blame] | 521 | // so that it can apply appropriate VR brightness settings. Also, update the |
| 522 | // brightness so the state is propogated to light. |
| 523 | boolean vrModeChange = false; |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 524 | if ((state == Display.STATE_VR || currentState == Display.STATE_VR) && |
| 525 | currentState != state) { |
| 526 | setVrMode(state == Display.STATE_VR); |
Karthik Ravi Shankar | 6685531 | 2017-10-04 13:30:13 -0700 | [diff] [blame] | 527 | vrModeChange = true; |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 531 | // Apply brightness changes given that we are in a non-suspended state. |
Karthik Ravi Shankar | 6685531 | 2017-10-04 13:30:13 -0700 | [diff] [blame] | 532 | if (brightnessChanged || vrModeChange) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 533 | setDisplayBrightness(brightness); |
| 534 | } |
| 535 | |
| 536 | // Enter the final desired state, possibly suspended. |
| 537 | if (state != currentState) { |
| 538 | setDisplayState(state); |
| 539 | } |
| 540 | } |
| 541 | |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 542 | private void setVrMode(boolean isVrEnabled) { |
| 543 | if (DEBUG) { |
| 544 | Slog.d(TAG, "setVrMode(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 545 | + "id=" + physicalDisplayId |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 546 | + ", state=" + Display.stateToString(state) + ")"); |
| 547 | } |
| 548 | mBacklight.setVrMode(isVrEnabled); |
| 549 | } |
| 550 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 551 | private void setDisplayState(int state) { |
| 552 | if (DEBUG) { |
| 553 | Slog.d(TAG, "setDisplayState(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 554 | + "id=" + physicalDisplayId |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 555 | + ", state=" + Display.stateToString(state) + ")"); |
| 556 | } |
| 557 | |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 558 | // We must tell sidekick to stop controlling the display before we |
| 559 | // can change its power mode, so do that first. |
| 560 | if (mSidekickActive) { |
| 561 | Trace.traceBegin(Trace.TRACE_TAG_POWER, |
| 562 | "SidekickInternal#endDisplayControl"); |
| 563 | try { |
| 564 | mSidekickInternal.endDisplayControl(); |
| 565 | } finally { |
| 566 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 567 | } |
| 568 | mSidekickActive = false; |
| 569 | } |
| 570 | final int mode = getPowerModeForState(state); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 571 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 572 | + "id=" + physicalDisplayId |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 573 | + ", state=" + Display.stateToString(state) + ")"); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 574 | try { |
| 575 | SurfaceControl.setDisplayPowerMode(token, mode); |
Michael Wright | c3e6af8 | 2017-07-25 22:31:03 +0100 | [diff] [blame] | 576 | Trace.traceCounter(Trace.TRACE_TAG_POWER, "DisplayPowerMode", mode); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 577 | } finally { |
| 578 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 579 | } |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 580 | // If we're entering a suspended (but not OFF) power state and we |
| 581 | // have a sidekick available, tell it now that it can take control. |
| 582 | if (Display.isSuspendedState(state) && state != Display.STATE_OFF |
| 583 | && mSidekickInternal != null && !mSidekickActive) { |
| 584 | Trace.traceBegin(Trace.TRACE_TAG_POWER, |
| 585 | "SidekickInternal#startDisplayControl"); |
| 586 | try { |
| 587 | mSidekickActive = mSidekickInternal.startDisplayControl(state); |
| 588 | } finally { |
| 589 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 590 | } |
| 591 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 592 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 593 | |
| 594 | private void setDisplayBrightness(int brightness) { |
| 595 | if (DEBUG) { |
| 596 | Slog.d(TAG, "setDisplayBrightness(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 597 | + "id=" + physicalDisplayId |
| 598 | + ", brightness=" + brightness + ")"); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 602 | + "id=" + physicalDisplayId + ", brightness=" + brightness + ")"); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 603 | try { |
| 604 | mBacklight.setBrightness(brightness); |
Michael Wright | c3e6af8 | 2017-07-25 22:31:03 +0100 | [diff] [blame] | 605 | Trace.traceCounter(Trace.TRACE_TAG_POWER, |
Michael Wright | a9f37ab | 2017-08-15 17:14:20 +0100 | [diff] [blame] | 606 | "ScreenBrightness", brightness); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 607 | } finally { |
| 608 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 609 | } |
| 610 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 611 | }; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 612 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 613 | return null; |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | @Override |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 617 | public void setRequestedColorModeLocked(int colorMode) { |
| 618 | if (requestColorModeLocked(colorMode)) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 619 | updateDeviceInfoLocked(); |
| 620 | } |
| 621 | } |
| 622 | |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 623 | @Override |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 624 | public void setAllowedDisplayModesLocked(int[] modes) { |
| 625 | updateAllowedModesLocked(modes); |
| 626 | } |
| 627 | |
| 628 | @Override |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 629 | public void onOverlayChangedLocked() { |
| 630 | updateDeviceInfoLocked(); |
| 631 | } |
| 632 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 633 | public void onActivePhysicalDisplayModeChangedLocked(int physIndex) { |
| 634 | if (updateActiveModeLocked(physIndex)) { |
| 635 | updateDeviceInfoLocked(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 636 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 637 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 638 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 639 | public boolean updateActiveModeLocked(int activePhysIndex) { |
| 640 | if (mActivePhysIndex == activePhysIndex) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 641 | return false; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 642 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 643 | mActivePhysIndex = activePhysIndex; |
| 644 | mActiveModeId = findMatchingModeIdLocked(activePhysIndex); |
| 645 | mActiveModeInvalid = mActiveModeId == 0; |
| 646 | if (mActiveModeInvalid) { |
| 647 | Slog.w(TAG, "In unknown mode after setting allowed configs" |
| 648 | + ": allowedPhysIndexes=" + mAllowedPhysIndexes |
| 649 | + ", activePhysIndex=" + mActivePhysIndex); |
| 650 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 651 | return true; |
| 652 | } |
| 653 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 654 | public void updateAllowedModesLocked(int[] allowedModes) { |
| 655 | if (Arrays.equals(allowedModes, mAllowedModeIds) && !mAllowedModeIdsInvalid) { |
| 656 | return; |
| 657 | } |
| 658 | if (updateAllowedModesInternalLocked(allowedModes)) { |
| 659 | updateDeviceInfoLocked(); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | public boolean updateAllowedModesInternalLocked(int[] allowedModes) { |
| 664 | if (DEBUG) { |
| 665 | Slog.w(TAG, "updateAllowedModesInternalLocked(allowedModes=" |
| 666 | + Arrays.toString(allowedModes) + ")"); |
| 667 | } |
| 668 | int[] allowedPhysIndexes = new int[allowedModes.length]; |
| 669 | int size = 0; |
| 670 | for (int modeId : allowedModes) { |
| 671 | int physIndex = findDisplayInfoIndexLocked(modeId); |
| 672 | if (physIndex < 0) { |
| 673 | Slog.w(TAG, "Requested mode ID " + modeId + " not available," |
| 674 | + " dropping from allowed set."); |
| 675 | } else { |
| 676 | allowedPhysIndexes[size++] = physIndex; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | // If we couldn't find one or more of the suggested allowed modes then we need to |
| 681 | // shrink the array to its actual size. |
| 682 | if (size != allowedModes.length) { |
| 683 | allowedPhysIndexes = Arrays.copyOf(allowedPhysIndexes, size); |
| 684 | } |
| 685 | |
| 686 | // If we found no suitable modes, then we try again with the default mode which we |
| 687 | // assume has a suitable physical config. |
| 688 | if (size == 0) { |
| 689 | if (DEBUG) { |
| 690 | Slog.w(TAG, "No valid modes allowed, falling back to default mode (id=" |
| 691 | + mDefaultModeId + ")"); |
| 692 | } |
| 693 | allowedModes = new int[] { mDefaultModeId }; |
| 694 | allowedPhysIndexes = new int[] { findDisplayInfoIndexLocked(mDefaultModeId) }; |
| 695 | } |
| 696 | |
| 697 | mAllowedModeIds = allowedModes; |
| 698 | mAllowedModeIdsInvalid = false; |
| 699 | |
| 700 | if (Arrays.equals(mAllowedPhysIndexes, allowedPhysIndexes)) { |
| 701 | return false; |
| 702 | } |
| 703 | mAllowedPhysIndexes = allowedPhysIndexes; |
| 704 | |
| 705 | if (DEBUG) { |
| 706 | Slog.w(TAG, "Setting allowed physical configs: allowedPhysIndexes=" |
| 707 | + Arrays.toString(allowedPhysIndexes)); |
| 708 | } |
| 709 | |
| 710 | SurfaceControl.setAllowedDisplayConfigs(getDisplayTokenLocked(), allowedPhysIndexes); |
| 711 | int activePhysIndex = SurfaceControl.getActiveConfig(getDisplayTokenLocked()); |
| 712 | return updateActiveModeLocked(activePhysIndex); |
| 713 | } |
| 714 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 715 | public boolean requestColorModeLocked(int colorMode) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 716 | if (mActiveColorMode == colorMode) { |
| 717 | return false; |
| 718 | } |
| 719 | if (!mSupportedColorModes.contains(colorMode)) { |
| 720 | Slog.w(TAG, "Unable to find color mode " + colorMode |
| 721 | + ", ignoring request."); |
| 722 | return false; |
| 723 | } |
| 724 | SurfaceControl.setActiveColorMode(getDisplayTokenLocked(), colorMode); |
| 725 | mActiveColorMode = colorMode; |
| 726 | mActiveColorModeInvalid = false; |
| 727 | return true; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 731 | public void dumpLocked(PrintWriter pw) { |
| 732 | super.dumpLocked(pw); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 733 | pw.println("mPhysicalDisplayId=" + mPhysicalDisplayId); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 734 | pw.println("mAllowedPhysIndexes=" + Arrays.toString(mAllowedPhysIndexes)); |
| 735 | pw.println("mAllowedModeIds=" + Arrays.toString(mAllowedModeIds)); |
| 736 | pw.println("mAllowedModeIdsInvalid=" + mAllowedModeIdsInvalid); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 737 | pw.println("mActivePhysIndex=" + mActivePhysIndex); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 738 | pw.println("mActiveModeId=" + mActiveModeId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 739 | pw.println("mActiveColorMode=" + mActiveColorMode); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 740 | pw.println("mDefaultModeId=" + mDefaultModeId); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 741 | pw.println("mState=" + Display.stateToString(mState)); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 742 | pw.println("mBrightness=" + mBrightness); |
| 743 | pw.println("mBacklight=" + mBacklight); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 744 | pw.println("mDisplayInfos="); |
| 745 | for (int i = 0; i < mDisplayInfos.length; i++) { |
| 746 | pw.println(" " + mDisplayInfos[i]); |
| 747 | } |
| 748 | pw.println("mSupportedModes="); |
| 749 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 750 | pw.println(" " + mSupportedModes.valueAt(i)); |
| 751 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 752 | pw.print("mSupportedColorModes=["); |
| 753 | for (int i = 0; i < mSupportedColorModes.size(); i++) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 754 | if (i != 0) { |
| 755 | pw.print(", "); |
| 756 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 757 | pw.print(mSupportedColorModes.get(i)); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 758 | } |
| 759 | pw.println("]"); |
| 760 | } |
| 761 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 762 | private int findDisplayInfoIndexLocked(int modeId) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 763 | DisplayModeRecord record = mSupportedModes.get(modeId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 764 | if (record != null) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 765 | for (int i = 0; i < mDisplayInfos.length; i++) { |
| 766 | SurfaceControl.PhysicalDisplayInfo info = mDisplayInfos[i]; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 767 | if (record.hasMatchingMode(info)){ |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 768 | return i; |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | return -1; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 775 | private int findMatchingModeIdLocked(int physIndex) { |
| 776 | SurfaceControl.PhysicalDisplayInfo info = mDisplayInfos[physIndex]; |
| 777 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 778 | DisplayModeRecord record = mSupportedModes.valueAt(i); |
| 779 | if (record.hasMatchingMode(info)) { |
| 780 | return record.mMode.getModeId(); |
| 781 | } |
| 782 | } |
| 783 | return 0; |
| 784 | } |
| 785 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 786 | private void updateDeviceInfoLocked() { |
| 787 | mInfo = null; |
| 788 | sendDisplayDeviceEventLocked(this, DISPLAY_DEVICE_EVENT_CHANGED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 789 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 790 | |
| 791 | private Display.Mode[] getDisplayModes(SparseArray<DisplayModeRecord> records) { |
| 792 | final int size = records.size(); |
| 793 | Display.Mode[] modes = new Display.Mode[size]; |
| 794 | for (int i = 0; i < size; i++) { |
| 795 | DisplayModeRecord record = records.valueAt(i); |
| 796 | modes[i] = record.mMode; |
| 797 | } |
| 798 | return modes; |
| 799 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 800 | } |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 801 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 802 | /** Supplies a context whose Resources apply runtime-overlays */ |
| 803 | Context getOverlayContext() { |
| 804 | return ActivityThread.currentActivityThread().getSystemUiContext(); |
| 805 | } |
| 806 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 807 | /** |
| 808 | * Keeps track of a display configuration. |
| 809 | */ |
| 810 | private static final class DisplayModeRecord { |
| 811 | public final Display.Mode mMode; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 812 | |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 813 | public DisplayModeRecord(SurfaceControl.PhysicalDisplayInfo phys) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 814 | mMode = createMode(phys.width, phys.height, phys.refreshRate); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Returns whether the mode generated by the given PhysicalDisplayInfo matches the mode |
| 819 | * contained by the record modulo mode ID. |
| 820 | * |
| 821 | * Note that this doesn't necessarily mean the the PhysicalDisplayInfos are identical, just |
| 822 | * that they generate identical modes. |
| 823 | */ |
| 824 | public boolean hasMatchingMode(SurfaceControl.PhysicalDisplayInfo info) { |
| 825 | int modeRefreshRate = Float.floatToIntBits(mMode.getRefreshRate()); |
| 826 | int displayInfoRefreshRate = Float.floatToIntBits(info.refreshRate); |
| 827 | return mMode.getPhysicalWidth() == info.width |
| 828 | && mMode.getPhysicalHeight() == info.height |
| 829 | && modeRefreshRate == displayInfoRefreshRate; |
| 830 | } |
| 831 | |
| 832 | public String toString() { |
| 833 | return "DisplayModeRecord{mMode=" + mMode + "}"; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 834 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 835 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 836 | |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 837 | private final class PhysicalDisplayEventReceiver extends DisplayEventReceiver { |
| 838 | PhysicalDisplayEventReceiver(Looper looper) { |
Jorim Jaggi | 34a0cdb | 2017-06-08 15:40:38 -0700 | [diff] [blame] | 839 | super(looper, VSYNC_SOURCE_APP); |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | @Override |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 843 | public void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected) { |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 844 | synchronized (getSyncRoot()) { |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 845 | if (connected) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 846 | tryConnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 847 | } else { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 848 | tryDisconnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 849 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 850 | } |
| 851 | } |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 852 | |
| 853 | @Override |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 854 | public void onConfigChanged(long timestampNanos, long physicalDisplayId, int physIndex) { |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 855 | if (DEBUG) { |
| 856 | Slog.d(TAG, "onConfigChanged(" |
| 857 | + "timestampNanos=" + timestampNanos |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 858 | + ", physicalDisplayId=" + physicalDisplayId |
| 859 | + ", physIndex=" + physIndex + ")"); |
| 860 | } |
| 861 | synchronized (getSyncRoot()) { |
| 862 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
| 863 | if (device == null) { |
| 864 | if (DEBUG) { |
| 865 | Slog.d(TAG, "Received config change for unhandled physical display: " |
| 866 | + "physicalDisplayId=" + physicalDisplayId); |
| 867 | } |
| 868 | return; |
| 869 | } |
| 870 | device.onActivePhysicalDisplayModeChangedLocked(physIndex); |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 871 | } |
| 872 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 873 | } |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 874 | } |