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