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