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