blob: 208295847e24dbeff8c2748536842450a081219c [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
Jorim Jaggied7993b2017-03-28 18:50:01 +010066import com.android.server.AnimationThread;
Jeff Brown4ccb8232014-01-16 22:16:42 -080067import com.android.server.DisplayThread;
68import com.android.server.LocalServices;
69import com.android.server.SystemService;
Dianne Hackborn8d044e82013-04-30 17:24:15 -070070import com.android.server.UiThread;
Jeff Brownfa25bf52012-07-23 19:26:30 -070071
72import java.io.FileDescriptor;
73import java.io.PrintWriter;
74import java.util.ArrayList;
Jeff Browna506a6e2013-06-04 00:02:38 -070075import java.util.Arrays;
Jeff Browne75926d2014-09-18 15:24:49 -070076import java.util.List;
Jeff Brown7f3994e2012-12-04 14:04:28 -080077import java.util.concurrent.CopyOnWriteArrayList;
Jeff Brownfa25bf52012-07-23 19:26:30 -070078
79/**
Jeff Brownbd6e1502012-08-28 03:27:37 -070080 * Manages attached displays.
Jeff Brownfa25bf52012-07-23 19:26:30 -070081 * <p>
Jeff Brownbd6e1502012-08-28 03:27:37 -070082 * The {@link DisplayManagerService} manages the global lifecycle of displays,
83 * decides how to configure logical displays based on the physical display devices currently
84 * attached, sends notifications to the system and to applications when the state
85 * changes, and so on.
86 * </p><p>
87 * The display manager service relies on a collection of {@link DisplayAdapter} components,
88 * for discovering and configuring physical display devices attached to the system.
89 * There are separate display adapters for each manner that devices are attached:
90 * one display adapter for built-in local displays, one for simulated non-functional
91 * displays when the system is headless, one for simulated overlay displays used for
92 * development, one for wifi displays, etc.
93 * </p><p>
94 * Display adapters are only weakly coupled to the display manager service.
95 * Display adapters communicate changes in display device state to the display manager
Craig Mautner722285e2012-09-07 13:55:58 -070096 * service asynchronously via a {@link DisplayAdapter.Listener} registered
Jeff Brownbd6e1502012-08-28 03:27:37 -070097 * by the display manager service. This separation of concerns is important for
98 * two main reasons. First, it neatly encapsulates the responsibilities of these
99 * two classes: display adapters handle individual display devices whereas
100 * the display manager service handles the global state. Second, it eliminates
101 * the potential for deadlocks resulting from asynchronous display device discovery.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700102 * </p>
103 *
104 * <h3>Synchronization</h3>
105 * <p>
106 * Because the display manager may be accessed by multiple threads, the synchronization
107 * story gets a little complicated. In particular, the window manager may call into
108 * the display manager while holding a surface transaction with the expectation that
109 * it can apply changes immediately. Unfortunately, that means we can't just do
110 * everything asynchronously (*grump*).
Jeff Brownbd6e1502012-08-28 03:27:37 -0700111 * </p><p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700112 * To make this work, all of the objects that belong to the display manager must
113 * use the same lock. We call this lock the synchronization root and it has a unique
114 * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are
115 * named with the "Locked" suffix.
116 * </p><p>
117 * Where things get tricky is that the display manager is not allowed to make
118 * any potentially reentrant calls, especially into the window manager. We generally
119 * avoid this by making all potentially reentrant out-calls asynchronous.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700120 * </p>
121 */
Jeff Brown4ccb8232014-01-16 22:16:42 -0800122public final class DisplayManagerService extends SystemService {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700123 private static final String TAG = "DisplayManagerService";
Jeff Brownbd6e1502012-08-28 03:27:37 -0700124 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700125
Jeff Brownbbd28a22012-09-20 16:47:15 -0700126 // When this system property is set to 0, WFD is forcibly disabled on boot.
127 // When this system property is set to 1, WFD is forcibly enabled on boot.
128 // Otherwise WFD is enabled according to the value of config_enableWifiDisplay.
129 private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
130
Jeff Brownbd6e1502012-08-28 03:27:37 -0700131 private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
132
133 private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER = 1;
134 private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2;
135 private static final int MSG_DELIVER_DISPLAY_EVENT = 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700136 private static final int MSG_REQUEST_TRAVERSAL = 4;
Jeff Brownd728bf52012-09-08 18:05:28 -0700137 private static final int MSG_UPDATE_VIEWPORT = 5;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700138
Jeff Brownb880d882014-02-10 19:47:07 -0800139 private final Context mContext;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700140 private final DisplayManagerHandler mHandler;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700141 private final Handler mUiHandler;
142 private final DisplayAdapterListener mDisplayAdapterListener;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800143 private WindowManagerInternal mWindowManagerInternal;
144 private InputManagerInternal mInputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700145 private IMediaProjectionManager mProjectionService;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700146
147 // The synchronization root for the display manager.
148 // This lock guards most of the display manager's state.
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800149 // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call
150 // into WindowManagerService methods that require mWindowMap while holding this unless you are
151 // very very sure that no deadlock can occur.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700152 private final SyncRoot mSyncRoot = new SyncRoot();
153
154 // True if in safe mode.
155 // This option may disable certain display adapters.
156 public boolean mSafeMode;
157
158 // True if we are in a special boot mode where only core applications and
159 // services should be started. This option may disable certain display adapters.
160 public boolean mOnlyCore;
161
Jeff Brown27f1d672012-10-17 18:32:34 -0700162 // True if the display manager service should pretend there is only one display
163 // and only tell applications about the existence of the default logical display.
164 // The display manager can still mirror content to secondary displays but applications
165 // cannot present unique content on those displays.
166 // Used for demonstration purposes only.
167 private final boolean mSingleDisplayDemoMode;
168
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700169 // All callback records indexed by calling process id.
170 public final SparseArray<CallbackRecord> mCallbacks =
Jeff Brownbd6e1502012-08-28 03:27:37 -0700171 new SparseArray<CallbackRecord>();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700172
Jeff Brownbd6e1502012-08-28 03:27:37 -0700173 // List of all currently registered display adapters.
174 private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
175
176 // List of all currently connected display devices.
177 private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>();
178
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700179 // List of all logical displays indexed by logical display id.
180 private final SparseArray<LogicalDisplay> mLogicalDisplays =
181 new SparseArray<LogicalDisplay>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700182 private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1;
183
Jeff Brown7f3994e2012-12-04 14:04:28 -0800184 // List of all display transaction listeners.
185 private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
186 new CopyOnWriteArrayList<DisplayTransactionListener>();
187
Jeff Brownad9ef192014-04-08 17:26:30 -0700188 // Display power controller.
189 private DisplayPowerController mDisplayPowerController;
190
Jeff Brown037c33e2014-04-09 00:31:55 -0700191 // The overall display state, independent of changes that might influence one
192 // display or another in particular.
Jeff Brown5d6443b2015-04-10 20:15:01 -0700193 private int mGlobalDisplayState = Display.STATE_ON;
194
195 // The overall display brightness.
196 // For now, this only applies to the built-in display but we may split it up eventually.
197 private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT;
Jeff Brown9e316a12012-10-08 19:17:06 -0700198
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700199 // Set to true when there are pending display changes that have yet to be applied
200 // to the surface flinger state.
201 private boolean mPendingTraversal;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700202
Jeff Browne08ae382012-09-07 20:36:36 -0700203 // The Wifi display adapter, or null if not registered.
204 private WifiDisplayAdapter mWifiDisplayAdapter;
205
Jeff Brownce468a32013-11-21 16:42:03 -0800206 // The number of active wifi display scan requests.
207 private int mWifiDisplayScanRequestCount;
208
Jeff Browna506a6e2013-06-04 00:02:38 -0700209 // The virtual display adapter, or null if not registered.
210 private VirtualDisplayAdapter mVirtualDisplayAdapter;
211
Jeff Brownd728bf52012-09-08 18:05:28 -0700212 // Viewports of the default display and the display that should receive touch
213 // input from an external source. Used by the input system.
214 private final DisplayViewport mDefaultViewport = new DisplayViewport();
215 private final DisplayViewport mExternalTouchViewport = new DisplayViewport();
216
Jeff Brown89d55462012-09-19 11:33:42 -0700217 // Persistent data store for all internal settings maintained by the display manager service.
218 private final PersistentDataStore mPersistentDataStore = new PersistentDataStore();
219
Jeff Brownbd6e1502012-08-28 03:27:37 -0700220 // Temporary callback list, used when sending display events to applications.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700221 // May be used outside of the lock but only on the handler thread.
222 private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700223
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700224 // Temporary display info, used for comparing display configurations.
225 private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
226
Jeff Brownd728bf52012-09-08 18:05:28 -0700227 // Temporary viewports, used when sending new viewport information to the
228 // input system. May be used outside of the lock but only on the handler thread.
229 private final DisplayViewport mTempDefaultViewport = new DisplayViewport();
230 private final DisplayViewport mTempExternalTouchViewport = new DisplayViewport();
231
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700232 // The default color mode for default displays. Overrides the usual
233 // Display.Display.COLOR_MODE_DEFAULT for displays with the
234 // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set.
235 private final int mDefaultDisplayDefaultColorMode;
236
Jeff Browne75926d2014-09-18 15:24:49 -0700237 // Temporary list of deferred work to perform when setting the display state.
238 // Only used by requestDisplayState. The field is self-synchronized and only
239 // intended for use inside of the requestGlobalDisplayStateInternal function.
240 private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>();
241
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800242 // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs.
243 private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>();
244
Jeff Brownb880d882014-02-10 19:47:07 -0800245 public DisplayManagerService(Context context) {
246 super(context);
247 mContext = context;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800248 mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700249 mUiHandler = UiThread.getHandler();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700250 mDisplayAdapterListener = new DisplayAdapterListener();
Jeff Brown27f1d672012-10-17 18:32:34 -0700251 mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700252 mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger(
253 com.android.internal.R.integer.config_defaultDisplayDefaultColorMode);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700254
255 PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
256 mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting();
Joel Fernandes2d314e12017-04-04 16:32:15 -0700257
258 }
259
260 public void setupSchedulerPolicies() {
Jorim Jaggied7993b2017-03-28 18:50:01 +0100261 // android.display and android.anim is critical to user experience and we should make sure
262 // it is not in the default foregroup groups, add it to top-app to make sure it uses all the
263 // cores and scheduling settings for top-app when it runs.
264 Process.setThreadGroupAndCpuset(DisplayThread.get().getThreadId(),
265 Process.THREAD_GROUP_TOP_APP);
266 Process.setThreadGroupAndCpuset(AnimationThread.get().getThreadId(),
267 Process.THREAD_GROUP_TOP_APP);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700268 }
269
Jeff Brown4ccb8232014-01-16 22:16:42 -0800270 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -0800271 public void onStart() {
Michael Wright1c9977b2016-07-12 13:30:10 -0700272 // We need to pre-load the persistent data store so it's ready before the default display
273 // adapter is up so that we have it's configuration. We could load it lazily, but since
274 // we're going to have to read it in eventually we may as well do it here rather than after
275 // we've waited for the diplay to register itself with us.
276 mPersistentDataStore.loadIfNeeded();
Jeff Brown4ccb8232014-01-16 22:16:42 -0800277 mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER);
278
279 publishBinderService(Context.DISPLAY_SERVICE, new BinderService(),
280 true /*allowIsolated*/);
281 publishLocalService(DisplayManagerInternal.class, new LocalService());
Justin Klaassen22eb1992016-07-11 20:52:23 -0700282 publishLocalService(DisplayTransformManager.class, new DisplayTransformManager());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800283 }
284
285 @Override
286 public void onBootPhase(int phase) {
287 if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) {
288 synchronized (mSyncRoot) {
289 long timeout = SystemClock.uptimeMillis() + WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
290 while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null) {
291 long delay = timeout - SystemClock.uptimeMillis();
292 if (delay <= 0) {
293 throw new RuntimeException("Timeout waiting for default display "
294 + "to be initialized.");
295 }
296 if (DEBUG) {
297 Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay);
298 }
299 try {
300 mSyncRoot.wait(delay);
301 } catch (InterruptedException ex) {
302 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700303 }
304 }
305 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700306 }
307
Jeff Brown4ccb8232014-01-16 22:16:42 -0800308 // TODO: Use dependencies or a boot phase
309 public void windowManagerAndInputReady() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700310 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800311 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
312 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Craig Mautner65d11b32012-10-01 13:59:52 -0700313 scheduleTraversalLocked(false);
Jeff Brownd728bf52012-09-08 18:05:28 -0700314 }
315 }
316
317 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700318 * Called when the system is ready to go.
319 */
320 public void systemReady(boolean safeMode, boolean onlyCore) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700321 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700322 mSafeMode = safeMode;
323 mOnlyCore = onlyCore;
324 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700325
Jeff Brownbd6e1502012-08-28 03:27:37 -0700326 mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
327 }
328
Jeff Brown4ccb8232014-01-16 22:16:42 -0800329 private void registerDisplayTransactionListenerInternal(
330 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800331 // List is self-synchronized copy-on-write.
332 mDisplayTransactionListeners.add(listener);
333 }
334
Jeff Brown4ccb8232014-01-16 22:16:42 -0800335 private void unregisterDisplayTransactionListenerInternal(
336 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800337 // List is self-synchronized copy-on-write.
338 mDisplayTransactionListeners.remove(listener);
339 }
340
Jeff Brown4ccb8232014-01-16 22:16:42 -0800341 private void setDisplayInfoOverrideFromWindowManagerInternal(
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700342 int displayId, DisplayInfo info) {
343 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700344 LogicalDisplay display = mLogicalDisplays.get(displayId);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700345 if (display != null) {
Jeff Brownef981a42013-08-07 14:13:37 -0700346 if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700347 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
Craig Mautner65d11b32012-10-01 13:59:52 -0700348 scheduleTraversalLocked(false);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700349 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700350 }
351 }
352 }
353
Andrii Kuliancd097992017-03-23 18:31:59 -0700354 /**
355 * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo)
356 */
357 private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) {
358 synchronized (mSyncRoot) {
359 final LogicalDisplay display = mLogicalDisplays.get(displayId);
360 if (display != null) {
361 display.getNonOverrideDisplayInfoLocked(outInfo);
362 }
363 }
364 }
365
Jeff Brown4ccb8232014-01-16 22:16:42 -0800366 private void performTraversalInTransactionFromWindowManagerInternal() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700367 synchronized (mSyncRoot) {
368 if (!mPendingTraversal) {
369 return;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700370 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700371 mPendingTraversal = false;
372
373 performTraversalInTransactionLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700374 }
Jeff Brown7f3994e2012-12-04 14:04:28 -0800375
376 // List is self-synchronized copy-on-write.
377 for (DisplayTransactionListener listener : mDisplayTransactionListeners) {
378 listener.onDisplayTransaction();
379 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700380 }
381
Jeff Brown5d6443b2015-04-10 20:15:01 -0700382 private void requestGlobalDisplayStateInternal(int state, int brightness) {
383 if (state == Display.STATE_UNKNOWN) {
384 state = Display.STATE_ON;
385 }
386 if (state == Display.STATE_OFF) {
387 brightness = PowerManager.BRIGHTNESS_OFF;
388 } else if (brightness < 0) {
389 brightness = PowerManager.BRIGHTNESS_DEFAULT;
390 } else if (brightness > PowerManager.BRIGHTNESS_ON) {
391 brightness = PowerManager.BRIGHTNESS_ON;
392 }
393
Jeff Browne75926d2014-09-18 15:24:49 -0700394 synchronized (mTempDisplayStateWorkQueue) {
395 try {
396 // Update the display state within the lock.
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700397 // Note that we do not need to schedule traversals here although it
398 // may happen as a side-effect of displays changing state.
Jeff Browne75926d2014-09-18 15:24:49 -0700399 synchronized (mSyncRoot) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700400 if (mGlobalDisplayState == state
401 && mGlobalDisplayBrightness == brightness) {
402 return; // no change
Jeff Browne75926d2014-09-18 15:24:49 -0700403 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700404
405 Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState("
406 + Display.stateToString(state)
407 + ", brightness=" + brightness + ")");
408 mGlobalDisplayState = state;
409 mGlobalDisplayBrightness = brightness;
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700410 applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue);
Jeff Browne75926d2014-09-18 15:24:49 -0700411 }
412
413 // Setting the display power state can take hundreds of milliseconds
414 // to complete so we defer the most expensive part of the work until
415 // after we have exited the critical section to avoid blocking other
416 // threads for a long time.
417 for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) {
418 mTempDisplayStateWorkQueue.get(i).run();
419 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700420 Trace.traceEnd(Trace.TRACE_TAG_POWER);
Jeff Browne75926d2014-09-18 15:24:49 -0700421 } finally {
422 mTempDisplayStateWorkQueue.clear();
Jeff Brown9e316a12012-10-08 19:17:06 -0700423 }
424 }
425 }
426
Jeff Brown4ccb8232014-01-16 22:16:42 -0800427 private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700428 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800429 LogicalDisplay display = mLogicalDisplays.get(displayId);
430 if (display != null) {
431 DisplayInfo info = display.getDisplayInfoLocked();
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800432 if (info.hasAccess(callingUid)
433 || isUidPresentOnDisplayInternal(callingUid, displayId)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800434 return info;
435 }
436 }
437 return null;
438 }
439 }
440
441 private int[] getDisplayIdsInternal(int callingUid) {
442 synchronized (mSyncRoot) {
443 final int count = mLogicalDisplays.size();
444 int[] displayIds = new int[count];
445 int n = 0;
446 for (int i = 0; i < count; i++) {
447 LogicalDisplay display = mLogicalDisplays.valueAt(i);
448 DisplayInfo info = display.getDisplayInfoLocked();
449 if (info.hasAccess(callingUid)) {
450 displayIds[n++] = mLogicalDisplays.keyAt(i);
451 }
452 }
453 if (n != count) {
454 displayIds = Arrays.copyOfRange(displayIds, 0, n);
455 }
456 return displayIds;
457 }
458 }
459
460 private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) {
461 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700462 if (mCallbacks.get(callingPid) != null) {
463 throw new SecurityException("The calling process has already "
464 + "registered an IDisplayManagerCallback.");
Jeff Brown64a55af2012-08-26 02:47:39 -0700465 }
466
Jeff Brownbd6e1502012-08-28 03:27:37 -0700467 CallbackRecord record = new CallbackRecord(callingPid, callback);
468 try {
469 IBinder binder = callback.asBinder();
470 binder.linkToDeath(record, 0);
471 } catch (RemoteException ex) {
472 // give up
473 throw new RuntimeException(ex);
474 }
475
476 mCallbacks.put(callingPid, record);
477 }
478 }
479
Jeff Brownce468a32013-11-21 16:42:03 -0800480 private void onCallbackDied(CallbackRecord record) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700481 synchronized (mSyncRoot) {
Jeff Brownce468a32013-11-21 16:42:03 -0800482 mCallbacks.remove(record.mPid);
483 stopWifiDisplayScanLocked(record);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700484 }
485 }
486
Jeff Brown4ccb8232014-01-16 22:16:42 -0800487 private void startWifiDisplayScanInternal(int callingPid) {
488 synchronized (mSyncRoot) {
489 CallbackRecord record = mCallbacks.get(callingPid);
490 if (record == null) {
491 throw new IllegalStateException("The calling process has not "
492 + "registered an IDisplayManagerCallback.");
Jeff Browne08ae382012-09-07 20:36:36 -0700493 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800494 startWifiDisplayScanLocked(record);
Jeff Browne08ae382012-09-07 20:36:36 -0700495 }
496 }
497
Jeff Brownce468a32013-11-21 16:42:03 -0800498 private void startWifiDisplayScanLocked(CallbackRecord record) {
499 if (!record.mWifiDisplayScanRequested) {
500 record.mWifiDisplayScanRequested = true;
501 if (mWifiDisplayScanRequestCount++ == 0) {
502 if (mWifiDisplayAdapter != null) {
503 mWifiDisplayAdapter.requestStartScanLocked();
504 }
505 }
506 }
507 }
508
Jeff Brown4ccb8232014-01-16 22:16:42 -0800509 private void stopWifiDisplayScanInternal(int callingPid) {
510 synchronized (mSyncRoot) {
511 CallbackRecord record = mCallbacks.get(callingPid);
512 if (record == null) {
513 throw new IllegalStateException("The calling process has not "
514 + "registered an IDisplayManagerCallback.");
Jeff Brownce468a32013-11-21 16:42:03 -0800515 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800516 stopWifiDisplayScanLocked(record);
Jeff Brownce468a32013-11-21 16:42:03 -0800517 }
518 }
519
520 private void stopWifiDisplayScanLocked(CallbackRecord record) {
521 if (record.mWifiDisplayScanRequested) {
522 record.mWifiDisplayScanRequested = false;
523 if (--mWifiDisplayScanRequestCount == 0) {
524 if (mWifiDisplayAdapter != null) {
525 mWifiDisplayAdapter.requestStopScanLocked();
526 }
527 } else if (mWifiDisplayScanRequestCount < 0) {
Dianne Hackborn8d051722014-10-01 14:59:58 -0700528 Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: "
Jeff Brownce468a32013-11-21 16:42:03 -0800529 + mWifiDisplayScanRequestCount);
530 mWifiDisplayScanRequestCount = 0;
531 }
532 }
533 }
534
Jeff Brown4ccb8232014-01-16 22:16:42 -0800535 private void connectWifiDisplayInternal(String address) {
536 synchronized (mSyncRoot) {
537 if (mWifiDisplayAdapter != null) {
538 mWifiDisplayAdapter.requestConnectLocked(address);
Jeff Browne08ae382012-09-07 20:36:36 -0700539 }
Jeff Browne08ae382012-09-07 20:36:36 -0700540 }
541 }
542
Jeff Brown4ccb8232014-01-16 22:16:42 -0800543 private void pauseWifiDisplayInternal() {
544 synchronized (mSyncRoot) {
545 if (mWifiDisplayAdapter != null) {
546 mWifiDisplayAdapter.requestPauseLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700547 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700548 }
549 }
550
Jeff Brown4ccb8232014-01-16 22:16:42 -0800551 private void resumeWifiDisplayInternal() {
552 synchronized (mSyncRoot) {
553 if (mWifiDisplayAdapter != null) {
554 mWifiDisplayAdapter.requestResumeLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700555 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700556 }
557 }
558
Jeff Brown4ccb8232014-01-16 22:16:42 -0800559 private void disconnectWifiDisplayInternal() {
560 synchronized (mSyncRoot) {
561 if (mWifiDisplayAdapter != null) {
562 mWifiDisplayAdapter.requestDisconnectLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700563 }
Jeff Browne08ae382012-09-07 20:36:36 -0700564 }
565 }
566
Jeff Brown4ccb8232014-01-16 22:16:42 -0800567 private void renameWifiDisplayInternal(String address, String alias) {
568 synchronized (mSyncRoot) {
569 if (mWifiDisplayAdapter != null) {
570 mWifiDisplayAdapter.requestRenameLocked(address, alias);
Jeff Brown89d55462012-09-19 11:33:42 -0700571 }
Jeff Brown89d55462012-09-19 11:33:42 -0700572 }
573 }
574
Jeff Brown4ccb8232014-01-16 22:16:42 -0800575 private void forgetWifiDisplayInternal(String address) {
576 synchronized (mSyncRoot) {
577 if (mWifiDisplayAdapter != null) {
578 mWifiDisplayAdapter.requestForgetLocked(address);
Jeff Brown89d55462012-09-19 11:33:42 -0700579 }
Jeff Brown89d55462012-09-19 11:33:42 -0700580 }
581 }
582
Jeff Brown4ccb8232014-01-16 22:16:42 -0800583 private WifiDisplayStatus getWifiDisplayStatusInternal() {
584 synchronized (mSyncRoot) {
585 if (mWifiDisplayAdapter != null) {
586 return mWifiDisplayAdapter.getWifiDisplayStatusLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700587 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800588 return new WifiDisplayStatus();
Jeff Browne08ae382012-09-07 20:36:36 -0700589 }
590 }
591
Michael Wright1c9977b2016-07-12 13:30:10 -0700592 private void requestColorModeInternal(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +0100593 synchronized (mSyncRoot) {
594 LogicalDisplay display = mLogicalDisplays.get(displayId);
595 if (display != null &&
Michael Wright1c9977b2016-07-12 13:30:10 -0700596 display.getRequestedColorModeLocked() != colorMode) {
597 display.setRequestedColorModeLocked(colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100598 scheduleTraversalLocked(false);
599 }
600 }
601 }
602
Michael Wright75ee9fc2014-09-01 19:55:22 -0700603 private int createVirtualDisplayInternal(IVirtualDisplayCallback callback,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700604 IMediaProjection projection, int callingUid, String packageName,
Jeff Brown7d00aff2013-08-02 19:03:49 -0700605 String name, int width, int height, int densityDpi, Surface surface, int flags) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800606 synchronized (mSyncRoot) {
607 if (mVirtualDisplayAdapter == null) {
608 Slog.w(TAG, "Rejecting request to create private virtual display "
609 + "because the virtual display adapter is not available.");
610 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700611 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800612
613 DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked(
Michael Wright75ee9fc2014-09-01 19:55:22 -0700614 callback, projection, callingUid, packageName,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700615 name, width, height, densityDpi, surface, flags);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800616 if (device == null) {
617 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700618 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700619
Jeff Brown4ccb8232014-01-16 22:16:42 -0800620 handleDisplayDeviceAddedLocked(device);
621 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
622 if (display != null) {
623 return display.getDisplayIdLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700624 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800625
626 // Something weird happened and the logical display was not created.
627 Slog.w(TAG, "Rejecting request to create virtual display "
628 + "because the logical display was not created.");
Michael Wright75ee9fc2014-09-01 19:55:22 -0700629 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800630 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700631 }
632 return -1;
633 }
634
Michael Wright01e840f2014-06-26 16:03:25 -0700635 private void resizeVirtualDisplayInternal(IBinder appToken,
636 int width, int height, int densityDpi) {
637 synchronized (mSyncRoot) {
638 if (mVirtualDisplayAdapter == null) {
639 return;
640 }
641
642 mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi);
643 }
644 }
645
Jeff Brown92207df2014-04-16 13:16:07 -0700646 private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) {
647 synchronized (mSyncRoot) {
648 if (mVirtualDisplayAdapter == null) {
649 return;
650 }
651
652 mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface);
653 }
654 }
655
Jeff Brown4ccb8232014-01-16 22:16:42 -0800656 private void releaseVirtualDisplayInternal(IBinder appToken) {
657 synchronized (mSyncRoot) {
658 if (mVirtualDisplayAdapter == null) {
659 return;
Jeff Browna506a6e2013-06-04 00:02:38 -0700660 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700661
Jeff Brown4ccb8232014-01-16 22:16:42 -0800662 DisplayDevice device =
663 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
664 if (device != null) {
665 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700666 }
667 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700668 }
669
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700670 private void registerDefaultDisplayAdapter() {
671 // Register default display adapter.
672 synchronized (mSyncRoot) {
Mike Lockwoode63f6f72013-11-15 11:01:47 -0800673 registerDisplayAdapterLocked(new LocalDisplayAdapter(
674 mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700675 }
676 }
677
678 private void registerAdditionalDisplayAdapters() {
679 synchronized (mSyncRoot) {
680 if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700681 registerOverlayDisplayAdapterLocked();
682 registerWifiDisplayAdapterLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700683 registerVirtualDisplayAdapterLocked();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700684 }
685 }
686 }
687
Jeff Brown89d55462012-09-19 11:33:42 -0700688 private void registerOverlayDisplayAdapterLocked() {
689 registerDisplayAdapterLocked(new OverlayDisplayAdapter(
690 mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler));
691 }
692
693 private void registerWifiDisplayAdapterLocked() {
694 if (mContext.getResources().getBoolean(
Jeff Brownbbd28a22012-09-20 16:47:15 -0700695 com.android.internal.R.bool.config_enableWifiDisplay)
696 || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) {
Jeff Brown89d55462012-09-19 11:33:42 -0700697 mWifiDisplayAdapter = new WifiDisplayAdapter(
698 mSyncRoot, mContext, mHandler, mDisplayAdapterListener,
699 mPersistentDataStore);
700 registerDisplayAdapterLocked(mWifiDisplayAdapter);
701 }
702 }
703
Jeff Browna506a6e2013-06-04 00:02:38 -0700704 private void registerVirtualDisplayAdapterLocked() {
705 mVirtualDisplayAdapter = new VirtualDisplayAdapter(
706 mSyncRoot, mContext, mHandler, mDisplayAdapterListener);
707 registerDisplayAdapterLocked(mVirtualDisplayAdapter);
708 }
709
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700710 private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
711 // In safe mode, we disable non-essential display adapters to give the user
712 // an opportunity to fix broken settings or other problems that might affect
713 // system stability.
714 // In only-core mode, we disable non-essential display adapters to minimize
715 // the number of dependencies that are started while in this mode and to
716 // prevent problems that might occur due to the device being encrypted.
717 return !mSafeMode && !mOnlyCore;
718 }
719
720 private void registerDisplayAdapterLocked(DisplayAdapter adapter) {
721 mDisplayAdapters.add(adapter);
722 adapter.registerLocked();
723 }
724
Jeff Brownbd6e1502012-08-28 03:27:37 -0700725 private void handleDisplayDeviceAdded(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700726 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700727 handleDisplayDeviceAddedLocked(device);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700728 }
729 }
730
Jeff Browna506a6e2013-06-04 00:02:38 -0700731 private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700732 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700733 if (mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700734 Slog.w(TAG, "Attempted to add already added display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700735 return;
736 }
737
Jeff Brown10acf6d2015-04-14 14:20:47 -0700738 Slog.i(TAG, "Display device added: " + info);
739 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700740
741 mDisplayDevices.add(device);
Michael Wright1c9977b2016-07-12 13:30:10 -0700742 LogicalDisplay display = addLogicalDisplayLocked(device);
Jeff Brown0033a862014-10-08 12:06:39 -0700743 Runnable work = updateDisplayStateLocked(device);
744 if (work != null) {
745 work.run();
746 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700747 if (display != null && display.getPrimaryDisplayDeviceLocked() == device) {
748 int colorMode = mPersistentDataStore.getColorMode(device);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700749 if (colorMode == Display.COLOR_MODE_INVALID) {
750 if ((device.getDisplayDeviceInfoLocked().flags
751 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
752 colorMode = mDefaultDisplayDefaultColorMode;
753 } else {
754 colorMode = Display.COLOR_MODE_DEFAULT;
755 }
756 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700757 display.setRequestedColorModeLocked(colorMode);
758 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700759 scheduleTraversalLocked(false);
760 }
761
Jeff Brownbd6e1502012-08-28 03:27:37 -0700762 private void handleDisplayDeviceChanged(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700763 synchronized (mSyncRoot) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700764 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700765 if (!mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700766 Slog.w(TAG, "Attempted to change non-existent display device: " + info);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700767 return;
768 }
769
Jeff Brown10acf6d2015-04-14 14:20:47 -0700770 int diff = device.mDebugLastLoggedDeviceInfo.diff(info);
771 if (diff == DisplayDeviceInfo.DIFF_STATE) {
772 Slog.i(TAG, "Display device changed state: \"" + info.name
773 + "\", " + Display.stateToString(info.state));
774 } else if (diff != 0) {
775 Slog.i(TAG, "Display device changed: " + info);
776 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700777 if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) {
778 try {
779 mPersistentDataStore.setColorMode(device, info.colorMode);
780 } finally {
781 mPersistentDataStore.saveIfNeeded();
782 }
783 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700784 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browne87bf032012-09-20 18:30:13 -0700785
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700786 device.applyPendingDisplayDeviceInfoChangesLocked();
787 if (updateLogicalDisplaysLocked()) {
Craig Mautner65d11b32012-10-01 13:59:52 -0700788 scheduleTraversalLocked(false);
Jeff Brown64a55af2012-08-26 02:47:39 -0700789 }
790 }
791 }
792
Jeff Brownbd6e1502012-08-28 03:27:37 -0700793 private void handleDisplayDeviceRemoved(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700794 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700795 handleDisplayDeviceRemovedLocked(device);
796 }
797 }
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700798
Jeff Browna506a6e2013-06-04 00:02:38 -0700799 private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700800 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700801 if (!mDisplayDevices.remove(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700802 Slog.w(TAG, "Attempted to remove non-existent display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700803 return;
804 }
805
Jeff Brown10acf6d2015-04-14 14:20:47 -0700806 Slog.i(TAG, "Display device removed: " + info);
807 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700808
Jeff Browna506a6e2013-06-04 00:02:38 -0700809 updateLogicalDisplaysLocked();
810 scheduleTraversalLocked(false);
811 }
812
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700813 private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700814 final int count = mDisplayDevices.size();
815 for (int i = 0; i < count; i++) {
816 DisplayDevice device = mDisplayDevices.get(i);
Jeff Browne75926d2014-09-18 15:24:49 -0700817 Runnable runnable = updateDisplayStateLocked(device);
818 if (runnable != null) {
819 workQueue.add(runnable);
820 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700821 }
822 }
823
Jeff Browne75926d2014-09-18 15:24:49 -0700824 private Runnable updateDisplayStateLocked(DisplayDevice device) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700825 // Blank or unblank the display immediately to match the state requested
Jeff Brown037c33e2014-04-09 00:31:55 -0700826 // by the display power controller (if known).
Jeff Browna506a6e2013-06-04 00:02:38 -0700827 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
828 if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700829 return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700830 }
Jeff Browne75926d2014-09-18 15:24:49 -0700831 return null;
Craig Mautner4f67ba62012-08-02 11:23:00 -0700832 }
833
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700834 // Adds a new logical display based on the given display device.
835 // Sends notifications if needed.
Michael Wright1c9977b2016-07-12 13:30:10 -0700836 private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700837 DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
838 boolean isDefault = (deviceInfo.flags
839 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
840 if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
841 Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
842 isDefault = false;
843 }
844
Jeff Brown27f1d672012-10-17 18:32:34 -0700845 if (!isDefault && mSingleDisplayDemoMode) {
846 Slog.i(TAG, "Not creating a logical display for a secondary display "
847 + " because single display demo mode is enabled: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -0700848 return null;
Jeff Brown27f1d672012-10-17 18:32:34 -0700849 }
850
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700851 final int displayId = assignDisplayIdLocked(isDefault);
852 final int layerStack = assignLayerStackLocked(displayId);
853
Jeff Brownd728bf52012-09-08 18:05:28 -0700854 LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700855 display.updateLocked(mDisplayDevices);
856 if (!display.isValidLocked()) {
857 // This should never happen currently.
858 Slog.w(TAG, "Ignoring display device because the logical display "
859 + "created from it was not considered valid: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -0700860 return null;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700861 }
862
863 mLogicalDisplays.put(displayId, display);
864
865 // Wake up waitForDefaultDisplay.
866 if (isDefault) {
867 mSyncRoot.notifyAll();
868 }
869
870 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
Michael Wright1c9977b2016-07-12 13:30:10 -0700871 return display;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700872 }
873
874 private int assignDisplayIdLocked(boolean isDefault) {
875 return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++;
876 }
877
878 private int assignLayerStackLocked(int displayId) {
879 // Currently layer stacks and display ids are the same.
880 // This need not be the case.
881 return displayId;
882 }
883
884 // Updates all existing logical displays given the current set of display devices.
885 // Removes invalid logical displays.
886 // Sends notifications if needed.
887 private boolean updateLogicalDisplaysLocked() {
888 boolean changed = false;
889 for (int i = mLogicalDisplays.size(); i-- > 0; ) {
890 final int displayId = mLogicalDisplays.keyAt(i);
891 LogicalDisplay display = mLogicalDisplays.valueAt(i);
892
893 mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
894 display.updateLocked(mDisplayDevices);
895 if (!display.isValidLocked()) {
896 mLogicalDisplays.removeAt(i);
897 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
898 changed = true;
899 } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
900 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
901 changed = true;
902 }
903 }
904 return changed;
905 }
906
907 private void performTraversalInTransactionLocked() {
Jeff Brownd728bf52012-09-08 18:05:28 -0700908 // Clear all viewports before configuring displays so that we can keep
909 // track of which ones we have configured.
910 clearViewportsLocked();
911
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700912 // Configure each display device.
913 final int count = mDisplayDevices.size();
914 for (int i = 0; i < count; i++) {
915 DisplayDevice device = mDisplayDevices.get(i);
916 configureDisplayInTransactionLocked(device);
917 device.performTraversalInTransactionLocked();
918 }
Jeff Brownd728bf52012-09-08 18:05:28 -0700919
920 // Tell the input system about these new viewports.
Jeff Brown4ccb8232014-01-16 22:16:42 -0800921 if (mInputManagerInternal != null) {
Jeff Brownd728bf52012-09-08 18:05:28 -0700922 mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
923 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700924 }
925
Michael Wright3f145a22014-07-22 19:46:03 -0700926 private void setDisplayPropertiesInternal(int displayId, boolean hasContent,
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700927 float requestedRefreshRate, int requestedModeId, boolean inTraversal) {
Craig Mautner722285e2012-09-07 13:55:58 -0700928 synchronized (mSyncRoot) {
929 LogicalDisplay display = mLogicalDisplays.get(displayId);
Michael Wright3f145a22014-07-22 19:46:03 -0700930 if (display == null) {
931 return;
932 }
933 if (display.hasContentLocked() != hasContent) {
Jeff Brown33041bd2013-08-02 21:11:14 -0700934 if (DEBUG) {
935 Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
936 + "hasContent=" + hasContent + ", inTraversal=" + inTraversal);
937 }
938
Craig Mautner722285e2012-09-07 13:55:58 -0700939 display.setHasContentLocked(hasContent);
Craig Mautner65d11b32012-10-01 13:59:52 -0700940 scheduleTraversalLocked(inTraversal);
Craig Mautner722285e2012-09-07 13:55:58 -0700941 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700942 if (requestedModeId == 0 && requestedRefreshRate != 0) {
943 // Scan supported modes returned by display.getInfo() to find a mode with the same
944 // size as the default display mode but with the specified refresh rate instead.
945 requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate(
946 requestedRefreshRate);
947 }
948 if (display.getRequestedModeIdLocked() != requestedModeId) {
Michael Wright3f145a22014-07-22 19:46:03 -0700949 if (DEBUG) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700950 Slog.d(TAG, "Display " + displayId + " switching to mode " + requestedModeId);
Michael Wright3f145a22014-07-22 19:46:03 -0700951 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700952 display.setRequestedModeIdLocked(requestedModeId);
Michael Wright3f145a22014-07-22 19:46:03 -0700953 scheduleTraversalLocked(inTraversal);
954 }
Craig Mautner722285e2012-09-07 13:55:58 -0700955 }
Jeff Brownd728bf52012-09-08 18:05:28 -0700956 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700957
Filip Gruszczynskid2e86402015-02-19 13:05:03 -0800958 private void setDisplayOffsetsInternal(int displayId, int x, int y) {
959 synchronized (mSyncRoot) {
960 LogicalDisplay display = mLogicalDisplays.get(displayId);
961 if (display == null) {
962 return;
963 }
964 if (display.getDisplayOffsetXLocked() != x
965 || display.getDisplayOffsetYLocked() != y) {
966 if (DEBUG) {
967 Slog.d(TAG, "Display " + displayId + " burn-in offset set to ("
968 + x + ", " + y + ")");
969 }
970 display.setDisplayOffsetsLocked(x, y);
971 scheduleTraversalLocked(false);
972 }
973 }
974 }
975
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800976 // Updates the lists of UIDs that are present on displays.
977 private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) {
978 synchronized (mSyncRoot) {
979 mDisplayAccessUIDs.clear();
980 for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) {
981 mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i),
982 newDisplayAccessUIDs.valueAt(i));
983 }
984 }
985 }
986
987 // Checks if provided UID's content is present on the display and UID has access to it.
988 private boolean isUidPresentOnDisplayInternal(int uid, int displayId) {
989 synchronized (mSyncRoot) {
990 final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId);
991 return displayUIDs != null && displayUIDs.indexOf(uid) != -1;
992 }
993 }
994
Jeff Brownd728bf52012-09-08 18:05:28 -0700995 private void clearViewportsLocked() {
996 mDefaultViewport.valid = false;
997 mExternalTouchViewport.valid = false;
Craig Mautner722285e2012-09-07 13:55:58 -0700998 }
999
1000 private void configureDisplayInTransactionLocked(DisplayDevice device) {
Jeff Brownd14c8c92014-01-07 18:13:09 -08001001 final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
1002 final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;
Jeff Browna506a6e2013-06-04 00:02:38 -07001003
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001004 // Find the logical display that the display device is showing.
Jeff Brownd14c8c92014-01-07 18:13:09 -08001005 // Certain displays only ever show their own content.
Craig Mautner722285e2012-09-07 13:55:58 -07001006 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
Jeff Brownd14c8c92014-01-07 18:13:09 -08001007 if (!ownContent) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001008 if (display != null && !display.hasContentLocked()) {
1009 // If the display does not have any content of its own, then
1010 // automatically mirror the default logical display contents.
1011 display = null;
1012 }
1013 if (display == null) {
1014 display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY);
1015 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001016 }
1017
1018 // Apply the logical display configuration to the display device.
1019 if (display == null) {
1020 // TODO: no logical display for the device, blank it
Jeff Brownd728bf52012-09-08 18:05:28 -07001021 Slog.w(TAG, "Missing logical display to use for physical display device: "
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001022 + device.getDisplayDeviceInfoLocked());
Jeff Brownd728bf52012-09-08 18:05:28 -07001023 return;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001024 }
Jeff Brown037c33e2014-04-09 00:31:55 -07001025 display.configureDisplayInTransactionLocked(device, info.state == Display.STATE_OFF);
Jeff Brownd728bf52012-09-08 18:05:28 -07001026
1027 // Update the viewports if needed.
Jeff Brownd728bf52012-09-08 18:05:28 -07001028 if (!mDefaultViewport.valid
1029 && (info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
1030 setViewportLocked(mDefaultViewport, display, device);
1031 }
1032 if (!mExternalTouchViewport.valid
1033 && info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
1034 setViewportLocked(mExternalTouchViewport, display, device);
1035 }
1036 }
1037
1038 private static void setViewportLocked(DisplayViewport viewport,
1039 LogicalDisplay display, DisplayDevice device) {
1040 viewport.valid = true;
1041 viewport.displayId = display.getDisplayIdLocked();
1042 device.populateViewportLocked(viewport);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001043 }
1044
1045 private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {
1046 final int count = mLogicalDisplays.size();
1047 for (int i = 0; i < count; i++) {
1048 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1049 if (display.getPrimaryDisplayDeviceLocked() == device) {
1050 return display;
1051 }
1052 }
1053 return null;
1054 }
1055
Jeff Brownbd6e1502012-08-28 03:27:37 -07001056 private void sendDisplayEventLocked(int displayId, int event) {
1057 Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
1058 mHandler.sendMessage(msg);
1059 }
1060
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001061 // Requests that performTraversalsInTransactionFromWindowManager be called at a
1062 // later time to apply changes to surfaces and displays.
Craig Mautner65d11b32012-10-01 13:59:52 -07001063 private void scheduleTraversalLocked(boolean inTraversal) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001064 if (!mPendingTraversal && mWindowManagerInternal != null) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001065 mPendingTraversal = true;
Craig Mautner65d11b32012-10-01 13:59:52 -07001066 if (!inTraversal) {
1067 mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL);
1068 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001069 }
1070 }
1071
1072 // Runs on Handler thread.
1073 // Delivers display event notifications to callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001074 private void deliverDisplayEvent(int displayId, int event) {
1075 if (DEBUG) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001076 Slog.d(TAG, "Delivering display event: displayId="
1077 + displayId + ", event=" + event);
Jeff Brownfa25bf52012-07-23 19:26:30 -07001078 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001079
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001080 // Grab the lock and copy the callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001081 final int count;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001082 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001083 count = mCallbacks.size();
1084 mTempCallbacks.clear();
1085 for (int i = 0; i < count; i++) {
1086 mTempCallbacks.add(mCallbacks.valueAt(i));
Craig Mautner4f67ba62012-08-02 11:23:00 -07001087 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001088 }
Craig Mautner4f67ba62012-08-02 11:23:00 -07001089
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001090 // After releasing the lock, send the notifications out.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001091 for (int i = 0; i < count; i++) {
1092 mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event);
1093 }
1094 mTempCallbacks.clear();
Craig Mautner4f67ba62012-08-02 11:23:00 -07001095 }
1096
Michael Wrightc39d47a2014-07-08 18:07:36 -07001097 private IMediaProjectionManager getProjectionService() {
1098 if (mProjectionService == null) {
1099 IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE);
1100 mProjectionService = IMediaProjectionManager.Stub.asInterface(b);
1101 }
1102 return mProjectionService;
1103 }
1104
Jeff Brown4ccb8232014-01-16 22:16:42 -08001105 private void dumpInternal(PrintWriter pw) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001106 pw.println("DISPLAY MANAGER (dumpsys display)");
Jeff Brownfa25bf52012-07-23 19:26:30 -07001107
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001108 synchronized (mSyncRoot) {
Jeff Brown9e316a12012-10-08 19:17:06 -07001109 pw.println(" mOnlyCode=" + mOnlyCore);
1110 pw.println(" mSafeMode=" + mSafeMode);
1111 pw.println(" mPendingTraversal=" + mPendingTraversal);
Jeff Brown037c33e2014-04-09 00:31:55 -07001112 pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState));
Jeff Brown9e316a12012-10-08 19:17:06 -07001113 pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId);
1114 pw.println(" mDefaultViewport=" + mDefaultViewport);
1115 pw.println(" mExternalTouchViewport=" + mExternalTouchViewport);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -07001116 pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode);
Jeff Brown27f1d672012-10-17 18:32:34 -07001117 pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
Jeff Brownce468a32013-11-21 16:42:03 -08001118 pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount);
Jeff Brown9e316a12012-10-08 19:17:06 -07001119
Jeff Brownbd6e1502012-08-28 03:27:37 -07001120 IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001121 ipw.increaseIndent();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001122
1123 pw.println();
1124 pw.println("Display Adapters: size=" + mDisplayAdapters.size());
Jeff Brown848c2dc2012-08-19 20:18:08 -07001125 for (DisplayAdapter adapter : mDisplayAdapters) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001126 pw.println(" " + adapter.getName());
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001127 adapter.dumpLocked(ipw);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001128 }
Craig Mautner9de49362012-08-02 14:30:30 -07001129
Jeff Brownbd6e1502012-08-28 03:27:37 -07001130 pw.println();
1131 pw.println("Display Devices: size=" + mDisplayDevices.size());
1132 for (DisplayDevice device : mDisplayDevices) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001133 pw.println(" " + device.getDisplayDeviceInfoLocked());
1134 device.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001135 }
1136
1137 final int logicalDisplayCount = mLogicalDisplays.size();
1138 pw.println();
1139 pw.println("Logical Displays: size=" + logicalDisplayCount);
1140 for (int i = 0; i < logicalDisplayCount; i++) {
1141 int displayId = mLogicalDisplays.keyAt(i);
1142 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1143 pw.println(" Display " + displayId + ":");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001144 display.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001145 }
Jeff Brownce468a32013-11-21 16:42:03 -08001146
1147 final int callbackCount = mCallbacks.size();
1148 pw.println();
1149 pw.println("Callbacks: size=" + callbackCount);
1150 for (int i = 0; i < callbackCount; i++) {
1151 CallbackRecord callback = mCallbacks.valueAt(i);
1152 pw.println(" " + i + ": mPid=" + callback.mPid
1153 + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
1154 }
Jeff Brownad9ef192014-04-08 17:26:30 -07001155
1156 if (mDisplayPowerController != null) {
1157 mDisplayPowerController.dump(pw);
1158 }
Michael Wright1c9977b2016-07-12 13:30:10 -07001159
1160 pw.println();
1161 mPersistentDataStore.dump(pw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001162 }
1163 }
1164
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001165 /**
1166 * This is the object that everything in the display manager locks on.
1167 * We make it an inner class within the {@link DisplayManagerService} to so that it is
1168 * clear that the object belongs to the display manager service and that it is
1169 * a unique object with a special purpose.
1170 */
1171 public static final class SyncRoot {
1172 }
1173
Jeff Brownbd6e1502012-08-28 03:27:37 -07001174 private final class DisplayManagerHandler extends Handler {
1175 public DisplayManagerHandler(Looper looper) {
1176 super(looper, null, true /*async*/);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001177 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001178
Jeff Brownbd6e1502012-08-28 03:27:37 -07001179 @Override
1180 public void handleMessage(Message msg) {
1181 switch (msg.what) {
1182 case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER:
1183 registerDefaultDisplayAdapter();
1184 break;
1185
1186 case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS:
1187 registerAdditionalDisplayAdapters();
1188 break;
1189
1190 case MSG_DELIVER_DISPLAY_EVENT:
1191 deliverDisplayEvent(msg.arg1, msg.arg2);
1192 break;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001193
1194 case MSG_REQUEST_TRAVERSAL:
Jeff Brown4ccb8232014-01-16 22:16:42 -08001195 mWindowManagerInternal.requestTraversalFromDisplayManager();
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001196 break;
Jeff Brownd728bf52012-09-08 18:05:28 -07001197
1198 case MSG_UPDATE_VIEWPORT: {
1199 synchronized (mSyncRoot) {
1200 mTempDefaultViewport.copyFrom(mDefaultViewport);
1201 mTempExternalTouchViewport.copyFrom(mExternalTouchViewport);
1202 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001203 mInputManagerInternal.setDisplayViewports(
Jeff Brownd728bf52012-09-08 18:05:28 -07001204 mTempDefaultViewport, mTempExternalTouchViewport);
1205 break;
1206 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001207 }
1208 }
1209 }
1210
1211 private final class DisplayAdapterListener implements DisplayAdapter.Listener {
1212 @Override
1213 public void onDisplayDeviceEvent(DisplayDevice device, int event) {
1214 switch (event) {
1215 case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED:
1216 handleDisplayDeviceAdded(device);
1217 break;
1218
1219 case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED:
1220 handleDisplayDeviceChanged(device);
1221 break;
1222
1223 case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED:
1224 handleDisplayDeviceRemoved(device);
1225 break;
1226 }
1227 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001228
1229 @Override
1230 public void onTraversalRequested() {
1231 synchronized (mSyncRoot) {
Craig Mautner65d11b32012-10-01 13:59:52 -07001232 scheduleTraversalLocked(false);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001233 }
1234 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001235 }
1236
1237 private final class CallbackRecord implements DeathRecipient {
Jeff Brownce468a32013-11-21 16:42:03 -08001238 public final int mPid;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001239 private final IDisplayManagerCallback mCallback;
1240
Jeff Brownce468a32013-11-21 16:42:03 -08001241 public boolean mWifiDisplayScanRequested;
1242
Jeff Brownbd6e1502012-08-28 03:27:37 -07001243 public CallbackRecord(int pid, IDisplayManagerCallback callback) {
1244 mPid = pid;
1245 mCallback = callback;
1246 }
1247
1248 @Override
1249 public void binderDied() {
1250 if (DEBUG) {
1251 Slog.d(TAG, "Display listener for pid " + mPid + " died.");
1252 }
Jeff Brownce468a32013-11-21 16:42:03 -08001253 onCallbackDied(this);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001254 }
1255
1256 public void notifyDisplayEventAsync(int displayId, int event) {
1257 try {
1258 mCallback.onDisplayEvent(displayId, event);
1259 } catch (RemoteException ex) {
1260 Slog.w(TAG, "Failed to notify process "
1261 + mPid + " that displays changed, assuming it died.", ex);
1262 binderDied();
1263 }
1264 }
1265 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001266
1267 private final class BinderService extends IDisplayManager.Stub {
1268 /**
1269 * Returns information about the specified logical display.
1270 *
1271 * @param displayId The logical display id.
1272 * @return The logical display info, or null if the display does not exist. The
1273 * returned object must be treated as immutable.
1274 */
1275 @Override // Binder call
1276 public DisplayInfo getDisplayInfo(int displayId) {
1277 final int callingUid = Binder.getCallingUid();
1278 final long token = Binder.clearCallingIdentity();
1279 try {
1280 return getDisplayInfoInternal(displayId, callingUid);
1281 } finally {
1282 Binder.restoreCallingIdentity(token);
1283 }
1284 }
1285
1286 /**
1287 * Returns the list of all display ids.
1288 */
1289 @Override // Binder call
1290 public int[] getDisplayIds() {
1291 final int callingUid = Binder.getCallingUid();
1292 final long token = Binder.clearCallingIdentity();
1293 try {
1294 return getDisplayIdsInternal(callingUid);
1295 } finally {
1296 Binder.restoreCallingIdentity(token);
1297 }
1298 }
1299
1300 @Override // Binder call
1301 public void registerCallback(IDisplayManagerCallback callback) {
1302 if (callback == null) {
1303 throw new IllegalArgumentException("listener must not be null");
1304 }
1305
1306 final int callingPid = Binder.getCallingPid();
1307 final long token = Binder.clearCallingIdentity();
1308 try {
1309 registerCallbackInternal(callback, callingPid);
1310 } finally {
1311 Binder.restoreCallingIdentity(token);
1312 }
1313 }
1314
1315 @Override // Binder call
1316 public void startWifiDisplayScan() {
1317 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1318 "Permission required to start wifi display scans");
1319
1320 final int callingPid = Binder.getCallingPid();
1321 final long token = Binder.clearCallingIdentity();
1322 try {
1323 startWifiDisplayScanInternal(callingPid);
1324 } finally {
1325 Binder.restoreCallingIdentity(token);
1326 }
1327 }
1328
1329 @Override // Binder call
1330 public void stopWifiDisplayScan() {
1331 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1332 "Permission required to stop wifi display scans");
1333
1334 final int callingPid = Binder.getCallingPid();
1335 final long token = Binder.clearCallingIdentity();
1336 try {
1337 stopWifiDisplayScanInternal(callingPid);
1338 } finally {
1339 Binder.restoreCallingIdentity(token);
1340 }
1341 }
1342
1343 @Override // Binder call
1344 public void connectWifiDisplay(String address) {
1345 if (address == null) {
1346 throw new IllegalArgumentException("address must not be null");
1347 }
1348 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1349 "Permission required to connect to a wifi display");
1350
1351 final long token = Binder.clearCallingIdentity();
1352 try {
1353 connectWifiDisplayInternal(address);
1354 } finally {
1355 Binder.restoreCallingIdentity(token);
1356 }
1357 }
1358
1359 @Override // Binder call
1360 public void disconnectWifiDisplay() {
1361 // This request does not require special permissions.
1362 // Any app can request disconnection from the currently active wifi display.
1363 // This exception should no longer be needed once wifi display control moves
1364 // to the media router service.
1365
1366 final long token = Binder.clearCallingIdentity();
1367 try {
1368 disconnectWifiDisplayInternal();
1369 } finally {
1370 Binder.restoreCallingIdentity(token);
1371 }
1372 }
1373
1374 @Override // Binder call
1375 public void renameWifiDisplay(String address, String alias) {
1376 if (address == null) {
1377 throw new IllegalArgumentException("address must not be null");
1378 }
1379 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1380 "Permission required to rename to a wifi display");
1381
1382 final long token = Binder.clearCallingIdentity();
1383 try {
1384 renameWifiDisplayInternal(address, alias);
1385 } finally {
1386 Binder.restoreCallingIdentity(token);
1387 }
1388 }
1389
1390 @Override // Binder call
1391 public void forgetWifiDisplay(String address) {
1392 if (address == null) {
1393 throw new IllegalArgumentException("address must not be null");
1394 }
1395 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1396 "Permission required to forget to a wifi display");
1397
1398 final long token = Binder.clearCallingIdentity();
1399 try {
1400 forgetWifiDisplayInternal(address);
1401 } finally {
1402 Binder.restoreCallingIdentity(token);
1403 }
1404 }
1405
1406 @Override // Binder call
1407 public void pauseWifiDisplay() {
1408 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1409 "Permission required to pause a wifi display session");
1410
1411 final long token = Binder.clearCallingIdentity();
1412 try {
1413 pauseWifiDisplayInternal();
1414 } finally {
1415 Binder.restoreCallingIdentity(token);
1416 }
1417 }
1418
1419 @Override // Binder call
1420 public void resumeWifiDisplay() {
1421 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1422 "Permission required to resume a wifi display session");
1423
1424 final long token = Binder.clearCallingIdentity();
1425 try {
1426 resumeWifiDisplayInternal();
1427 } finally {
1428 Binder.restoreCallingIdentity(token);
1429 }
1430 }
1431
1432 @Override // Binder call
1433 public WifiDisplayStatus getWifiDisplayStatus() {
1434 // This request does not require special permissions.
1435 // Any app can get information about available wifi displays.
1436
1437 final long token = Binder.clearCallingIdentity();
1438 try {
1439 return getWifiDisplayStatusInternal();
1440 } finally {
1441 Binder.restoreCallingIdentity(token);
1442 }
1443 }
1444
1445 @Override // Binder call
Michael Wright1c9977b2016-07-12 13:30:10 -07001446 public void requestColorMode(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +01001447 mContext.enforceCallingOrSelfPermission(
Michael Wright1c9977b2016-07-12 13:30:10 -07001448 Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE,
1449 "Permission required to change the display color mode");
Michael Wright58e829f2015-09-15 00:13:26 +01001450 final long token = Binder.clearCallingIdentity();
1451 try {
Michael Wright1c9977b2016-07-12 13:30:10 -07001452 requestColorModeInternal(displayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +01001453 } finally {
1454 Binder.restoreCallingIdentity(token);
1455 }
1456 }
1457
1458 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001459 public int createVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001460 IMediaProjection projection, String packageName, String name,
1461 int width, int height, int densityDpi, Surface surface, int flags) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001462 final int callingUid = Binder.getCallingUid();
1463 if (!validatePackageName(callingUid, packageName)) {
1464 throw new SecurityException("packageName must match the calling uid");
1465 }
Michael Wright75ee9fc2014-09-01 19:55:22 -07001466 if (callback == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001467 throw new IllegalArgumentException("appToken must not be null");
1468 }
1469 if (TextUtils.isEmpty(name)) {
1470 throw new IllegalArgumentException("name must be non-null and non-empty");
1471 }
1472 if (width <= 0 || height <= 0 || densityDpi <= 0) {
1473 throw new IllegalArgumentException("width, height, and densityDpi must be "
1474 + "greater than 0");
1475 }
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07001476 if (surface != null && surface.isSingleBuffered()) {
Pablo Ceballosaff2f942016-07-29 14:49:55 -07001477 throw new IllegalArgumentException("Surface can't be single-buffered");
1478 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07001479
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001480 if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
1481 flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
1482
1483 // Public displays can't be allowed to show content when locked.
Andrii Kulian7211d2e2017-01-27 15:58:05 -08001484 if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001485 throw new IllegalArgumentException(
1486 "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE");
1487 }
Michael Wright6720be42014-07-29 19:14:16 -07001488 }
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001489 if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) {
1490 flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
Michael Wright6720be42014-07-29 19:14:16 -07001491 }
1492
Michael Wrightc39d47a2014-07-08 18:07:36 -07001493 if (projection != null) {
1494 try {
1495 if (!getProjectionService().isValidMediaProjection(projection)) {
1496 throw new SecurityException("Invalid media projection");
1497 }
Michael Wright6720be42014-07-29 19:14:16 -07001498 flags = projection.applyVirtualDisplayFlags(flags);
Michael Wrightc39d47a2014-07-08 18:07:36 -07001499 } catch (RemoteException e) {
Michael Wright6720be42014-07-29 19:14:16 -07001500 throw new SecurityException("unable to validate media projection or flags");
Michael Wrightc39d47a2014-07-08 18:07:36 -07001501 }
1502 }
1503
Michael Wright6720be42014-07-29 19:14:16 -07001504 if (callingUid != Process.SYSTEM_UID &&
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001505 (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07001506 if (!canProjectVideo(projection)) {
1507 throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
1508 + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate "
1509 + "MediaProjection token in order to create a screen sharing virtual "
1510 + "display.");
1511 }
1512 }
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001513 if ((flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07001514 if (!canProjectSecureVideo(projection)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001515 throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT "
Michael Wrightc39d47a2014-07-08 18:07:36 -07001516 + "or an appropriate MediaProjection token to create a "
1517 + "secure virtual display.");
Jeff Brown4ccb8232014-01-16 22:16:42 -08001518 }
1519 }
1520
1521 final long token = Binder.clearCallingIdentity();
1522 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001523 return createVirtualDisplayInternal(callback, projection, callingUid,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001524 packageName, name, width, height, densityDpi, surface, flags);
Jeff Brown4ccb8232014-01-16 22:16:42 -08001525 } finally {
1526 Binder.restoreCallingIdentity(token);
1527 }
1528 }
1529
1530 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001531 public void resizeVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wright01e840f2014-06-26 16:03:25 -07001532 int width, int height, int densityDpi) {
1533 final long token = Binder.clearCallingIdentity();
1534 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001535 resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi);
Michael Wright01e840f2014-06-26 16:03:25 -07001536 } finally {
1537 Binder.restoreCallingIdentity(token);
1538 }
1539 }
1540
1541 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001542 public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) {
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07001543 if (surface != null && surface.isSingleBuffered()) {
1544 throw new IllegalArgumentException("Surface can't be single-buffered");
1545 }
Jeff Brown92207df2014-04-16 13:16:07 -07001546 final long token = Binder.clearCallingIdentity();
1547 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001548 setVirtualDisplaySurfaceInternal(callback.asBinder(), surface);
Jeff Brown92207df2014-04-16 13:16:07 -07001549 } finally {
1550 Binder.restoreCallingIdentity(token);
1551 }
1552 }
1553
1554 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001555 public void releaseVirtualDisplay(IVirtualDisplayCallback callback) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001556 final long token = Binder.clearCallingIdentity();
1557 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07001558 releaseVirtualDisplayInternal(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -08001559 } finally {
1560 Binder.restoreCallingIdentity(token);
1561 }
1562 }
1563
1564 @Override // Binder call
1565 public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001566 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jeff Brown4ccb8232014-01-16 22:16:42 -08001567
1568 final long token = Binder.clearCallingIdentity();
1569 try {
1570 dumpInternal(pw);
1571 } finally {
1572 Binder.restoreCallingIdentity(token);
1573 }
1574 }
1575
1576 private boolean validatePackageName(int uid, String packageName) {
1577 if (packageName != null) {
1578 String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
1579 if (packageNames != null) {
1580 for (String n : packageNames) {
1581 if (n.equals(packageName)) {
1582 return true;
1583 }
1584 }
1585 }
1586 }
1587 return false;
1588 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07001589
1590 private boolean canProjectVideo(IMediaProjection projection) {
1591 if (projection != null) {
1592 try {
1593 if (projection.canProjectVideo()) {
1594 return true;
1595 }
1596 } catch (RemoteException e) {
1597 Slog.e(TAG, "Unable to query projection service for permissions", e);
1598 }
1599 }
1600 if (mContext.checkCallingPermission(
1601 android.Manifest.permission.CAPTURE_VIDEO_OUTPUT)
Michael Wright0ccc2b02014-07-24 18:20:41 -07001602 == PackageManager.PERMISSION_GRANTED) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07001603 return true;
1604 }
1605 return canProjectSecureVideo(projection);
1606 }
1607
1608 private boolean canProjectSecureVideo(IMediaProjection projection) {
1609 if (projection != null) {
1610 try {
1611 if (projection.canProjectSecureVideo()){
1612 return true;
1613 }
1614 } catch (RemoteException e) {
1615 Slog.e(TAG, "Unable to query projection service for permissions", e);
1616 }
1617 }
1618 return mContext.checkCallingPermission(
1619 android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT)
Michael Wright0ccc2b02014-07-24 18:20:41 -07001620 == PackageManager.PERMISSION_GRANTED;
Michael Wrightc39d47a2014-07-08 18:07:36 -07001621 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001622 }
1623
1624 private final class LocalService extends DisplayManagerInternal {
1625 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07001626 public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler,
Jeff Brownad9ef192014-04-08 17:26:30 -07001627 SensorManager sensorManager) {
1628 synchronized (mSyncRoot) {
Jeff Brown037c33e2014-04-09 00:31:55 -07001629 DisplayBlanker blanker = new DisplayBlanker() {
1630 @Override
Jeff Brown5d6443b2015-04-10 20:15:01 -07001631 public void requestDisplayState(int state, int brightness) {
Jeff Brown037c33e2014-04-09 00:31:55 -07001632 // The order of operations is important for legacy reasons.
1633 if (state == Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07001634 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07001635 }
1636
1637 callbacks.onDisplayStateChange(state);
1638
1639 if (state != Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07001640 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07001641 }
1642 }
1643 };
Jeff Brownad9ef192014-04-08 17:26:30 -07001644 mDisplayPowerController = new DisplayPowerController(
Jeff Brown037c33e2014-04-09 00:31:55 -07001645 mContext, callbacks, handler, sensorManager, blanker);
Jeff Brownad9ef192014-04-08 17:26:30 -07001646 }
1647 }
1648
1649 @Override
1650 public boolean requestPowerState(DisplayPowerRequest request,
1651 boolean waitForNegativeProximity) {
1652 return mDisplayPowerController.requestPowerState(request,
1653 waitForNegativeProximity);
1654 }
1655
1656 @Override
1657 public boolean isProximitySensorAvailable() {
1658 return mDisplayPowerController.isProximitySensorAvailable();
1659 }
1660
1661 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -08001662 public DisplayInfo getDisplayInfo(int displayId) {
1663 return getDisplayInfoInternal(displayId, Process.myUid());
1664 }
1665
1666 @Override
1667 public void registerDisplayTransactionListener(DisplayTransactionListener listener) {
1668 if (listener == null) {
1669 throw new IllegalArgumentException("listener must not be null");
1670 }
1671
1672 registerDisplayTransactionListenerInternal(listener);
1673 }
1674
1675 @Override
1676 public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) {
1677 if (listener == null) {
1678 throw new IllegalArgumentException("listener must not be null");
1679 }
1680
1681 unregisterDisplayTransactionListenerInternal(listener);
1682 }
1683
1684 @Override
1685 public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) {
1686 setDisplayInfoOverrideFromWindowManagerInternal(displayId, info);
1687 }
1688
1689 @Override
Andrii Kuliancd097992017-03-23 18:31:59 -07001690 public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) {
1691 getNonOverrideDisplayInfoInternal(displayId, outInfo);
1692 }
1693
1694 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -08001695 public void performTraversalInTransactionFromWindowManager() {
1696 performTraversalInTransactionFromWindowManagerInternal();
1697 }
1698
1699 @Override
Michael Wright3f145a22014-07-22 19:46:03 -07001700 public void setDisplayProperties(int displayId, boolean hasContent,
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001701 float requestedRefreshRate, int requestedMode, boolean inTraversal) {
1702 setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate,
1703 requestedMode, inTraversal);
Jeff Brown4ccb8232014-01-16 22:16:42 -08001704 }
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08001705
1706 @Override
1707 public void setDisplayOffsets(int displayId, int x, int y) {
1708 setDisplayOffsetsInternal(displayId, x, y);
1709 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08001710
1711 @Override
1712 public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) {
1713 setDisplayAccessUIDsInternal(newDisplayAccessUIDs);
1714 }
1715
1716 @Override
1717 public boolean isUidPresentOnDisplay(int uid, int displayId) {
1718 return isUidPresentOnDisplayInternal(uid, displayId);
1719 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001720 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001721}