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