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