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