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