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