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