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