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; |
| 20 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; |
| 21 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; |
| 22 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE; |
| 23 | import static android.hardware.display.DisplayManager |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 24 | .VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 25 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 26 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 27 | import com.android.internal.util.DumpUtils; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 28 | import com.android.internal.util.IndentingPrintWriter; |
| 29 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 30 | import android.Manifest; |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.pm.PackageManager; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 34 | import android.content.res.Resources; |
| 35 | import android.graphics.Point; |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 36 | import android.hardware.SensorManager; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 37 | import android.hardware.display.DisplayManagerGlobal; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 38 | import android.hardware.display.DisplayManagerInternal; |
| 39 | import android.hardware.display.DisplayViewport; |
| 40 | import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 41 | import android.hardware.display.IDisplayManager; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 42 | import android.hardware.display.IDisplayManagerCallback; |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 43 | import android.hardware.display.IVirtualDisplayCallback; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 44 | import android.hardware.display.WifiDisplayStatus; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 45 | import android.hardware.input.InputManagerInternal; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 46 | import android.media.projection.IMediaProjection; |
| 47 | import android.media.projection.IMediaProjectionManager; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 48 | import android.os.Binder; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 49 | import android.os.Handler; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 50 | import android.os.IBinder; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 51 | import android.os.IBinder.DeathRecipient; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 52 | import android.os.Looper; |
| 53 | import android.os.Message; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 54 | import android.os.PowerManager; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 55 | import android.os.Process; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 56 | import android.os.RemoteException; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 57 | import android.os.ServiceManager; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 58 | import android.os.SystemClock; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 59 | import android.os.SystemProperties; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 60 | import android.os.Trace; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 61 | import android.text.TextUtils; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 62 | import android.util.IntArray; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 63 | import android.util.Slog; |
| 64 | import android.util.SparseArray; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 65 | import android.view.Display; |
| 66 | import android.view.DisplayInfo; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 67 | import android.view.Surface; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 68 | import android.view.WindowManagerInternal; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 69 | |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 70 | import com.android.server.AnimationThread; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 71 | import com.android.server.DisplayThread; |
| 72 | import com.android.server.LocalServices; |
| 73 | import com.android.server.SystemService; |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 74 | import com.android.server.UiThread; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 75 | |
| 76 | import java.io.FileDescriptor; |
| 77 | import java.io.PrintWriter; |
| 78 | import java.util.ArrayList; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 79 | import java.util.Arrays; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 80 | import java.util.List; |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 81 | import java.util.concurrent.CopyOnWriteArrayList; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 84 | * Manages attached displays. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 85 | * <p> |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 86 | * The {@link DisplayManagerService} manages the global lifecycle of displays, |
| 87 | * decides how to configure logical displays based on the physical display devices currently |
| 88 | * attached, sends notifications to the system and to applications when the state |
| 89 | * changes, and so on. |
| 90 | * </p><p> |
| 91 | * The display manager service relies on a collection of {@link DisplayAdapter} components, |
| 92 | * for discovering and configuring physical display devices attached to the system. |
| 93 | * There are separate display adapters for each manner that devices are attached: |
| 94 | * one display adapter for built-in local displays, one for simulated non-functional |
| 95 | * displays when the system is headless, one for simulated overlay displays used for |
| 96 | * development, one for wifi displays, etc. |
| 97 | * </p><p> |
| 98 | * Display adapters are only weakly coupled to the display manager service. |
| 99 | * Display adapters communicate changes in display device state to the display manager |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 100 | * service asynchronously via a {@link DisplayAdapter.Listener} registered |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 101 | * by the display manager service. This separation of concerns is important for |
| 102 | * two main reasons. First, it neatly encapsulates the responsibilities of these |
| 103 | * two classes: display adapters handle individual display devices whereas |
| 104 | * the display manager service handles the global state. Second, it eliminates |
| 105 | * the potential for deadlocks resulting from asynchronous display device discovery. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 106 | * </p> |
| 107 | * |
| 108 | * <h3>Synchronization</h3> |
| 109 | * <p> |
| 110 | * Because the display manager may be accessed by multiple threads, the synchronization |
| 111 | * story gets a little complicated. In particular, the window manager may call into |
| 112 | * the display manager while holding a surface transaction with the expectation that |
| 113 | * it can apply changes immediately. Unfortunately, that means we can't just do |
| 114 | * everything asynchronously (*grump*). |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 115 | * </p><p> |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 116 | * To make this work, all of the objects that belong to the display manager must |
| 117 | * use the same lock. We call this lock the synchronization root and it has a unique |
| 118 | * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are |
| 119 | * named with the "Locked" suffix. |
| 120 | * </p><p> |
| 121 | * Where things get tricky is that the display manager is not allowed to make |
| 122 | * any potentially reentrant calls, especially into the window manager. We generally |
| 123 | * avoid this by making all potentially reentrant out-calls asynchronous. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 124 | * </p> |
| 125 | */ |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 126 | public final class DisplayManagerService extends SystemService { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 127 | private static final String TAG = "DisplayManagerService"; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 128 | private static final boolean DEBUG = false; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 129 | |
Jeff Brown | bbd28a2 | 2012-09-20 16:47:15 -0700 | [diff] [blame] | 130 | // When this system property is set to 0, WFD is forcibly disabled on boot. |
| 131 | // When this system property is set to 1, WFD is forcibly enabled on boot. |
| 132 | // Otherwise WFD is enabled according to the value of config_enableWifiDisplay. |
| 133 | private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable"; |
| 134 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 135 | private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000; |
| 136 | |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 137 | private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS = 1; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 138 | private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2; |
| 139 | private static final int MSG_DELIVER_DISPLAY_EVENT = 3; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 140 | private static final int MSG_REQUEST_TRAVERSAL = 4; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 141 | private static final int MSG_UPDATE_VIEWPORT = 5; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 142 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 143 | private final Context mContext; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 144 | private final DisplayManagerHandler mHandler; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 145 | private final Handler mUiHandler; |
| 146 | private final DisplayAdapterListener mDisplayAdapterListener; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 147 | private WindowManagerInternal mWindowManagerInternal; |
| 148 | private InputManagerInternal mInputManagerInternal; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 149 | private IMediaProjectionManager mProjectionService; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 150 | |
| 151 | // The synchronization root for the display manager. |
| 152 | // This lock guards most of the display manager's state. |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 153 | // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call |
| 154 | // into WindowManagerService methods that require mWindowMap while holding this unless you are |
| 155 | // very very sure that no deadlock can occur. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 156 | private final SyncRoot mSyncRoot = new SyncRoot(); |
| 157 | |
| 158 | // True if in safe mode. |
| 159 | // This option may disable certain display adapters. |
| 160 | public boolean mSafeMode; |
| 161 | |
| 162 | // True if we are in a special boot mode where only core applications and |
| 163 | // services should be started. This option may disable certain display adapters. |
| 164 | public boolean mOnlyCore; |
| 165 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 166 | // True if the display manager service should pretend there is only one display |
| 167 | // and only tell applications about the existence of the default logical display. |
| 168 | // The display manager can still mirror content to secondary displays but applications |
| 169 | // cannot present unique content on those displays. |
| 170 | // Used for demonstration purposes only. |
| 171 | private final boolean mSingleDisplayDemoMode; |
| 172 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 173 | // All callback records indexed by calling process id. |
| 174 | public final SparseArray<CallbackRecord> mCallbacks = |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 175 | new SparseArray<CallbackRecord>(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 176 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 177 | // List of all currently registered display adapters. |
| 178 | private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>(); |
| 179 | |
| 180 | // List of all currently connected display devices. |
| 181 | private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>(); |
| 182 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 183 | // List of all logical displays indexed by logical display id. |
| 184 | private final SparseArray<LogicalDisplay> mLogicalDisplays = |
| 185 | new SparseArray<LogicalDisplay>(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 186 | private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1; |
| 187 | |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 188 | // List of all display transaction listeners. |
| 189 | private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners = |
| 190 | new CopyOnWriteArrayList<DisplayTransactionListener>(); |
| 191 | |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 192 | // Display power controller. |
| 193 | private DisplayPowerController mDisplayPowerController; |
| 194 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 195 | // The overall display state, independent of changes that might influence one |
| 196 | // display or another in particular. |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 197 | private int mGlobalDisplayState = Display.STATE_ON; |
| 198 | |
| 199 | // The overall display brightness. |
| 200 | // For now, this only applies to the built-in display but we may split it up eventually. |
| 201 | private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT; |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 202 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 203 | // Set to true when there are pending display changes that have yet to be applied |
| 204 | // to the surface flinger state. |
| 205 | private boolean mPendingTraversal; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 206 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 207 | // The Wifi display adapter, or null if not registered. |
| 208 | private WifiDisplayAdapter mWifiDisplayAdapter; |
| 209 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 210 | // The number of active wifi display scan requests. |
| 211 | private int mWifiDisplayScanRequestCount; |
| 212 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 213 | // The virtual display adapter, or null if not registered. |
| 214 | private VirtualDisplayAdapter mVirtualDisplayAdapter; |
| 215 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 216 | // The stable device screen height and width. These are not tied to a specific display, even |
| 217 | // the default display, because they need to be stable over the course of the device's entire |
| 218 | // life, even if the default display changes (e.g. a new monitor is plugged into a PC-like |
| 219 | // device). |
| 220 | private Point mStableDisplaySize = new Point(); |
| 221 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 222 | // Viewports of the default display and the display that should receive touch |
| 223 | // input from an external source. Used by the input system. |
| 224 | private final DisplayViewport mDefaultViewport = new DisplayViewport(); |
| 225 | private final DisplayViewport mExternalTouchViewport = new DisplayViewport(); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 226 | private final ArrayList<DisplayViewport> mVirtualTouchViewports = new ArrayList<>(); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 227 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 228 | // Persistent data store for all internal settings maintained by the display manager service. |
| 229 | private final PersistentDataStore mPersistentDataStore = new PersistentDataStore(); |
| 230 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 231 | // Temporary callback list, used when sending display events to applications. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 232 | // May be used outside of the lock but only on the handler thread. |
| 233 | private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 234 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 235 | // Temporary display info, used for comparing display configurations. |
| 236 | private final DisplayInfo mTempDisplayInfo = new DisplayInfo(); |
| 237 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 238 | // Temporary viewports, used when sending new viewport information to the |
| 239 | // input system. May be used outside of the lock but only on the handler thread. |
| 240 | private final DisplayViewport mTempDefaultViewport = new DisplayViewport(); |
| 241 | private final DisplayViewport mTempExternalTouchViewport = new DisplayViewport(); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 242 | private final ArrayList<DisplayViewport> mTempVirtualTouchViewports = new ArrayList<>(); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 243 | |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 244 | // The default color mode for default displays. Overrides the usual |
| 245 | // Display.Display.COLOR_MODE_DEFAULT for displays with the |
| 246 | // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set. |
| 247 | private final int mDefaultDisplayDefaultColorMode; |
| 248 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 249 | // Temporary list of deferred work to perform when setting the display state. |
| 250 | // Only used by requestDisplayState. The field is self-synchronized and only |
| 251 | // intended for use inside of the requestGlobalDisplayStateInternal function. |
| 252 | private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>(); |
| 253 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 254 | // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs. |
| 255 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 256 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 257 | private final Injector mInjector; |
| 258 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 259 | public DisplayManagerService(Context context) { |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 260 | this(context, new Injector()); |
| 261 | } |
| 262 | |
| 263 | @VisibleForTesting |
| 264 | DisplayManagerService(Context context, Injector injector) { |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 265 | super(context); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 266 | mInjector = injector; |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 267 | mContext = context; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 268 | mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper()); |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 269 | mUiHandler = UiThread.getHandler(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 270 | mDisplayAdapterListener = new DisplayAdapterListener(); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 271 | mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false); |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 272 | mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger( |
| 273 | com.android.internal.R.integer.config_defaultDisplayDefaultColorMode); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 274 | |
| 275 | PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 276 | mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting(); |
Joel Fernandes | 2d314e1 | 2017-04-04 16:32:15 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | public void setupSchedulerPolicies() { |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 280 | // android.display and android.anim is critical to user experience and we should make sure |
| 281 | // it is not in the default foregroup groups, add it to top-app to make sure it uses all the |
| 282 | // cores and scheduling settings for top-app when it runs. |
| 283 | Process.setThreadGroupAndCpuset(DisplayThread.get().getThreadId(), |
| 284 | Process.THREAD_GROUP_TOP_APP); |
| 285 | Process.setThreadGroupAndCpuset(AnimationThread.get().getThreadId(), |
| 286 | Process.THREAD_GROUP_TOP_APP); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 289 | @Override |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 290 | public void onStart() { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 291 | // We need to pre-load the persistent data store so it's ready before the default display |
| 292 | // adapter is up so that we have it's configuration. We could load it lazily, but since |
| 293 | // 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] | 294 | // we've waited for the display to register itself with us. |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 295 | synchronized(mSyncRoot) { |
| 296 | mPersistentDataStore.loadIfNeeded(); |
| 297 | loadStableDisplayValuesLocked(); |
| 298 | } |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 299 | mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 300 | |
| 301 | publishBinderService(Context.DISPLAY_SERVICE, new BinderService(), |
| 302 | true /*allowIsolated*/); |
| 303 | publishLocalService(DisplayManagerInternal.class, new LocalService()); |
Justin Klaassen | 22eb199 | 2016-07-11 20:52:23 -0700 | [diff] [blame] | 304 | publishLocalService(DisplayTransformManager.class, new DisplayTransformManager()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public void onBootPhase(int phase) { |
| 309 | if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) { |
| 310 | synchronized (mSyncRoot) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 311 | long timeout = SystemClock.uptimeMillis() |
| 312 | + mInjector.getDefaultDisplayDelayTimeout(); |
| 313 | while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null || |
| 314 | mVirtualDisplayAdapter == null) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 315 | long delay = timeout - SystemClock.uptimeMillis(); |
| 316 | if (delay <= 0) { |
| 317 | throw new RuntimeException("Timeout waiting for default display " |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 318 | + "to be initialized. DefaultDisplay=" |
| 319 | + mLogicalDisplays.get(Display.DEFAULT_DISPLAY) |
| 320 | + ", mVirtualDisplayAdapter=" + mVirtualDisplayAdapter); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 321 | } |
| 322 | if (DEBUG) { |
| 323 | Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay); |
| 324 | } |
| 325 | try { |
| 326 | mSyncRoot.wait(delay); |
| 327 | } catch (InterruptedException ex) { |
| 328 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 334 | // TODO: Use dependencies or a boot phase |
| 335 | public void windowManagerAndInputReady() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 336 | synchronized (mSyncRoot) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 337 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
| 338 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 339 | scheduleTraversalLocked(false); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
| 343 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 344 | * Called when the system is ready to go. |
| 345 | */ |
| 346 | public void systemReady(boolean safeMode, boolean onlyCore) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 347 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 348 | mSafeMode = safeMode; |
| 349 | mOnlyCore = onlyCore; |
| 350 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 351 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 352 | mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS); |
| 353 | } |
| 354 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 355 | @VisibleForTesting |
| 356 | Handler getDisplayHandler() { |
| 357 | return mHandler; |
| 358 | } |
| 359 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 360 | private void loadStableDisplayValuesLocked() { |
| 361 | final Point size = mPersistentDataStore.getStableDisplaySize(); |
| 362 | if (size.x > 0 && size.y > 0) { |
| 363 | // Just set these values directly so we don't write the display persistent data again |
| 364 | // unnecessarily |
| 365 | mStableDisplaySize.set(size.x, size.y); |
| 366 | } else { |
| 367 | final Resources res = mContext.getResources(); |
| 368 | final int width = res.getInteger( |
| 369 | com.android.internal.R.integer.config_stableDeviceDisplayWidth); |
| 370 | final int height = res.getInteger( |
| 371 | com.android.internal.R.integer.config_stableDeviceDisplayHeight); |
| 372 | if (width > 0 && height > 0) { |
| 373 | setStableDisplaySizeLocked(width, height); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | private Point getStableDisplaySizeInternal() { |
| 379 | Point r = new Point(); |
| 380 | synchronized (mSyncRoot) { |
| 381 | if (mStableDisplaySize.x > 0 && mStableDisplaySize.y > 0) { |
| 382 | r.set(mStableDisplaySize.x, mStableDisplaySize.y); |
| 383 | } |
| 384 | } |
| 385 | return r; |
| 386 | } |
| 387 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 388 | private void registerDisplayTransactionListenerInternal( |
| 389 | DisplayTransactionListener listener) { |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 390 | // List is self-synchronized copy-on-write. |
| 391 | mDisplayTransactionListeners.add(listener); |
| 392 | } |
| 393 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 394 | private void unregisterDisplayTransactionListenerInternal( |
| 395 | DisplayTransactionListener listener) { |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 396 | // List is self-synchronized copy-on-write. |
| 397 | mDisplayTransactionListeners.remove(listener); |
| 398 | } |
| 399 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 400 | private void setDisplayInfoOverrideFromWindowManagerInternal( |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 401 | int displayId, DisplayInfo info) { |
| 402 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 403 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 404 | if (display != null) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 405 | if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 406 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 407 | scheduleTraversalLocked(false); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 408 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 413 | /** |
| 414 | * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo) |
| 415 | */ |
| 416 | private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) { |
| 417 | synchronized (mSyncRoot) { |
| 418 | final LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 419 | if (display != null) { |
| 420 | display.getNonOverrideDisplayInfoLocked(outInfo); |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 425 | @VisibleForTesting |
| 426 | void performTraversalInTransactionFromWindowManagerInternal() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 427 | synchronized (mSyncRoot) { |
| 428 | if (!mPendingTraversal) { |
| 429 | return; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 430 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 431 | mPendingTraversal = false; |
| 432 | |
| 433 | performTraversalInTransactionLocked(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 434 | } |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 435 | |
| 436 | // List is self-synchronized copy-on-write. |
| 437 | for (DisplayTransactionListener listener : mDisplayTransactionListeners) { |
| 438 | listener.onDisplayTransaction(); |
| 439 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 442 | private void requestGlobalDisplayStateInternal(int state, int brightness) { |
| 443 | if (state == Display.STATE_UNKNOWN) { |
| 444 | state = Display.STATE_ON; |
| 445 | } |
| 446 | if (state == Display.STATE_OFF) { |
| 447 | brightness = PowerManager.BRIGHTNESS_OFF; |
| 448 | } else if (brightness < 0) { |
| 449 | brightness = PowerManager.BRIGHTNESS_DEFAULT; |
| 450 | } else if (brightness > PowerManager.BRIGHTNESS_ON) { |
| 451 | brightness = PowerManager.BRIGHTNESS_ON; |
| 452 | } |
| 453 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 454 | synchronized (mTempDisplayStateWorkQueue) { |
| 455 | try { |
| 456 | // Update the display state within the lock. |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 457 | // Note that we do not need to schedule traversals here although it |
| 458 | // may happen as a side-effect of displays changing state. |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 459 | synchronized (mSyncRoot) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 460 | if (mGlobalDisplayState == state |
| 461 | && mGlobalDisplayBrightness == brightness) { |
| 462 | return; // no change |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 463 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 464 | |
| 465 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState(" |
| 466 | + Display.stateToString(state) |
| 467 | + ", brightness=" + brightness + ")"); |
| 468 | mGlobalDisplayState = state; |
| 469 | mGlobalDisplayBrightness = brightness; |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 470 | applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | // Setting the display power state can take hundreds of milliseconds |
| 474 | // to complete so we defer the most expensive part of the work until |
| 475 | // after we have exited the critical section to avoid blocking other |
| 476 | // threads for a long time. |
| 477 | for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) { |
| 478 | mTempDisplayStateWorkQueue.get(i).run(); |
| 479 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 480 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 481 | } finally { |
| 482 | mTempDisplayStateWorkQueue.clear(); |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 487 | private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 488 | synchronized (mSyncRoot) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 489 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 490 | if (display != null) { |
| 491 | DisplayInfo info = display.getDisplayInfoLocked(); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 492 | if (info.hasAccess(callingUid) |
| 493 | || isUidPresentOnDisplayInternal(callingUid, displayId)) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 494 | return info; |
| 495 | } |
| 496 | } |
| 497 | return null; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | private int[] getDisplayIdsInternal(int callingUid) { |
| 502 | synchronized (mSyncRoot) { |
| 503 | final int count = mLogicalDisplays.size(); |
| 504 | int[] displayIds = new int[count]; |
| 505 | int n = 0; |
| 506 | for (int i = 0; i < count; i++) { |
| 507 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 508 | DisplayInfo info = display.getDisplayInfoLocked(); |
| 509 | if (info.hasAccess(callingUid)) { |
| 510 | displayIds[n++] = mLogicalDisplays.keyAt(i); |
| 511 | } |
| 512 | } |
| 513 | if (n != count) { |
| 514 | displayIds = Arrays.copyOfRange(displayIds, 0, n); |
| 515 | } |
| 516 | return displayIds; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) { |
| 521 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 522 | if (mCallbacks.get(callingPid) != null) { |
| 523 | throw new SecurityException("The calling process has already " |
| 524 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 527 | CallbackRecord record = new CallbackRecord(callingPid, callback); |
| 528 | try { |
| 529 | IBinder binder = callback.asBinder(); |
| 530 | binder.linkToDeath(record, 0); |
| 531 | } catch (RemoteException ex) { |
| 532 | // give up |
| 533 | throw new RuntimeException(ex); |
| 534 | } |
| 535 | |
| 536 | mCallbacks.put(callingPid, record); |
| 537 | } |
| 538 | } |
| 539 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 540 | private void onCallbackDied(CallbackRecord record) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 541 | synchronized (mSyncRoot) { |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 542 | mCallbacks.remove(record.mPid); |
| 543 | stopWifiDisplayScanLocked(record); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 547 | private void startWifiDisplayScanInternal(int callingPid) { |
| 548 | synchronized (mSyncRoot) { |
| 549 | CallbackRecord record = mCallbacks.get(callingPid); |
| 550 | if (record == null) { |
| 551 | throw new IllegalStateException("The calling process has not " |
| 552 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 553 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 554 | startWifiDisplayScanLocked(record); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 558 | private void startWifiDisplayScanLocked(CallbackRecord record) { |
| 559 | if (!record.mWifiDisplayScanRequested) { |
| 560 | record.mWifiDisplayScanRequested = true; |
| 561 | if (mWifiDisplayScanRequestCount++ == 0) { |
| 562 | if (mWifiDisplayAdapter != null) { |
| 563 | mWifiDisplayAdapter.requestStartScanLocked(); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 569 | private void stopWifiDisplayScanInternal(int callingPid) { |
| 570 | synchronized (mSyncRoot) { |
| 571 | CallbackRecord record = mCallbacks.get(callingPid); |
| 572 | if (record == null) { |
| 573 | throw new IllegalStateException("The calling process has not " |
| 574 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 575 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 576 | stopWifiDisplayScanLocked(record); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
| 580 | private void stopWifiDisplayScanLocked(CallbackRecord record) { |
| 581 | if (record.mWifiDisplayScanRequested) { |
| 582 | record.mWifiDisplayScanRequested = false; |
| 583 | if (--mWifiDisplayScanRequestCount == 0) { |
| 584 | if (mWifiDisplayAdapter != null) { |
| 585 | mWifiDisplayAdapter.requestStopScanLocked(); |
| 586 | } |
| 587 | } else if (mWifiDisplayScanRequestCount < 0) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 588 | Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: " |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 589 | + mWifiDisplayScanRequestCount); |
| 590 | mWifiDisplayScanRequestCount = 0; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 595 | private void connectWifiDisplayInternal(String address) { |
| 596 | synchronized (mSyncRoot) { |
| 597 | if (mWifiDisplayAdapter != null) { |
| 598 | mWifiDisplayAdapter.requestConnectLocked(address); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 599 | } |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 603 | private void pauseWifiDisplayInternal() { |
| 604 | synchronized (mSyncRoot) { |
| 605 | if (mWifiDisplayAdapter != null) { |
| 606 | mWifiDisplayAdapter.requestPauseLocked(); |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 607 | } |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 611 | private void resumeWifiDisplayInternal() { |
| 612 | synchronized (mSyncRoot) { |
| 613 | if (mWifiDisplayAdapter != null) { |
| 614 | mWifiDisplayAdapter.requestResumeLocked(); |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 615 | } |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 619 | private void disconnectWifiDisplayInternal() { |
| 620 | synchronized (mSyncRoot) { |
| 621 | if (mWifiDisplayAdapter != null) { |
| 622 | mWifiDisplayAdapter.requestDisconnectLocked(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 623 | } |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 627 | private void renameWifiDisplayInternal(String address, String alias) { |
| 628 | synchronized (mSyncRoot) { |
| 629 | if (mWifiDisplayAdapter != null) { |
| 630 | mWifiDisplayAdapter.requestRenameLocked(address, alias); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 631 | } |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 635 | private void forgetWifiDisplayInternal(String address) { |
| 636 | synchronized (mSyncRoot) { |
| 637 | if (mWifiDisplayAdapter != null) { |
| 638 | mWifiDisplayAdapter.requestForgetLocked(address); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 639 | } |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 643 | private WifiDisplayStatus getWifiDisplayStatusInternal() { |
| 644 | synchronized (mSyncRoot) { |
| 645 | if (mWifiDisplayAdapter != null) { |
| 646 | return mWifiDisplayAdapter.getWifiDisplayStatusLocked(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 647 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 648 | return new WifiDisplayStatus(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 652 | private void requestColorModeInternal(int displayId, int colorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 653 | synchronized (mSyncRoot) { |
| 654 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 655 | if (display != null && |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 656 | display.getRequestedColorModeLocked() != colorMode) { |
| 657 | display.setRequestedColorModeLocked(colorMode); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 658 | scheduleTraversalLocked(false); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 663 | private int createVirtualDisplayInternal(IVirtualDisplayCallback callback, |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 664 | IMediaProjection projection, int callingUid, String packageName, String name, int width, |
| 665 | int height, int densityDpi, Surface surface, int flags, String uniqueId) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 666 | synchronized (mSyncRoot) { |
| 667 | if (mVirtualDisplayAdapter == null) { |
| 668 | Slog.w(TAG, "Rejecting request to create private virtual display " |
| 669 | + "because the virtual display adapter is not available."); |
| 670 | return -1; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 671 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 672 | |
| 673 | DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked( |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 674 | callback, projection, callingUid, packageName, name, width, height, densityDpi, |
| 675 | surface, flags, uniqueId); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 676 | if (device == null) { |
| 677 | return -1; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 678 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 679 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 680 | handleDisplayDeviceAddedLocked(device); |
| 681 | LogicalDisplay display = findLogicalDisplayForDeviceLocked(device); |
| 682 | if (display != null) { |
| 683 | return display.getDisplayIdLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 684 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 685 | |
| 686 | // Something weird happened and the logical display was not created. |
| 687 | Slog.w(TAG, "Rejecting request to create virtual display " |
| 688 | + "because the logical display was not created."); |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 689 | mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 690 | handleDisplayDeviceRemovedLocked(device); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 691 | } |
| 692 | return -1; |
| 693 | } |
| 694 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 695 | private void resizeVirtualDisplayInternal(IBinder appToken, |
| 696 | int width, int height, int densityDpi) { |
| 697 | synchronized (mSyncRoot) { |
| 698 | if (mVirtualDisplayAdapter == null) { |
| 699 | return; |
| 700 | } |
| 701 | |
| 702 | mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi); |
| 703 | } |
| 704 | } |
| 705 | |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 706 | private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) { |
| 707 | synchronized (mSyncRoot) { |
| 708 | if (mVirtualDisplayAdapter == null) { |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface); |
| 713 | } |
| 714 | } |
| 715 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 716 | private void releaseVirtualDisplayInternal(IBinder appToken) { |
| 717 | synchronized (mSyncRoot) { |
| 718 | if (mVirtualDisplayAdapter == null) { |
| 719 | return; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 720 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 721 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 722 | DisplayDevice device = |
| 723 | mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken); |
| 724 | if (device != null) { |
| 725 | handleDisplayDeviceRemovedLocked(device); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 730 | private void registerDefaultDisplayAdapters() { |
| 731 | // Register default display adapters. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 732 | synchronized (mSyncRoot) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 733 | // main display adapter |
Mike Lockwood | e63f6f7 | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 734 | registerDisplayAdapterLocked(new LocalDisplayAdapter( |
| 735 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener)); |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 736 | |
| 737 | // Standalone VR devices rely on a virtual display as their primary display for |
| 738 | // 2D UI. We register virtual display adapter along side the main display adapter |
| 739 | // here so that it is ready by the time the system sends the home Intent for |
| 740 | // early apps like SetupWizard/Launcher. In particular, SUW is displayed using |
| 741 | // the virtual display inside VR before any VR-specific apps even run. |
| 742 | mVirtualDisplayAdapter = mInjector.getVirtualDisplayAdapter(mSyncRoot, mContext, |
| 743 | mHandler, mDisplayAdapterListener); |
| 744 | if (mVirtualDisplayAdapter != null) { |
| 745 | registerDisplayAdapterLocked(mVirtualDisplayAdapter); |
| 746 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
| 750 | private void registerAdditionalDisplayAdapters() { |
| 751 | synchronized (mSyncRoot) { |
| 752 | if (shouldRegisterNonEssentialDisplayAdaptersLocked()) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 753 | registerOverlayDisplayAdapterLocked(); |
| 754 | registerWifiDisplayAdapterLocked(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | } |
| 758 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 759 | private void registerOverlayDisplayAdapterLocked() { |
| 760 | registerDisplayAdapterLocked(new OverlayDisplayAdapter( |
| 761 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler)); |
| 762 | } |
| 763 | |
| 764 | private void registerWifiDisplayAdapterLocked() { |
| 765 | if (mContext.getResources().getBoolean( |
Jeff Brown | bbd28a2 | 2012-09-20 16:47:15 -0700 | [diff] [blame] | 766 | com.android.internal.R.bool.config_enableWifiDisplay) |
| 767 | || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 768 | mWifiDisplayAdapter = new WifiDisplayAdapter( |
| 769 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener, |
| 770 | mPersistentDataStore); |
| 771 | registerDisplayAdapterLocked(mWifiDisplayAdapter); |
| 772 | } |
| 773 | } |
| 774 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 775 | private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() { |
| 776 | // In safe mode, we disable non-essential display adapters to give the user |
| 777 | // an opportunity to fix broken settings or other problems that might affect |
| 778 | // system stability. |
| 779 | // In only-core mode, we disable non-essential display adapters to minimize |
| 780 | // the number of dependencies that are started while in this mode and to |
| 781 | // prevent problems that might occur due to the device being encrypted. |
| 782 | return !mSafeMode && !mOnlyCore; |
| 783 | } |
| 784 | |
| 785 | private void registerDisplayAdapterLocked(DisplayAdapter adapter) { |
| 786 | mDisplayAdapters.add(adapter); |
| 787 | adapter.registerLocked(); |
| 788 | } |
| 789 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 790 | private void handleDisplayDeviceAdded(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 791 | synchronized (mSyncRoot) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 792 | handleDisplayDeviceAddedLocked(device); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 796 | private void handleDisplayDeviceAddedLocked(DisplayDevice device) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 797 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 798 | if (mDisplayDevices.contains(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 799 | Slog.w(TAG, "Attempted to add already added display device: " + info); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 800 | return; |
| 801 | } |
| 802 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 803 | Slog.i(TAG, "Display device added: " + info); |
| 804 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 805 | |
| 806 | mDisplayDevices.add(device); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 807 | LogicalDisplay display = addLogicalDisplayLocked(device); |
Jeff Brown | 0033a86 | 2014-10-08 12:06:39 -0700 | [diff] [blame] | 808 | Runnable work = updateDisplayStateLocked(device); |
| 809 | if (work != null) { |
| 810 | work.run(); |
| 811 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 812 | scheduleTraversalLocked(false); |
| 813 | } |
| 814 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 815 | private void handleDisplayDeviceChanged(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 816 | synchronized (mSyncRoot) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 817 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 818 | if (!mDisplayDevices.contains(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 819 | Slog.w(TAG, "Attempted to change non-existent display device: " + info); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 820 | return; |
| 821 | } |
| 822 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 823 | int diff = device.mDebugLastLoggedDeviceInfo.diff(info); |
| 824 | if (diff == DisplayDeviceInfo.DIFF_STATE) { |
| 825 | Slog.i(TAG, "Display device changed state: \"" + info.name |
| 826 | + "\", " + Display.stateToString(info.state)); |
| 827 | } else if (diff != 0) { |
| 828 | Slog.i(TAG, "Display device changed: " + info); |
| 829 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 830 | if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) { |
| 831 | try { |
| 832 | mPersistentDataStore.setColorMode(device, info.colorMode); |
| 833 | } finally { |
| 834 | mPersistentDataStore.saveIfNeeded(); |
| 835 | } |
| 836 | } |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 837 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 838 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 839 | device.applyPendingDisplayDeviceInfoChangesLocked(); |
| 840 | if (updateLogicalDisplaysLocked()) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 841 | scheduleTraversalLocked(false); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 846 | private void handleDisplayDeviceRemoved(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 847 | synchronized (mSyncRoot) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 848 | handleDisplayDeviceRemovedLocked(device); |
| 849 | } |
| 850 | } |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 851 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 852 | private void handleDisplayDeviceRemovedLocked(DisplayDevice device) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 853 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 854 | if (!mDisplayDevices.remove(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 855 | Slog.w(TAG, "Attempted to remove non-existent display device: " + info); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 856 | return; |
| 857 | } |
| 858 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 859 | Slog.i(TAG, "Display device removed: " + info); |
| 860 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 861 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 862 | updateLogicalDisplaysLocked(); |
| 863 | scheduleTraversalLocked(false); |
| 864 | } |
| 865 | |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 866 | private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 867 | final int count = mDisplayDevices.size(); |
| 868 | for (int i = 0; i < count; i++) { |
| 869 | DisplayDevice device = mDisplayDevices.get(i); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 870 | Runnable runnable = updateDisplayStateLocked(device); |
| 871 | if (runnable != null) { |
| 872 | workQueue.add(runnable); |
| 873 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 877 | private Runnable updateDisplayStateLocked(DisplayDevice device) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 878 | // Blank or unblank the display immediately to match the state requested |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 879 | // by the display power controller (if known). |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 880 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
| 881 | if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 882 | return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 883 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 884 | return null; |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 887 | // Adds a new logical display based on the given display device. |
| 888 | // Sends notifications if needed. |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 889 | private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 890 | DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked(); |
| 891 | boolean isDefault = (deviceInfo.flags |
| 892 | & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0; |
| 893 | if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) { |
| 894 | Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo); |
| 895 | isDefault = false; |
| 896 | } |
| 897 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 898 | if (!isDefault && mSingleDisplayDemoMode) { |
| 899 | Slog.i(TAG, "Not creating a logical display for a secondary display " |
| 900 | + " because single display demo mode is enabled: " + deviceInfo); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 901 | return null; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 904 | final int displayId = assignDisplayIdLocked(isDefault); |
| 905 | final int layerStack = assignLayerStackLocked(displayId); |
| 906 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 907 | LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 908 | display.updateLocked(mDisplayDevices); |
| 909 | if (!display.isValidLocked()) { |
| 910 | // This should never happen currently. |
| 911 | Slog.w(TAG, "Ignoring display device because the logical display " |
| 912 | + "created from it was not considered valid: " + deviceInfo); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 913 | return null; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 916 | configureColorModeLocked(display, device); |
| 917 | if (isDefault) { |
| 918 | recordStableDisplayStatsIfNeededLocked(display); |
| 919 | } |
| 920 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 921 | mLogicalDisplays.put(displayId, display); |
| 922 | |
| 923 | // Wake up waitForDefaultDisplay. |
| 924 | if (isDefault) { |
| 925 | mSyncRoot.notifyAll(); |
| 926 | } |
| 927 | |
| 928 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 929 | return display; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | private int assignDisplayIdLocked(boolean isDefault) { |
| 933 | return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++; |
| 934 | } |
| 935 | |
| 936 | private int assignLayerStackLocked(int displayId) { |
| 937 | // Currently layer stacks and display ids are the same. |
| 938 | // This need not be the case. |
| 939 | return displayId; |
| 940 | } |
| 941 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 942 | private void configureColorModeLocked(LogicalDisplay display, DisplayDevice device) { |
| 943 | if (display.getPrimaryDisplayDeviceLocked() == device) { |
| 944 | int colorMode = mPersistentDataStore.getColorMode(device); |
| 945 | if (colorMode == Display.COLOR_MODE_INVALID) { |
| 946 | if ((device.getDisplayDeviceInfoLocked().flags |
| 947 | & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) { |
| 948 | colorMode = mDefaultDisplayDefaultColorMode; |
| 949 | } else { |
| 950 | colorMode = Display.COLOR_MODE_DEFAULT; |
| 951 | } |
| 952 | } |
| 953 | display.setRequestedColorModeLocked(colorMode); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | // If we've never recorded stable device stats for this device before and they aren't |
| 958 | // explicitly configured, go ahead and record the stable device stats now based on the status |
| 959 | // of the default display at first boot. |
| 960 | private void recordStableDisplayStatsIfNeededLocked(LogicalDisplay d) { |
| 961 | if (mStableDisplaySize.x <= 0 && mStableDisplaySize.y <= 0) { |
| 962 | DisplayInfo info = d.getDisplayInfoLocked(); |
| 963 | setStableDisplaySizeLocked(info.getNaturalWidth(), info.getNaturalHeight()); |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | private void setStableDisplaySizeLocked(int width, int height) { |
| 968 | mStableDisplaySize = new Point(width, height); |
| 969 | try { |
| 970 | mPersistentDataStore.setStableDisplaySize(mStableDisplaySize); |
| 971 | } finally { |
| 972 | mPersistentDataStore.saveIfNeeded(); |
| 973 | } |
| 974 | } |
| 975 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 976 | // Updates all existing logical displays given the current set of display devices. |
| 977 | // Removes invalid logical displays. |
| 978 | // Sends notifications if needed. |
| 979 | private boolean updateLogicalDisplaysLocked() { |
| 980 | boolean changed = false; |
| 981 | for (int i = mLogicalDisplays.size(); i-- > 0; ) { |
| 982 | final int displayId = mLogicalDisplays.keyAt(i); |
| 983 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 984 | |
| 985 | mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked()); |
| 986 | display.updateLocked(mDisplayDevices); |
| 987 | if (!display.isValidLocked()) { |
| 988 | mLogicalDisplays.removeAt(i); |
| 989 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED); |
| 990 | changed = true; |
| 991 | } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) { |
| 992 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED); |
| 993 | changed = true; |
| 994 | } |
| 995 | } |
| 996 | return changed; |
| 997 | } |
| 998 | |
| 999 | private void performTraversalInTransactionLocked() { |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1000 | // Clear all viewports before configuring displays so that we can keep |
| 1001 | // track of which ones we have configured. |
| 1002 | clearViewportsLocked(); |
| 1003 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1004 | // Configure each display device. |
| 1005 | final int count = mDisplayDevices.size(); |
| 1006 | for (int i = 0; i < count; i++) { |
| 1007 | DisplayDevice device = mDisplayDevices.get(i); |
| 1008 | configureDisplayInTransactionLocked(device); |
| 1009 | device.performTraversalInTransactionLocked(); |
| 1010 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1011 | |
| 1012 | // Tell the input system about these new viewports. |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1013 | if (mInputManagerInternal != null) { |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1014 | mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT); |
| 1015 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1018 | private void setDisplayPropertiesInternal(int displayId, boolean hasContent, |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1019 | float requestedRefreshRate, int requestedModeId, boolean inTraversal) { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1020 | synchronized (mSyncRoot) { |
| 1021 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1022 | if (display == null) { |
| 1023 | return; |
| 1024 | } |
| 1025 | if (display.hasContentLocked() != hasContent) { |
Jeff Brown | 33041bd | 2013-08-02 21:11:14 -0700 | [diff] [blame] | 1026 | if (DEBUG) { |
| 1027 | Slog.d(TAG, "Display " + displayId + " hasContent flag changed: " |
| 1028 | + "hasContent=" + hasContent + ", inTraversal=" + inTraversal); |
| 1029 | } |
| 1030 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1031 | display.setHasContentLocked(hasContent); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1032 | scheduleTraversalLocked(inTraversal); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1033 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1034 | if (requestedModeId == 0 && requestedRefreshRate != 0) { |
| 1035 | // Scan supported modes returned by display.getInfo() to find a mode with the same |
| 1036 | // size as the default display mode but with the specified refresh rate instead. |
| 1037 | requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate( |
| 1038 | requestedRefreshRate); |
| 1039 | } |
| 1040 | if (display.getRequestedModeIdLocked() != requestedModeId) { |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1041 | if (DEBUG) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1042 | Slog.d(TAG, "Display " + displayId + " switching to mode " + requestedModeId); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1043 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1044 | display.setRequestedModeIdLocked(requestedModeId); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1045 | scheduleTraversalLocked(inTraversal); |
| 1046 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1047 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1048 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1049 | |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 1050 | private void setDisplayOffsetsInternal(int displayId, int x, int y) { |
| 1051 | synchronized (mSyncRoot) { |
| 1052 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1053 | if (display == null) { |
| 1054 | return; |
| 1055 | } |
| 1056 | if (display.getDisplayOffsetXLocked() != x |
| 1057 | || display.getDisplayOffsetYLocked() != y) { |
| 1058 | if (DEBUG) { |
| 1059 | Slog.d(TAG, "Display " + displayId + " burn-in offset set to (" |
| 1060 | + x + ", " + y + ")"); |
| 1061 | } |
| 1062 | display.setDisplayOffsetsLocked(x, y); |
| 1063 | scheduleTraversalLocked(false); |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1068 | // Updates the lists of UIDs that are present on displays. |
| 1069 | private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) { |
| 1070 | synchronized (mSyncRoot) { |
| 1071 | mDisplayAccessUIDs.clear(); |
| 1072 | for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) { |
| 1073 | mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i), |
| 1074 | newDisplayAccessUIDs.valueAt(i)); |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | // Checks if provided UID's content is present on the display and UID has access to it. |
| 1080 | private boolean isUidPresentOnDisplayInternal(int uid, int displayId) { |
| 1081 | synchronized (mSyncRoot) { |
| 1082 | final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId); |
| 1083 | return displayUIDs != null && displayUIDs.indexOf(uid) != -1; |
| 1084 | } |
| 1085 | } |
| 1086 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1087 | private void clearViewportsLocked() { |
| 1088 | mDefaultViewport.valid = false; |
| 1089 | mExternalTouchViewport.valid = false; |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1090 | mVirtualTouchViewports.clear(); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | private void configureDisplayInTransactionLocked(DisplayDevice device) { |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1094 | final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
| 1095 | final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1096 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1097 | // Find the logical display that the display device is showing. |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1098 | // Certain displays only ever show their own content. |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1099 | LogicalDisplay display = findLogicalDisplayForDeviceLocked(device); |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1100 | if (!ownContent) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1101 | if (display != null && !display.hasContentLocked()) { |
| 1102 | // If the display does not have any content of its own, then |
| 1103 | // automatically mirror the default logical display contents. |
| 1104 | display = null; |
| 1105 | } |
| 1106 | if (display == null) { |
| 1107 | display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY); |
| 1108 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | // Apply the logical display configuration to the display device. |
| 1112 | if (display == null) { |
| 1113 | // TODO: no logical display for the device, blank it |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1114 | Slog.w(TAG, "Missing logical display to use for physical display device: " |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1115 | + device.getDisplayDeviceInfoLocked()); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1116 | return; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1117 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1118 | display.configureDisplayInTransactionLocked(device, info.state == Display.STATE_OFF); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1119 | |
| 1120 | // Update the viewports if needed. |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1121 | if (!mDefaultViewport.valid |
| 1122 | && (info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) { |
| 1123 | setViewportLocked(mDefaultViewport, display, device); |
| 1124 | } |
| 1125 | if (!mExternalTouchViewport.valid |
| 1126 | && info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) { |
| 1127 | setViewportLocked(mExternalTouchViewport, display, device); |
| 1128 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1129 | |
| 1130 | if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL && !TextUtils.isEmpty(info.uniqueId)) { |
| 1131 | final DisplayViewport viewport = getVirtualTouchViewportLocked(info.uniqueId); |
| 1132 | setViewportLocked(viewport, display, device); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /** Gets the virtual device viewport or creates it if not yet created. */ |
| 1137 | private DisplayViewport getVirtualTouchViewportLocked(@NonNull String uniqueId) { |
| 1138 | DisplayViewport viewport; |
| 1139 | final int count = mVirtualTouchViewports.size(); |
| 1140 | for (int i = 0; i < count; i++) { |
| 1141 | viewport = mVirtualTouchViewports.get(i); |
| 1142 | if (uniqueId.equals(viewport.uniqueId)) { |
| 1143 | return viewport; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | viewport = new DisplayViewport(); |
| 1148 | viewport.uniqueId = uniqueId; |
| 1149 | mVirtualTouchViewports.add(viewport); |
| 1150 | return viewport; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | private static void setViewportLocked(DisplayViewport viewport, |
| 1154 | LogicalDisplay display, DisplayDevice device) { |
| 1155 | viewport.valid = true; |
| 1156 | viewport.displayId = display.getDisplayIdLocked(); |
| 1157 | device.populateViewportLocked(viewport); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) { |
| 1161 | final int count = mLogicalDisplays.size(); |
| 1162 | for (int i = 0; i < count; i++) { |
| 1163 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1164 | if (display.getPrimaryDisplayDeviceLocked() == device) { |
| 1165 | return display; |
| 1166 | } |
| 1167 | } |
| 1168 | return null; |
| 1169 | } |
| 1170 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1171 | private void sendDisplayEventLocked(int displayId, int event) { |
| 1172 | Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event); |
| 1173 | mHandler.sendMessage(msg); |
| 1174 | } |
| 1175 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1176 | // Requests that performTraversalsInTransactionFromWindowManager be called at a |
| 1177 | // later time to apply changes to surfaces and displays. |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1178 | private void scheduleTraversalLocked(boolean inTraversal) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1179 | if (!mPendingTraversal && mWindowManagerInternal != null) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1180 | mPendingTraversal = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1181 | if (!inTraversal) { |
| 1182 | mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL); |
| 1183 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | // Runs on Handler thread. |
| 1188 | // Delivers display event notifications to callbacks. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1189 | private void deliverDisplayEvent(int displayId, int event) { |
| 1190 | if (DEBUG) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1191 | Slog.d(TAG, "Delivering display event: displayId=" |
| 1192 | + displayId + ", event=" + event); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1193 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1194 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1195 | // Grab the lock and copy the callbacks. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1196 | final int count; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1197 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1198 | count = mCallbacks.size(); |
| 1199 | mTempCallbacks.clear(); |
| 1200 | for (int i = 0; i < count; i++) { |
| 1201 | mTempCallbacks.add(mCallbacks.valueAt(i)); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1202 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1203 | } |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1204 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1205 | // After releasing the lock, send the notifications out. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1206 | for (int i = 0; i < count; i++) { |
| 1207 | mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event); |
| 1208 | } |
| 1209 | mTempCallbacks.clear(); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1212 | private IMediaProjectionManager getProjectionService() { |
| 1213 | if (mProjectionService == null) { |
| 1214 | IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE); |
| 1215 | mProjectionService = IMediaProjectionManager.Stub.asInterface(b); |
| 1216 | } |
| 1217 | return mProjectionService; |
| 1218 | } |
| 1219 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1220 | private void dumpInternal(PrintWriter pw) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1221 | pw.println("DISPLAY MANAGER (dumpsys display)"); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1222 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1223 | synchronized (mSyncRoot) { |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1224 | pw.println(" mOnlyCode=" + mOnlyCore); |
| 1225 | pw.println(" mSafeMode=" + mSafeMode); |
| 1226 | pw.println(" mPendingTraversal=" + mPendingTraversal); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1227 | pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState)); |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1228 | pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId); |
| 1229 | pw.println(" mDefaultViewport=" + mDefaultViewport); |
| 1230 | pw.println(" mExternalTouchViewport=" + mExternalTouchViewport); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1231 | pw.println(" mVirtualTouchViewports=" + mVirtualTouchViewports); |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 1232 | pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1233 | pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1234 | pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount); |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1235 | pw.println(" mStableDisplaySize=" + mStableDisplaySize); |
| 1236 | |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1237 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1238 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1239 | ipw.increaseIndent(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1240 | |
| 1241 | pw.println(); |
| 1242 | pw.println("Display Adapters: size=" + mDisplayAdapters.size()); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1243 | for (DisplayAdapter adapter : mDisplayAdapters) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1244 | pw.println(" " + adapter.getName()); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1245 | adapter.dumpLocked(ipw); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1246 | } |
Craig Mautner | 9de4936 | 2012-08-02 14:30:30 -0700 | [diff] [blame] | 1247 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1248 | pw.println(); |
| 1249 | pw.println("Display Devices: size=" + mDisplayDevices.size()); |
| 1250 | for (DisplayDevice device : mDisplayDevices) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1251 | pw.println(" " + device.getDisplayDeviceInfoLocked()); |
| 1252 | device.dumpLocked(ipw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | final int logicalDisplayCount = mLogicalDisplays.size(); |
| 1256 | pw.println(); |
| 1257 | pw.println("Logical Displays: size=" + logicalDisplayCount); |
| 1258 | for (int i = 0; i < logicalDisplayCount; i++) { |
| 1259 | int displayId = mLogicalDisplays.keyAt(i); |
| 1260 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1261 | pw.println(" Display " + displayId + ":"); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1262 | display.dumpLocked(ipw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1263 | } |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1264 | |
| 1265 | final int callbackCount = mCallbacks.size(); |
| 1266 | pw.println(); |
| 1267 | pw.println("Callbacks: size=" + callbackCount); |
| 1268 | for (int i = 0; i < callbackCount; i++) { |
| 1269 | CallbackRecord callback = mCallbacks.valueAt(i); |
| 1270 | pw.println(" " + i + ": mPid=" + callback.mPid |
| 1271 | + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested); |
| 1272 | } |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 1273 | |
| 1274 | if (mDisplayPowerController != null) { |
| 1275 | mDisplayPowerController.dump(pw); |
| 1276 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1277 | |
| 1278 | pw.println(); |
| 1279 | mPersistentDataStore.dump(pw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1280 | } |
| 1281 | } |
| 1282 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1283 | /** |
| 1284 | * This is the object that everything in the display manager locks on. |
| 1285 | * We make it an inner class within the {@link DisplayManagerService} to so that it is |
| 1286 | * clear that the object belongs to the display manager service and that it is |
| 1287 | * a unique object with a special purpose. |
| 1288 | */ |
| 1289 | public static final class SyncRoot { |
| 1290 | } |
| 1291 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1292 | @VisibleForTesting |
| 1293 | static class Injector { |
| 1294 | VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context, |
| 1295 | Handler handler, DisplayAdapter.Listener displayAdapterListener) { |
| 1296 | return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener); |
| 1297 | } |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 1298 | |
| 1299 | long getDefaultDisplayDelayTimeout() { |
| 1300 | return WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT; |
| 1301 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Alex Sakhartchouk | 879d24f | 2017-06-20 22:01:19 -0400 | [diff] [blame] | 1304 | @VisibleForTesting |
| 1305 | DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) { |
| 1306 | synchronized (mSyncRoot) { |
| 1307 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1308 | if (display != null) { |
| 1309 | DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked(); |
| 1310 | return displayDevice.getDisplayDeviceInfoLocked(); |
| 1311 | } |
| 1312 | return null; |
| 1313 | } |
| 1314 | } |
| 1315 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1316 | private final class DisplayManagerHandler extends Handler { |
| 1317 | public DisplayManagerHandler(Looper looper) { |
| 1318 | super(looper, null, true /*async*/); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1319 | } |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 1320 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1321 | @Override |
| 1322 | public void handleMessage(Message msg) { |
| 1323 | switch (msg.what) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 1324 | case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS: |
| 1325 | registerDefaultDisplayAdapters(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1326 | break; |
| 1327 | |
| 1328 | case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS: |
| 1329 | registerAdditionalDisplayAdapters(); |
| 1330 | break; |
| 1331 | |
| 1332 | case MSG_DELIVER_DISPLAY_EVENT: |
| 1333 | deliverDisplayEvent(msg.arg1, msg.arg2); |
| 1334 | break; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1335 | |
| 1336 | case MSG_REQUEST_TRAVERSAL: |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1337 | mWindowManagerInternal.requestTraversalFromDisplayManager(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1338 | break; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1339 | |
| 1340 | case MSG_UPDATE_VIEWPORT: { |
| 1341 | synchronized (mSyncRoot) { |
| 1342 | mTempDefaultViewport.copyFrom(mDefaultViewport); |
| 1343 | mTempExternalTouchViewport.copyFrom(mExternalTouchViewport); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1344 | if (!mTempVirtualTouchViewports.equals(mVirtualTouchViewports)) { |
| 1345 | mTempVirtualTouchViewports.clear(); |
| 1346 | for (DisplayViewport d : mVirtualTouchViewports) { |
| 1347 | mTempVirtualTouchViewports.add(d.makeCopy()); |
| 1348 | } |
| 1349 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1350 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1351 | mInputManagerInternal.setDisplayViewports(mTempDefaultViewport, |
| 1352 | mTempExternalTouchViewport, mTempVirtualTouchViewports); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1353 | break; |
| 1354 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | private final class DisplayAdapterListener implements DisplayAdapter.Listener { |
| 1360 | @Override |
| 1361 | public void onDisplayDeviceEvent(DisplayDevice device, int event) { |
| 1362 | switch (event) { |
| 1363 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED: |
| 1364 | handleDisplayDeviceAdded(device); |
| 1365 | break; |
| 1366 | |
| 1367 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED: |
| 1368 | handleDisplayDeviceChanged(device); |
| 1369 | break; |
| 1370 | |
| 1371 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED: |
| 1372 | handleDisplayDeviceRemoved(device); |
| 1373 | break; |
| 1374 | } |
| 1375 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1376 | |
| 1377 | @Override |
| 1378 | public void onTraversalRequested() { |
| 1379 | synchronized (mSyncRoot) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1380 | scheduleTraversalLocked(false); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1381 | } |
| 1382 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | private final class CallbackRecord implements DeathRecipient { |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1386 | public final int mPid; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1387 | private final IDisplayManagerCallback mCallback; |
| 1388 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1389 | public boolean mWifiDisplayScanRequested; |
| 1390 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1391 | public CallbackRecord(int pid, IDisplayManagerCallback callback) { |
| 1392 | mPid = pid; |
| 1393 | mCallback = callback; |
| 1394 | } |
| 1395 | |
| 1396 | @Override |
| 1397 | public void binderDied() { |
| 1398 | if (DEBUG) { |
| 1399 | Slog.d(TAG, "Display listener for pid " + mPid + " died."); |
| 1400 | } |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1401 | onCallbackDied(this); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | public void notifyDisplayEventAsync(int displayId, int event) { |
| 1405 | try { |
| 1406 | mCallback.onDisplayEvent(displayId, event); |
| 1407 | } catch (RemoteException ex) { |
| 1408 | Slog.w(TAG, "Failed to notify process " |
| 1409 | + mPid + " that displays changed, assuming it died.", ex); |
| 1410 | binderDied(); |
| 1411 | } |
| 1412 | } |
| 1413 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1414 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1415 | @VisibleForTesting |
| 1416 | final class BinderService extends IDisplayManager.Stub { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1417 | /** |
| 1418 | * Returns information about the specified logical display. |
| 1419 | * |
| 1420 | * @param displayId The logical display id. |
| 1421 | * @return The logical display info, or null if the display does not exist. The |
| 1422 | * returned object must be treated as immutable. |
| 1423 | */ |
| 1424 | @Override // Binder call |
| 1425 | public DisplayInfo getDisplayInfo(int displayId) { |
| 1426 | final int callingUid = Binder.getCallingUid(); |
| 1427 | final long token = Binder.clearCallingIdentity(); |
| 1428 | try { |
| 1429 | return getDisplayInfoInternal(displayId, callingUid); |
| 1430 | } finally { |
| 1431 | Binder.restoreCallingIdentity(token); |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | /** |
| 1436 | * Returns the list of all display ids. |
| 1437 | */ |
| 1438 | @Override // Binder call |
| 1439 | public int[] getDisplayIds() { |
| 1440 | final int callingUid = Binder.getCallingUid(); |
| 1441 | final long token = Binder.clearCallingIdentity(); |
| 1442 | try { |
| 1443 | return getDisplayIdsInternal(callingUid); |
| 1444 | } finally { |
| 1445 | Binder.restoreCallingIdentity(token); |
| 1446 | } |
| 1447 | } |
| 1448 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1449 | /** |
| 1450 | * Returns the stable device display size, in pixels. |
| 1451 | */ |
| 1452 | @Override // Binder call |
| 1453 | public Point getStableDisplaySize() { |
| 1454 | final long token = Binder.clearCallingIdentity(); |
| 1455 | try { |
| 1456 | return getStableDisplaySizeInternal(); |
| 1457 | } finally { |
| 1458 | Binder.restoreCallingIdentity(token); |
| 1459 | } |
| 1460 | } |
| 1461 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1462 | @Override // Binder call |
| 1463 | public void registerCallback(IDisplayManagerCallback callback) { |
| 1464 | if (callback == null) { |
| 1465 | throw new IllegalArgumentException("listener must not be null"); |
| 1466 | } |
| 1467 | |
| 1468 | final int callingPid = Binder.getCallingPid(); |
| 1469 | final long token = Binder.clearCallingIdentity(); |
| 1470 | try { |
| 1471 | registerCallbackInternal(callback, callingPid); |
| 1472 | } finally { |
| 1473 | Binder.restoreCallingIdentity(token); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | @Override // Binder call |
| 1478 | public void startWifiDisplayScan() { |
| 1479 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1480 | "Permission required to start wifi display scans"); |
| 1481 | |
| 1482 | final int callingPid = Binder.getCallingPid(); |
| 1483 | final long token = Binder.clearCallingIdentity(); |
| 1484 | try { |
| 1485 | startWifiDisplayScanInternal(callingPid); |
| 1486 | } finally { |
| 1487 | Binder.restoreCallingIdentity(token); |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | @Override // Binder call |
| 1492 | public void stopWifiDisplayScan() { |
| 1493 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1494 | "Permission required to stop wifi display scans"); |
| 1495 | |
| 1496 | final int callingPid = Binder.getCallingPid(); |
| 1497 | final long token = Binder.clearCallingIdentity(); |
| 1498 | try { |
| 1499 | stopWifiDisplayScanInternal(callingPid); |
| 1500 | } finally { |
| 1501 | Binder.restoreCallingIdentity(token); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | @Override // Binder call |
| 1506 | public void connectWifiDisplay(String address) { |
| 1507 | if (address == null) { |
| 1508 | throw new IllegalArgumentException("address must not be null"); |
| 1509 | } |
| 1510 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1511 | "Permission required to connect to a wifi display"); |
| 1512 | |
| 1513 | final long token = Binder.clearCallingIdentity(); |
| 1514 | try { |
| 1515 | connectWifiDisplayInternal(address); |
| 1516 | } finally { |
| 1517 | Binder.restoreCallingIdentity(token); |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | @Override // Binder call |
| 1522 | public void disconnectWifiDisplay() { |
| 1523 | // This request does not require special permissions. |
| 1524 | // Any app can request disconnection from the currently active wifi display. |
| 1525 | // This exception should no longer be needed once wifi display control moves |
| 1526 | // to the media router service. |
| 1527 | |
| 1528 | final long token = Binder.clearCallingIdentity(); |
| 1529 | try { |
| 1530 | disconnectWifiDisplayInternal(); |
| 1531 | } finally { |
| 1532 | Binder.restoreCallingIdentity(token); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | @Override // Binder call |
| 1537 | public void renameWifiDisplay(String address, String alias) { |
| 1538 | if (address == null) { |
| 1539 | throw new IllegalArgumentException("address must not be null"); |
| 1540 | } |
| 1541 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1542 | "Permission required to rename to a wifi display"); |
| 1543 | |
| 1544 | final long token = Binder.clearCallingIdentity(); |
| 1545 | try { |
| 1546 | renameWifiDisplayInternal(address, alias); |
| 1547 | } finally { |
| 1548 | Binder.restoreCallingIdentity(token); |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | @Override // Binder call |
| 1553 | public void forgetWifiDisplay(String address) { |
| 1554 | if (address == null) { |
| 1555 | throw new IllegalArgumentException("address must not be null"); |
| 1556 | } |
| 1557 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1558 | "Permission required to forget to a wifi display"); |
| 1559 | |
| 1560 | final long token = Binder.clearCallingIdentity(); |
| 1561 | try { |
| 1562 | forgetWifiDisplayInternal(address); |
| 1563 | } finally { |
| 1564 | Binder.restoreCallingIdentity(token); |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | @Override // Binder call |
| 1569 | public void pauseWifiDisplay() { |
| 1570 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1571 | "Permission required to pause a wifi display session"); |
| 1572 | |
| 1573 | final long token = Binder.clearCallingIdentity(); |
| 1574 | try { |
| 1575 | pauseWifiDisplayInternal(); |
| 1576 | } finally { |
| 1577 | Binder.restoreCallingIdentity(token); |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | @Override // Binder call |
| 1582 | public void resumeWifiDisplay() { |
| 1583 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1584 | "Permission required to resume a wifi display session"); |
| 1585 | |
| 1586 | final long token = Binder.clearCallingIdentity(); |
| 1587 | try { |
| 1588 | resumeWifiDisplayInternal(); |
| 1589 | } finally { |
| 1590 | Binder.restoreCallingIdentity(token); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | @Override // Binder call |
| 1595 | public WifiDisplayStatus getWifiDisplayStatus() { |
| 1596 | // This request does not require special permissions. |
| 1597 | // Any app can get information about available wifi displays. |
| 1598 | |
| 1599 | final long token = Binder.clearCallingIdentity(); |
| 1600 | try { |
| 1601 | return getWifiDisplayStatusInternal(); |
| 1602 | } finally { |
| 1603 | Binder.restoreCallingIdentity(token); |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | @Override // Binder call |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1608 | public void requestColorMode(int displayId, int colorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1609 | mContext.enforceCallingOrSelfPermission( |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1610 | Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE, |
| 1611 | "Permission required to change the display color mode"); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1612 | final long token = Binder.clearCallingIdentity(); |
| 1613 | try { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1614 | requestColorModeInternal(displayId, colorMode); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1615 | } finally { |
| 1616 | Binder.restoreCallingIdentity(token); |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1621 | public int createVirtualDisplay(IVirtualDisplayCallback callback, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1622 | IMediaProjection projection, String packageName, String name, |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1623 | int width, int height, int densityDpi, Surface surface, int flags, |
| 1624 | String uniqueId) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1625 | final int callingUid = Binder.getCallingUid(); |
| 1626 | if (!validatePackageName(callingUid, packageName)) { |
| 1627 | throw new SecurityException("packageName must match the calling uid"); |
| 1628 | } |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1629 | if (callback == null) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1630 | throw new IllegalArgumentException("appToken must not be null"); |
| 1631 | } |
| 1632 | if (TextUtils.isEmpty(name)) { |
| 1633 | throw new IllegalArgumentException("name must be non-null and non-empty"); |
| 1634 | } |
| 1635 | if (width <= 0 || height <= 0 || densityDpi <= 0) { |
| 1636 | throw new IllegalArgumentException("width, height, and densityDpi must be " |
| 1637 | + "greater than 0"); |
| 1638 | } |
Pablo Ceballos | eb3370d | 2016-08-31 15:00:17 -0700 | [diff] [blame] | 1639 | if (surface != null && surface.isSingleBuffered()) { |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 1640 | throw new IllegalArgumentException("Surface can't be single-buffered"); |
| 1641 | } |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1642 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1643 | if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) { |
| 1644 | flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
| 1645 | |
| 1646 | // Public displays can't be allowed to show content when locked. |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 1647 | if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) { |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1648 | throw new IllegalArgumentException( |
| 1649 | "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE"); |
| 1650 | } |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1651 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1652 | if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) { |
| 1653 | flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1656 | if (projection != null) { |
| 1657 | try { |
| 1658 | if (!getProjectionService().isValidMediaProjection(projection)) { |
| 1659 | throw new SecurityException("Invalid media projection"); |
| 1660 | } |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1661 | flags = projection.applyVirtualDisplayFlags(flags); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1662 | } catch (RemoteException e) { |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1663 | throw new SecurityException("unable to validate media projection or flags"); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1664 | } |
| 1665 | } |
| 1666 | |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1667 | if (callingUid != Process.SYSTEM_UID && |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1668 | (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1669 | if (!canProjectVideo(projection)) { |
| 1670 | throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or " |
| 1671 | + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate " |
| 1672 | + "MediaProjection token in order to create a screen sharing virtual " |
| 1673 | + "display."); |
| 1674 | } |
| 1675 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1676 | if ((flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1677 | if (!canProjectSecureVideo(projection)) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1678 | throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT " |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1679 | + "or an appropriate MediaProjection token to create a " |
| 1680 | + "secure virtual display."); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | final long token = Binder.clearCallingIdentity(); |
| 1685 | try { |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1686 | return createVirtualDisplayInternal(callback, projection, callingUid, packageName, |
| 1687 | name, width, height, densityDpi, surface, flags, uniqueId); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1688 | } finally { |
| 1689 | Binder.restoreCallingIdentity(token); |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1694 | public void resizeVirtualDisplay(IVirtualDisplayCallback callback, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1695 | int width, int height, int densityDpi) { |
| 1696 | final long token = Binder.clearCallingIdentity(); |
| 1697 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1698 | resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi); |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1699 | } finally { |
| 1700 | Binder.restoreCallingIdentity(token); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1705 | public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) { |
Pablo Ceballos | eb3370d | 2016-08-31 15:00:17 -0700 | [diff] [blame] | 1706 | if (surface != null && surface.isSingleBuffered()) { |
| 1707 | throw new IllegalArgumentException("Surface can't be single-buffered"); |
| 1708 | } |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 1709 | final long token = Binder.clearCallingIdentity(); |
| 1710 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1711 | setVirtualDisplaySurfaceInternal(callback.asBinder(), surface); |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 1712 | } finally { |
| 1713 | Binder.restoreCallingIdentity(token); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1718 | public void releaseVirtualDisplay(IVirtualDisplayCallback callback) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1719 | final long token = Binder.clearCallingIdentity(); |
| 1720 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1721 | releaseVirtualDisplayInternal(callback.asBinder()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1722 | } finally { |
| 1723 | Binder.restoreCallingIdentity(token); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | @Override // Binder call |
| 1728 | public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 1729 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1730 | |
| 1731 | final long token = Binder.clearCallingIdentity(); |
| 1732 | try { |
| 1733 | dumpInternal(pw); |
| 1734 | } finally { |
| 1735 | Binder.restoreCallingIdentity(token); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | private boolean validatePackageName(int uid, String packageName) { |
| 1740 | if (packageName != null) { |
| 1741 | String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); |
| 1742 | if (packageNames != null) { |
| 1743 | for (String n : packageNames) { |
| 1744 | if (n.equals(packageName)) { |
| 1745 | return true; |
| 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | } |
| 1750 | return false; |
| 1751 | } |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1752 | |
| 1753 | private boolean canProjectVideo(IMediaProjection projection) { |
| 1754 | if (projection != null) { |
| 1755 | try { |
| 1756 | if (projection.canProjectVideo()) { |
| 1757 | return true; |
| 1758 | } |
| 1759 | } catch (RemoteException e) { |
| 1760 | Slog.e(TAG, "Unable to query projection service for permissions", e); |
| 1761 | } |
| 1762 | } |
| 1763 | if (mContext.checkCallingPermission( |
| 1764 | android.Manifest.permission.CAPTURE_VIDEO_OUTPUT) |
Michael Wright | 0ccc2b0 | 2014-07-24 18:20:41 -0700 | [diff] [blame] | 1765 | == PackageManager.PERMISSION_GRANTED) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1766 | return true; |
| 1767 | } |
| 1768 | return canProjectSecureVideo(projection); |
| 1769 | } |
| 1770 | |
| 1771 | private boolean canProjectSecureVideo(IMediaProjection projection) { |
| 1772 | if (projection != null) { |
| 1773 | try { |
| 1774 | if (projection.canProjectSecureVideo()){ |
| 1775 | return true; |
| 1776 | } |
| 1777 | } catch (RemoteException e) { |
| 1778 | Slog.e(TAG, "Unable to query projection service for permissions", e); |
| 1779 | } |
| 1780 | } |
| 1781 | return mContext.checkCallingPermission( |
| 1782 | android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT) |
Michael Wright | 0ccc2b0 | 2014-07-24 18:20:41 -0700 | [diff] [blame] | 1783 | == PackageManager.PERMISSION_GRANTED; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1784 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | private final class LocalService extends DisplayManagerInternal { |
| 1788 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1789 | public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler, |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 1790 | SensorManager sensorManager) { |
| 1791 | synchronized (mSyncRoot) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1792 | DisplayBlanker blanker = new DisplayBlanker() { |
| 1793 | @Override |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 1794 | public void requestDisplayState(int state, int brightness) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1795 | // The order of operations is important for legacy reasons. |
| 1796 | if (state == Display.STATE_OFF) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 1797 | requestGlobalDisplayStateInternal(state, brightness); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | callbacks.onDisplayStateChange(state); |
| 1801 | |
| 1802 | if (state != Display.STATE_OFF) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 1803 | requestGlobalDisplayStateInternal(state, brightness); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | }; |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 1807 | mDisplayPowerController = new DisplayPowerController( |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1808 | mContext, callbacks, handler, sensorManager, blanker); |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | @Override |
| 1813 | public boolean requestPowerState(DisplayPowerRequest request, |
| 1814 | boolean waitForNegativeProximity) { |
| 1815 | return mDisplayPowerController.requestPowerState(request, |
| 1816 | waitForNegativeProximity); |
| 1817 | } |
| 1818 | |
| 1819 | @Override |
| 1820 | public boolean isProximitySensorAvailable() { |
| 1821 | return mDisplayPowerController.isProximitySensorAvailable(); |
| 1822 | } |
| 1823 | |
| 1824 | @Override |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1825 | public DisplayInfo getDisplayInfo(int displayId) { |
| 1826 | return getDisplayInfoInternal(displayId, Process.myUid()); |
| 1827 | } |
| 1828 | |
| 1829 | @Override |
| 1830 | public void registerDisplayTransactionListener(DisplayTransactionListener listener) { |
| 1831 | if (listener == null) { |
| 1832 | throw new IllegalArgumentException("listener must not be null"); |
| 1833 | } |
| 1834 | |
| 1835 | registerDisplayTransactionListenerInternal(listener); |
| 1836 | } |
| 1837 | |
| 1838 | @Override |
| 1839 | public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) { |
| 1840 | if (listener == null) { |
| 1841 | throw new IllegalArgumentException("listener must not be null"); |
| 1842 | } |
| 1843 | |
| 1844 | unregisterDisplayTransactionListenerInternal(listener); |
| 1845 | } |
| 1846 | |
| 1847 | @Override |
| 1848 | public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) { |
| 1849 | setDisplayInfoOverrideFromWindowManagerInternal(displayId, info); |
| 1850 | } |
| 1851 | |
| 1852 | @Override |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 1853 | public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) { |
| 1854 | getNonOverrideDisplayInfoInternal(displayId, outInfo); |
| 1855 | } |
| 1856 | |
| 1857 | @Override |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1858 | public void performTraversalInTransactionFromWindowManager() { |
| 1859 | performTraversalInTransactionFromWindowManagerInternal(); |
| 1860 | } |
| 1861 | |
| 1862 | @Override |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1863 | public void setDisplayProperties(int displayId, boolean hasContent, |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1864 | float requestedRefreshRate, int requestedMode, boolean inTraversal) { |
| 1865 | setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate, |
| 1866 | requestedMode, inTraversal); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1867 | } |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 1868 | |
| 1869 | @Override |
| 1870 | public void setDisplayOffsets(int displayId, int x, int y) { |
| 1871 | setDisplayOffsetsInternal(displayId, x, y); |
| 1872 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1873 | |
| 1874 | @Override |
| 1875 | public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) { |
| 1876 | setDisplayAccessUIDsInternal(newDisplayAccessUIDs); |
| 1877 | } |
| 1878 | |
| 1879 | @Override |
| 1880 | public boolean isUidPresentOnDisplay(int uid, int displayId) { |
| 1881 | return isUidPresentOnDisplayInternal(uid, displayId); |
| 1882 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1883 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1884 | } |