blob: ddd918fdcc5d40ed66d9a663333b9148378b5782 [file] [log] [blame]
Jeff Brownfa25bf52012-07-23 19:26:30 -07001/*
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
17package com.android.server.display;
18
Andrii Kulianfc8f82b2017-01-26 13:17:27 -080019import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
20import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
21import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
22import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE;
23import static android.hardware.display.DisplayManager
Andrii Kulian7211d2e2017-01-27 15:58:05 -080024 .VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -080025
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060026import com.android.internal.util.DumpUtils;
Jeff Brownbd6e1502012-08-28 03:27:37 -070027import com.android.internal.util.IndentingPrintWriter;
28
Jeff Brownfa25bf52012-07-23 19:26:30 -070029import android.Manifest;
30import android.content.Context;
31import android.content.pm.PackageManager;
Jeff Brownad9ef192014-04-08 17:26:30 -070032import android.hardware.SensorManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070033import android.hardware.display.DisplayManagerGlobal;
Jeff Brown4ccb8232014-01-16 22:16:42 -080034import android.hardware.display.DisplayManagerInternal;
35import android.hardware.display.DisplayViewport;
36import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener;
Jeff Brownfa25bf52012-07-23 19:26:30 -070037import android.hardware.display.IDisplayManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070038import android.hardware.display.IDisplayManagerCallback;
Michael Wright75ee9fc2014-09-01 19:55:22 -070039import android.hardware.display.IVirtualDisplayCallback;
Jeff Browne08ae382012-09-07 20:36:36 -070040import android.hardware.display.WifiDisplayStatus;
Jeff Brown4ccb8232014-01-16 22:16:42 -080041import android.hardware.input.InputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -070042import android.media.projection.IMediaProjection;
43import android.media.projection.IMediaProjectionManager;
Jeff Brownfa25bf52012-07-23 19:26:30 -070044import android.os.Binder;
Jeff Brownbd6e1502012-08-28 03:27:37 -070045import android.os.Handler;
Jeff Brown64a55af2012-08-26 02:47:39 -070046import android.os.IBinder;
Jeff Brown4ccb8232014-01-16 22:16:42 -080047import android.os.IBinder.DeathRecipient;
Jeff Brownbd6e1502012-08-28 03:27:37 -070048import android.os.Looper;
49import android.os.Message;
Jeff Brown5d6443b2015-04-10 20:15:01 -070050import android.os.PowerManager;
Craig Mautner4504de52013-12-20 09:06:56 -080051import android.os.Process;
Jeff Brownbd6e1502012-08-28 03:27:37 -070052import android.os.RemoteException;
Michael Wrightc39d47a2014-07-08 18:07:36 -070053import android.os.ServiceManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070054import android.os.SystemClock;
Jeff Brownfa25bf52012-07-23 19:26:30 -070055import android.os.SystemProperties;
Jeff Brown5d6443b2015-04-10 20:15:01 -070056import android.os.Trace;
Jeff Browna506a6e2013-06-04 00:02:38 -070057import android.text.TextUtils;
Andrii Kulianfb1bf692017-01-17 11:17:34 -080058import android.util.IntArray;
Jeff Brownbd6e1502012-08-28 03:27:37 -070059import android.util.Slog;
60import android.util.SparseArray;
Jeff Brownfa25bf52012-07-23 19:26:30 -070061import android.view.Display;
62import android.view.DisplayInfo;
Jeff Browna506a6e2013-06-04 00:02:38 -070063import android.view.Surface;
Jeff Brown4ccb8232014-01-16 22:16:42 -080064import android.view.WindowManagerInternal;
Jeff Browna506a6e2013-06-04 00:02:38 -070065
Jeff Brown4ccb8232014-01-16 22:16:42 -080066import com.android.server.DisplayThread;
67import com.android.server.LocalServices;
68import com.android.server.SystemService;
Dianne Hackborn8d044e82013-04-30 17:24:15 -070069import com.android.server.UiThread;
Jeff Brownfa25bf52012-07-23 19:26:30 -070070
71import java.io.FileDescriptor;
72import java.io.PrintWriter;
73import java.util.ArrayList;
Jeff Browna506a6e2013-06-04 00:02:38 -070074import java.util.Arrays;
Jeff Browne75926d2014-09-18 15:24:49 -070075import java.util.List;
Jeff Brown7f3994e2012-12-04 14:04:28 -080076import java.util.concurrent.CopyOnWriteArrayList;
Jeff Brownfa25bf52012-07-23 19:26:30 -070077
78/**
Jeff Brownbd6e1502012-08-28 03:27:37 -070079 * Manages attached displays.
Jeff Brownfa25bf52012-07-23 19:26:30 -070080 * <p>
Jeff Brownbd6e1502012-08-28 03:27:37 -070081 * The {@link DisplayManagerService} manages the global lifecycle of displays,
82 * decides how to configure logical displays based on the physical display devices currently
83 * attached, sends notifications to the system and to applications when the state
84 * changes, and so on.
85 * </p><p>
86 * The display manager service relies on a collection of {@link DisplayAdapter} components,
87 * for discovering and configuring physical display devices attached to the system.
88 * There are separate display adapters for each manner that devices are attached:
89 * one display adapter for built-in local displays, one for simulated non-functional
90 * displays when the system is headless, one for simulated overlay displays used for
91 * development, one for wifi displays, etc.
92 * </p><p>
93 * Display adapters are only weakly coupled to the display manager service.
94 * Display adapters communicate changes in display device state to the display manager
Craig Mautner722285e2012-09-07 13:55:58 -070095 * service asynchronously via a {@link DisplayAdapter.Listener} registered
Jeff Brownbd6e1502012-08-28 03:27:37 -070096 * by the display manager service. This separation of concerns is important for
97 * two main reasons. First, it neatly encapsulates the responsibilities of these
98 * two classes: display adapters handle individual display devices whereas
99 * the display manager service handles the global state. Second, it eliminates
100 * the potential for deadlocks resulting from asynchronous display device discovery.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700101 * </p>
102 *
103 * <h3>Synchronization</h3>
104 * <p>
105 * Because the display manager may be accessed by multiple threads, the synchronization
106 * story gets a little complicated. In particular, the window manager may call into
107 * the display manager while holding a surface transaction with the expectation that
108 * it can apply changes immediately. Unfortunately, that means we can't just do
109 * everything asynchronously (*grump*).
Jeff Brownbd6e1502012-08-28 03:27:37 -0700110 * </p><p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700111 * To make this work, all of the objects that belong to the display manager must
112 * use the same lock. We call this lock the synchronization root and it has a unique
113 * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are
114 * named with the "Locked" suffix.
115 * </p><p>
116 * Where things get tricky is that the display manager is not allowed to make
117 * any potentially reentrant calls, especially into the window manager. We generally
118 * avoid this by making all potentially reentrant out-calls asynchronous.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700119 * </p>
120 */
Jeff Brown4ccb8232014-01-16 22:16:42 -0800121public final class DisplayManagerService extends SystemService {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700122 private static final String TAG = "DisplayManagerService";
Jeff Brownbd6e1502012-08-28 03:27:37 -0700123 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700124
Jeff Brownbbd28a22012-09-20 16:47:15 -0700125 // When this system property is set to 0, WFD is forcibly disabled on boot.
126 // When this system property is set to 1, WFD is forcibly enabled on boot.
127 // Otherwise WFD is enabled according to the value of config_enableWifiDisplay.
128 private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
129
Jeff Brownbd6e1502012-08-28 03:27:37 -0700130 private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
131
132 private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER = 1;
133 private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2;
134 private static final int MSG_DELIVER_DISPLAY_EVENT = 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700135 private static final int MSG_REQUEST_TRAVERSAL = 4;
Jeff Brownd728bf52012-09-08 18:05:28 -0700136 private static final int MSG_UPDATE_VIEWPORT = 5;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700137
Jeff Brownb880d882014-02-10 19:47:07 -0800138 private final Context mContext;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700139 private final DisplayManagerHandler mHandler;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700140 private final Handler mUiHandler;
141 private final DisplayAdapterListener mDisplayAdapterListener;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800142 private WindowManagerInternal mWindowManagerInternal;
143 private InputManagerInternal mInputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700144 private IMediaProjectionManager mProjectionService;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700145
146 // The synchronization root for the display manager.
147 // This lock guards most of the display manager's state.
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800148 // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call
149 // into WindowManagerService methods that require mWindowMap while holding this unless you are
150 // very very sure that no deadlock can occur.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700151 private final SyncRoot mSyncRoot = new SyncRoot();
152
153 // True if in safe mode.
154 // This option may disable certain display adapters.
155 public boolean mSafeMode;
156
157 // True if we are in a special boot mode where only core applications and
158 // services should be started. This option may disable certain display adapters.
159 public boolean mOnlyCore;
160
Jeff Brown27f1d672012-10-17 18:32:34 -0700161 // True if the display manager service should pretend there is only one display
162 // and only tell applications about the existence of the default logical display.
163 // The display manager can still mirror content to secondary displays but applications
164 // cannot present unique content on those displays.
165 // Used for demonstration purposes only.
166 private final boolean mSingleDisplayDemoMode;
167
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700168 // All callback records indexed by calling process id.
169 public final SparseArray<CallbackRecord> mCallbacks =
Jeff Brownbd6e1502012-08-28 03:27:37 -0700170 new SparseArray<CallbackRecord>();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700171
Jeff Brownbd6e1502012-08-28 03:27:37 -0700172 // List of all currently registered display adapters.
173 private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
174
175 // List of all currently connected display devices.
176 private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>();
177
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700178 // List of all logical displays indexed by logical display id.
179 private final SparseArray<LogicalDisplay> mLogicalDisplays =
180 new SparseArray<LogicalDisplay>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700181 private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1;
182
Jeff Brown7f3994e2012-12-04 14:04:28 -0800183 // List of all display transaction listeners.
184 private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
185 new CopyOnWriteArrayList<DisplayTransactionListener>();
186
Jeff Brownad9ef192014-04-08 17:26:30 -0700187 // Display power controller.
188 private DisplayPowerController mDisplayPowerController;
189
Jeff Brown037c33e2014-04-09 00:31:55 -0700190 // The overall display state, independent of changes that might influence one
191 // display or another in particular.
Jeff Brown5d6443b2015-04-10 20:15:01 -0700192 private int mGlobalDisplayState = Display.STATE_ON;
193
194 // The overall display brightness.
195 // For now, this only applies to the built-in display but we may split it up eventually.
196 private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT;
Jeff Brown9e316a12012-10-08 19:17:06 -0700197
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700198 // Set to true when there are pending display changes that have yet to be applied
199 // to the surface flinger state.
200 private boolean mPendingTraversal;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700201
Jeff Browne08ae382012-09-07 20:36:36 -0700202 // The Wifi display adapter, or null if not registered.
203 private WifiDisplayAdapter mWifiDisplayAdapter;
204
Jeff Brownce468a32013-11-21 16:42:03 -0800205 // The number of active wifi display scan requests.
206 private int mWifiDisplayScanRequestCount;
207
Jeff Browna506a6e2013-06-04 00:02:38 -0700208 // The virtual display adapter, or null if not registered.
209 private VirtualDisplayAdapter mVirtualDisplayAdapter;
210
Jeff Brownd728bf52012-09-08 18:05:28 -0700211 // Viewports of the default display and the display that should receive touch
212 // input from an external source. Used by the input system.
213 private final DisplayViewport mDefaultViewport = new DisplayViewport();
214 private final DisplayViewport mExternalTouchViewport = new DisplayViewport();
215
Jeff Brown89d55462012-09-19 11:33:42 -0700216 // Persistent data store for all internal settings maintained by the display manager service.
217 private final PersistentDataStore mPersistentDataStore = new PersistentDataStore();
218
Jeff Brownbd6e1502012-08-28 03:27:37 -0700219 // Temporary callback list, used when sending display events to applications.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700220 // May be used outside of the lock but only on the handler thread.
221 private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700222
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700223 // Temporary display info, used for comparing display configurations.
224 private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
225
Jeff Brownd728bf52012-09-08 18:05:28 -0700226 // Temporary viewports, used when sending new viewport information to the
227 // input system. May be used outside of the lock but only on the handler thread.
228 private final DisplayViewport mTempDefaultViewport = new DisplayViewport();
229 private final DisplayViewport mTempExternalTouchViewport = new DisplayViewport();
230
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700231 // The default color mode for default displays. Overrides the usual
232 // Display.Display.COLOR_MODE_DEFAULT for displays with the
233 // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set.
234 private final int mDefaultDisplayDefaultColorMode;
235
Jeff Browne75926d2014-09-18 15:24:49 -0700236 // Temporary list of deferred work to perform when setting the display state.
237 // Only used by requestDisplayState. The field is self-synchronized and only
238 // intended for use inside of the requestGlobalDisplayStateInternal function.
239 private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>();
240
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800241 // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs.
242 private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>();
243
Jeff Brownb880d882014-02-10 19:47:07 -0800244 public DisplayManagerService(Context context) {
245 super(context);
246 mContext = context;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800247 mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700248 mUiHandler = UiThread.getHandler();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700249 mDisplayAdapterListener = new DisplayAdapterListener();
Jeff Brown27f1d672012-10-17 18:32:34 -0700250 mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700251 mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger(
252 com.android.internal.R.integer.config_defaultDisplayDefaultColorMode);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700253
254 PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
255 mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting();
Craig Mautner4f67ba62012-08-02 11:23:00 -0700256 }
257
Jeff Brown4ccb8232014-01-16 22:16:42 -0800258 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -0800259 public void onStart() {
Michael Wright1c9977b2016-07-12 13:30:10 -0700260 // We need to pre-load the persistent data store so it's ready before the default display
261 // adapter is up so that we have it's configuration. We could load it lazily, but since
262 // we're going to have to read it in eventually we may as well do it here rather than after
263 // we've waited for the diplay to register itself with us.
264 mPersistentDataStore.loadIfNeeded();
Jeff Brown4ccb8232014-01-16 22:16:42 -0800265 mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER);
266
267 publishBinderService(Context.DISPLAY_SERVICE, new BinderService(),
268 true /*allowIsolated*/);
269 publishLocalService(DisplayManagerInternal.class, new LocalService());
Justin Klaassen22eb1992016-07-11 20:52:23 -0700270 publishLocalService(DisplayTransformManager.class, new DisplayTransformManager());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800271 }
272
273 @Override
274 public void onBootPhase(int phase) {
275 if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) {
276 synchronized (mSyncRoot) {
277 long timeout = SystemClock.uptimeMillis() + WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
278 while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null) {
279 long delay = timeout - SystemClock.uptimeMillis();
280 if (delay <= 0) {
281 throw new RuntimeException("Timeout waiting for default display "
282 + "to be initialized.");
283 }
284 if (DEBUG) {
285 Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay);
286 }
287 try {
288 mSyncRoot.wait(delay);
289 } catch (InterruptedException ex) {
290 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700291 }
292 }
293 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700294 }
295
Jeff Brown4ccb8232014-01-16 22:16:42 -0800296 // TODO: Use dependencies or a boot phase
297 public void windowManagerAndInputReady() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700298 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800299 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
300 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Craig Mautner65d11b32012-10-01 13:59:52 -0700301 scheduleTraversalLocked(false);
Jeff Brownd728bf52012-09-08 18:05:28 -0700302 }
303 }
304
305 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700306 * Called when the system is ready to go.
307 */
308 public void systemReady(boolean safeMode, boolean onlyCore) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700309 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700310 mSafeMode = safeMode;
311 mOnlyCore = onlyCore;
312 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700313
Jeff Brownbd6e1502012-08-28 03:27:37 -0700314 mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
315 }
316
Jeff Brown4ccb8232014-01-16 22:16:42 -0800317 private void registerDisplayTransactionListenerInternal(
318 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800319 // List is self-synchronized copy-on-write.
320 mDisplayTransactionListeners.add(listener);
321 }
322
Jeff Brown4ccb8232014-01-16 22:16:42 -0800323 private void unregisterDisplayTransactionListenerInternal(
324 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800325 // List is self-synchronized copy-on-write.
326 mDisplayTransactionListeners.remove(listener);
327 }
328
Jeff Brown4ccb8232014-01-16 22:16:42 -0800329 private void setDisplayInfoOverrideFromWindowManagerInternal(
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700330 int displayId, DisplayInfo info) {
331 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700332 LogicalDisplay display = mLogicalDisplays.get(displayId);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700333 if (display != null) {
Jeff Brownef981a42013-08-07 14:13:37 -0700334 if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700335 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
Craig Mautner65d11b32012-10-01 13:59:52 -0700336 scheduleTraversalLocked(false);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700337 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700338 }
339 }
340 }
341
Andrii Kuliancd097992017-03-23 18:31:59 -0700342 /**
343 * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo)
344 */
345 private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) {
346 synchronized (mSyncRoot) {
347 final LogicalDisplay display = mLogicalDisplays.get(displayId);
348 if (display != null) {
349 display.getNonOverrideDisplayInfoLocked(outInfo);
350 }
351 }
352 }
353
Jeff Brown4ccb8232014-01-16 22:16:42 -0800354 private void performTraversalInTransactionFromWindowManagerInternal() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700355 synchronized (mSyncRoot) {
356 if (!mPendingTraversal) {
357 return;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700358 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700359 mPendingTraversal = false;
360
361 performTraversalInTransactionLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700362 }
Jeff Brown7f3994e2012-12-04 14:04:28 -0800363
364 // List is self-synchronized copy-on-write.
365 for (DisplayTransactionListener listener : mDisplayTransactionListeners) {
366 listener.onDisplayTransaction();
367 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700368 }
369
Jeff Brown5d6443b2015-04-10 20:15:01 -0700370 private void requestGlobalDisplayStateInternal(int state, int brightness) {
371 if (state == Display.STATE_UNKNOWN) {
372 state = Display.STATE_ON;
373 }
374 if (state == Display.STATE_OFF) {
375 brightness = PowerManager.BRIGHTNESS_OFF;
376 } else if (brightness < 0) {
377 brightness = PowerManager.BRIGHTNESS_DEFAULT;
378 } else if (brightness > PowerManager.BRIGHTNESS_ON) {
379 brightness = PowerManager.BRIGHTNESS_ON;
380 }
381
Jeff Browne75926d2014-09-18 15:24:49 -0700382 synchronized (mTempDisplayStateWorkQueue) {
383 try {
384 // Update the display state within the lock.
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700385 // Note that we do not need to schedule traversals here although it
386 // may happen as a side-effect of displays changing state.
Jeff Browne75926d2014-09-18 15:24:49 -0700387 synchronized (mSyncRoot) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700388 if (mGlobalDisplayState == state
389 && mGlobalDisplayBrightness == brightness) {
390 return; // no change
Jeff Browne75926d2014-09-18 15:24:49 -0700391 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700392
393 Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState("
394 + Display.stateToString(state)
395 + ", brightness=" + brightness + ")");
396 mGlobalDisplayState = state;
397 mGlobalDisplayBrightness = brightness;
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700398 applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue);
Jeff Browne75926d2014-09-18 15:24:49 -0700399 }
400
401 // Setting the display power state can take hundreds of milliseconds
402 // to complete so we defer the most expensive part of the work until
403 // after we have exited the critical section to avoid blocking other
404 // threads for a long time.
405 for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) {
406 mTempDisplayStateWorkQueue.get(i).run();
407 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700408 Trace.traceEnd(Trace.TRACE_TAG_POWER);
Jeff Browne75926d2014-09-18 15:24:49 -0700409 } finally {
410 mTempDisplayStateWorkQueue.clear();
Jeff Brown9e316a12012-10-08 19:17:06 -0700411 }
412 }
413 }
414
Jeff Brown4ccb8232014-01-16 22:16:42 -0800415 private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700416 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800417 LogicalDisplay display = mLogicalDisplays.get(displayId);
418 if (display != null) {
419 DisplayInfo info = display.getDisplayInfoLocked();
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800420 if (info.hasAccess(callingUid)
421 || isUidPresentOnDisplayInternal(callingUid, displayId)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800422 return info;
423 }
424 }
425 return null;
426 }
427 }
428
429 private int[] getDisplayIdsInternal(int callingUid) {
430 synchronized (mSyncRoot) {
431 final int count = mLogicalDisplays.size();
432 int[] displayIds = new int[count];
433 int n = 0;
434 for (int i = 0; i < count; i++) {
435 LogicalDisplay display = mLogicalDisplays.valueAt(i);
436 DisplayInfo info = display.getDisplayInfoLocked();
437 if (info.hasAccess(callingUid)) {
438 displayIds[n++] = mLogicalDisplays.keyAt(i);
439 }
440 }
441 if (n != count) {
442 displayIds = Arrays.copyOfRange(displayIds, 0, n);
443 }
444 return displayIds;
445 }
446 }
447
448 private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) {
449 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700450 if (mCallbacks.get(callingPid) != null) {
451 throw new SecurityException("The calling process has already "
452 + "registered an IDisplayManagerCallback.");
Jeff Brown64a55af2012-08-26 02:47:39 -0700453 }
454
Jeff Brownbd6e1502012-08-28 03:27:37 -0700455 CallbackRecord record = new CallbackRecord(callingPid, callback);
456 try {
457 IBinder binder = callback.asBinder();
458 binder.linkToDeath(record, 0);
459 } catch (RemoteException ex) {
460 // give up
461 throw new RuntimeException(ex);
462 }
463
464 mCallbacks.put(callingPid, record);
465 }
466 }
467
Jeff Brownce468a32013-11-21 16:42:03 -0800468 private void onCallbackDied(CallbackRecord record) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700469 synchronized (mSyncRoot) {
Jeff Brownce468a32013-11-21 16:42:03 -0800470 mCallbacks.remove(record.mPid);
471 stopWifiDisplayScanLocked(record);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700472 }
473 }
474
Jeff Brown4ccb8232014-01-16 22:16:42 -0800475 private void startWifiDisplayScanInternal(int callingPid) {
476 synchronized (mSyncRoot) {
477 CallbackRecord record = mCallbacks.get(callingPid);
478 if (record == null) {
479 throw new IllegalStateException("The calling process has not "
480 + "registered an IDisplayManagerCallback.");
Jeff Browne08ae382012-09-07 20:36:36 -0700481 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800482 startWifiDisplayScanLocked(record);
Jeff Browne08ae382012-09-07 20:36:36 -0700483 }
484 }
485
Jeff Brownce468a32013-11-21 16:42:03 -0800486 private void startWifiDisplayScanLocked(CallbackRecord record) {
487 if (!record.mWifiDisplayScanRequested) {
488 record.mWifiDisplayScanRequested = true;
489 if (mWifiDisplayScanRequestCount++ == 0) {
490 if (mWifiDisplayAdapter != null) {
491 mWifiDisplayAdapter.requestStartScanLocked();
492 }
493 }
494 }
495 }
496
Jeff Brown4ccb8232014-01-16 22:16:42 -0800497 private void stopWifiDisplayScanInternal(int callingPid) {
498 synchronized (mSyncRoot) {
499 CallbackRecord record = mCallbacks.get(callingPid);
500 if (record == null) {
501 throw new IllegalStateException("The calling process has not "
502 + "registered an IDisplayManagerCallback.");
Jeff Brownce468a32013-11-21 16:42:03 -0800503 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800504 stopWifiDisplayScanLocked(record);
Jeff Brownce468a32013-11-21 16:42:03 -0800505 }
506 }
507
508 private void stopWifiDisplayScanLocked(CallbackRecord record) {
509 if (record.mWifiDisplayScanRequested) {
510 record.mWifiDisplayScanRequested = false;
511 if (--mWifiDisplayScanRequestCount == 0) {
512 if (mWifiDisplayAdapter != null) {
513 mWifiDisplayAdapter.requestStopScanLocked();
514 }
515 } else if (mWifiDisplayScanRequestCount < 0) {
Dianne Hackborn8d051722014-10-01 14:59:58 -0700516 Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: "
Jeff Brownce468a32013-11-21 16:42:03 -0800517 + mWifiDisplayScanRequestCount);
518 mWifiDisplayScanRequestCount = 0;
519 }
520 }
521 }
522
Jeff Brown4ccb8232014-01-16 22:16:42 -0800523 private void connectWifiDisplayInternal(String address) {
524 synchronized (mSyncRoot) {
525 if (mWifiDisplayAdapter != null) {
526 mWifiDisplayAdapter.requestConnectLocked(address);
Jeff Browne08ae382012-09-07 20:36:36 -0700527 }
Jeff Browne08ae382012-09-07 20:36:36 -0700528 }
529 }
530
Jeff Brown4ccb8232014-01-16 22:16:42 -0800531 private void pauseWifiDisplayInternal() {
532 synchronized (mSyncRoot) {
533 if (mWifiDisplayAdapter != null) {
534 mWifiDisplayAdapter.requestPauseLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700535 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700536 }
537 }
538
Jeff Brown4ccb8232014-01-16 22:16:42 -0800539 private void resumeWifiDisplayInternal() {
540 synchronized (mSyncRoot) {
541 if (mWifiDisplayAdapter != null) {
542 mWifiDisplayAdapter.requestResumeLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700543 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700544 }
545 }
546
Jeff Brown4ccb8232014-01-16 22:16:42 -0800547 private void disconnectWifiDisplayInternal() {
548 synchronized (mSyncRoot) {
549 if (mWifiDisplayAdapter != null) {
550 mWifiDisplayAdapter.requestDisconnectLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700551 }
Jeff Browne08ae382012-09-07 20:36:36 -0700552 }
553 }
554
Jeff Brown4ccb8232014-01-16 22:16:42 -0800555 private void renameWifiDisplayInternal(String address, String alias) {
556 synchronized (mSyncRoot) {
557 if (mWifiDisplayAdapter != null) {
558 mWifiDisplayAdapter.requestRenameLocked(address, alias);
Jeff Brown89d55462012-09-19 11:33:42 -0700559 }
Jeff Brown89d55462012-09-19 11:33:42 -0700560 }
561 }
562
Jeff Brown4ccb8232014-01-16 22:16:42 -0800563 private void forgetWifiDisplayInternal(String address) {
564 synchronized (mSyncRoot) {
565 if (mWifiDisplayAdapter != null) {
566 mWifiDisplayAdapter.requestForgetLocked(address);
Jeff Brown89d55462012-09-19 11:33:42 -0700567 }
Jeff Brown89d55462012-09-19 11:33:42 -0700568 }
569 }
570
Jeff Brown4ccb8232014-01-16 22:16:42 -0800571 private WifiDisplayStatus getWifiDisplayStatusInternal() {
572 synchronized (mSyncRoot) {
573 if (mWifiDisplayAdapter != null) {
574 return mWifiDisplayAdapter.getWifiDisplayStatusLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700575 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800576 return new WifiDisplayStatus();
Jeff Browne08ae382012-09-07 20:36:36 -0700577 }
578 }
579
Michael Wright1c9977b2016-07-12 13:30:10 -0700580 private void requestColorModeInternal(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +0100581 synchronized (mSyncRoot) {
582 LogicalDisplay display = mLogicalDisplays.get(displayId);
583 if (display != null &&
Michael Wright1c9977b2016-07-12 13:30:10 -0700584 display.getRequestedColorModeLocked() != colorMode) {
585 display.setRequestedColorModeLocked(colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100586 scheduleTraversalLocked(false);
587 }
588 }
589 }
590
Michael Wright75ee9fc2014-09-01 19:55:22 -0700591 private int createVirtualDisplayInternal(IVirtualDisplayCallback callback,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700592 IMediaProjection projection, int callingUid, String packageName,
Jeff Brown7d00aff2013-08-02 19:03:49 -0700593 String name, int width, int height, int densityDpi, Surface surface, int flags) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800594 synchronized (mSyncRoot) {
595 if (mVirtualDisplayAdapter == null) {
596 Slog.w(TAG, "Rejecting request to create private virtual display "
597 + "because the virtual display adapter is not available.");
598 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700599 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800600
601 DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked(
Michael Wright75ee9fc2014-09-01 19:55:22 -0700602 callback, projection, callingUid, packageName,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700603 name, width, height, densityDpi, surface, flags);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800604 if (device == null) {
605 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700606 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700607
Jeff Brown4ccb8232014-01-16 22:16:42 -0800608 handleDisplayDeviceAddedLocked(device);
609 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
610 if (display != null) {
611 return display.getDisplayIdLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700612 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800613
614 // Something weird happened and the logical display was not created.
615 Slog.w(TAG, "Rejecting request to create virtual display "
616 + "because the logical display was not created.");
Michael Wright75ee9fc2014-09-01 19:55:22 -0700617 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800618 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700619 }
620 return -1;
621 }
622
Michael Wright01e840f2014-06-26 16:03:25 -0700623 private void resizeVirtualDisplayInternal(IBinder appToken,
624 int width, int height, int densityDpi) {
625 synchronized (mSyncRoot) {
626 if (mVirtualDisplayAdapter == null) {
627 return;
628 }
629
630 mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi);
631 }
632 }
633
Jeff Brown92207df2014-04-16 13:16:07 -0700634 private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) {
635 synchronized (mSyncRoot) {
636 if (mVirtualDisplayAdapter == null) {
637 return;
638 }
639
640 mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface);
641 }
642 }
643
Jeff Brown4ccb8232014-01-16 22:16:42 -0800644 private void releaseVirtualDisplayInternal(IBinder appToken) {
645 synchronized (mSyncRoot) {
646 if (mVirtualDisplayAdapter == null) {
647 return;
Jeff Browna506a6e2013-06-04 00:02:38 -0700648 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700649
Jeff Brown4ccb8232014-01-16 22:16:42 -0800650 DisplayDevice device =
651 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
652 if (device != null) {
653 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700654 }
655 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700656 }
657
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700658 private void registerDefaultDisplayAdapter() {
659 // Register default display adapter.
660 synchronized (mSyncRoot) {
Mike Lockwoode63f6f72013-11-15 11:01:47 -0800661 registerDisplayAdapterLocked(new LocalDisplayAdapter(
662 mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700663 }
664 }
665
666 private void registerAdditionalDisplayAdapters() {
667 synchronized (mSyncRoot) {
668 if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700669 registerOverlayDisplayAdapterLocked();
670 registerWifiDisplayAdapterLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700671 registerVirtualDisplayAdapterLocked();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700672 }
673 }
674 }
675
Jeff Brown89d55462012-09-19 11:33:42 -0700676 private void registerOverlayDisplayAdapterLocked() {
677 registerDisplayAdapterLocked(new OverlayDisplayAdapter(
678 mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler));
679 }
680
681 private void registerWifiDisplayAdapterLocked() {
682 if (mContext.getResources().getBoolean(
Jeff Brownbbd28a22012-09-20 16:47:15 -0700683 com.android.internal.R.bool.config_enableWifiDisplay)
684 || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) {
Jeff Brown89d55462012-09-19 11:33:42 -0700685 mWifiDisplayAdapter = new WifiDisplayAdapter(
686 mSyncRoot, mContext, mHandler, mDisplayAdapterListener,
687 mPersistentDataStore);
688 registerDisplayAdapterLocked(mWifiDisplayAdapter);
689 }
690 }
691
Jeff Browna506a6e2013-06-04 00:02:38 -0700692 private void registerVirtualDisplayAdapterLocked() {
693 mVirtualDisplayAdapter = new VirtualDisplayAdapter(
694 mSyncRoot, mContext, mHandler, mDisplayAdapterListener);
695 registerDisplayAdapterLocked(mVirtualDisplayAdapter);
696 }
697
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700698 private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
699 // In safe mode, we disable non-essential display adapters to give the user
700 // an opportunity to fix broken settings or other problems that might affect
701 // system stability.
702 // In only-core mode, we disable non-essential display adapters to minimize
703 // the number of dependencies that are started while in this mode and to
704 // prevent problems that might occur due to the device being encrypted.
705 return !mSafeMode && !mOnlyCore;
706 }
707
708 private void registerDisplayAdapterLocked(DisplayAdapter adapter) {
709 mDisplayAdapters.add(adapter);
710 adapter.registerLocked();
711 }
712
Jeff Brownbd6e1502012-08-28 03:27:37 -0700713 private void handleDisplayDeviceAdded(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700714 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700715 handleDisplayDeviceAddedLocked(device);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700716 }
717 }
718
Jeff Browna506a6e2013-06-04 00:02:38 -0700719 private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700720 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700721 if (mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700722 Slog.w(TAG, "Attempted to add already added display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700723 return;
724 }
725
Jeff Brown10acf6d2015-04-14 14:20:47 -0700726 Slog.i(TAG, "Display device added: " + info);
727 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700728
729 mDisplayDevices.add(device);
Michael Wright1c9977b2016-07-12 13:30:10 -0700730 LogicalDisplay display = addLogicalDisplayLocked(device);
Jeff Brown0033a862014-10-08 12:06:39 -0700731 Runnable work = updateDisplayStateLocked(device);
732 if (work != null) {
733 work.run();
734 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700735 if (display != null && display.getPrimaryDisplayDeviceLocked() == device) {
736 int colorMode = mPersistentDataStore.getColorMode(device);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700737 if (colorMode == Display.COLOR_MODE_INVALID) {
738 if ((device.getDisplayDeviceInfoLocked().flags
739 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
740 colorMode = mDefaultDisplayDefaultColorMode;
741 } else {
742 colorMode = Display.COLOR_MODE_DEFAULT;
743 }
744 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700745 display.setRequestedColorModeLocked(colorMode);
746 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700747 scheduleTraversalLocked(false);
748 }
749
Jeff Brownbd6e1502012-08-28 03:27:37 -0700750 private void handleDisplayDeviceChanged(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700751 synchronized (mSyncRoot) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700752 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700753 if (!mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700754 Slog.w(TAG, "Attempted to change non-existent display device: " + info);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700755 return;
756 }
757
Jeff Brown10acf6d2015-04-14 14:20:47 -0700758 int diff = device.mDebugLastLoggedDeviceInfo.diff(info);
759 if (diff == DisplayDeviceInfo.DIFF_STATE) {
760 Slog.i(TAG, "Display device changed state: \"" + info.name
761 + "\", " + Display.stateToString(info.state));
762 } else if (diff != 0) {
763 Slog.i(TAG, "Display device changed: " + info);
764 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700765 if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) {
766 try {
767 mPersistentDataStore.setColorMode(device, info.colorMode);
768 } finally {
769 mPersistentDataStore.saveIfNeeded();
770 }
771 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700772 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browne87bf032012-09-20 18:30:13 -0700773
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700774 device.applyPendingDisplayDeviceInfoChangesLocked();
775 if (updateLogicalDisplaysLocked()) {
Craig Mautner65d11b32012-10-01 13:59:52 -0700776 scheduleTraversalLocked(false);
Jeff Brown64a55af2012-08-26 02:47:39 -0700777 }
778 }
779 }
780
Jeff Brownbd6e1502012-08-28 03:27:37 -0700781 private void handleDisplayDeviceRemoved(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700782 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700783 handleDisplayDeviceRemovedLocked(device);
784 }
785 }
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700786
Jeff Browna506a6e2013-06-04 00:02:38 -0700787 private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700788 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700789 if (!mDisplayDevices.remove(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700790 Slog.w(TAG, "Attempted to remove non-existent display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700791 return;
792 }
793
Jeff Brown10acf6d2015-04-14 14:20:47 -0700794 Slog.i(TAG, "Display device removed: " + info);
795 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700796
Jeff Browna506a6e2013-06-04 00:02:38 -0700797 updateLogicalDisplaysLocked();
798 scheduleTraversalLocked(false);
799 }
800
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700801 private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700802 final int count = mDisplayDevices.size();
803 for (int i = 0; i < count; i++) {
804 DisplayDevice device = mDisplayDevices.get(i);
Jeff Browne75926d2014-09-18 15:24:49 -0700805 Runnable runnable = updateDisplayStateLocked(device);
806 if (runnable != null) {
807 workQueue.add(runnable);
808 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700809 }
810 }
811
Jeff Browne75926d2014-09-18 15:24:49 -0700812 private Runnable updateDisplayStateLocked(DisplayDevice device) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700813 // Blank or unblank the display immediately to match the state requested
Jeff Brown037c33e2014-04-09 00:31:55 -0700814 // by the display power controller (if known).
Jeff Browna506a6e2013-06-04 00:02:38 -0700815 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
816 if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700817 return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700818 }
Jeff Browne75926d2014-09-18 15:24:49 -0700819 return null;
Craig Mautner4f67ba62012-08-02 11:23:00 -0700820 }
821
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700822 // Adds a new logical display based on the given display device.
823 // Sends notifications if needed.
Michael Wright1c9977b2016-07-12 13:30:10 -0700824 private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700825 DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
826 boolean isDefault = (deviceInfo.flags
827 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
828 if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
829 Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
830 isDefault = false;
831 }
832
Jeff Brown27f1d672012-10-17 18:32:34 -0700833 if (!isDefault && mSingleDisplayDemoMode) {
834 Slog.i(TAG, "Not creating a logical display for a secondary display "
835 + " because single display demo mode is enabled: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -0700836 return null;
Jeff Brown27f1d672012-10-17 18:32:34 -0700837 }
838
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700839 final int displayId = assignDisplayIdLocked(isDefault);
840 final int layerStack = assignLayerStackLocked(displayId);
841
Jeff Brownd728bf52012-09-08 18:05:28 -0700842 LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700843 display.updateLocked(mDisplayDevices);
844 if (!display.isValidLocked()) {
845 // This should never happen currently.
846 Slog.w(TAG, "Ignoring display device because the logical display "
847 + "created from it was not considered valid: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -0700848 return null;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700849 }
850
851 mLogicalDisplays.put(displayId, display);
852
853 // Wake up waitForDefaultDisplay.
854 if (isDefault) {
855 mSyncRoot.notifyAll();
856 }
857
858 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
Michael Wright1c9977b2016-07-12 13:30:10 -0700859 return display;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700860 }
861
862 private int assignDisplayIdLocked(boolean isDefault) {
863 return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++;
864 }
865
866 private int assignLayerStackLocked(int displayId) {
867 // Currently layer stacks and display ids are the same.
868 // This need not be the case.
869 return displayId;
870 }
871
872 // Updates all existing logical displays given the current set of display devices.
873 // Removes invalid logical displays.
874 // Sends notifications if needed.
875 private boolean updateLogicalDisplaysLocked() {
876 boolean changed = false;
877 for (int i = mLogicalDisplays.size(); i-- > 0; ) {
878 final int displayId = mLogicalDisplays.keyAt(i);
879 LogicalDisplay display = mLogicalDisplays.valueAt(i);
880
881 mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
882 display.updateLocked(mDisplayDevices);
883 if (!display.isValidLocked()) {
884 mLogicalDisplays.removeAt(i);
885 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
886 changed = true;
887 } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
888 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
889 changed = true;
890 }
891 }
892 return changed;
893 }
894
895 private void performTraversalInTransactionLocked() {
Jeff Brownd728bf52012-09-08 18:05:28 -0700896 // Clear all viewports before configuring displays so that we can keep
897 // track of which ones we have configured.
898 clearViewportsLocked();
899
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700900 // Configure each display device.
901 final int count = mDisplayDevices.size();
902 for (int i = 0; i < count; i++) {
903 DisplayDevice device = mDisplayDevices.get(i);
904 configureDisplayInTransactionLocked(device);
905 device.performTraversalInTransactionLocked();
906 }
Jeff Brownd728bf52012-09-08 18:05:28 -0700907
908 // Tell the input system about these new viewports.
Jeff Brown4ccb8232014-01-16 22:16:42 -0800909 if (mInputManagerInternal != null) {
Jeff Brownd728bf52012-09-08 18:05:28 -0700910 mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
911 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700912 }
913
Michael Wright3f145a22014-07-22 19:46:03 -0700914 private void setDisplayPropertiesInternal(int displayId, boolean hasContent,
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700915 float requestedRefreshRate, int requestedModeId, boolean inTraversal) {
Craig Mautner722285e2012-09-07 13:55:58 -0700916 synchronized (mSyncRoot) {
917 LogicalDisplay display = mLogicalDisplays.get(displayId);
Michael Wright3f145a22014-07-22 19:46:03 -0700918 if (display == null) {
919 return;
920 }
921 if (display.hasContentLocked() != hasContent) {
Jeff Brown33041bd2013-08-02 21:11:14 -0700922 if (DEBUG) {
923 Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
924 + "hasContent=" + hasContent + ", inTraversal=" + inTraversal);
925 }
926
Craig Mautner722285e2012-09-07 13:55:58 -0700927 display.setHasContentLocked(hasContent);
Craig Mautner65d11b32012-10-01 13:59:52 -0700928 scheduleTraversalLocked(inTraversal);
Craig Mautner722285e2012-09-07 13:55:58 -0700929 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700930 if (requestedModeId == 0 && requestedRefreshRate != 0) {
931 // Scan supported modes returned by display.getInfo() to find a mode with the same
932 // size as the default display mode but with the specified refresh rate instead.
933 requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate(
934 requestedRefreshRate);
935 }
936 if (display.getRequestedModeIdLocked() != requestedModeId) {
Michael Wright3f145a22014-07-22 19:46:03 -0700937 if (DEBUG) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700938 Slog.d(TAG, "Display " + displayId + " switching to mode " + requestedModeId);
Michael Wright3f145a22014-07-22 19:46:03 -0700939 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700940 display.setRequestedModeIdLocked(requestedModeId);
Michael Wright3f145a22014-07-22 19:46:03 -0700941 scheduleTraversalLocked(inTraversal);
942 }
Craig Mautner722285e2012-09-07 13:55:58 -0700943 }
Jeff Brownd728bf52012-09-08 18:05:28 -0700944 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700945
Filip Gruszczynskid2e86402015-02-19 13:05:03 -0800946 private void setDisplayOffsetsInternal(int displayId, int x, int y) {
947 synchronized (mSyncRoot) {
948 LogicalDisplay display = mLogicalDisplays.get(displayId);
949 if (display == null) {
950 return;
951 }
952 if (display.getDisplayOffsetXLocked() != x
953 || display.getDisplayOffsetYLocked() != y) {
954 if (DEBUG) {
955 Slog.d(TAG, "Display " + displayId + " burn-in offset set to ("
956 + x + ", " + y + ")");
957 }
958 display.setDisplayOffsetsLocked(x, y);
959 scheduleTraversalLocked(false);
960 }
961 }
962 }
963
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800964 // Updates the lists of UIDs that are present on displays.
965 private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) {
966 synchronized (mSyncRoot) {
967 mDisplayAccessUIDs.clear();
968 for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) {
969 mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i),
970 newDisplayAccessUIDs.valueAt(i));
971 }
972 }
973 }
974
975 // Checks if provided UID's content is present on the display and UID has access to it.
976 private boolean isUidPresentOnDisplayInternal(int uid, int displayId) {
977 synchronized (mSyncRoot) {
978 final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId);
979 return displayUIDs != null && displayUIDs.indexOf(uid) != -1;
980 }
981 }
982
Jeff Brownd728bf52012-09-08 18:05:28 -0700983 private void clearViewportsLocked() {
984 mDefaultViewport.valid = false;
985 mExternalTouchViewport.valid = false;
Craig Mautner722285e2012-09-07 13:55:58 -0700986 }
987
988 private void configureDisplayInTransactionLocked(DisplayDevice device) {
Jeff Brownd14c8c92014-01-07 18:13:09 -0800989 final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
990 final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;
Jeff Browna506a6e2013-06-04 00:02:38 -0700991
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700992 // Find the logical display that the display device is showing.
Jeff Brownd14c8c92014-01-07 18:13:09 -0800993 // Certain displays only ever show their own content.
Craig Mautner722285e2012-09-07 13:55:58 -0700994 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
Jeff Brownd14c8c92014-01-07 18:13:09 -0800995 if (!ownContent) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700996 if (display != null && !display.hasContentLocked()) {
997 // If the display does not have any content of its own, then
998 // automatically mirror the default logical display contents.
999 display = null;
1000 }
1001 if (display == null) {
1002 display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY);
1003 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001004 }
1005
1006 // Apply the logical display configuration to the display device.
1007 if (display == null) {
1008 // TODO: no logical display for the device, blank it
Jeff Brownd728bf52012-09-08 18:05:28 -07001009 Slog.w(TAG, "Missing logical display to use for physical display device: "
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001010 + device.getDisplayDeviceInfoLocked());
Jeff Brownd728bf52012-09-08 18:05:28 -07001011 return;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001012 }
Jeff Brown037c33e2014-04-09 00:31:55 -07001013 display.configureDisplayInTransactionLocked(device, info.state == Display.STATE_OFF);
Jeff Brownd728bf52012-09-08 18:05:28 -07001014
1015 // Update the viewports if needed.
Jeff Brownd728bf52012-09-08 18:05:28 -07001016 if (!mDefaultViewport.valid
1017 && (info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
1018 setViewportLocked(mDefaultViewport, display, device);
1019 }
1020 if (!mExternalTouchViewport.valid
1021 && info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
1022 setViewportLocked(mExternalTouchViewport, display, device);
1023 }
1024 }
1025
1026 private static void setViewportLocked(DisplayViewport viewport,
1027 LogicalDisplay display, DisplayDevice device) {
1028 viewport.valid = true;
1029 viewport.displayId = display.getDisplayIdLocked();
1030 device.populateViewportLocked(viewport);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001031 }
1032
1033 private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {
1034 final int count = mLogicalDisplays.size();
1035 for (int i = 0; i < count; i++) {
1036 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1037 if (display.getPrimaryDisplayDeviceLocked() == device) {
1038 return display;
1039 }
1040 }
1041 return null;
1042 }
1043
Jeff Brownbd6e1502012-08-28 03:27:37 -07001044 private void sendDisplayEventLocked(int displayId, int event) {
1045 Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
1046 mHandler.sendMessage(msg);
1047 }
1048
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001049 // Requests that performTraversalsInTransactionFromWindowManager be called at a
1050 // later time to apply changes to surfaces and displays.
Craig Mautner65d11b32012-10-01 13:59:52 -07001051 private void scheduleTraversalLocked(boolean inTraversal) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001052 if (!mPendingTraversal && mWindowManagerInternal != null) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001053 mPendingTraversal = true;
Craig Mautner65d11b32012-10-01 13:59:52 -07001054 if (!inTraversal) {
1055 mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL);
1056 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001057 }
1058 }
1059
1060 // Runs on Handler thread.
1061 // Delivers display event notifications to callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001062 private void deliverDisplayEvent(int displayId, int event) {
1063 if (DEBUG) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001064 Slog.d(TAG, "Delivering display event: displayId="
1065 + displayId + ", event=" + event);
Jeff Brownfa25bf52012-07-23 19:26:30 -07001066 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001067
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001068 // Grab the lock and copy the callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001069 final int count;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001070 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001071 count = mCallbacks.size();
1072 mTempCallbacks.clear();
1073 for (int i = 0; i < count; i++) {
1074 mTempCallbacks.add(mCallbacks.valueAt(i));
Craig Mautner4f67ba62012-08-02 11:23:00 -07001075 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001076 }
Craig Mautner4f67ba62012-08-02 11:23:00 -07001077
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001078 // After releasing the lock, send the notifications out.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001079 for (int i = 0; i < count; i++) {
1080 mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event);
1081 }
1082 mTempCallbacks.clear();
Craig Mautner4f67ba62012-08-02 11:23:00 -07001083 }
1084
Michael Wrightc39d47a2014-07-08 18:07:36 -07001085 private IMediaProjectionManager getProjectionService() {
1086 if (mProjectionService == null) {
1087 IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE);
1088 mProjectionService = IMediaProjectionManager.Stub.asInterface(b);
1089 }
1090 return mProjectionService;
1091 }
1092
Jeff Brown4ccb8232014-01-16 22:16:42 -08001093 private void dumpInternal(PrintWriter pw) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001094 pw.println("DISPLAY MANAGER (dumpsys display)");
Jeff Brownfa25bf52012-07-23 19:26:30 -07001095
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001096 synchronized (mSyncRoot) {
Jeff Brown9e316a12012-10-08 19:17:06 -07001097 pw.println(" mOnlyCode=" + mOnlyCore);
1098 pw.println(" mSafeMode=" + mSafeMode);
1099 pw.println(" mPendingTraversal=" + mPendingTraversal);
Jeff Brown037c33e2014-04-09 00:31:55 -07001100 pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState));
Jeff Brown9e316a12012-10-08 19:17:06 -07001101 pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId);
1102 pw.println(" mDefaultViewport=" + mDefaultViewport);
1103 pw.println(" mExternalTouchViewport=" + mExternalTouchViewport);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -07001104 pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode);
Jeff Brown27f1d672012-10-17 18:32:34 -07001105 pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
Jeff Brownce468a32013-11-21 16:42:03 -08001106 pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount);
Jeff Brown9e316a12012-10-08 19:17:06 -07001107
Jeff Brownbd6e1502012-08-28 03:27:37 -07001108 IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001109 ipw.increaseIndent();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001110
1111 pw.println();
1112 pw.println("Display Adapters: size=" + mDisplayAdapters.size());
Jeff Brown848c2dc2012-08-19 20:18:08 -07001113 for (DisplayAdapter adapter : mDisplayAdapters) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001114 pw.println(" " + adapter.getName());
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001115 adapter.dumpLocked(ipw);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001116 }
Craig Mautner9de49362012-08-02 14:30:30 -07001117
Jeff Brownbd6e1502012-08-28 03:27:37 -07001118 pw.println();
1119 pw.println("Display Devices: size=" + mDisplayDevices.size());
1120 for (DisplayDevice device : mDisplayDevices) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001121 pw.println(" " + device.getDisplayDeviceInfoLocked());
1122 device.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001123 }
1124
1125 final int logicalDisplayCount = mLogicalDisplays.size();
1126 pw.println();
1127 pw.println("Logical Displays: size=" + logicalDisplayCount);
1128 for (int i = 0; i < logicalDisplayCount; i++) {
1129 int displayId = mLogicalDisplays.keyAt(i);
1130 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1131 pw.println(" Display " + displayId + ":");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001132 display.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001133 }
Jeff Brownce468a32013-11-21 16:42:03 -08001134
1135 final int callbackCount = mCallbacks.size();
1136 pw.println();
1137 pw.println("Callbacks: size=" + callbackCount);
1138 for (int i = 0; i < callbackCount; i++) {
1139 CallbackRecord callback = mCallbacks.valueAt(i);
1140 pw.println(" " + i + ": mPid=" + callback.mPid
1141 + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
1142 }
Jeff Brownad9ef192014-04-08 17:26:30 -07001143
1144 if (mDisplayPowerController != null) {
1145 mDisplayPowerController.dump(pw);
1146 }
Michael Wright1c9977b2016-07-12 13:30:10 -07001147
1148 pw.println();
1149 mPersistentDataStore.dump(pw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001150 }
1151 }
1152
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001153 /**
1154 * This is the object that everything in the display manager locks on.
1155 * We make it an inner class within the {@link DisplayManagerService} to so that it is
1156 * clear that the object belongs to the display manager service and that it is
1157 * a unique object with a special purpose.
1158 */
1159 public static final class SyncRoot {
1160 }
1161
Jeff Brownbd6e1502012-08-28 03:27:37 -07001162 private final class DisplayManagerHandler extends Handler {
1163 public DisplayManagerHandler(Looper looper) {
1164 super(looper, null, true /*async*/);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001165 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001166
Jeff Brownbd6e1502012-08-28 03:27:37 -07001167 @Override
1168 public void handleMessage(Message msg) {
1169 switch (msg.what) {
1170 case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER:
1171 registerDefaultDisplayAdapter();
1172 break;
1173
1174 case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS:
1175 registerAdditionalDisplayAdapters();
1176 break;
1177
1178 case MSG_DELIVER_DISPLAY_EVENT:
1179 deliverDisplayEvent(msg.arg1, msg.arg2);
1180 break;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001181
1182 case MSG_REQUEST_TRAVERSAL:
Jeff Brown4ccb8232014-01-16 22:16:42 -08001183 mWindowManagerInternal.requestTraversalFromDisplayManager();
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001184 break;
Jeff Brownd728bf52012-09-08 18:05:28 -07001185
1186 case MSG_UPDATE_VIEWPORT: {
1187 synchronized (mSyncRoot) {
1188 mTempDefaultViewport.copyFrom(mDefaultViewport);
1189 mTempExternalTouchViewport.copyFrom(mExternalTouchViewport);
1190 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001191 mInputManagerInternal.setDisplayViewports(
Jeff Brownd728bf52012-09-08 18:05:28 -07001192 mTempDefaultViewport, mTempExternalTouchViewport);
1193 break;
1194 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001195 }
1196 }
1197 }
1198
1199 private final class DisplayAdapterListener implements DisplayAdapter.Listener {
1200 @Override
1201 public void onDisplayDeviceEvent(DisplayDevice device, int event) {
1202 switch (event) {
1203 case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED:
1204 handleDisplayDeviceAdded(device);
1205 break;
1206
1207 case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED:
1208 handleDisplayDeviceChanged(device);
1209 break;
1210
1211 case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED:
1212 handleDisplayDeviceRemoved(device);
1213 break;
1214 }
1215 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001216
1217 @Override
1218 public void onTraversalRequested() {
1219 synchronized (mSyncRoot) {
Craig Mautner65d11b32012-10-01 13:59:52 -07001220 scheduleTraversalLocked(false);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001221 }
1222 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001223 }
1224
1225 private final class CallbackRecord implements DeathRecipient {
Jeff Brownce468a32013-11-21 16:42:03 -08001226 public final int mPid;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001227 private final IDisplayManagerCallback mCallback;
1228
Jeff Brownce468a32013-11-21 16:42:03 -08001229 public boolean mWifiDisplayScanRequested;
1230
Jeff Brownbd6e1502012-08-28 03:27:37 -07001231 public CallbackRecord(int pid, IDisplayManagerCallback callback) {
1232 mPid = pid;
1233 mCallback = callback;
1234 }
1235
1236 @Override
1237 public void binderDied() {
1238 if (DEBUG) {
1239 Slog.d(TAG, "Display listener for pid " + mPid + " died.");
1240 }
Jeff Brownce468a32013-11-21 16:42:03 -08001241 onCallbackDied(this);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001242 }
1243
1244 public void notifyDisplayEventAsync(int displayId, int event) {
1245 try {
1246 mCallback.onDisplayEvent(displayId, event);
1247 } catch (RemoteException ex) {
1248 Slog.w(TAG, "Failed to notify process "
1249 + mPid + " that displays changed, assuming it died.", ex);
1250 binderDied();
1251 }
1252 }
1253 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001254
1255 private final class BinderService extends IDisplayManager.Stub {
1256 /**
1257 * Returns information about the specified logical display.
1258 *
1259 * @param displayId The logical display id.
1260 * @return The logical display info, or null if the display does not exist. The
1261 * returned object must be treated as immutable.
1262 */
1263 @Override // Binder call
1264 public DisplayInfo getDisplayInfo(int displayId) {
1265 final int callingUid = Binder.getCallingUid();
1266 final long token = Binder.clearCallingIdentity();
1267 try {
1268 return getDisplayInfoInternal(displayId, callingUid);
1269 } finally {
1270 Binder.restoreCallingIdentity(token);
1271 }
1272 }
1273
1274 /**
1275 * Returns the list of all display ids.
1276 */
1277 @Override // Binder call
1278 public int[] getDisplayIds() {
1279 final int callingUid = Binder.getCallingUid();
1280 final long token = Binder.clearCallingIdentity();
1281 try {
1282 return getDisplayIdsInternal(callingUid);
1283 } finally {
1284 Binder.restoreCallingIdentity(token);
1285 }
1286 }
1287
1288 @Override // Binder call
1289 public void registerCallback(IDisplayManagerCallback callback) {
1290 if (callback == null) {
1291 throw new IllegalArgumentException("listener must not be null");
1292 }
1293
1294 final int callingPid = Binder.getCallingPid();
1295 final long token = Binder.clearCallingIdentity();
1296 try {
1297 registerCallbackInternal(callback, callingPid);
1298 } finally {
1299 Binder.restoreCallingIdentity(token);
1300 }
1301 }
1302
1303 @Override // Binder call
1304 public void startWifiDisplayScan() {
1305 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1306 "Permission required to start wifi display scans");
1307
1308 final int callingPid = Binder.getCallingPid();
1309 final long token = Binder.clearCallingIdentity();
1310 try {
1311 startWifiDisplayScanInternal(callingPid);
1312 } finally {
1313 Binder.restoreCallingIdentity(token);
1314 }
1315 }
1316
1317 @Override // Binder call
1318 public void stopWifiDisplayScan() {
1319 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1320 "Permission required to stop wifi display scans");
1321
1322 final int callingPid = Binder.getCallingPid();
1323 final long token = Binder.clearCallingIdentity();
1324 try {
1325 stopWifiDisplayScanInternal(callingPid);
1326 } finally {
1327 Binder.restoreCallingIdentity(token);
1328 }
1329 }
1330
1331 @Override // Binder call
1332 public void connectWifiDisplay(String address) {
1333 if (address == null) {
1334 throw new IllegalArgumentException("address must not be null");
1335 }
1336 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1337 "Permission required to connect to a wifi display");
1338
1339 final long token = Binder.clearCallingIdentity();
1340 try {
1341 connectWifiDisplayInternal(address);
1342 } finally {
1343 Binder.restoreCallingIdentity(token);
1344 }
1345 }
1346
1347 @Override // Binder call
1348 public void disconnectWifiDisplay() {
1349 // This request does not require special permissions.
1350 // Any app can request disconnection from the currently active wifi display.
1351 // This exception should no longer be needed once wifi display control moves
1352 // to the media router service.
1353
1354 final long token = Binder.clearCallingIdentity();
1355 try {
1356 disconnectWifiDisplayInternal();
1357 } finally {
1358 Binder.restoreCallingIdentity(token);
1359 }
1360 }
1361
1362 @Override // Binder call
1363 public void renameWifiDisplay(String address, String alias) {
1364 if (address == null) {
1365 throw new IllegalArgumentException("address must not be null");
1366 }
1367 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1368 "Permission required to rename to a wifi display");
1369
1370 final long token = Binder.clearCallingIdentity();
1371 try {
1372 renameWifiDisplayInternal(address, alias);
1373 } finally {
1374 Binder.restoreCallingIdentity(token);
1375 }
1376 }
1377
1378 @Override // Binder call
1379 public void forgetWifiDisplay(String address) {
1380 if (address == null) {
1381 throw new IllegalArgumentException("address must not be null");
1382 }
1383 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1384 "Permission required to forget to a wifi display");
1385
1386 final long token = Binder.clearCallingIdentity();
1387 try {
1388 forgetWifiDisplayInternal(address);
1389 } finally {
1390 Binder.restoreCallingIdentity(token);
1391 }
1392 }
1393
1394 @Override // Binder call
1395 public void pauseWifiDisplay() {
1396 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1397 "Permission required to pause a wifi display session");
1398
1399 final long token = Binder.clearCallingIdentity();
1400 try {
1401 pauseWifiDisplayInternal();
1402 } finally {
1403 Binder.restoreCallingIdentity(token);
1404 }
1405 }
1406
1407 @Override // Binder call
1408 public void resumeWifiDisplay() {
1409 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1410 "Permission required to resume a wifi display session");
1411
1412 final long token = Binder.clearCallingIdentity();
1413 try {
1414 resumeWifiDisplayInternal();
1415 } finally {
1416 Binder.restoreCallingIdentity(token);
1417 }
1418 }
1419
1420 @Override // Binder call
1421 public WifiDisplayStatus getWifiDisplayStatus() {
1422 // This request does not require special permissions.
1423 // Any app can get information about available wifi displays.
1424
1425 final long token = Binder.clearCallingIdentity();
1426 try {
1427 return getWifiDisplayStatusInternal();
1428 } finally {
1429 Binder.restoreCallingIdentity(token);
1430 }
1431 }
1432
1433 @Override // Binder call
Michael Wright1c9977b2016-07-12 13:30:10 -07001434 public void requestColorMode(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +01001435 mContext.enforceCallingOrSelfPermission(
Michael Wright1c9977b2016-07-12 13:30:10 -07001436 Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE,
1437 "Permission required to change the display color mode");
Michael Wright58e829f2015-09-15 00:13:26 +01001438 final long token = Binder.clearCallingIdentity();
1439 try {
Michael Wright1c9977b2016-07-12 13:30:10 -07001440 requestColorModeInternal(displayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +01001441 } finally {
1442 Binder.restoreCallingIdentity(token);
1443 }
1444 }
1445
1446 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001447 public int createVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001448 IMediaProjection projection, String packageName, String name,
1449 int width, int height, int densityDpi, Surface surface, int flags) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001450 final int callingUid = Binder.getCallingUid();
1451 if (!validatePackageName(callingUid, packageName)) {
1452 throw new SecurityException("packageName must match the calling uid");
1453 }
Michael Wright75ee9fc2014-09-01 19:55:22 -07001454 if (callback == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001455 throw new IllegalArgumentException("appToken must not be null");
1456 }
1457 if (TextUtils.isEmpty(name)) {
1458 throw new IllegalArgumentException("name must be non-null and non-empty");
1459 }
1460 if (width <= 0 || height <= 0 || densityDpi <= 0) {
1461 throw new IllegalArgumentException("width, height, and densityDpi must be "
1462 + "greater than 0");
1463 }
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07001464 if (surface != null && surface.isSingleBuffered()) {
Pablo Ceballosaff2f942016-07-29 14:49:55 -07001465 throw new IllegalArgumentException("Surface can't be single-buffered");
1466 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07001467
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001468 if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
1469 flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
1470
1471 // Public displays can't be allowed to show content when locked.
Andrii Kulian7211d2e2017-01-27 15:58:05 -08001472 if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001473 throw new IllegalArgumentException(
1474 "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE");
1475 }
Michael Wright6720be42014-07-29 19:14:16 -07001476 }
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001477 if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) {
1478 flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
Michael Wright6720be42014-07-29 19:14:16 -07001479 }
1480
Michael Wrightc39d47a2014-07-08 18:07:36 -07001481 if (projection != null) {
1482 try {
1483 if (!getProjectionService().isValidMediaProjection(projection)) {
1484 throw new SecurityException("Invalid media projection");
1485 }
Michael Wright6720be42014-07-29 19:14:16 -07001486 flags = projection.applyVirtualDisplayFlags(flags);
Michael Wrightc39d47a2014-07-08 18:07:36 -07001487 } catch (RemoteException e) {
Michael Wright6720be42014-07-29 19:14:16 -07001488 throw new SecurityException("unable to validate media projection or flags");
Michael Wrightc39d47a2014-07-08 18:07:36 -07001489 }
1490 }
1491
Michael Wright6720be42014-07-29 19:14:16 -07001492 if (callingUid != Process.SYSTEM_UID &&
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001493 (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07001494 if (!canProjectVideo(projection)) {
1495 throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
1496 + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate "
1497 + "MediaProjection token in order to create a screen sharing virtual "
1498 + "display.");
1499 }
1500 }
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001501 if ((flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07001502 if (!canProjectSecureVideo(projection)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001503 throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT "
Michael Wrightc39d47a2014-07-08 18:07:36 -07001504 + "or an appropriate MediaProjection token to create a "
1505 + "secure virtual display.");
Jeff Brown4ccb8232014-01-16 22:16:42 -08001506 }
1507 }
1508
1509 final long token = Binder.clearCallingIdentity();
1510 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001511 return createVirtualDisplayInternal(callback, projection, callingUid,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001512 packageName, name, width, height, densityDpi, surface, flags);
Jeff Brown4ccb8232014-01-16 22:16:42 -08001513 } finally {
1514 Binder.restoreCallingIdentity(token);
1515 }
1516 }
1517
1518 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001519 public void resizeVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wright01e840f2014-06-26 16:03:25 -07001520 int width, int height, int densityDpi) {
1521 final long token = Binder.clearCallingIdentity();
1522 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001523 resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi);
Michael Wright01e840f2014-06-26 16:03:25 -07001524 } finally {
1525 Binder.restoreCallingIdentity(token);
1526 }
1527 }
1528
1529 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001530 public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) {
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07001531 if (surface != null && surface.isSingleBuffered()) {
1532 throw new IllegalArgumentException("Surface can't be single-buffered");
1533 }
Jeff Brown92207df2014-04-16 13:16:07 -07001534 final long token = Binder.clearCallingIdentity();
1535 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001536 setVirtualDisplaySurfaceInternal(callback.asBinder(), surface);
Jeff Brown92207df2014-04-16 13:16:07 -07001537 } finally {
1538 Binder.restoreCallingIdentity(token);
1539 }
1540 }
1541
1542 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001543 public void releaseVirtualDisplay(IVirtualDisplayCallback callback) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001544 final long token = Binder.clearCallingIdentity();
1545 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001546 releaseVirtualDisplayInternal(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -08001547 } finally {
1548 Binder.restoreCallingIdentity(token);
1549 }
1550 }
1551
1552 @Override // Binder call
1553 public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001554 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jeff Brown4ccb8232014-01-16 22:16:42 -08001555
1556 final long token = Binder.clearCallingIdentity();
1557 try {
1558 dumpInternal(pw);
1559 } finally {
1560 Binder.restoreCallingIdentity(token);
1561 }
1562 }
1563
1564 private boolean validatePackageName(int uid, String packageName) {
1565 if (packageName != null) {
1566 String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
1567 if (packageNames != null) {
1568 for (String n : packageNames) {
1569 if (n.equals(packageName)) {
1570 return true;
1571 }
1572 }
1573 }
1574 }
1575 return false;
1576 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07001577
1578 private boolean canProjectVideo(IMediaProjection projection) {
1579 if (projection != null) {
1580 try {
1581 if (projection.canProjectVideo()) {
1582 return true;
1583 }
1584 } catch (RemoteException e) {
1585 Slog.e(TAG, "Unable to query projection service for permissions", e);
1586 }
1587 }
1588 if (mContext.checkCallingPermission(
1589 android.Manifest.permission.CAPTURE_VIDEO_OUTPUT)
Michael Wright0ccc2b02014-07-24 18:20:41 -07001590 == PackageManager.PERMISSION_GRANTED) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07001591 return true;
1592 }
1593 return canProjectSecureVideo(projection);
1594 }
1595
1596 private boolean canProjectSecureVideo(IMediaProjection projection) {
1597 if (projection != null) {
1598 try {
1599 if (projection.canProjectSecureVideo()){
1600 return true;
1601 }
1602 } catch (RemoteException e) {
1603 Slog.e(TAG, "Unable to query projection service for permissions", e);
1604 }
1605 }
1606 return mContext.checkCallingPermission(
1607 android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT)
Michael Wright0ccc2b02014-07-24 18:20:41 -07001608 == PackageManager.PERMISSION_GRANTED;
Michael Wrightc39d47a2014-07-08 18:07:36 -07001609 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001610 }
1611
1612 private final class LocalService extends DisplayManagerInternal {
1613 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07001614 public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler,
Jeff Brownad9ef192014-04-08 17:26:30 -07001615 SensorManager sensorManager) {
1616 synchronized (mSyncRoot) {
Jeff Brown037c33e2014-04-09 00:31:55 -07001617 DisplayBlanker blanker = new DisplayBlanker() {
1618 @Override
Jeff Brown5d6443b2015-04-10 20:15:01 -07001619 public void requestDisplayState(int state, int brightness) {
Jeff Brown037c33e2014-04-09 00:31:55 -07001620 // The order of operations is important for legacy reasons.
1621 if (state == Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07001622 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07001623 }
1624
1625 callbacks.onDisplayStateChange(state);
1626
1627 if (state != Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07001628 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07001629 }
1630 }
1631 };
Jeff Brownad9ef192014-04-08 17:26:30 -07001632 mDisplayPowerController = new DisplayPowerController(
Jeff Brown037c33e2014-04-09 00:31:55 -07001633 mContext, callbacks, handler, sensorManager, blanker);
Jeff Brownad9ef192014-04-08 17:26:30 -07001634 }
1635 }
1636
1637 @Override
1638 public boolean requestPowerState(DisplayPowerRequest request,
1639 boolean waitForNegativeProximity) {
1640 return mDisplayPowerController.requestPowerState(request,
1641 waitForNegativeProximity);
1642 }
1643
1644 @Override
1645 public boolean isProximitySensorAvailable() {
1646 return mDisplayPowerController.isProximitySensorAvailable();
1647 }
1648
1649 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -08001650 public DisplayInfo getDisplayInfo(int displayId) {
1651 return getDisplayInfoInternal(displayId, Process.myUid());
1652 }
1653
1654 @Override
1655 public void registerDisplayTransactionListener(DisplayTransactionListener listener) {
1656 if (listener == null) {
1657 throw new IllegalArgumentException("listener must not be null");
1658 }
1659
1660 registerDisplayTransactionListenerInternal(listener);
1661 }
1662
1663 @Override
1664 public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) {
1665 if (listener == null) {
1666 throw new IllegalArgumentException("listener must not be null");
1667 }
1668
1669 unregisterDisplayTransactionListenerInternal(listener);
1670 }
1671
1672 @Override
1673 public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) {
1674 setDisplayInfoOverrideFromWindowManagerInternal(displayId, info);
1675 }
1676
1677 @Override
Andrii Kuliancd097992017-03-23 18:31:59 -07001678 public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) {
1679 getNonOverrideDisplayInfoInternal(displayId, outInfo);
1680 }
1681
1682 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -08001683 public void performTraversalInTransactionFromWindowManager() {
1684 performTraversalInTransactionFromWindowManagerInternal();
1685 }
1686
1687 @Override
Michael Wright3f145a22014-07-22 19:46:03 -07001688 public void setDisplayProperties(int displayId, boolean hasContent,
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001689 float requestedRefreshRate, int requestedMode, boolean inTraversal) {
1690 setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate,
1691 requestedMode, inTraversal);
Jeff Brown4ccb8232014-01-16 22:16:42 -08001692 }
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08001693
1694 @Override
1695 public void setDisplayOffsets(int displayId, int x, int y) {
1696 setDisplayOffsetsInternal(displayId, x, y);
1697 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08001698
1699 @Override
1700 public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) {
1701 setDisplayAccessUIDsInternal(newDisplayAccessUIDs);
1702 }
1703
1704 @Override
1705 public boolean isUidPresentOnDisplay(int uid, int displayId) {
1706 return isUidPresentOnDisplayInternal(uid, displayId);
1707 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001708 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001709}