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