Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -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 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 19 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
| 20 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; |
| 21 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; |
| 22 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE; |
| 23 | import static android.hardware.display.DisplayManager |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 24 | .VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 25 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 26 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 27 | import com.android.internal.util.DumpUtils; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 28 | import com.android.internal.util.IndentingPrintWriter; |
| 29 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 30 | import android.Manifest; |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 32 | import android.annotation.Nullable; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 33 | import android.annotation.UserIdInt; |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 34 | import android.app.AppOpsManager; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.pm.PackageManager; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 37 | import android.content.pm.ParceledListSlice; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 38 | import android.content.res.Resources; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 39 | import android.content.res.TypedArray; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 40 | import android.graphics.Point; |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 41 | import android.hardware.SensorManager; |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 42 | import android.hardware.display.AmbientBrightnessDayStats; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 43 | import android.hardware.display.BrightnessChangeEvent; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 44 | import android.hardware.display.BrightnessConfiguration; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 45 | import android.hardware.display.Curve; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 46 | import android.hardware.display.DisplayManagerGlobal; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 47 | import android.hardware.display.DisplayManagerInternal; |
| 48 | import android.hardware.display.DisplayViewport; |
| 49 | import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 50 | import android.hardware.display.IDisplayManager; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 51 | import android.hardware.display.IDisplayManagerCallback; |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 52 | import android.hardware.display.IVirtualDisplayCallback; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 53 | import android.hardware.display.WifiDisplayStatus; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 54 | import android.hardware.input.InputManagerInternal; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 55 | import android.media.projection.IMediaProjection; |
| 56 | import android.media.projection.IMediaProjectionManager; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 57 | import android.os.Binder; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 58 | import android.os.Handler; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 59 | import android.os.IBinder; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 60 | import android.os.IBinder.DeathRecipient; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 61 | import android.os.Looper; |
| 62 | import android.os.Message; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 63 | import android.os.PowerManager; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 64 | import android.os.Process; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 65 | import android.os.RemoteException; |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 66 | import android.os.ResultReceiver; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 67 | import android.os.ServiceManager; |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 68 | import android.os.ShellCallback; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 69 | import android.os.SystemClock; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 70 | import android.os.SystemProperties; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 71 | import android.os.Trace; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 72 | import android.os.UserHandle; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 73 | import android.os.UserManager; |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 74 | import android.provider.Settings; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 75 | import android.text.TextUtils; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 76 | import android.util.IntArray; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 77 | import android.util.Pair; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 78 | import android.util.Slog; |
| 79 | import android.util.SparseArray; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 80 | import android.util.Spline; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 81 | import android.view.Display; |
| 82 | import android.view.DisplayInfo; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 83 | import android.view.Surface; |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 84 | import android.view.SurfaceControl; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 85 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 86 | import com.android.internal.util.Preconditions; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 87 | import com.android.server.AnimationThread; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 88 | import com.android.server.DisplayThread; |
| 89 | import com.android.server.LocalServices; |
| 90 | import com.android.server.SystemService; |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 91 | import com.android.server.UiThread; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 92 | import com.android.server.wm.WindowManagerInternal; |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 93 | import com.android.server.wm.SurfaceAnimationThread; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 94 | |
| 95 | import java.io.FileDescriptor; |
| 96 | import java.io.PrintWriter; |
| 97 | import java.util.ArrayList; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 98 | import java.util.Arrays; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 99 | import java.util.List; |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 100 | import java.util.concurrent.CopyOnWriteArrayList; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 103 | * Manages attached displays. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 104 | * <p> |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 105 | * The {@link DisplayManagerService} manages the global lifecycle of displays, |
| 106 | * decides how to configure logical displays based on the physical display devices currently |
| 107 | * attached, sends notifications to the system and to applications when the state |
| 108 | * changes, and so on. |
| 109 | * </p><p> |
| 110 | * The display manager service relies on a collection of {@link DisplayAdapter} components, |
| 111 | * for discovering and configuring physical display devices attached to the system. |
| 112 | * There are separate display adapters for each manner that devices are attached: |
| 113 | * one display adapter for built-in local displays, one for simulated non-functional |
| 114 | * displays when the system is headless, one for simulated overlay displays used for |
| 115 | * development, one for wifi displays, etc. |
| 116 | * </p><p> |
| 117 | * Display adapters are only weakly coupled to the display manager service. |
| 118 | * Display adapters communicate changes in display device state to the display manager |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 119 | * service asynchronously via a {@link DisplayAdapter.Listener} registered |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 120 | * by the display manager service. This separation of concerns is important for |
| 121 | * two main reasons. First, it neatly encapsulates the responsibilities of these |
| 122 | * two classes: display adapters handle individual display devices whereas |
| 123 | * the display manager service handles the global state. Second, it eliminates |
| 124 | * the potential for deadlocks resulting from asynchronous display device discovery. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 125 | * </p> |
| 126 | * |
| 127 | * <h3>Synchronization</h3> |
| 128 | * <p> |
| 129 | * Because the display manager may be accessed by multiple threads, the synchronization |
| 130 | * story gets a little complicated. In particular, the window manager may call into |
| 131 | * the display manager while holding a surface transaction with the expectation that |
| 132 | * it can apply changes immediately. Unfortunately, that means we can't just do |
| 133 | * everything asynchronously (*grump*). |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 134 | * </p><p> |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 135 | * To make this work, all of the objects that belong to the display manager must |
| 136 | * use the same lock. We call this lock the synchronization root and it has a unique |
| 137 | * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are |
| 138 | * named with the "Locked" suffix. |
| 139 | * </p><p> |
| 140 | * Where things get tricky is that the display manager is not allowed to make |
| 141 | * any potentially reentrant calls, especially into the window manager. We generally |
| 142 | * avoid this by making all potentially reentrant out-calls asynchronous. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 143 | * </p> |
| 144 | */ |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 145 | public final class DisplayManagerService extends SystemService { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 146 | private static final String TAG = "DisplayManagerService"; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 147 | private static final boolean DEBUG = false; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 148 | |
Jeff Brown | bbd28a2 | 2012-09-20 16:47:15 -0700 | [diff] [blame] | 149 | // When this system property is set to 0, WFD is forcibly disabled on boot. |
| 150 | // When this system property is set to 1, WFD is forcibly enabled on boot. |
| 151 | // Otherwise WFD is enabled according to the value of config_enableWifiDisplay. |
| 152 | private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable"; |
| 153 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 154 | private static final String PROP_DEFAULT_DISPLAY_TOP_INSET = "persist.sys.displayinset.top"; |
| 155 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 156 | private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000; |
| 157 | |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 158 | private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS = 1; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 159 | private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2; |
| 160 | private static final int MSG_DELIVER_DISPLAY_EVENT = 3; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 161 | private static final int MSG_REQUEST_TRAVERSAL = 4; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 162 | private static final int MSG_UPDATE_VIEWPORT = 5; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 163 | private static final int MSG_REGISTER_BRIGHTNESS_TRACKER = 6; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 164 | private static final int MSG_LOAD_BRIGHTNESS_CONFIGURATION = 7; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 165 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 166 | private final Context mContext; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 167 | private final DisplayManagerHandler mHandler; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 168 | private final Handler mUiHandler; |
| 169 | private final DisplayAdapterListener mDisplayAdapterListener; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 170 | private WindowManagerInternal mWindowManagerInternal; |
| 171 | private InputManagerInternal mInputManagerInternal; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 172 | private IMediaProjectionManager mProjectionService; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 173 | |
| 174 | // The synchronization root for the display manager. |
| 175 | // This lock guards most of the display manager's state. |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 176 | // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call |
| 177 | // into WindowManagerService methods that require mWindowMap while holding this unless you are |
| 178 | // very very sure that no deadlock can occur. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 179 | private final SyncRoot mSyncRoot = new SyncRoot(); |
| 180 | |
| 181 | // True if in safe mode. |
| 182 | // This option may disable certain display adapters. |
| 183 | public boolean mSafeMode; |
| 184 | |
| 185 | // True if we are in a special boot mode where only core applications and |
| 186 | // services should be started. This option may disable certain display adapters. |
| 187 | public boolean mOnlyCore; |
| 188 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 189 | // True if the display manager service should pretend there is only one display |
| 190 | // and only tell applications about the existence of the default logical display. |
| 191 | // The display manager can still mirror content to secondary displays but applications |
| 192 | // cannot present unique content on those displays. |
| 193 | // Used for demonstration purposes only. |
| 194 | private final boolean mSingleDisplayDemoMode; |
| 195 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 196 | // All callback records indexed by calling process id. |
| 197 | public final SparseArray<CallbackRecord> mCallbacks = |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 198 | new SparseArray<CallbackRecord>(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 199 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 200 | // List of all currently registered display adapters. |
| 201 | private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>(); |
| 202 | |
| 203 | // List of all currently connected display devices. |
| 204 | private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>(); |
| 205 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 206 | // List of all logical displays indexed by logical display id. |
| 207 | private final SparseArray<LogicalDisplay> mLogicalDisplays = |
| 208 | new SparseArray<LogicalDisplay>(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 209 | private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1; |
| 210 | |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 211 | // List of all display transaction listeners. |
| 212 | private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners = |
| 213 | new CopyOnWriteArrayList<DisplayTransactionListener>(); |
| 214 | |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 215 | // Display power controller. |
| 216 | private DisplayPowerController mDisplayPowerController; |
| 217 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 218 | // The overall display state, independent of changes that might influence one |
| 219 | // display or another in particular. |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 220 | private int mGlobalDisplayState = Display.STATE_ON; |
| 221 | |
| 222 | // The overall display brightness. |
| 223 | // For now, this only applies to the built-in display but we may split it up eventually. |
| 224 | private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT; |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 225 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 226 | // Set to true when there are pending display changes that have yet to be applied |
| 227 | // to the surface flinger state. |
| 228 | private boolean mPendingTraversal; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 229 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 230 | // The Wifi display adapter, or null if not registered. |
| 231 | private WifiDisplayAdapter mWifiDisplayAdapter; |
| 232 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 233 | // The number of active wifi display scan requests. |
| 234 | private int mWifiDisplayScanRequestCount; |
| 235 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 236 | // The virtual display adapter, or null if not registered. |
| 237 | private VirtualDisplayAdapter mVirtualDisplayAdapter; |
| 238 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 239 | // The User ID of the current user |
| 240 | private @UserIdInt int mCurrentUserId; |
| 241 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 242 | // The stable device screen height and width. These are not tied to a specific display, even |
| 243 | // the default display, because they need to be stable over the course of the device's entire |
| 244 | // life, even if the default display changes (e.g. a new monitor is plugged into a PC-like |
| 245 | // device). |
| 246 | private Point mStableDisplaySize = new Point(); |
| 247 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 248 | // Whether the system has finished booting or not. |
| 249 | private boolean mSystemReady; |
| 250 | |
| 251 | // The top inset of the default display. |
| 252 | // This gets persisted so that the boot animation knows how to transition from the display's |
| 253 | // full size to the size configured by the user. Right now we only persist and animate the top |
| 254 | // inset, but theoretically we could do it for all of them. |
| 255 | private int mDefaultDisplayTopInset; |
| 256 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 257 | // Viewports of the default display and the display that should receive touch |
| 258 | // input from an external source. Used by the input system. |
| 259 | private final DisplayViewport mDefaultViewport = new DisplayViewport(); |
| 260 | private final DisplayViewport mExternalTouchViewport = new DisplayViewport(); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 261 | private final ArrayList<DisplayViewport> mVirtualTouchViewports = new ArrayList<>(); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 262 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 263 | // Persistent data store for all internal settings maintained by the display manager service. |
| 264 | private final PersistentDataStore mPersistentDataStore = new PersistentDataStore(); |
| 265 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 266 | // Temporary callback list, used when sending display events to applications. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 267 | // May be used outside of the lock but only on the handler thread. |
| 268 | private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 269 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 270 | // Temporary display info, used for comparing display configurations. |
| 271 | private final DisplayInfo mTempDisplayInfo = new DisplayInfo(); |
| 272 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 273 | // Temporary viewports, used when sending new viewport information to the |
| 274 | // input system. May be used outside of the lock but only on the handler thread. |
| 275 | private final DisplayViewport mTempDefaultViewport = new DisplayViewport(); |
| 276 | private final DisplayViewport mTempExternalTouchViewport = new DisplayViewport(); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 277 | private final ArrayList<DisplayViewport> mTempVirtualTouchViewports = new ArrayList<>(); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 278 | |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 279 | // The default color mode for default displays. Overrides the usual |
| 280 | // Display.Display.COLOR_MODE_DEFAULT for displays with the |
| 281 | // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set. |
| 282 | private final int mDefaultDisplayDefaultColorMode; |
| 283 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 284 | // Temporary list of deferred work to perform when setting the display state. |
| 285 | // Only used by requestDisplayState. The field is self-synchronized and only |
| 286 | // intended for use inside of the requestGlobalDisplayStateInternal function. |
| 287 | private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>(); |
| 288 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 289 | // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs. |
| 290 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 291 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 292 | private final Injector mInjector; |
| 293 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 294 | // The minimum brightness curve, which guarantess that any brightness curve that dips below it |
| 295 | // is rejected by the system. |
| 296 | private final Curve mMinimumBrightnessCurve; |
| 297 | private final Spline mMinimumBrightnessSpline; |
| 298 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 299 | public DisplayManagerService(Context context) { |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 300 | this(context, new Injector()); |
| 301 | } |
| 302 | |
| 303 | @VisibleForTesting |
| 304 | DisplayManagerService(Context context, Injector injector) { |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 305 | super(context); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 306 | mInjector = injector; |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 307 | mContext = context; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 308 | mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper()); |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 309 | mUiHandler = UiThread.getHandler(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 310 | mDisplayAdapterListener = new DisplayAdapterListener(); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 311 | mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false); |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 312 | Resources resources = mContext.getResources(); |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 313 | mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger( |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 314 | com.android.internal.R.integer.config_defaultDisplayDefaultColorMode); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 315 | mDefaultDisplayTopInset = SystemProperties.getInt(PROP_DEFAULT_DISPLAY_TOP_INSET, -1); |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 316 | float[] lux = getFloatArray(resources.obtainTypedArray( |
| 317 | com.android.internal.R.array.config_minimumBrightnessCurveLux)); |
| 318 | float[] nits = getFloatArray(resources.obtainTypedArray( |
| 319 | com.android.internal.R.array.config_minimumBrightnessCurveNits)); |
| 320 | mMinimumBrightnessCurve = new Curve(lux, nits); |
| 321 | mMinimumBrightnessSpline = Spline.createSpline(lux, nits); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 322 | |
| 323 | PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 324 | mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting(); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 325 | mCurrentUserId = UserHandle.USER_SYSTEM; |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 326 | |
| 327 | mSystemReady = false; |
Joel Fernandes | 2d314e1 | 2017-04-04 16:32:15 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | public void setupSchedulerPolicies() { |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 331 | // android.display and android.anim is critical to user experience and we should make sure |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 332 | // it is not in the default foregroup groups, add it to top-app to make sure it uses all |
| 333 | // the cores and scheduling settings for top-app when it runs. |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 334 | Process.setThreadGroupAndCpuset(DisplayThread.get().getThreadId(), |
| 335 | Process.THREAD_GROUP_TOP_APP); |
| 336 | Process.setThreadGroupAndCpuset(AnimationThread.get().getThreadId(), |
| 337 | Process.THREAD_GROUP_TOP_APP); |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 338 | Process.setThreadGroupAndCpuset(SurfaceAnimationThread.get().getThreadId(), |
| 339 | Process.THREAD_GROUP_TOP_APP); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 342 | @Override |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 343 | public void onStart() { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 344 | // We need to pre-load the persistent data store so it's ready before the default display |
| 345 | // adapter is up so that we have it's configuration. We could load it lazily, but since |
| 346 | // we're going to have to read it in eventually we may as well do it here rather than after |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 347 | // we've waited for the display to register itself with us. |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 348 | synchronized(mSyncRoot) { |
| 349 | mPersistentDataStore.loadIfNeeded(); |
| 350 | loadStableDisplayValuesLocked(); |
| 351 | } |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 352 | mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 353 | |
| 354 | publishBinderService(Context.DISPLAY_SERVICE, new BinderService(), |
| 355 | true /*allowIsolated*/); |
| 356 | publishLocalService(DisplayManagerInternal.class, new LocalService()); |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 357 | publishLocalService(DisplayTransformManager.class, new DisplayTransformManager()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public void onBootPhase(int phase) { |
| 362 | if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) { |
| 363 | synchronized (mSyncRoot) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 364 | long timeout = SystemClock.uptimeMillis() |
| 365 | + mInjector.getDefaultDisplayDelayTimeout(); |
| 366 | while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null || |
| 367 | mVirtualDisplayAdapter == null) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 368 | long delay = timeout - SystemClock.uptimeMillis(); |
| 369 | if (delay <= 0) { |
| 370 | throw new RuntimeException("Timeout waiting for default display " |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 371 | + "to be initialized. DefaultDisplay=" |
| 372 | + mLogicalDisplays.get(Display.DEFAULT_DISPLAY) |
| 373 | + ", mVirtualDisplayAdapter=" + mVirtualDisplayAdapter); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 374 | } |
| 375 | if (DEBUG) { |
| 376 | Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay); |
| 377 | } |
| 378 | try { |
| 379 | mSyncRoot.wait(delay); |
| 380 | } catch (InterruptedException ex) { |
| 381 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 387 | @Override |
| 388 | public void onSwitchUser(@UserIdInt int newUserId) { |
| 389 | final int userSerial = getUserManager().getUserSerialNumber(newUserId); |
| 390 | synchronized (mSyncRoot) { |
| 391 | if (mCurrentUserId != newUserId) { |
| 392 | mCurrentUserId = newUserId; |
| 393 | BrightnessConfiguration config = |
| 394 | mPersistentDataStore.getBrightnessConfiguration(userSerial); |
| 395 | mDisplayPowerController.setBrightnessConfiguration(config); |
| 396 | } |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 397 | mDisplayPowerController.onSwitchUser(newUserId); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 401 | // TODO: Use dependencies or a boot phase |
| 402 | public void windowManagerAndInputReady() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 403 | synchronized (mSyncRoot) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 404 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
| 405 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 406 | scheduleTraversalLocked(false); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 411 | * Called when the system is ready to go. |
| 412 | */ |
| 413 | public void systemReady(boolean safeMode, boolean onlyCore) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 414 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 415 | mSafeMode = safeMode; |
| 416 | mOnlyCore = onlyCore; |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 417 | mSystemReady = true; |
| 418 | // Just in case the top inset changed before the system was ready. At this point, any |
| 419 | // relevant configuration should be in place. |
| 420 | recordTopInsetLocked(mLogicalDisplays.get(Display.DEFAULT_DISPLAY)); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 421 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 422 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 423 | mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS); |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 424 | mHandler.sendEmptyMessage(MSG_REGISTER_BRIGHTNESS_TRACKER); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 427 | @VisibleForTesting |
| 428 | Handler getDisplayHandler() { |
| 429 | return mHandler; |
| 430 | } |
| 431 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 432 | private void loadStableDisplayValuesLocked() { |
| 433 | final Point size = mPersistentDataStore.getStableDisplaySize(); |
| 434 | if (size.x > 0 && size.y > 0) { |
| 435 | // Just set these values directly so we don't write the display persistent data again |
| 436 | // unnecessarily |
| 437 | mStableDisplaySize.set(size.x, size.y); |
| 438 | } else { |
| 439 | final Resources res = mContext.getResources(); |
| 440 | final int width = res.getInteger( |
| 441 | com.android.internal.R.integer.config_stableDeviceDisplayWidth); |
| 442 | final int height = res.getInteger( |
| 443 | com.android.internal.R.integer.config_stableDeviceDisplayHeight); |
| 444 | if (width > 0 && height > 0) { |
| 445 | setStableDisplaySizeLocked(width, height); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | private Point getStableDisplaySizeInternal() { |
| 451 | Point r = new Point(); |
| 452 | synchronized (mSyncRoot) { |
| 453 | if (mStableDisplaySize.x > 0 && mStableDisplaySize.y > 0) { |
| 454 | r.set(mStableDisplaySize.x, mStableDisplaySize.y); |
| 455 | } |
| 456 | } |
| 457 | return r; |
| 458 | } |
| 459 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 460 | private void registerDisplayTransactionListenerInternal( |
| 461 | DisplayTransactionListener listener) { |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 462 | // List is self-synchronized copy-on-write. |
| 463 | mDisplayTransactionListeners.add(listener); |
| 464 | } |
| 465 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 466 | private void unregisterDisplayTransactionListenerInternal( |
| 467 | DisplayTransactionListener listener) { |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 468 | // List is self-synchronized copy-on-write. |
| 469 | mDisplayTransactionListeners.remove(listener); |
| 470 | } |
| 471 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 472 | private void setDisplayInfoOverrideFromWindowManagerInternal( |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 473 | int displayId, DisplayInfo info) { |
| 474 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 475 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 476 | if (display != null) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 477 | if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) { |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 478 | handleLogicalDisplayChanged(displayId, display); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 479 | scheduleTraversalLocked(false); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 480 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 485 | /** |
| 486 | * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo) |
| 487 | */ |
| 488 | private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) { |
| 489 | synchronized (mSyncRoot) { |
| 490 | final LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 491 | if (display != null) { |
| 492 | display.getNonOverrideDisplayInfoLocked(outInfo); |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 497 | @VisibleForTesting |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 498 | void performTraversalInternal(SurfaceControl.Transaction t) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 499 | synchronized (mSyncRoot) { |
| 500 | if (!mPendingTraversal) { |
| 501 | return; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 502 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 503 | mPendingTraversal = false; |
| 504 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 505 | performTraversalLocked(t); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 506 | } |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 507 | |
| 508 | // List is self-synchronized copy-on-write. |
| 509 | for (DisplayTransactionListener listener : mDisplayTransactionListeners) { |
| 510 | listener.onDisplayTransaction(); |
| 511 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 514 | private void requestGlobalDisplayStateInternal(int state, int brightness) { |
| 515 | if (state == Display.STATE_UNKNOWN) { |
| 516 | state = Display.STATE_ON; |
| 517 | } |
| 518 | if (state == Display.STATE_OFF) { |
| 519 | brightness = PowerManager.BRIGHTNESS_OFF; |
| 520 | } else if (brightness < 0) { |
| 521 | brightness = PowerManager.BRIGHTNESS_DEFAULT; |
| 522 | } else if (brightness > PowerManager.BRIGHTNESS_ON) { |
| 523 | brightness = PowerManager.BRIGHTNESS_ON; |
| 524 | } |
| 525 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 526 | synchronized (mTempDisplayStateWorkQueue) { |
| 527 | try { |
| 528 | // Update the display state within the lock. |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 529 | // Note that we do not need to schedule traversals here although it |
| 530 | // may happen as a side-effect of displays changing state. |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 531 | synchronized (mSyncRoot) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 532 | if (mGlobalDisplayState == state |
| 533 | && mGlobalDisplayBrightness == brightness) { |
| 534 | return; // no change |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 535 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 536 | |
| 537 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState(" |
| 538 | + Display.stateToString(state) |
| 539 | + ", brightness=" + brightness + ")"); |
| 540 | mGlobalDisplayState = state; |
| 541 | mGlobalDisplayBrightness = brightness; |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 542 | applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | // Setting the display power state can take hundreds of milliseconds |
| 546 | // to complete so we defer the most expensive part of the work until |
| 547 | // after we have exited the critical section to avoid blocking other |
| 548 | // threads for a long time. |
| 549 | for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) { |
| 550 | mTempDisplayStateWorkQueue.get(i).run(); |
| 551 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 552 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 553 | } finally { |
| 554 | mTempDisplayStateWorkQueue.clear(); |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 559 | private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 560 | synchronized (mSyncRoot) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 561 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 562 | if (display != null) { |
| 563 | DisplayInfo info = display.getDisplayInfoLocked(); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 564 | if (info.hasAccess(callingUid) |
| 565 | || isUidPresentOnDisplayInternal(callingUid, displayId)) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 566 | return info; |
| 567 | } |
| 568 | } |
| 569 | return null; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | private int[] getDisplayIdsInternal(int callingUid) { |
| 574 | synchronized (mSyncRoot) { |
| 575 | final int count = mLogicalDisplays.size(); |
| 576 | int[] displayIds = new int[count]; |
| 577 | int n = 0; |
| 578 | for (int i = 0; i < count; i++) { |
| 579 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 580 | DisplayInfo info = display.getDisplayInfoLocked(); |
| 581 | if (info.hasAccess(callingUid)) { |
| 582 | displayIds[n++] = mLogicalDisplays.keyAt(i); |
| 583 | } |
| 584 | } |
| 585 | if (n != count) { |
| 586 | displayIds = Arrays.copyOfRange(displayIds, 0, n); |
| 587 | } |
| 588 | return displayIds; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) { |
| 593 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 594 | if (mCallbacks.get(callingPid) != null) { |
| 595 | throw new SecurityException("The calling process has already " |
| 596 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 599 | CallbackRecord record = new CallbackRecord(callingPid, callback); |
| 600 | try { |
| 601 | IBinder binder = callback.asBinder(); |
| 602 | binder.linkToDeath(record, 0); |
| 603 | } catch (RemoteException ex) { |
| 604 | // give up |
| 605 | throw new RuntimeException(ex); |
| 606 | } |
| 607 | |
| 608 | mCallbacks.put(callingPid, record); |
| 609 | } |
| 610 | } |
| 611 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 612 | private void onCallbackDied(CallbackRecord record) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 613 | synchronized (mSyncRoot) { |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 614 | mCallbacks.remove(record.mPid); |
| 615 | stopWifiDisplayScanLocked(record); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 619 | private void startWifiDisplayScanInternal(int callingPid) { |
| 620 | synchronized (mSyncRoot) { |
| 621 | CallbackRecord record = mCallbacks.get(callingPid); |
| 622 | if (record == null) { |
| 623 | throw new IllegalStateException("The calling process has not " |
| 624 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 625 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 626 | startWifiDisplayScanLocked(record); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 630 | private void startWifiDisplayScanLocked(CallbackRecord record) { |
| 631 | if (!record.mWifiDisplayScanRequested) { |
| 632 | record.mWifiDisplayScanRequested = true; |
| 633 | if (mWifiDisplayScanRequestCount++ == 0) { |
| 634 | if (mWifiDisplayAdapter != null) { |
| 635 | mWifiDisplayAdapter.requestStartScanLocked(); |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 641 | private void stopWifiDisplayScanInternal(int callingPid) { |
| 642 | synchronized (mSyncRoot) { |
| 643 | CallbackRecord record = mCallbacks.get(callingPid); |
| 644 | if (record == null) { |
| 645 | throw new IllegalStateException("The calling process has not " |
| 646 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 647 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 648 | stopWifiDisplayScanLocked(record); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | private void stopWifiDisplayScanLocked(CallbackRecord record) { |
| 653 | if (record.mWifiDisplayScanRequested) { |
| 654 | record.mWifiDisplayScanRequested = false; |
| 655 | if (--mWifiDisplayScanRequestCount == 0) { |
| 656 | if (mWifiDisplayAdapter != null) { |
| 657 | mWifiDisplayAdapter.requestStopScanLocked(); |
| 658 | } |
| 659 | } else if (mWifiDisplayScanRequestCount < 0) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 660 | Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: " |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 661 | + mWifiDisplayScanRequestCount); |
| 662 | mWifiDisplayScanRequestCount = 0; |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 667 | private void connectWifiDisplayInternal(String address) { |
| 668 | synchronized (mSyncRoot) { |
| 669 | if (mWifiDisplayAdapter != null) { |
| 670 | mWifiDisplayAdapter.requestConnectLocked(address); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 671 | } |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 675 | private void pauseWifiDisplayInternal() { |
| 676 | synchronized (mSyncRoot) { |
| 677 | if (mWifiDisplayAdapter != null) { |
| 678 | mWifiDisplayAdapter.requestPauseLocked(); |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 679 | } |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 683 | private void resumeWifiDisplayInternal() { |
| 684 | synchronized (mSyncRoot) { |
| 685 | if (mWifiDisplayAdapter != null) { |
| 686 | mWifiDisplayAdapter.requestResumeLocked(); |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 687 | } |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 691 | private void disconnectWifiDisplayInternal() { |
| 692 | synchronized (mSyncRoot) { |
| 693 | if (mWifiDisplayAdapter != null) { |
| 694 | mWifiDisplayAdapter.requestDisconnectLocked(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 695 | } |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 699 | private void renameWifiDisplayInternal(String address, String alias) { |
| 700 | synchronized (mSyncRoot) { |
| 701 | if (mWifiDisplayAdapter != null) { |
| 702 | mWifiDisplayAdapter.requestRenameLocked(address, alias); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 703 | } |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 707 | private void forgetWifiDisplayInternal(String address) { |
| 708 | synchronized (mSyncRoot) { |
| 709 | if (mWifiDisplayAdapter != null) { |
| 710 | mWifiDisplayAdapter.requestForgetLocked(address); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 711 | } |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 715 | private WifiDisplayStatus getWifiDisplayStatusInternal() { |
| 716 | synchronized (mSyncRoot) { |
| 717 | if (mWifiDisplayAdapter != null) { |
| 718 | return mWifiDisplayAdapter.getWifiDisplayStatusLocked(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 719 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 720 | return new WifiDisplayStatus(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 724 | private void requestColorModeInternal(int displayId, int colorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 725 | synchronized (mSyncRoot) { |
| 726 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 727 | if (display != null && |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 728 | display.getRequestedColorModeLocked() != colorMode) { |
| 729 | display.setRequestedColorModeLocked(colorMode); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 730 | scheduleTraversalLocked(false); |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
Bryan Mawhinney | 462e29d | 2018-03-22 15:52:41 +0000 | [diff] [blame] | 735 | private void setSaturationLevelInternal(float level) { |
| 736 | if (level < 0 || level > 1) { |
| 737 | throw new IllegalArgumentException("Saturation level must be between 0 and 1"); |
| 738 | } |
| 739 | float[] matrix = (level == 1.0f ? null : computeSaturationMatrix(level)); |
| 740 | DisplayTransformManager dtm = LocalServices.getService(DisplayTransformManager.class); |
| 741 | dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_SATURATION, matrix); |
| 742 | } |
| 743 | |
| 744 | private static float[] computeSaturationMatrix(float saturation) { |
| 745 | float desaturation = 1.0f - saturation; |
| 746 | float[] luminance = {0.231f * desaturation, 0.715f * desaturation, 0.072f * desaturation}; |
| 747 | float[] matrix = { |
| 748 | luminance[0] + saturation, luminance[0], luminance[0], 0, |
| 749 | luminance[1], luminance[1] + saturation, luminance[1], 0, |
| 750 | luminance[2], luminance[2], luminance[2] + saturation, 0, |
| 751 | 0, 0, 0, 1 |
| 752 | }; |
| 753 | return matrix; |
| 754 | } |
| 755 | |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 756 | private int createVirtualDisplayInternal(IVirtualDisplayCallback callback, |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 757 | IMediaProjection projection, int callingUid, String packageName, String name, int width, |
| 758 | int height, int densityDpi, Surface surface, int flags, String uniqueId) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 759 | synchronized (mSyncRoot) { |
| 760 | if (mVirtualDisplayAdapter == null) { |
| 761 | Slog.w(TAG, "Rejecting request to create private virtual display " |
| 762 | + "because the virtual display adapter is not available."); |
| 763 | return -1; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 764 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 765 | |
| 766 | DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked( |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 767 | callback, projection, callingUid, packageName, name, width, height, densityDpi, |
| 768 | surface, flags, uniqueId); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 769 | if (device == null) { |
| 770 | return -1; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 771 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 772 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 773 | handleDisplayDeviceAddedLocked(device); |
| 774 | LogicalDisplay display = findLogicalDisplayForDeviceLocked(device); |
| 775 | if (display != null) { |
| 776 | return display.getDisplayIdLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 777 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 778 | |
| 779 | // Something weird happened and the logical display was not created. |
| 780 | Slog.w(TAG, "Rejecting request to create virtual display " |
| 781 | + "because the logical display was not created."); |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 782 | mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 783 | handleDisplayDeviceRemovedLocked(device); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 784 | } |
| 785 | return -1; |
| 786 | } |
| 787 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 788 | private void resizeVirtualDisplayInternal(IBinder appToken, |
| 789 | int width, int height, int densityDpi) { |
| 790 | synchronized (mSyncRoot) { |
| 791 | if (mVirtualDisplayAdapter == null) { |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi); |
| 796 | } |
| 797 | } |
| 798 | |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 799 | private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) { |
| 800 | synchronized (mSyncRoot) { |
| 801 | if (mVirtualDisplayAdapter == null) { |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface); |
| 806 | } |
| 807 | } |
| 808 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 809 | private void releaseVirtualDisplayInternal(IBinder appToken) { |
| 810 | synchronized (mSyncRoot) { |
| 811 | if (mVirtualDisplayAdapter == null) { |
| 812 | return; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 813 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 814 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 815 | DisplayDevice device = |
| 816 | mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken); |
| 817 | if (device != null) { |
| 818 | handleDisplayDeviceRemovedLocked(device); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 823 | private void registerDefaultDisplayAdapters() { |
| 824 | // Register default display adapters. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 825 | synchronized (mSyncRoot) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 826 | // main display adapter |
Mike Lockwood | e63f6f7 | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 827 | registerDisplayAdapterLocked(new LocalDisplayAdapter( |
| 828 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener)); |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 829 | |
| 830 | // Standalone VR devices rely on a virtual display as their primary display for |
| 831 | // 2D UI. We register virtual display adapter along side the main display adapter |
| 832 | // here so that it is ready by the time the system sends the home Intent for |
| 833 | // early apps like SetupWizard/Launcher. In particular, SUW is displayed using |
| 834 | // the virtual display inside VR before any VR-specific apps even run. |
| 835 | mVirtualDisplayAdapter = mInjector.getVirtualDisplayAdapter(mSyncRoot, mContext, |
| 836 | mHandler, mDisplayAdapterListener); |
| 837 | if (mVirtualDisplayAdapter != null) { |
| 838 | registerDisplayAdapterLocked(mVirtualDisplayAdapter); |
| 839 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
| 843 | private void registerAdditionalDisplayAdapters() { |
| 844 | synchronized (mSyncRoot) { |
| 845 | if (shouldRegisterNonEssentialDisplayAdaptersLocked()) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 846 | registerOverlayDisplayAdapterLocked(); |
| 847 | registerWifiDisplayAdapterLocked(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | } |
| 851 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 852 | private void registerOverlayDisplayAdapterLocked() { |
| 853 | registerDisplayAdapterLocked(new OverlayDisplayAdapter( |
| 854 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler)); |
| 855 | } |
| 856 | |
| 857 | private void registerWifiDisplayAdapterLocked() { |
| 858 | if (mContext.getResources().getBoolean( |
Jeff Brown | bbd28a2 | 2012-09-20 16:47:15 -0700 | [diff] [blame] | 859 | com.android.internal.R.bool.config_enableWifiDisplay) |
| 860 | || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 861 | mWifiDisplayAdapter = new WifiDisplayAdapter( |
| 862 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener, |
| 863 | mPersistentDataStore); |
| 864 | registerDisplayAdapterLocked(mWifiDisplayAdapter); |
| 865 | } |
| 866 | } |
| 867 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 868 | private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() { |
| 869 | // In safe mode, we disable non-essential display adapters to give the user |
| 870 | // an opportunity to fix broken settings or other problems that might affect |
| 871 | // system stability. |
| 872 | // In only-core mode, we disable non-essential display adapters to minimize |
| 873 | // the number of dependencies that are started while in this mode and to |
| 874 | // prevent problems that might occur due to the device being encrypted. |
| 875 | return !mSafeMode && !mOnlyCore; |
| 876 | } |
| 877 | |
| 878 | private void registerDisplayAdapterLocked(DisplayAdapter adapter) { |
| 879 | mDisplayAdapters.add(adapter); |
| 880 | adapter.registerLocked(); |
| 881 | } |
| 882 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 883 | private void handleDisplayDeviceAdded(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 884 | synchronized (mSyncRoot) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 885 | handleDisplayDeviceAddedLocked(device); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 889 | private void handleDisplayDeviceAddedLocked(DisplayDevice device) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 890 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 891 | if (mDisplayDevices.contains(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 892 | Slog.w(TAG, "Attempted to add already added display device: " + info); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 893 | return; |
| 894 | } |
| 895 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 896 | Slog.i(TAG, "Display device added: " + info); |
| 897 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 898 | |
| 899 | mDisplayDevices.add(device); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 900 | LogicalDisplay display = addLogicalDisplayLocked(device); |
Jeff Brown | 0033a86 | 2014-10-08 12:06:39 -0700 | [diff] [blame] | 901 | Runnable work = updateDisplayStateLocked(device); |
| 902 | if (work != null) { |
| 903 | work.run(); |
| 904 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 905 | scheduleTraversalLocked(false); |
| 906 | } |
| 907 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 908 | private void handleDisplayDeviceChanged(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 909 | synchronized (mSyncRoot) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 910 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 911 | if (!mDisplayDevices.contains(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 912 | Slog.w(TAG, "Attempted to change non-existent display device: " + info); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 913 | return; |
| 914 | } |
| 915 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 916 | int diff = device.mDebugLastLoggedDeviceInfo.diff(info); |
| 917 | if (diff == DisplayDeviceInfo.DIFF_STATE) { |
| 918 | Slog.i(TAG, "Display device changed state: \"" + info.name |
| 919 | + "\", " + Display.stateToString(info.state)); |
| 920 | } else if (diff != 0) { |
| 921 | Slog.i(TAG, "Display device changed: " + info); |
| 922 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 923 | if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) { |
| 924 | try { |
| 925 | mPersistentDataStore.setColorMode(device, info.colorMode); |
| 926 | } finally { |
| 927 | mPersistentDataStore.saveIfNeeded(); |
| 928 | } |
| 929 | } |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 930 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 931 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 932 | device.applyPendingDisplayDeviceInfoChangesLocked(); |
| 933 | if (updateLogicalDisplaysLocked()) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 934 | scheduleTraversalLocked(false); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | } |
| 938 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 939 | private void handleDisplayDeviceRemoved(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 940 | synchronized (mSyncRoot) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 941 | handleDisplayDeviceRemovedLocked(device); |
| 942 | } |
| 943 | } |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 944 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 945 | private void handleDisplayDeviceRemovedLocked(DisplayDevice device) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 946 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 947 | if (!mDisplayDevices.remove(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 948 | Slog.w(TAG, "Attempted to remove non-existent display device: " + info); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 949 | return; |
| 950 | } |
| 951 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 952 | Slog.i(TAG, "Display device removed: " + info); |
| 953 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 954 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 955 | updateLogicalDisplaysLocked(); |
| 956 | scheduleTraversalLocked(false); |
| 957 | } |
| 958 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 959 | private void handleLogicalDisplayChanged(int displayId, @NonNull LogicalDisplay display) { |
| 960 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 961 | recordTopInsetLocked(display); |
| 962 | } |
| 963 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED); |
| 964 | } |
| 965 | |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 966 | private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 967 | final int count = mDisplayDevices.size(); |
| 968 | for (int i = 0; i < count; i++) { |
| 969 | DisplayDevice device = mDisplayDevices.get(i); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 970 | Runnable runnable = updateDisplayStateLocked(device); |
| 971 | if (runnable != null) { |
| 972 | workQueue.add(runnable); |
| 973 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 977 | private Runnable updateDisplayStateLocked(DisplayDevice device) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 978 | // Blank or unblank the display immediately to match the state requested |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 979 | // by the display power controller (if known). |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 980 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
| 981 | if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 982 | return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 983 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 984 | return null; |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 987 | // Adds a new logical display based on the given display device. |
| 988 | // Sends notifications if needed. |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 989 | private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 990 | DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked(); |
| 991 | boolean isDefault = (deviceInfo.flags |
| 992 | & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0; |
| 993 | if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) { |
| 994 | Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo); |
| 995 | isDefault = false; |
| 996 | } |
| 997 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 998 | if (!isDefault && mSingleDisplayDemoMode) { |
| 999 | Slog.i(TAG, "Not creating a logical display for a secondary display " |
| 1000 | + " because single display demo mode is enabled: " + deviceInfo); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1001 | return null; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1004 | final int displayId = assignDisplayIdLocked(isDefault); |
| 1005 | final int layerStack = assignLayerStackLocked(displayId); |
| 1006 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1007 | LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1008 | display.updateLocked(mDisplayDevices); |
| 1009 | if (!display.isValidLocked()) { |
| 1010 | // This should never happen currently. |
| 1011 | Slog.w(TAG, "Ignoring display device because the logical display " |
| 1012 | + "created from it was not considered valid: " + deviceInfo); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1013 | return null; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1016 | configureColorModeLocked(display, device); |
| 1017 | if (isDefault) { |
| 1018 | recordStableDisplayStatsIfNeededLocked(display); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 1019 | recordTopInsetLocked(display); |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1022 | mLogicalDisplays.put(displayId, display); |
| 1023 | |
| 1024 | // Wake up waitForDefaultDisplay. |
| 1025 | if (isDefault) { |
| 1026 | mSyncRoot.notifyAll(); |
| 1027 | } |
| 1028 | |
| 1029 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1030 | return display; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | private int assignDisplayIdLocked(boolean isDefault) { |
| 1034 | return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++; |
| 1035 | } |
| 1036 | |
| 1037 | private int assignLayerStackLocked(int displayId) { |
| 1038 | // Currently layer stacks and display ids are the same. |
| 1039 | // This need not be the case. |
| 1040 | return displayId; |
| 1041 | } |
| 1042 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1043 | private void configureColorModeLocked(LogicalDisplay display, DisplayDevice device) { |
| 1044 | if (display.getPrimaryDisplayDeviceLocked() == device) { |
| 1045 | int colorMode = mPersistentDataStore.getColorMode(device); |
| 1046 | if (colorMode == Display.COLOR_MODE_INVALID) { |
| 1047 | if ((device.getDisplayDeviceInfoLocked().flags |
| 1048 | & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) { |
| 1049 | colorMode = mDefaultDisplayDefaultColorMode; |
| 1050 | } else { |
| 1051 | colorMode = Display.COLOR_MODE_DEFAULT; |
| 1052 | } |
| 1053 | } |
| 1054 | display.setRequestedColorModeLocked(colorMode); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | // If we've never recorded stable device stats for this device before and they aren't |
| 1059 | // explicitly configured, go ahead and record the stable device stats now based on the status |
| 1060 | // of the default display at first boot. |
| 1061 | private void recordStableDisplayStatsIfNeededLocked(LogicalDisplay d) { |
| 1062 | if (mStableDisplaySize.x <= 0 && mStableDisplaySize.y <= 0) { |
| 1063 | DisplayInfo info = d.getDisplayInfoLocked(); |
| 1064 | setStableDisplaySizeLocked(info.getNaturalWidth(), info.getNaturalHeight()); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 1068 | private void recordTopInsetLocked(@Nullable LogicalDisplay d) { |
| 1069 | // We must only persist the inset after boot has completed, otherwise we will end up |
| 1070 | // overwriting the persisted value before the masking flag has been loaded from the |
| 1071 | // resource overlay. |
| 1072 | if (!mSystemReady || d == null) { |
| 1073 | return; |
| 1074 | } |
| 1075 | int topInset = d.getInsets().top; |
| 1076 | if (topInset == mDefaultDisplayTopInset) { |
| 1077 | return; |
| 1078 | } |
| 1079 | mDefaultDisplayTopInset = topInset; |
| 1080 | SystemProperties.set(PROP_DEFAULT_DISPLAY_TOP_INSET, Integer.toString(topInset)); |
| 1081 | } |
| 1082 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1083 | private void setStableDisplaySizeLocked(int width, int height) { |
| 1084 | mStableDisplaySize = new Point(width, height); |
| 1085 | try { |
| 1086 | mPersistentDataStore.setStableDisplaySize(mStableDisplaySize); |
| 1087 | } finally { |
| 1088 | mPersistentDataStore.saveIfNeeded(); |
| 1089 | } |
| 1090 | } |
| 1091 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1092 | @VisibleForTesting |
| 1093 | Curve getMinimumBrightnessCurveInternal() { |
| 1094 | return mMinimumBrightnessCurve; |
| 1095 | } |
| 1096 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1097 | private void setBrightnessConfigurationForUserInternal( |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 1098 | @Nullable BrightnessConfiguration c, @UserIdInt int userId, |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 1099 | @Nullable String packageName) { |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1100 | validateBrightnessConfiguration(c); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1101 | final int userSerial = getUserManager().getUserSerialNumber(userId); |
| 1102 | synchronized (mSyncRoot) { |
| 1103 | try { |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 1104 | mPersistentDataStore.setBrightnessConfigurationForUser(c, userSerial, |
| 1105 | packageName); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1106 | } finally { |
| 1107 | mPersistentDataStore.saveIfNeeded(); |
| 1108 | } |
| 1109 | if (userId == mCurrentUserId) { |
| 1110 | mDisplayPowerController.setBrightnessConfiguration(c); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1115 | @VisibleForTesting |
| 1116 | void validateBrightnessConfiguration(BrightnessConfiguration config) { |
| 1117 | if (config == null) { |
| 1118 | return; |
| 1119 | } |
| 1120 | if (isBrightnessConfigurationTooDark(config)) { |
| 1121 | throw new IllegalArgumentException("brightness curve is too dark"); |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | private boolean isBrightnessConfigurationTooDark(BrightnessConfiguration config) { |
| 1126 | Pair<float[], float[]> curve = config.getCurve(); |
| 1127 | float[] lux = curve.first; |
| 1128 | float[] nits = curve.second; |
| 1129 | for (int i = 0; i < lux.length; i++) { |
| 1130 | if (nits[i] < mMinimumBrightnessSpline.interpolate(lux[i])) { |
| 1131 | return true; |
| 1132 | } |
| 1133 | } |
| 1134 | return false; |
| 1135 | } |
| 1136 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1137 | private void loadBrightnessConfiguration() { |
| 1138 | synchronized (mSyncRoot) { |
| 1139 | final int userSerial = getUserManager().getUserSerialNumber(mCurrentUserId); |
| 1140 | BrightnessConfiguration config = |
| 1141 | mPersistentDataStore.getBrightnessConfiguration(userSerial); |
| 1142 | mDisplayPowerController.setBrightnessConfiguration(config); |
| 1143 | } |
| 1144 | } |
| 1145 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1146 | // Updates all existing logical displays given the current set of display devices. |
| 1147 | // Removes invalid logical displays. |
| 1148 | // Sends notifications if needed. |
| 1149 | private boolean updateLogicalDisplaysLocked() { |
| 1150 | boolean changed = false; |
| 1151 | for (int i = mLogicalDisplays.size(); i-- > 0; ) { |
| 1152 | final int displayId = mLogicalDisplays.keyAt(i); |
| 1153 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1154 | |
| 1155 | mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked()); |
| 1156 | display.updateLocked(mDisplayDevices); |
| 1157 | if (!display.isValidLocked()) { |
| 1158 | mLogicalDisplays.removeAt(i); |
| 1159 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED); |
| 1160 | changed = true; |
| 1161 | } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) { |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame^] | 1162 | handleLogicalDisplayChanged(displayId, display); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1163 | changed = true; |
| 1164 | } |
| 1165 | } |
| 1166 | return changed; |
| 1167 | } |
| 1168 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1169 | private void performTraversalLocked(SurfaceControl.Transaction t) { |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1170 | // Clear all viewports before configuring displays so that we can keep |
| 1171 | // track of which ones we have configured. |
| 1172 | clearViewportsLocked(); |
| 1173 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1174 | // Configure each display device. |
| 1175 | final int count = mDisplayDevices.size(); |
| 1176 | for (int i = 0; i < count; i++) { |
| 1177 | DisplayDevice device = mDisplayDevices.get(i); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1178 | configureDisplayLocked(t, device); |
| 1179 | device.performTraversalLocked(t); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1180 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1181 | |
| 1182 | // Tell the input system about these new viewports. |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1183 | if (mInputManagerInternal != null) { |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1184 | mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT); |
| 1185 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1188 | private void setDisplayPropertiesInternal(int displayId, boolean hasContent, |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1189 | float requestedRefreshRate, int requestedModeId, boolean inTraversal) { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1190 | synchronized (mSyncRoot) { |
| 1191 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1192 | if (display == null) { |
| 1193 | return; |
| 1194 | } |
| 1195 | if (display.hasContentLocked() != hasContent) { |
Jeff Brown | 33041bd | 2013-08-02 21:11:14 -0700 | [diff] [blame] | 1196 | if (DEBUG) { |
| 1197 | Slog.d(TAG, "Display " + displayId + " hasContent flag changed: " |
| 1198 | + "hasContent=" + hasContent + ", inTraversal=" + inTraversal); |
| 1199 | } |
| 1200 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1201 | display.setHasContentLocked(hasContent); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1202 | scheduleTraversalLocked(inTraversal); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1203 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1204 | if (requestedModeId == 0 && requestedRefreshRate != 0) { |
| 1205 | // Scan supported modes returned by display.getInfo() to find a mode with the same |
| 1206 | // size as the default display mode but with the specified refresh rate instead. |
| 1207 | requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate( |
| 1208 | requestedRefreshRate); |
| 1209 | } |
| 1210 | if (display.getRequestedModeIdLocked() != requestedModeId) { |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1211 | if (DEBUG) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1212 | Slog.d(TAG, "Display " + displayId + " switching to mode " + requestedModeId); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1213 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1214 | display.setRequestedModeIdLocked(requestedModeId); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1215 | scheduleTraversalLocked(inTraversal); |
| 1216 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1217 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1218 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1219 | |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 1220 | private void setDisplayOffsetsInternal(int displayId, int x, int y) { |
| 1221 | synchronized (mSyncRoot) { |
| 1222 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1223 | if (display == null) { |
| 1224 | return; |
| 1225 | } |
| 1226 | if (display.getDisplayOffsetXLocked() != x |
| 1227 | || display.getDisplayOffsetYLocked() != y) { |
| 1228 | if (DEBUG) { |
| 1229 | Slog.d(TAG, "Display " + displayId + " burn-in offset set to (" |
| 1230 | + x + ", " + y + ")"); |
| 1231 | } |
| 1232 | display.setDisplayOffsetsLocked(x, y); |
| 1233 | scheduleTraversalLocked(false); |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1238 | // Updates the lists of UIDs that are present on displays. |
| 1239 | private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) { |
| 1240 | synchronized (mSyncRoot) { |
| 1241 | mDisplayAccessUIDs.clear(); |
| 1242 | for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) { |
| 1243 | mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i), |
| 1244 | newDisplayAccessUIDs.valueAt(i)); |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | // Checks if provided UID's content is present on the display and UID has access to it. |
| 1250 | private boolean isUidPresentOnDisplayInternal(int uid, int displayId) { |
| 1251 | synchronized (mSyncRoot) { |
| 1252 | final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId); |
| 1253 | return displayUIDs != null && displayUIDs.indexOf(uid) != -1; |
| 1254 | } |
| 1255 | } |
| 1256 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1257 | private void clearViewportsLocked() { |
| 1258 | mDefaultViewport.valid = false; |
| 1259 | mExternalTouchViewport.valid = false; |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1260 | mVirtualTouchViewports.clear(); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1263 | private void configureDisplayLocked(SurfaceControl.Transaction t, DisplayDevice device) { |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1264 | final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
| 1265 | final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1266 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1267 | // Find the logical display that the display device is showing. |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1268 | // Certain displays only ever show their own content. |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1269 | LogicalDisplay display = findLogicalDisplayForDeviceLocked(device); |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1270 | if (!ownContent) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1271 | if (display != null && !display.hasContentLocked()) { |
| 1272 | // If the display does not have any content of its own, then |
| 1273 | // automatically mirror the default logical display contents. |
| 1274 | display = null; |
| 1275 | } |
| 1276 | if (display == null) { |
| 1277 | display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY); |
| 1278 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | // Apply the logical display configuration to the display device. |
| 1282 | if (display == null) { |
| 1283 | // TODO: no logical display for the device, blank it |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1284 | Slog.w(TAG, "Missing logical display to use for physical display device: " |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1285 | + device.getDisplayDeviceInfoLocked()); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1286 | return; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1287 | } |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1288 | display.configureDisplayLocked(t, device, info.state == Display.STATE_OFF); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1289 | |
| 1290 | // Update the viewports if needed. |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1291 | if (!mDefaultViewport.valid |
| 1292 | && (info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) { |
| 1293 | setViewportLocked(mDefaultViewport, display, device); |
| 1294 | } |
| 1295 | if (!mExternalTouchViewport.valid |
| 1296 | && info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) { |
| 1297 | setViewportLocked(mExternalTouchViewport, display, device); |
| 1298 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1299 | |
| 1300 | if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL && !TextUtils.isEmpty(info.uniqueId)) { |
| 1301 | final DisplayViewport viewport = getVirtualTouchViewportLocked(info.uniqueId); |
| 1302 | setViewportLocked(viewport, display, device); |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | /** Gets the virtual device viewport or creates it if not yet created. */ |
| 1307 | private DisplayViewport getVirtualTouchViewportLocked(@NonNull String uniqueId) { |
| 1308 | DisplayViewport viewport; |
| 1309 | final int count = mVirtualTouchViewports.size(); |
| 1310 | for (int i = 0; i < count; i++) { |
| 1311 | viewport = mVirtualTouchViewports.get(i); |
| 1312 | if (uniqueId.equals(viewport.uniqueId)) { |
| 1313 | return viewport; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | viewport = new DisplayViewport(); |
| 1318 | viewport.uniqueId = uniqueId; |
| 1319 | mVirtualTouchViewports.add(viewport); |
| 1320 | return viewport; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | private static void setViewportLocked(DisplayViewport viewport, |
| 1324 | LogicalDisplay display, DisplayDevice device) { |
| 1325 | viewport.valid = true; |
| 1326 | viewport.displayId = display.getDisplayIdLocked(); |
| 1327 | device.populateViewportLocked(viewport); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) { |
| 1331 | final int count = mLogicalDisplays.size(); |
| 1332 | for (int i = 0; i < count; i++) { |
| 1333 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1334 | if (display.getPrimaryDisplayDeviceLocked() == device) { |
| 1335 | return display; |
| 1336 | } |
| 1337 | } |
| 1338 | return null; |
| 1339 | } |
| 1340 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1341 | private void sendDisplayEventLocked(int displayId, int event) { |
| 1342 | Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event); |
| 1343 | mHandler.sendMessage(msg); |
| 1344 | } |
| 1345 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1346 | // Requests that performTraversals be called at a |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1347 | // later time to apply changes to surfaces and displays. |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1348 | private void scheduleTraversalLocked(boolean inTraversal) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1349 | if (!mPendingTraversal && mWindowManagerInternal != null) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1350 | mPendingTraversal = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1351 | if (!inTraversal) { |
| 1352 | mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL); |
| 1353 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | // Runs on Handler thread. |
| 1358 | // Delivers display event notifications to callbacks. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1359 | private void deliverDisplayEvent(int displayId, int event) { |
| 1360 | if (DEBUG) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1361 | Slog.d(TAG, "Delivering display event: displayId=" |
| 1362 | + displayId + ", event=" + event); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1363 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1364 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1365 | // Grab the lock and copy the callbacks. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1366 | final int count; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1367 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1368 | count = mCallbacks.size(); |
| 1369 | mTempCallbacks.clear(); |
| 1370 | for (int i = 0; i < count; i++) { |
| 1371 | mTempCallbacks.add(mCallbacks.valueAt(i)); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1372 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1373 | } |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1374 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1375 | // After releasing the lock, send the notifications out. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1376 | for (int i = 0; i < count; i++) { |
| 1377 | mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event); |
| 1378 | } |
| 1379 | mTempCallbacks.clear(); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1382 | private IMediaProjectionManager getProjectionService() { |
| 1383 | if (mProjectionService == null) { |
| 1384 | IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE); |
| 1385 | mProjectionService = IMediaProjectionManager.Stub.asInterface(b); |
| 1386 | } |
| 1387 | return mProjectionService; |
| 1388 | } |
| 1389 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1390 | private UserManager getUserManager() { |
| 1391 | return mContext.getSystemService(UserManager.class); |
| 1392 | } |
| 1393 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1394 | private void dumpInternal(PrintWriter pw) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1395 | pw.println("DISPLAY MANAGER (dumpsys display)"); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1396 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1397 | synchronized (mSyncRoot) { |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1398 | pw.println(" mOnlyCode=" + mOnlyCore); |
| 1399 | pw.println(" mSafeMode=" + mSafeMode); |
| 1400 | pw.println(" mPendingTraversal=" + mPendingTraversal); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1401 | pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState)); |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1402 | pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId); |
| 1403 | pw.println(" mDefaultViewport=" + mDefaultViewport); |
| 1404 | pw.println(" mExternalTouchViewport=" + mExternalTouchViewport); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1405 | pw.println(" mVirtualTouchViewports=" + mVirtualTouchViewports); |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 1406 | pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1407 | pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1408 | pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount); |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1409 | pw.println(" mStableDisplaySize=" + mStableDisplaySize); |
| 1410 | |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1411 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1412 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1413 | ipw.increaseIndent(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1414 | |
| 1415 | pw.println(); |
| 1416 | pw.println("Display Adapters: size=" + mDisplayAdapters.size()); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1417 | for (DisplayAdapter adapter : mDisplayAdapters) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1418 | pw.println(" " + adapter.getName()); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1419 | adapter.dumpLocked(ipw); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1420 | } |
Craig Mautner | 9de4936 | 2012-08-02 14:30:30 -0700 | [diff] [blame] | 1421 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1422 | pw.println(); |
| 1423 | pw.println("Display Devices: size=" + mDisplayDevices.size()); |
| 1424 | for (DisplayDevice device : mDisplayDevices) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1425 | pw.println(" " + device.getDisplayDeviceInfoLocked()); |
| 1426 | device.dumpLocked(ipw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | final int logicalDisplayCount = mLogicalDisplays.size(); |
| 1430 | pw.println(); |
| 1431 | pw.println("Logical Displays: size=" + logicalDisplayCount); |
| 1432 | for (int i = 0; i < logicalDisplayCount; i++) { |
| 1433 | int displayId = mLogicalDisplays.keyAt(i); |
| 1434 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1435 | pw.println(" Display " + displayId + ":"); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1436 | display.dumpLocked(ipw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1437 | } |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1438 | |
| 1439 | final int callbackCount = mCallbacks.size(); |
| 1440 | pw.println(); |
| 1441 | pw.println("Callbacks: size=" + callbackCount); |
| 1442 | for (int i = 0; i < callbackCount; i++) { |
| 1443 | CallbackRecord callback = mCallbacks.valueAt(i); |
| 1444 | pw.println(" " + i + ": mPid=" + callback.mPid |
| 1445 | + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested); |
| 1446 | } |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 1447 | |
| 1448 | if (mDisplayPowerController != null) { |
| 1449 | mDisplayPowerController.dump(pw); |
| 1450 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1451 | |
| 1452 | pw.println(); |
| 1453 | mPersistentDataStore.dump(pw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1457 | private static float[] getFloatArray(TypedArray array) { |
| 1458 | int length = array.length(); |
| 1459 | float[] floatArray = new float[length]; |
| 1460 | for (int i = 0; i < length; i++) { |
| 1461 | floatArray[i] = array.getFloat(i, Float.NaN); |
| 1462 | } |
| 1463 | array.recycle(); |
| 1464 | return floatArray; |
| 1465 | } |
| 1466 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1467 | /** |
| 1468 | * This is the object that everything in the display manager locks on. |
| 1469 | * We make it an inner class within the {@link DisplayManagerService} to so that it is |
| 1470 | * clear that the object belongs to the display manager service and that it is |
| 1471 | * a unique object with a special purpose. |
| 1472 | */ |
| 1473 | public static final class SyncRoot { |
| 1474 | } |
| 1475 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1476 | @VisibleForTesting |
| 1477 | static class Injector { |
| 1478 | VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context, |
| 1479 | Handler handler, DisplayAdapter.Listener displayAdapterListener) { |
| 1480 | return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener); |
| 1481 | } |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 1482 | |
| 1483 | long getDefaultDisplayDelayTimeout() { |
| 1484 | return WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT; |
| 1485 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Alex Sakhartchouk | 879d24f | 2017-06-20 22:01:19 -0400 | [diff] [blame] | 1488 | @VisibleForTesting |
| 1489 | DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) { |
| 1490 | synchronized (mSyncRoot) { |
| 1491 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1492 | if (display != null) { |
| 1493 | DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked(); |
| 1494 | return displayDevice.getDisplayDeviceInfoLocked(); |
| 1495 | } |
| 1496 | return null; |
| 1497 | } |
| 1498 | } |
| 1499 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1500 | private final class DisplayManagerHandler extends Handler { |
| 1501 | public DisplayManagerHandler(Looper looper) { |
| 1502 | super(looper, null, true /*async*/); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1503 | } |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 1504 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1505 | @Override |
| 1506 | public void handleMessage(Message msg) { |
| 1507 | switch (msg.what) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 1508 | case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS: |
| 1509 | registerDefaultDisplayAdapters(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1510 | break; |
| 1511 | |
| 1512 | case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS: |
| 1513 | registerAdditionalDisplayAdapters(); |
| 1514 | break; |
| 1515 | |
| 1516 | case MSG_DELIVER_DISPLAY_EVENT: |
| 1517 | deliverDisplayEvent(msg.arg1, msg.arg2); |
| 1518 | break; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1519 | |
| 1520 | case MSG_REQUEST_TRAVERSAL: |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1521 | mWindowManagerInternal.requestTraversalFromDisplayManager(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1522 | break; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1523 | |
| 1524 | case MSG_UPDATE_VIEWPORT: { |
| 1525 | synchronized (mSyncRoot) { |
| 1526 | mTempDefaultViewport.copyFrom(mDefaultViewport); |
| 1527 | mTempExternalTouchViewport.copyFrom(mExternalTouchViewport); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1528 | if (!mTempVirtualTouchViewports.equals(mVirtualTouchViewports)) { |
| 1529 | mTempVirtualTouchViewports.clear(); |
| 1530 | for (DisplayViewport d : mVirtualTouchViewports) { |
| 1531 | mTempVirtualTouchViewports.add(d.makeCopy()); |
| 1532 | } |
| 1533 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1534 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1535 | mInputManagerInternal.setDisplayViewports(mTempDefaultViewport, |
| 1536 | mTempExternalTouchViewport, mTempVirtualTouchViewports); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1537 | break; |
| 1538 | } |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 1539 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1540 | case MSG_LOAD_BRIGHTNESS_CONFIGURATION: |
| 1541 | loadBrightnessConfiguration(); |
| 1542 | break; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | private final class DisplayAdapterListener implements DisplayAdapter.Listener { |
| 1548 | @Override |
| 1549 | public void onDisplayDeviceEvent(DisplayDevice device, int event) { |
| 1550 | switch (event) { |
| 1551 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED: |
| 1552 | handleDisplayDeviceAdded(device); |
| 1553 | break; |
| 1554 | |
| 1555 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED: |
| 1556 | handleDisplayDeviceChanged(device); |
| 1557 | break; |
| 1558 | |
| 1559 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED: |
| 1560 | handleDisplayDeviceRemoved(device); |
| 1561 | break; |
| 1562 | } |
| 1563 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1564 | |
| 1565 | @Override |
| 1566 | public void onTraversalRequested() { |
| 1567 | synchronized (mSyncRoot) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1568 | scheduleTraversalLocked(false); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1569 | } |
| 1570 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | private final class CallbackRecord implements DeathRecipient { |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1574 | public final int mPid; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1575 | private final IDisplayManagerCallback mCallback; |
| 1576 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1577 | public boolean mWifiDisplayScanRequested; |
| 1578 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1579 | public CallbackRecord(int pid, IDisplayManagerCallback callback) { |
| 1580 | mPid = pid; |
| 1581 | mCallback = callback; |
| 1582 | } |
| 1583 | |
| 1584 | @Override |
| 1585 | public void binderDied() { |
| 1586 | if (DEBUG) { |
| 1587 | Slog.d(TAG, "Display listener for pid " + mPid + " died."); |
| 1588 | } |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1589 | onCallbackDied(this); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | public void notifyDisplayEventAsync(int displayId, int event) { |
| 1593 | try { |
| 1594 | mCallback.onDisplayEvent(displayId, event); |
| 1595 | } catch (RemoteException ex) { |
| 1596 | Slog.w(TAG, "Failed to notify process " |
| 1597 | + mPid + " that displays changed, assuming it died.", ex); |
| 1598 | binderDied(); |
| 1599 | } |
| 1600 | } |
| 1601 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1602 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1603 | @VisibleForTesting |
| 1604 | final class BinderService extends IDisplayManager.Stub { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1605 | /** |
| 1606 | * Returns information about the specified logical display. |
| 1607 | * |
| 1608 | * @param displayId The logical display id. |
| 1609 | * @return The logical display info, or null if the display does not exist. The |
| 1610 | * returned object must be treated as immutable. |
| 1611 | */ |
| 1612 | @Override // Binder call |
| 1613 | public DisplayInfo getDisplayInfo(int displayId) { |
| 1614 | final int callingUid = Binder.getCallingUid(); |
| 1615 | final long token = Binder.clearCallingIdentity(); |
| 1616 | try { |
| 1617 | return getDisplayInfoInternal(displayId, callingUid); |
| 1618 | } finally { |
| 1619 | Binder.restoreCallingIdentity(token); |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | /** |
| 1624 | * Returns the list of all display ids. |
| 1625 | */ |
| 1626 | @Override // Binder call |
| 1627 | public int[] getDisplayIds() { |
| 1628 | final int callingUid = Binder.getCallingUid(); |
| 1629 | final long token = Binder.clearCallingIdentity(); |
| 1630 | try { |
| 1631 | return getDisplayIdsInternal(callingUid); |
| 1632 | } finally { |
| 1633 | Binder.restoreCallingIdentity(token); |
| 1634 | } |
| 1635 | } |
| 1636 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1637 | /** |
| 1638 | * Returns the stable device display size, in pixels. |
| 1639 | */ |
| 1640 | @Override // Binder call |
| 1641 | public Point getStableDisplaySize() { |
| 1642 | final long token = Binder.clearCallingIdentity(); |
| 1643 | try { |
| 1644 | return getStableDisplaySizeInternal(); |
| 1645 | } finally { |
| 1646 | Binder.restoreCallingIdentity(token); |
| 1647 | } |
| 1648 | } |
| 1649 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1650 | @Override // Binder call |
| 1651 | public void registerCallback(IDisplayManagerCallback callback) { |
| 1652 | if (callback == null) { |
| 1653 | throw new IllegalArgumentException("listener must not be null"); |
| 1654 | } |
| 1655 | |
| 1656 | final int callingPid = Binder.getCallingPid(); |
| 1657 | final long token = Binder.clearCallingIdentity(); |
| 1658 | try { |
| 1659 | registerCallbackInternal(callback, callingPid); |
| 1660 | } finally { |
| 1661 | Binder.restoreCallingIdentity(token); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | @Override // Binder call |
| 1666 | public void startWifiDisplayScan() { |
| 1667 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1668 | "Permission required to start wifi display scans"); |
| 1669 | |
| 1670 | final int callingPid = Binder.getCallingPid(); |
| 1671 | final long token = Binder.clearCallingIdentity(); |
| 1672 | try { |
| 1673 | startWifiDisplayScanInternal(callingPid); |
| 1674 | } finally { |
| 1675 | Binder.restoreCallingIdentity(token); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | @Override // Binder call |
| 1680 | public void stopWifiDisplayScan() { |
| 1681 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1682 | "Permission required to stop wifi display scans"); |
| 1683 | |
| 1684 | final int callingPid = Binder.getCallingPid(); |
| 1685 | final long token = Binder.clearCallingIdentity(); |
| 1686 | try { |
| 1687 | stopWifiDisplayScanInternal(callingPid); |
| 1688 | } finally { |
| 1689 | Binder.restoreCallingIdentity(token); |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | @Override // Binder call |
| 1694 | public void connectWifiDisplay(String address) { |
| 1695 | if (address == null) { |
| 1696 | throw new IllegalArgumentException("address must not be null"); |
| 1697 | } |
| 1698 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1699 | "Permission required to connect to a wifi display"); |
| 1700 | |
| 1701 | final long token = Binder.clearCallingIdentity(); |
| 1702 | try { |
| 1703 | connectWifiDisplayInternal(address); |
| 1704 | } finally { |
| 1705 | Binder.restoreCallingIdentity(token); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | @Override // Binder call |
| 1710 | public void disconnectWifiDisplay() { |
| 1711 | // This request does not require special permissions. |
| 1712 | // Any app can request disconnection from the currently active wifi display. |
| 1713 | // This exception should no longer be needed once wifi display control moves |
| 1714 | // to the media router service. |
| 1715 | |
| 1716 | final long token = Binder.clearCallingIdentity(); |
| 1717 | try { |
| 1718 | disconnectWifiDisplayInternal(); |
| 1719 | } finally { |
| 1720 | Binder.restoreCallingIdentity(token); |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | @Override // Binder call |
| 1725 | public void renameWifiDisplay(String address, String alias) { |
| 1726 | if (address == null) { |
| 1727 | throw new IllegalArgumentException("address must not be null"); |
| 1728 | } |
| 1729 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1730 | "Permission required to rename to a wifi display"); |
| 1731 | |
| 1732 | final long token = Binder.clearCallingIdentity(); |
| 1733 | try { |
| 1734 | renameWifiDisplayInternal(address, alias); |
| 1735 | } finally { |
| 1736 | Binder.restoreCallingIdentity(token); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | @Override // Binder call |
| 1741 | public void forgetWifiDisplay(String address) { |
| 1742 | if (address == null) { |
| 1743 | throw new IllegalArgumentException("address must not be null"); |
| 1744 | } |
| 1745 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1746 | "Permission required to forget to a wifi display"); |
| 1747 | |
| 1748 | final long token = Binder.clearCallingIdentity(); |
| 1749 | try { |
| 1750 | forgetWifiDisplayInternal(address); |
| 1751 | } finally { |
| 1752 | Binder.restoreCallingIdentity(token); |
| 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | @Override // Binder call |
| 1757 | public void pauseWifiDisplay() { |
| 1758 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1759 | "Permission required to pause a wifi display session"); |
| 1760 | |
| 1761 | final long token = Binder.clearCallingIdentity(); |
| 1762 | try { |
| 1763 | pauseWifiDisplayInternal(); |
| 1764 | } finally { |
| 1765 | Binder.restoreCallingIdentity(token); |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | @Override // Binder call |
| 1770 | public void resumeWifiDisplay() { |
| 1771 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1772 | "Permission required to resume a wifi display session"); |
| 1773 | |
| 1774 | final long token = Binder.clearCallingIdentity(); |
| 1775 | try { |
| 1776 | resumeWifiDisplayInternal(); |
| 1777 | } finally { |
| 1778 | Binder.restoreCallingIdentity(token); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | @Override // Binder call |
| 1783 | public WifiDisplayStatus getWifiDisplayStatus() { |
| 1784 | // This request does not require special permissions. |
| 1785 | // Any app can get information about available wifi displays. |
| 1786 | |
| 1787 | final long token = Binder.clearCallingIdentity(); |
| 1788 | try { |
| 1789 | return getWifiDisplayStatusInternal(); |
| 1790 | } finally { |
| 1791 | Binder.restoreCallingIdentity(token); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | @Override // Binder call |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1796 | public void requestColorMode(int displayId, int colorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1797 | mContext.enforceCallingOrSelfPermission( |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1798 | Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE, |
| 1799 | "Permission required to change the display color mode"); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1800 | final long token = Binder.clearCallingIdentity(); |
| 1801 | try { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1802 | requestColorModeInternal(displayId, colorMode); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1803 | } finally { |
| 1804 | Binder.restoreCallingIdentity(token); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | @Override // Binder call |
Bryan Mawhinney | 462e29d | 2018-03-22 15:52:41 +0000 | [diff] [blame] | 1809 | public void setSaturationLevel(float level) { |
| 1810 | mContext.enforceCallingOrSelfPermission( |
| 1811 | Manifest.permission.CONTROL_DISPLAY_SATURATION, |
| 1812 | "Permission required to set display saturation level"); |
| 1813 | final long token = Binder.clearCallingIdentity(); |
| 1814 | try { |
| 1815 | setSaturationLevelInternal(level); |
| 1816 | } finally { |
| 1817 | Binder.restoreCallingIdentity(token); |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1822 | public int createVirtualDisplay(IVirtualDisplayCallback callback, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1823 | IMediaProjection projection, String packageName, String name, |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1824 | int width, int height, int densityDpi, Surface surface, int flags, |
| 1825 | String uniqueId) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1826 | final int callingUid = Binder.getCallingUid(); |
| 1827 | if (!validatePackageName(callingUid, packageName)) { |
| 1828 | throw new SecurityException("packageName must match the calling uid"); |
| 1829 | } |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1830 | if (callback == null) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1831 | throw new IllegalArgumentException("appToken must not be null"); |
| 1832 | } |
| 1833 | if (TextUtils.isEmpty(name)) { |
| 1834 | throw new IllegalArgumentException("name must be non-null and non-empty"); |
| 1835 | } |
| 1836 | if (width <= 0 || height <= 0 || densityDpi <= 0) { |
| 1837 | throw new IllegalArgumentException("width, height, and densityDpi must be " |
| 1838 | + "greater than 0"); |
| 1839 | } |
Pablo Ceballos | eb3370d | 2016-08-31 15:00:17 -0700 | [diff] [blame] | 1840 | if (surface != null && surface.isSingleBuffered()) { |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 1841 | throw new IllegalArgumentException("Surface can't be single-buffered"); |
| 1842 | } |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1843 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1844 | if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) { |
| 1845 | flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
| 1846 | |
| 1847 | // Public displays can't be allowed to show content when locked. |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 1848 | if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) { |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1849 | throw new IllegalArgumentException( |
| 1850 | "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE"); |
| 1851 | } |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1852 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1853 | if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) { |
| 1854 | flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1857 | if (projection != null) { |
| 1858 | try { |
| 1859 | if (!getProjectionService().isValidMediaProjection(projection)) { |
| 1860 | throw new SecurityException("Invalid media projection"); |
| 1861 | } |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1862 | flags = projection.applyVirtualDisplayFlags(flags); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1863 | } catch (RemoteException e) { |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1864 | throw new SecurityException("unable to validate media projection or flags"); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1868 | if (callingUid != Process.SYSTEM_UID && |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1869 | (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1870 | if (!canProjectVideo(projection)) { |
| 1871 | throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or " |
| 1872 | + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate " |
| 1873 | + "MediaProjection token in order to create a screen sharing virtual " |
| 1874 | + "display."); |
| 1875 | } |
| 1876 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1877 | if ((flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1878 | if (!canProjectSecureVideo(projection)) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1879 | throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT " |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1880 | + "or an appropriate MediaProjection token to create a " |
| 1881 | + "secure virtual display."); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | final long token = Binder.clearCallingIdentity(); |
| 1886 | try { |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1887 | return createVirtualDisplayInternal(callback, projection, callingUid, packageName, |
| 1888 | name, width, height, densityDpi, surface, flags, uniqueId); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1889 | } finally { |
| 1890 | Binder.restoreCallingIdentity(token); |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1895 | public void resizeVirtualDisplay(IVirtualDisplayCallback callback, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1896 | int width, int height, int densityDpi) { |
| 1897 | final long token = Binder.clearCallingIdentity(); |
| 1898 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1899 | resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi); |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1900 | } finally { |
| 1901 | Binder.restoreCallingIdentity(token); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1906 | public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) { |
Pablo Ceballos | eb3370d | 2016-08-31 15:00:17 -0700 | [diff] [blame] | 1907 | if (surface != null && surface.isSingleBuffered()) { |
| 1908 | throw new IllegalArgumentException("Surface can't be single-buffered"); |
| 1909 | } |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 1910 | final long token = Binder.clearCallingIdentity(); |
| 1911 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1912 | setVirtualDisplaySurfaceInternal(callback.asBinder(), surface); |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 1913 | } finally { |
| 1914 | Binder.restoreCallingIdentity(token); |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1919 | public void releaseVirtualDisplay(IVirtualDisplayCallback callback) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1920 | final long token = Binder.clearCallingIdentity(); |
| 1921 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1922 | releaseVirtualDisplayInternal(callback.asBinder()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1923 | } finally { |
| 1924 | Binder.restoreCallingIdentity(token); |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | @Override // Binder call |
| 1929 | public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 1930 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1931 | |
| 1932 | final long token = Binder.clearCallingIdentity(); |
| 1933 | try { |
| 1934 | dumpInternal(pw); |
| 1935 | } finally { |
| 1936 | Binder.restoreCallingIdentity(token); |
| 1937 | } |
| 1938 | } |
| 1939 | |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 1940 | @Override // Binder call |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 1941 | public ParceledListSlice<BrightnessChangeEvent> getBrightnessEvents(String callingPackage) { |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 1942 | mContext.enforceCallingOrSelfPermission( |
| 1943 | Manifest.permission.BRIGHTNESS_SLIDER_USAGE, |
| 1944 | "Permission to read brightness events."); |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 1945 | |
| 1946 | final int callingUid = Binder.getCallingUid(); |
| 1947 | AppOpsManager appOpsManager = mContext.getSystemService(AppOpsManager.class); |
Jeff Sharkey | d931119 | 2018-04-16 16:50:34 +0000 | [diff] [blame] | 1948 | final int mode = appOpsManager.noteOp(AppOpsManager.OP_GET_USAGE_STATS, |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 1949 | callingUid, callingPackage); |
| 1950 | final boolean hasUsageStats; |
| 1951 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 1952 | // The default behavior here is to check if PackageManager has given the app |
| 1953 | // permission. |
| 1954 | hasUsageStats = mContext.checkCallingPermission( |
| 1955 | Manifest.permission.PACKAGE_USAGE_STATS) |
| 1956 | == PackageManager.PERMISSION_GRANTED; |
| 1957 | } else { |
| 1958 | hasUsageStats = mode == AppOpsManager.MODE_ALLOWED; |
| 1959 | } |
| 1960 | |
| 1961 | final int userId = UserHandle.getUserId(callingUid); |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 1962 | final long token = Binder.clearCallingIdentity(); |
| 1963 | try { |
Michael Wright | 144aac9 | 2017-12-21 18:37:41 +0000 | [diff] [blame] | 1964 | synchronized (mSyncRoot) { |
| 1965 | return mDisplayPowerController.getBrightnessEvents(userId, hasUsageStats); |
| 1966 | } |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 1967 | } finally { |
| 1968 | Binder.restoreCallingIdentity(token); |
| 1969 | } |
| 1970 | } |
| 1971 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1972 | @Override // Binder call |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 1973 | public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats() { |
| 1974 | mContext.enforceCallingOrSelfPermission( |
| 1975 | Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS, |
| 1976 | "Permission required to to access ambient light stats."); |
| 1977 | final int callingUid = Binder.getCallingUid(); |
| 1978 | final int userId = UserHandle.getUserId(callingUid); |
| 1979 | final long token = Binder.clearCallingIdentity(); |
| 1980 | try { |
| 1981 | synchronized (mSyncRoot) { |
| 1982 | return mDisplayPowerController.getAmbientBrightnessStats(userId); |
| 1983 | } |
| 1984 | } finally { |
| 1985 | Binder.restoreCallingIdentity(token); |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | @Override // Binder call |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1990 | public void setBrightnessConfigurationForUser( |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 1991 | BrightnessConfiguration c, @UserIdInt int userId, String packageName) { |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1992 | mContext.enforceCallingOrSelfPermission( |
| 1993 | Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS, |
| 1994 | "Permission required to change the display's brightness configuration"); |
| 1995 | if (userId != UserHandle.getCallingUserId()) { |
| 1996 | mContext.enforceCallingOrSelfPermission( |
| 1997 | Manifest.permission.INTERACT_ACROSS_USERS, |
| 1998 | "Permission required to change the display brightness" |
| 1999 | + " configuration of another user"); |
| 2000 | } |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 2001 | if (packageName != null && !validatePackageName(getCallingUid(), packageName)) { |
| 2002 | packageName = null; |
| 2003 | } |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2004 | final long token = Binder.clearCallingIdentity(); |
| 2005 | try { |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 2006 | setBrightnessConfigurationForUserInternal(c, userId, packageName); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2007 | } finally { |
| 2008 | Binder.restoreCallingIdentity(token); |
| 2009 | } |
| 2010 | } |
| 2011 | |
Michael Wright | d846023 | 2018-01-16 18:04:59 +0000 | [diff] [blame] | 2012 | @Override // Binder call |
Kenny Guy | 6d1009f | 2018-03-14 14:28:23 +0000 | [diff] [blame] | 2013 | public BrightnessConfiguration getBrightnessConfigurationForUser(int userId) { |
| 2014 | mContext.enforceCallingOrSelfPermission( |
| 2015 | Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS, |
| 2016 | "Permission required to read the display's brightness configuration"); |
| 2017 | if (userId != UserHandle.getCallingUserId()) { |
| 2018 | mContext.enforceCallingOrSelfPermission( |
| 2019 | Manifest.permission.INTERACT_ACROSS_USERS, |
| 2020 | "Permission required to read the display brightness" |
| 2021 | + " configuration of another user"); |
| 2022 | } |
| 2023 | final long token = Binder.clearCallingIdentity(); |
| 2024 | try { |
| 2025 | final int userSerial = getUserManager().getUserSerialNumber(userId); |
| 2026 | synchronized (mSyncRoot) { |
| 2027 | BrightnessConfiguration config = |
| 2028 | mPersistentDataStore.getBrightnessConfiguration(userSerial); |
| 2029 | if (config == null) { |
| 2030 | config = mDisplayPowerController.getDefaultBrightnessConfiguration(); |
| 2031 | } |
| 2032 | return config; |
| 2033 | } |
| 2034 | } finally { |
| 2035 | Binder.restoreCallingIdentity(token); |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | @Override // Binder call |
| 2040 | public BrightnessConfiguration getDefaultBrightnessConfiguration() { |
| 2041 | mContext.enforceCallingOrSelfPermission( |
| 2042 | Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS, |
| 2043 | "Permission required to read the display's default brightness configuration"); |
| 2044 | final long token = Binder.clearCallingIdentity(); |
| 2045 | try { |
| 2046 | synchronized (mSyncRoot) { |
| 2047 | return mDisplayPowerController.getDefaultBrightnessConfiguration(); |
| 2048 | } |
| 2049 | } finally { |
| 2050 | Binder.restoreCallingIdentity(token); |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | @Override // Binder call |
Michael Wright | d846023 | 2018-01-16 18:04:59 +0000 | [diff] [blame] | 2055 | public void setTemporaryBrightness(int brightness) { |
| 2056 | mContext.enforceCallingOrSelfPermission( |
| 2057 | Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS, |
| 2058 | "Permission required to set the display's brightness"); |
| 2059 | final long token = Binder.clearCallingIdentity(); |
| 2060 | try { |
| 2061 | synchronized (mSyncRoot) { |
| 2062 | mDisplayPowerController.setTemporaryBrightness(brightness); |
| 2063 | } |
| 2064 | } finally { |
| 2065 | Binder.restoreCallingIdentity(token); |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | @Override // Binder call |
| 2070 | public void setTemporaryAutoBrightnessAdjustment(float adjustment) { |
| 2071 | mContext.enforceCallingOrSelfPermission( |
| 2072 | Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS, |
| 2073 | "Permission required to set the display's auto brightness adjustment"); |
| 2074 | final long token = Binder.clearCallingIdentity(); |
| 2075 | try { |
| 2076 | synchronized (mSyncRoot) { |
| 2077 | mDisplayPowerController.setTemporaryAutoBrightnessAdjustment(adjustment); |
| 2078 | } |
| 2079 | } finally { |
| 2080 | Binder.restoreCallingIdentity(token); |
| 2081 | } |
| 2082 | } |
| 2083 | |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 2084 | @Override // Binder call |
| 2085 | public void onShellCommand(FileDescriptor in, FileDescriptor out, |
| 2086 | FileDescriptor err, String[] args, ShellCallback callback, |
| 2087 | ResultReceiver resultReceiver) { |
| 2088 | final long token = Binder.clearCallingIdentity(); |
| 2089 | try { |
| 2090 | DisplayManagerShellCommand command = new DisplayManagerShellCommand(this); |
| 2091 | command.exec(this, in, out, err, args, callback, resultReceiver); |
| 2092 | } finally { |
| 2093 | Binder.restoreCallingIdentity(token); |
| 2094 | } |
| 2095 | } |
| 2096 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 2097 | @Override // Binder call |
| 2098 | public Curve getMinimumBrightnessCurve() { |
| 2099 | final long token = Binder.clearCallingIdentity(); |
| 2100 | try { |
| 2101 | return getMinimumBrightnessCurveInternal(); |
| 2102 | } finally { |
| 2103 | Binder.restoreCallingIdentity(token); |
| 2104 | } |
| 2105 | } |
| 2106 | |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 2107 | void setBrightness(int brightness) { |
| 2108 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2109 | Settings.System.SCREEN_BRIGHTNESS, brightness, UserHandle.USER_CURRENT); |
| 2110 | } |
| 2111 | |
| 2112 | void resetBrightnessConfiguration() { |
| 2113 | setBrightnessConfigurationForUserInternal(null, mContext.getUserId(), |
| 2114 | mContext.getPackageName()); |
| 2115 | } |
| 2116 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2117 | private boolean validatePackageName(int uid, String packageName) { |
| 2118 | if (packageName != null) { |
| 2119 | String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); |
| 2120 | if (packageNames != null) { |
| 2121 | for (String n : packageNames) { |
| 2122 | if (n.equals(packageName)) { |
| 2123 | return true; |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | return false; |
| 2129 | } |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2130 | |
| 2131 | private boolean canProjectVideo(IMediaProjection projection) { |
| 2132 | if (projection != null) { |
| 2133 | try { |
| 2134 | if (projection.canProjectVideo()) { |
| 2135 | return true; |
| 2136 | } |
| 2137 | } catch (RemoteException e) { |
| 2138 | Slog.e(TAG, "Unable to query projection service for permissions", e); |
| 2139 | } |
| 2140 | } |
| 2141 | if (mContext.checkCallingPermission( |
| 2142 | android.Manifest.permission.CAPTURE_VIDEO_OUTPUT) |
Michael Wright | 0ccc2b0 | 2014-07-24 18:20:41 -0700 | [diff] [blame] | 2143 | == PackageManager.PERMISSION_GRANTED) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2144 | return true; |
| 2145 | } |
| 2146 | return canProjectSecureVideo(projection); |
| 2147 | } |
| 2148 | |
| 2149 | private boolean canProjectSecureVideo(IMediaProjection projection) { |
| 2150 | if (projection != null) { |
| 2151 | try { |
| 2152 | if (projection.canProjectSecureVideo()){ |
| 2153 | return true; |
| 2154 | } |
| 2155 | } catch (RemoteException e) { |
| 2156 | Slog.e(TAG, "Unable to query projection service for permissions", e); |
| 2157 | } |
| 2158 | } |
| 2159 | return mContext.checkCallingPermission( |
| 2160 | android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT) |
Michael Wright | 0ccc2b0 | 2014-07-24 18:20:41 -0700 | [diff] [blame] | 2161 | == PackageManager.PERMISSION_GRANTED; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2162 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | private final class LocalService extends DisplayManagerInternal { |
| 2166 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2167 | public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler, |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2168 | SensorManager sensorManager) { |
| 2169 | synchronized (mSyncRoot) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2170 | DisplayBlanker blanker = new DisplayBlanker() { |
| 2171 | @Override |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 2172 | public void requestDisplayState(int state, int brightness) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2173 | // The order of operations is important for legacy reasons. |
| 2174 | if (state == Display.STATE_OFF) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 2175 | requestGlobalDisplayStateInternal(state, brightness); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | callbacks.onDisplayStateChange(state); |
| 2179 | |
| 2180 | if (state != Display.STATE_OFF) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 2181 | requestGlobalDisplayStateInternal(state, brightness); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | }; |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2185 | mDisplayPowerController = new DisplayPowerController( |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2186 | mContext, callbacks, handler, sensorManager, blanker); |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2187 | } |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2188 | |
| 2189 | mHandler.sendEmptyMessage(MSG_LOAD_BRIGHTNESS_CONFIGURATION); |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | @Override |
| 2193 | public boolean requestPowerState(DisplayPowerRequest request, |
| 2194 | boolean waitForNegativeProximity) { |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2195 | synchronized (mSyncRoot) { |
| 2196 | return mDisplayPowerController.requestPowerState(request, |
| 2197 | waitForNegativeProximity); |
| 2198 | } |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | @Override |
| 2202 | public boolean isProximitySensorAvailable() { |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2203 | synchronized (mSyncRoot) { |
| 2204 | return mDisplayPowerController.isProximitySensorAvailable(); |
| 2205 | } |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | @Override |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2209 | public DisplayInfo getDisplayInfo(int displayId) { |
| 2210 | return getDisplayInfoInternal(displayId, Process.myUid()); |
| 2211 | } |
| 2212 | |
| 2213 | @Override |
| 2214 | public void registerDisplayTransactionListener(DisplayTransactionListener listener) { |
| 2215 | if (listener == null) { |
| 2216 | throw new IllegalArgumentException("listener must not be null"); |
| 2217 | } |
| 2218 | |
| 2219 | registerDisplayTransactionListenerInternal(listener); |
| 2220 | } |
| 2221 | |
| 2222 | @Override |
| 2223 | public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) { |
| 2224 | if (listener == null) { |
| 2225 | throw new IllegalArgumentException("listener must not be null"); |
| 2226 | } |
| 2227 | |
| 2228 | unregisterDisplayTransactionListenerInternal(listener); |
| 2229 | } |
| 2230 | |
| 2231 | @Override |
| 2232 | public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) { |
| 2233 | setDisplayInfoOverrideFromWindowManagerInternal(displayId, info); |
| 2234 | } |
| 2235 | |
| 2236 | @Override |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2237 | public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) { |
| 2238 | getNonOverrideDisplayInfoInternal(displayId, outInfo); |
| 2239 | } |
| 2240 | |
| 2241 | @Override |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 2242 | public void performTraversal(SurfaceControl.Transaction t) { |
| 2243 | performTraversalInternal(t); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | @Override |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 2247 | public void setDisplayProperties(int displayId, boolean hasContent, |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 2248 | float requestedRefreshRate, int requestedMode, boolean inTraversal) { |
| 2249 | setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate, |
| 2250 | requestedMode, inTraversal); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2251 | } |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 2252 | |
| 2253 | @Override |
| 2254 | public void setDisplayOffsets(int displayId, int x, int y) { |
| 2255 | setDisplayOffsetsInternal(displayId, x, y); |
| 2256 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2257 | |
| 2258 | @Override |
| 2259 | public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) { |
| 2260 | setDisplayAccessUIDsInternal(newDisplayAccessUIDs); |
| 2261 | } |
| 2262 | |
| 2263 | @Override |
| 2264 | public boolean isUidPresentOnDisplay(int uid, int displayId) { |
| 2265 | return isUidPresentOnDisplayInternal(uid, displayId); |
| 2266 | } |
Kenny Guy | cfe7b70 | 2017-11-14 21:04:58 +0000 | [diff] [blame] | 2267 | |
| 2268 | @Override |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 2269 | public void persistBrightnessTrackerState() { |
Michael Wright | 144aac9 | 2017-12-21 18:37:41 +0000 | [diff] [blame] | 2270 | synchronized (mSyncRoot) { |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 2271 | mDisplayPowerController.persistBrightnessTrackerState(); |
Michael Wright | 144aac9 | 2017-12-21 18:37:41 +0000 | [diff] [blame] | 2272 | } |
Kenny Guy | cfe7b70 | 2017-11-14 21:04:58 +0000 | [diff] [blame] | 2273 | } |
Adrian Roos | e1d68cd | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 2274 | |
| 2275 | @Override |
| 2276 | public void onOverlayChanged() { |
| 2277 | synchronized (mSyncRoot) { |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 2278 | for (int i = 0; i < mDisplayDevices.size(); i++) { |
| 2279 | mDisplayDevices.get(i).onOverlayChangedLocked(); |
Adrian Roos | e1d68cd | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2283 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2284 | } |