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