blob: 10386e70facbb65355f5656f68b37082b4716c5c [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
Chilun67a379b2019-04-11 19:49:42 +080019import static android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT;
20import static android.Manifest.permission.CAPTURE_VIDEO_OUTPUT;
21import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -080022import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
Chilun67a379b2019-04-11 19:49:42 +080023import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -080024import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
25import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
26import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE;
Chilun67a379b2019-04-11 19:49:42 +080027import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +010028import static android.hardware.display.DisplayViewport.VIEWPORT_EXTERNAL;
29import static android.hardware.display.DisplayViewport.VIEWPORT_INTERNAL;
30import static android.hardware.display.DisplayViewport.VIEWPORT_VIRTUAL;
Jeff Brownbd6e1502012-08-28 03:27:37 -070031
Jeff Brownfa25bf52012-07-23 19:26:30 -070032import android.Manifest;
Santos Cordonee8931e2017-04-05 10:31:15 -070033import android.annotation.NonNull;
Kenny Guy05ce8092018-01-17 13:44:20 +000034import android.annotation.Nullable;
Michael Wrighteef0e132017-11-21 17:57:52 +000035import android.annotation.UserIdInt;
Kenny Guy29aa30e2017-11-30 13:43:46 +000036import android.app.AppOpsManager;
Jeff Brownfa25bf52012-07-23 19:26:30 -070037import android.content.Context;
38import android.content.pm.PackageManager;
Kenny Guy22bd0442017-10-26 00:15:54 +010039import android.content.pm.ParceledListSlice;
Michael Wrighteedcbf12017-08-16 23:14:54 +010040import android.content.res.Resources;
Dan Gittik122df862018-03-28 16:59:22 +010041import android.content.res.TypedArray;
Peiyong Lin277eaff2019-01-16 16:18:22 -080042import android.graphics.ColorSpace;
Michael Wrighteedcbf12017-08-16 23:14:54 +010043import android.graphics.Point;
Robert Carr5c52b132019-02-15 15:48:11 -080044import android.graphics.Rect;
Jeff Brownad9ef192014-04-08 17:26:30 -070045import android.hardware.SensorManager;
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +000046import android.hardware.display.AmbientBrightnessDayStats;
Kenny Guy22bd0442017-10-26 00:15:54 +010047import android.hardware.display.BrightnessChangeEvent;
Michael Wrighteef0e132017-11-21 17:57:52 +000048import android.hardware.display.BrightnessConfiguration;
Dan Gittik122df862018-03-28 16:59:22 +010049import android.hardware.display.Curve;
Jeff Brownbd6e1502012-08-28 03:27:37 -070050import android.hardware.display.DisplayManagerGlobal;
Jeff Brown4ccb8232014-01-16 22:16:42 -080051import android.hardware.display.DisplayManagerInternal;
Jeff Brown4ccb8232014-01-16 22:16:42 -080052import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +010053import android.hardware.display.DisplayViewport;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070054import android.hardware.display.DisplayedContentSample;
55import android.hardware.display.DisplayedContentSamplingAttributes;
Jeff Brownfa25bf52012-07-23 19:26:30 -070056import android.hardware.display.IDisplayManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070057import android.hardware.display.IDisplayManagerCallback;
Michael Wright75ee9fc2014-09-01 19:55:22 -070058import android.hardware.display.IVirtualDisplayCallback;
Jeff Browne08ae382012-09-07 20:36:36 -070059import android.hardware.display.WifiDisplayStatus;
Jeff Brown4ccb8232014-01-16 22:16:42 -080060import android.hardware.input.InputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -070061import android.media.projection.IMediaProjection;
62import android.media.projection.IMediaProjectionManager;
Jeff Brownfa25bf52012-07-23 19:26:30 -070063import android.os.Binder;
Jeff Brownbd6e1502012-08-28 03:27:37 -070064import android.os.Handler;
Jeff Brown64a55af2012-08-26 02:47:39 -070065import android.os.IBinder;
Jeff Brown4ccb8232014-01-16 22:16:42 -080066import android.os.IBinder.DeathRecipient;
Jeff Brownbd6e1502012-08-28 03:27:37 -070067import android.os.Looper;
68import android.os.Message;
Jeff Brown5d6443b2015-04-10 20:15:01 -070069import android.os.PowerManager;
Craig Mautner4504de52013-12-20 09:06:56 -080070import android.os.Process;
Jeff Brownbd6e1502012-08-28 03:27:37 -070071import android.os.RemoteException;
Dan Gittik7a32fba2018-03-28 12:19:38 +010072import android.os.ResultReceiver;
Michael Wrightc39d47a2014-07-08 18:07:36 -070073import android.os.ServiceManager;
Dan Gittik7a32fba2018-03-28 12:19:38 +010074import android.os.ShellCallback;
Jeff Brownbd6e1502012-08-28 03:27:37 -070075import android.os.SystemClock;
Jeff Brownfa25bf52012-07-23 19:26:30 -070076import android.os.SystemProperties;
Jeff Brown5d6443b2015-04-10 20:15:01 -070077import android.os.Trace;
Kenny Guy22bd0442017-10-26 00:15:54 +010078import android.os.UserHandle;
Michael Wrighteef0e132017-11-21 17:57:52 +000079import android.os.UserManager;
Dan Gittik7a32fba2018-03-28 12:19:38 +010080import android.provider.Settings;
Jeff Browna506a6e2013-06-04 00:02:38 -070081import android.text.TextUtils;
Andrii Kulianfb1bf692017-01-17 11:17:34 -080082import android.util.IntArray;
Dan Gittik122df862018-03-28 16:59:22 +010083import android.util.Pair;
Jeff Brownbd6e1502012-08-28 03:27:37 -070084import android.util.Slog;
85import android.util.SparseArray;
Dan Gittik122df862018-03-28 16:59:22 +010086import android.util.Spline;
Jeff Brownfa25bf52012-07-23 19:26:30 -070087import android.view.Display;
88import android.view.DisplayInfo;
Jeff Browna506a6e2013-06-04 00:02:38 -070089import android.view.Surface;
Robert Carrae606b42018-02-15 15:36:23 -080090import android.view.SurfaceControl;
Jeff Browna506a6e2013-06-04 00:02:38 -070091
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +010092import com.android.internal.annotations.GuardedBy;
93import com.android.internal.annotations.VisibleForTesting;
94import com.android.internal.util.DumpUtils;
95import com.android.internal.util.IndentingPrintWriter;
Jorim Jaggied7993b2017-03-28 18:50:01 +010096import com.android.server.AnimationThread;
Jeff Brown4ccb8232014-01-16 22:16:42 -080097import com.android.server.DisplayThread;
98import com.android.server.LocalServices;
99import com.android.server.SystemService;
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700100import com.android.server.UiThread;
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200101import com.android.server.wm.SurfaceAnimationThread;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100102import com.android.server.wm.WindowManagerInternal;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700103
104import java.io.FileDescriptor;
105import java.io.PrintWriter;
106import java.util.ArrayList;
Jeff Browna506a6e2013-06-04 00:02:38 -0700107import java.util.Arrays;
Jeff Browne75926d2014-09-18 15:24:49 -0700108import java.util.List;
Jeff Brown7f3994e2012-12-04 14:04:28 -0800109import java.util.concurrent.CopyOnWriteArrayList;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700110
111/**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700112 * Manages attached displays.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700113 * <p>
Jeff Brownbd6e1502012-08-28 03:27:37 -0700114 * The {@link DisplayManagerService} manages the global lifecycle of displays,
115 * decides how to configure logical displays based on the physical display devices currently
116 * attached, sends notifications to the system and to applications when the state
117 * changes, and so on.
118 * </p><p>
119 * The display manager service relies on a collection of {@link DisplayAdapter} components,
120 * for discovering and configuring physical display devices attached to the system.
121 * There are separate display adapters for each manner that devices are attached:
122 * one display adapter for built-in local displays, one for simulated non-functional
123 * displays when the system is headless, one for simulated overlay displays used for
124 * development, one for wifi displays, etc.
125 * </p><p>
126 * Display adapters are only weakly coupled to the display manager service.
127 * Display adapters communicate changes in display device state to the display manager
Craig Mautner722285e2012-09-07 13:55:58 -0700128 * service asynchronously via a {@link DisplayAdapter.Listener} registered
Jeff Brownbd6e1502012-08-28 03:27:37 -0700129 * by the display manager service. This separation of concerns is important for
130 * two main reasons. First, it neatly encapsulates the responsibilities of these
131 * two classes: display adapters handle individual display devices whereas
132 * the display manager service handles the global state. Second, it eliminates
133 * the potential for deadlocks resulting from asynchronous display device discovery.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700134 * </p>
135 *
136 * <h3>Synchronization</h3>
137 * <p>
138 * Because the display manager may be accessed by multiple threads, the synchronization
139 * story gets a little complicated. In particular, the window manager may call into
140 * the display manager while holding a surface transaction with the expectation that
141 * it can apply changes immediately. Unfortunately, that means we can't just do
142 * everything asynchronously (*grump*).
Jeff Brownbd6e1502012-08-28 03:27:37 -0700143 * </p><p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700144 * To make this work, all of the objects that belong to the display manager must
145 * use the same lock. We call this lock the synchronization root and it has a unique
146 * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are
147 * named with the "Locked" suffix.
148 * </p><p>
149 * Where things get tricky is that the display manager is not allowed to make
150 * any potentially reentrant calls, especially into the window manager. We generally
151 * avoid this by making all potentially reentrant out-calls asynchronous.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700152 * </p>
153 */
Jeff Brown4ccb8232014-01-16 22:16:42 -0800154public final class DisplayManagerService extends SystemService {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700155 private static final String TAG = "DisplayManagerService";
Jeff Brownbd6e1502012-08-28 03:27:37 -0700156 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700157
Jeff Brownbbd28a22012-09-20 16:47:15 -0700158 // When this system property is set to 0, WFD is forcibly disabled on boot.
159 // When this system property is set to 1, WFD is forcibly enabled on boot.
160 // Otherwise WFD is enabled according to the value of config_enableWifiDisplay.
161 private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
162
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200163 private static final String PROP_DEFAULT_DISPLAY_TOP_INSET = "persist.sys.displayinset.top";
164
Jeff Brownbd6e1502012-08-28 03:27:37 -0700165 private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
166
Santos Cordonc22c5632017-06-21 16:03:49 -0700167 private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS = 1;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700168 private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2;
169 private static final int MSG_DELIVER_DISPLAY_EVENT = 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700170 private static final int MSG_REQUEST_TRAVERSAL = 4;
Jeff Brownd728bf52012-09-08 18:05:28 -0700171 private static final int MSG_UPDATE_VIEWPORT = 5;
Michael Wrighta3dab232019-02-22 16:54:21 +0000172 private static final int MSG_LOAD_BRIGHTNESS_CONFIGURATION = 6;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700173
Jeff Brownb880d882014-02-10 19:47:07 -0800174 private final Context mContext;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700175 private final DisplayManagerHandler mHandler;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700176 private final Handler mUiHandler;
177 private final DisplayAdapterListener mDisplayAdapterListener;
Michael Wrighta3dab232019-02-22 16:54:21 +0000178 private final DisplayModeDirector mDisplayModeDirector;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800179 private WindowManagerInternal mWindowManagerInternal;
180 private InputManagerInternal mInputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700181 private IMediaProjectionManager mProjectionService;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700182
183 // The synchronization root for the display manager.
184 // This lock guards most of the display manager's state.
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800185 // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call
186 // into WindowManagerService methods that require mWindowMap while holding this unless you are
187 // very very sure that no deadlock can occur.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700188 private final SyncRoot mSyncRoot = new SyncRoot();
189
190 // True if in safe mode.
191 // This option may disable certain display adapters.
192 public boolean mSafeMode;
193
194 // True if we are in a special boot mode where only core applications and
195 // services should be started. This option may disable certain display adapters.
196 public boolean mOnlyCore;
197
Jeff Brown27f1d672012-10-17 18:32:34 -0700198 // True if the display manager service should pretend there is only one display
199 // and only tell applications about the existence of the default logical display.
200 // The display manager can still mirror content to secondary displays but applications
201 // cannot present unique content on those displays.
202 // Used for demonstration purposes only.
203 private final boolean mSingleDisplayDemoMode;
204
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700205 // All callback records indexed by calling process id.
206 public final SparseArray<CallbackRecord> mCallbacks =
Jeff Brownbd6e1502012-08-28 03:27:37 -0700207 new SparseArray<CallbackRecord>();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700208
Jeff Brownbd6e1502012-08-28 03:27:37 -0700209 // List of all currently registered display adapters.
210 private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
211
212 // List of all currently connected display devices.
213 private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>();
214
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700215 // List of all logical displays indexed by logical display id.
216 private final SparseArray<LogicalDisplay> mLogicalDisplays =
217 new SparseArray<LogicalDisplay>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700218 private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1;
219
Jeff Brown7f3994e2012-12-04 14:04:28 -0800220 // List of all display transaction listeners.
221 private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
222 new CopyOnWriteArrayList<DisplayTransactionListener>();
223
Jeff Brownad9ef192014-04-08 17:26:30 -0700224 // Display power controller.
225 private DisplayPowerController mDisplayPowerController;
226
Jeff Brown037c33e2014-04-09 00:31:55 -0700227 // The overall display state, independent of changes that might influence one
228 // display or another in particular.
Jeff Brown5d6443b2015-04-10 20:15:01 -0700229 private int mGlobalDisplayState = Display.STATE_ON;
230
231 // The overall display brightness.
232 // For now, this only applies to the built-in display but we may split it up eventually.
233 private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT;
Jeff Brown9e316a12012-10-08 19:17:06 -0700234
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700235 // Set to true when there are pending display changes that have yet to be applied
236 // to the surface flinger state.
237 private boolean mPendingTraversal;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700238
Jeff Browne08ae382012-09-07 20:36:36 -0700239 // The Wifi display adapter, or null if not registered.
240 private WifiDisplayAdapter mWifiDisplayAdapter;
241
Jeff Brownce468a32013-11-21 16:42:03 -0800242 // The number of active wifi display scan requests.
243 private int mWifiDisplayScanRequestCount;
244
Jeff Browna506a6e2013-06-04 00:02:38 -0700245 // The virtual display adapter, or null if not registered.
246 private VirtualDisplayAdapter mVirtualDisplayAdapter;
247
Michael Wrighteef0e132017-11-21 17:57:52 +0000248 // The User ID of the current user
249 private @UserIdInt int mCurrentUserId;
250
Michael Wrighteedcbf12017-08-16 23:14:54 +0100251 // The stable device screen height and width. These are not tied to a specific display, even
252 // the default display, because they need to be stable over the course of the device's entire
253 // life, even if the default display changes (e.g. a new monitor is plugged into a PC-like
254 // device).
255 private Point mStableDisplaySize = new Point();
256
Winson72dbe7e2019-04-29 14:55:30 -0700257 // Whether the system has finished booting or not.
258 private boolean mSystemReady;
259
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200260 // The top inset of the default display.
261 // This gets persisted so that the boot animation knows how to transition from the display's
262 // full size to the size configured by the user. Right now we only persist and animate the top
263 // inset, but theoretically we could do it for all of them.
264 private int mDefaultDisplayTopInset;
265
Jeff Brownd728bf52012-09-08 18:05:28 -0700266 // Viewports of the default display and the display that should receive touch
267 // input from an external source. Used by the input system.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100268 @GuardedBy("mSyncRoot")
269 private final ArrayList<DisplayViewport> mViewports = new ArrayList<>();
Jeff Brownd728bf52012-09-08 18:05:28 -0700270
Jeff Brown89d55462012-09-19 11:33:42 -0700271 // Persistent data store for all internal settings maintained by the display manager service.
272 private final PersistentDataStore mPersistentDataStore = new PersistentDataStore();
273
Jeff Brownbd6e1502012-08-28 03:27:37 -0700274 // Temporary callback list, used when sending display events to applications.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700275 // May be used outside of the lock but only on the handler thread.
276 private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700277
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700278 // Temporary display info, used for comparing display configurations.
279 private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
280
Jeff Brownd728bf52012-09-08 18:05:28 -0700281 // Temporary viewports, used when sending new viewport information to the
282 // input system. May be used outside of the lock but only on the handler thread.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100283 private final ArrayList<DisplayViewport> mTempViewports = new ArrayList<>();
Jeff Brownd728bf52012-09-08 18:05:28 -0700284
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700285 // The default color mode for default displays. Overrides the usual
286 // Display.Display.COLOR_MODE_DEFAULT for displays with the
287 // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set.
288 private final int mDefaultDisplayDefaultColorMode;
289
Jeff Browne75926d2014-09-18 15:24:49 -0700290 // Temporary list of deferred work to perform when setting the display state.
291 // Only used by requestDisplayState. The field is self-synchronized and only
292 // intended for use inside of the requestGlobalDisplayStateInternal function.
293 private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>();
294
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800295 // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs.
296 private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>();
297
Santos Cordonee8931e2017-04-05 10:31:15 -0700298 private final Injector mInjector;
299
Dan Gittik122df862018-03-28 16:59:22 +0100300 // The minimum brightness curve, which guarantess that any brightness curve that dips below it
301 // is rejected by the system.
302 private final Curve mMinimumBrightnessCurve;
303 private final Spline mMinimumBrightnessSpline;
Peiyong Lin277eaff2019-01-16 16:18:22 -0800304 private final ColorSpace mWideColorSpace;
Dan Gittik122df862018-03-28 16:59:22 +0100305
Long Lingbc841b02019-07-03 16:43:15 -0700306 private SensorManager mSensorManager;
307
Jeff Brownb880d882014-02-10 19:47:07 -0800308 public DisplayManagerService(Context context) {
Santos Cordonee8931e2017-04-05 10:31:15 -0700309 this(context, new Injector());
310 }
311
312 @VisibleForTesting
313 DisplayManagerService(Context context, Injector injector) {
Jeff Brownb880d882014-02-10 19:47:07 -0800314 super(context);
Santos Cordonee8931e2017-04-05 10:31:15 -0700315 mInjector = injector;
Jeff Brownb880d882014-02-10 19:47:07 -0800316 mContext = context;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800317 mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700318 mUiHandler = UiThread.getHandler();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700319 mDisplayAdapterListener = new DisplayAdapterListener();
Michael Wrighta3dab232019-02-22 16:54:21 +0000320 mDisplayModeDirector = new DisplayModeDirector(context, mHandler);
Jeff Brown27f1d672012-10-17 18:32:34 -0700321 mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
Dan Gittik122df862018-03-28 16:59:22 +0100322 Resources resources = mContext.getResources();
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700323 mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger(
Michael Wrighteef0e132017-11-21 17:57:52 +0000324 com.android.internal.R.integer.config_defaultDisplayDefaultColorMode);
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200325 mDefaultDisplayTopInset = SystemProperties.getInt(PROP_DEFAULT_DISPLAY_TOP_INSET, -1);
Dan Gittik122df862018-03-28 16:59:22 +0100326 float[] lux = getFloatArray(resources.obtainTypedArray(
327 com.android.internal.R.array.config_minimumBrightnessCurveLux));
328 float[] nits = getFloatArray(resources.obtainTypedArray(
329 com.android.internal.R.array.config_minimumBrightnessCurveNits));
330 mMinimumBrightnessCurve = new Curve(lux, nits);
331 mMinimumBrightnessSpline = Spline.createSpline(lux, nits);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700332
Michael Wrighta3dab232019-02-22 16:54:21 +0000333 PowerManager pm = mContext.getSystemService(PowerManager.class);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700334 mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting();
Michael Wrighteef0e132017-11-21 17:57:52 +0000335 mCurrentUserId = UserHandle.USER_SYSTEM;
Peiyong Lin277eaff2019-01-16 16:18:22 -0800336 ColorSpace[] colorSpaces = SurfaceControl.getCompositionColorSpaces();
337 mWideColorSpace = colorSpaces[1];
Winson72dbe7e2019-04-29 14:55:30 -0700338
339 mSystemReady = false;
Joel Fernandes2d314e12017-04-04 16:32:15 -0700340 }
341
342 public void setupSchedulerPolicies() {
Jorim Jaggied7993b2017-03-28 18:50:01 +0100343 // android.display and android.anim is critical to user experience and we should make sure
Michael Wrighteef0e132017-11-21 17:57:52 +0000344 // it is not in the default foregroup groups, add it to top-app to make sure it uses all
345 // the cores and scheduling settings for top-app when it runs.
Jorim Jaggied7993b2017-03-28 18:50:01 +0100346 Process.setThreadGroupAndCpuset(DisplayThread.get().getThreadId(),
347 Process.THREAD_GROUP_TOP_APP);
348 Process.setThreadGroupAndCpuset(AnimationThread.get().getThreadId(),
349 Process.THREAD_GROUP_TOP_APP);
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200350 Process.setThreadGroupAndCpuset(SurfaceAnimationThread.get().getThreadId(),
351 Process.THREAD_GROUP_TOP_APP);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700352 }
353
Jeff Brown4ccb8232014-01-16 22:16:42 -0800354 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -0800355 public void onStart() {
Michael Wright1c9977b2016-07-12 13:30:10 -0700356 // We need to pre-load the persistent data store so it's ready before the default display
357 // adapter is up so that we have it's configuration. We could load it lazily, but since
358 // we're going to have to read it in eventually we may as well do it here rather than after
Santos Cordonc22c5632017-06-21 16:03:49 -0700359 // we've waited for the display to register itself with us.
Michael Wrighta3dab232019-02-22 16:54:21 +0000360 synchronized (mSyncRoot) {
361 mPersistentDataStore.loadIfNeeded();
362 loadStableDisplayValuesLocked();
Michael Wrighteedcbf12017-08-16 23:14:54 +0100363 }
Santos Cordonc22c5632017-06-21 16:03:49 -0700364 mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800365
366 publishBinderService(Context.DISPLAY_SERVICE, new BinderService(),
367 true /*allowIsolated*/);
368 publishLocalService(DisplayManagerInternal.class, new LocalService());
369 }
370
371 @Override
372 public void onBootPhase(int phase) {
373 if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) {
374 synchronized (mSyncRoot) {
Santos Cordonc22c5632017-06-21 16:03:49 -0700375 long timeout = SystemClock.uptimeMillis()
376 + mInjector.getDefaultDisplayDelayTimeout();
377 while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null ||
378 mVirtualDisplayAdapter == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800379 long delay = timeout - SystemClock.uptimeMillis();
380 if (delay <= 0) {
381 throw new RuntimeException("Timeout waiting for default display "
Santos Cordonc22c5632017-06-21 16:03:49 -0700382 + "to be initialized. DefaultDisplay="
383 + mLogicalDisplays.get(Display.DEFAULT_DISPLAY)
384 + ", mVirtualDisplayAdapter=" + mVirtualDisplayAdapter);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800385 }
386 if (DEBUG) {
387 Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay);
388 }
389 try {
390 mSyncRoot.wait(delay);
391 } catch (InterruptedException ex) {
392 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700393 }
394 }
395 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700396 }
397
Michael Wrighteef0e132017-11-21 17:57:52 +0000398 @Override
399 public void onSwitchUser(@UserIdInt int newUserId) {
400 final int userSerial = getUserManager().getUserSerialNumber(newUserId);
401 synchronized (mSyncRoot) {
402 if (mCurrentUserId != newUserId) {
403 mCurrentUserId = newUserId;
404 BrightnessConfiguration config =
405 mPersistentDataStore.getBrightnessConfiguration(userSerial);
406 mDisplayPowerController.setBrightnessConfiguration(config);
407 }
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +0000408 mDisplayPowerController.onSwitchUser(newUserId);
Michael Wrighteef0e132017-11-21 17:57:52 +0000409 }
410 }
411
Jeff Brown4ccb8232014-01-16 22:16:42 -0800412 // TODO: Use dependencies or a boot phase
413 public void windowManagerAndInputReady() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700414 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800415 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
416 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Craig Mautner65d11b32012-10-01 13:59:52 -0700417 scheduleTraversalLocked(false);
Jeff Brownd728bf52012-09-08 18:05:28 -0700418 }
419 }
420
421 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700422 * Called when the system is ready to go.
423 */
424 public void systemReady(boolean safeMode, boolean onlyCore) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700425 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700426 mSafeMode = safeMode;
427 mOnlyCore = onlyCore;
Winson72dbe7e2019-04-29 14:55:30 -0700428 mSystemReady = true;
429 // Just in case the top inset changed before the system was ready. At this point, any
430 // relevant configuration should be in place.
431 recordTopInsetLocked(mLogicalDisplays.get(Display.DEFAULT_DISPLAY));
Jeff Brownbd6e1502012-08-28 03:27:37 -0700432 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700433
Ana Kruleca74a8642019-11-14 00:51:00 +0100434 mDisplayModeDirector.setDesiredDisplayModeSpecsListener(
435 new DesiredDisplayModeSpecsObserver());
Long Lingbc841b02019-07-03 16:43:15 -0700436 mDisplayModeDirector.start(mSensorManager);
Michael Wrighta3dab232019-02-22 16:54:21 +0000437
Jeff Brownbd6e1502012-08-28 03:27:37 -0700438 mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
439 }
440
Santos Cordonee8931e2017-04-05 10:31:15 -0700441 @VisibleForTesting
442 Handler getDisplayHandler() {
443 return mHandler;
444 }
445
Michael Wrighteedcbf12017-08-16 23:14:54 +0100446 private void loadStableDisplayValuesLocked() {
447 final Point size = mPersistentDataStore.getStableDisplaySize();
448 if (size.x > 0 && size.y > 0) {
449 // Just set these values directly so we don't write the display persistent data again
450 // unnecessarily
451 mStableDisplaySize.set(size.x, size.y);
452 } else {
453 final Resources res = mContext.getResources();
454 final int width = res.getInteger(
455 com.android.internal.R.integer.config_stableDeviceDisplayWidth);
456 final int height = res.getInteger(
457 com.android.internal.R.integer.config_stableDeviceDisplayHeight);
458 if (width > 0 && height > 0) {
459 setStableDisplaySizeLocked(width, height);
460 }
461 }
462 }
463
464 private Point getStableDisplaySizeInternal() {
465 Point r = new Point();
466 synchronized (mSyncRoot) {
467 if (mStableDisplaySize.x > 0 && mStableDisplaySize.y > 0) {
468 r.set(mStableDisplaySize.x, mStableDisplaySize.y);
469 }
470 }
471 return r;
472 }
473
Jeff Brown4ccb8232014-01-16 22:16:42 -0800474 private void registerDisplayTransactionListenerInternal(
475 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800476 // List is self-synchronized copy-on-write.
477 mDisplayTransactionListeners.add(listener);
478 }
479
Jeff Brown4ccb8232014-01-16 22:16:42 -0800480 private void unregisterDisplayTransactionListenerInternal(
481 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800482 // List is self-synchronized copy-on-write.
483 mDisplayTransactionListeners.remove(listener);
484 }
485
Jeff Brown4ccb8232014-01-16 22:16:42 -0800486 private void setDisplayInfoOverrideFromWindowManagerInternal(
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700487 int displayId, DisplayInfo info) {
488 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700489 LogicalDisplay display = mLogicalDisplays.get(displayId);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700490 if (display != null) {
Jeff Brownef981a42013-08-07 14:13:37 -0700491 if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200492 handleLogicalDisplayChanged(displayId, display);
Craig Mautner65d11b32012-10-01 13:59:52 -0700493 scheduleTraversalLocked(false);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700494 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700495 }
496 }
497 }
498
Andrii Kuliancd097992017-03-23 18:31:59 -0700499 /**
500 * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo)
501 */
502 private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) {
503 synchronized (mSyncRoot) {
504 final LogicalDisplay display = mLogicalDisplays.get(displayId);
505 if (display != null) {
506 display.getNonOverrideDisplayInfoLocked(outInfo);
507 }
508 }
509 }
510
Santos Cordonee8931e2017-04-05 10:31:15 -0700511 @VisibleForTesting
Robert Carrae606b42018-02-15 15:36:23 -0800512 void performTraversalInternal(SurfaceControl.Transaction t) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700513 synchronized (mSyncRoot) {
514 if (!mPendingTraversal) {
515 return;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700516 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700517 mPendingTraversal = false;
518
Robert Carrae606b42018-02-15 15:36:23 -0800519 performTraversalLocked(t);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700520 }
Jeff Brown7f3994e2012-12-04 14:04:28 -0800521
522 // List is self-synchronized copy-on-write.
523 for (DisplayTransactionListener listener : mDisplayTransactionListeners) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800524 listener.onDisplayTransaction(t);
Jeff Brown7f3994e2012-12-04 14:04:28 -0800525 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700526 }
527
Jeff Brown5d6443b2015-04-10 20:15:01 -0700528 private void requestGlobalDisplayStateInternal(int state, int brightness) {
529 if (state == Display.STATE_UNKNOWN) {
530 state = Display.STATE_ON;
531 }
532 if (state == Display.STATE_OFF) {
533 brightness = PowerManager.BRIGHTNESS_OFF;
534 } else if (brightness < 0) {
535 brightness = PowerManager.BRIGHTNESS_DEFAULT;
536 } else if (brightness > PowerManager.BRIGHTNESS_ON) {
537 brightness = PowerManager.BRIGHTNESS_ON;
538 }
539
Jeff Browne75926d2014-09-18 15:24:49 -0700540 synchronized (mTempDisplayStateWorkQueue) {
541 try {
542 // Update the display state within the lock.
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700543 // Note that we do not need to schedule traversals here although it
544 // may happen as a side-effect of displays changing state.
Jeff Browne75926d2014-09-18 15:24:49 -0700545 synchronized (mSyncRoot) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700546 if (mGlobalDisplayState == state
547 && mGlobalDisplayBrightness == brightness) {
548 return; // no change
Jeff Browne75926d2014-09-18 15:24:49 -0700549 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700550
551 Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState("
552 + Display.stateToString(state)
553 + ", brightness=" + brightness + ")");
554 mGlobalDisplayState = state;
555 mGlobalDisplayBrightness = brightness;
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700556 applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue);
Jeff Browne75926d2014-09-18 15:24:49 -0700557 }
558
559 // Setting the display power state can take hundreds of milliseconds
560 // to complete so we defer the most expensive part of the work until
561 // after we have exited the critical section to avoid blocking other
562 // threads for a long time.
563 for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) {
564 mTempDisplayStateWorkQueue.get(i).run();
565 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700566 Trace.traceEnd(Trace.TRACE_TAG_POWER);
Jeff Browne75926d2014-09-18 15:24:49 -0700567 } finally {
568 mTempDisplayStateWorkQueue.clear();
Jeff Brown9e316a12012-10-08 19:17:06 -0700569 }
570 }
571 }
572
Jeff Brown4ccb8232014-01-16 22:16:42 -0800573 private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700574 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800575 LogicalDisplay display = mLogicalDisplays.get(displayId);
576 if (display != null) {
577 DisplayInfo info = display.getDisplayInfoLocked();
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800578 if (info.hasAccess(callingUid)
579 || isUidPresentOnDisplayInternal(callingUid, displayId)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800580 return info;
581 }
582 }
583 return null;
584 }
585 }
586
587 private int[] getDisplayIdsInternal(int callingUid) {
588 synchronized (mSyncRoot) {
589 final int count = mLogicalDisplays.size();
590 int[] displayIds = new int[count];
591 int n = 0;
592 for (int i = 0; i < count; i++) {
593 LogicalDisplay display = mLogicalDisplays.valueAt(i);
594 DisplayInfo info = display.getDisplayInfoLocked();
595 if (info.hasAccess(callingUid)) {
596 displayIds[n++] = mLogicalDisplays.keyAt(i);
597 }
598 }
599 if (n != count) {
600 displayIds = Arrays.copyOfRange(displayIds, 0, n);
601 }
602 return displayIds;
603 }
604 }
605
606 private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) {
607 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700608 if (mCallbacks.get(callingPid) != null) {
609 throw new SecurityException("The calling process has already "
610 + "registered an IDisplayManagerCallback.");
Jeff Brown64a55af2012-08-26 02:47:39 -0700611 }
612
Jeff Brownbd6e1502012-08-28 03:27:37 -0700613 CallbackRecord record = new CallbackRecord(callingPid, callback);
614 try {
615 IBinder binder = callback.asBinder();
616 binder.linkToDeath(record, 0);
617 } catch (RemoteException ex) {
618 // give up
619 throw new RuntimeException(ex);
620 }
621
622 mCallbacks.put(callingPid, record);
623 }
624 }
625
Jeff Brownce468a32013-11-21 16:42:03 -0800626 private void onCallbackDied(CallbackRecord record) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700627 synchronized (mSyncRoot) {
Jeff Brownce468a32013-11-21 16:42:03 -0800628 mCallbacks.remove(record.mPid);
629 stopWifiDisplayScanLocked(record);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700630 }
631 }
632
Jeff Brown4ccb8232014-01-16 22:16:42 -0800633 private void startWifiDisplayScanInternal(int callingPid) {
634 synchronized (mSyncRoot) {
635 CallbackRecord record = mCallbacks.get(callingPid);
636 if (record == null) {
637 throw new IllegalStateException("The calling process has not "
638 + "registered an IDisplayManagerCallback.");
Jeff Browne08ae382012-09-07 20:36:36 -0700639 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800640 startWifiDisplayScanLocked(record);
Jeff Browne08ae382012-09-07 20:36:36 -0700641 }
642 }
643
Jeff Brownce468a32013-11-21 16:42:03 -0800644 private void startWifiDisplayScanLocked(CallbackRecord record) {
645 if (!record.mWifiDisplayScanRequested) {
646 record.mWifiDisplayScanRequested = true;
647 if (mWifiDisplayScanRequestCount++ == 0) {
648 if (mWifiDisplayAdapter != null) {
649 mWifiDisplayAdapter.requestStartScanLocked();
650 }
651 }
652 }
653 }
654
Jeff Brown4ccb8232014-01-16 22:16:42 -0800655 private void stopWifiDisplayScanInternal(int callingPid) {
656 synchronized (mSyncRoot) {
657 CallbackRecord record = mCallbacks.get(callingPid);
658 if (record == null) {
659 throw new IllegalStateException("The calling process has not "
660 + "registered an IDisplayManagerCallback.");
Jeff Brownce468a32013-11-21 16:42:03 -0800661 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800662 stopWifiDisplayScanLocked(record);
Jeff Brownce468a32013-11-21 16:42:03 -0800663 }
664 }
665
666 private void stopWifiDisplayScanLocked(CallbackRecord record) {
667 if (record.mWifiDisplayScanRequested) {
668 record.mWifiDisplayScanRequested = false;
669 if (--mWifiDisplayScanRequestCount == 0) {
670 if (mWifiDisplayAdapter != null) {
671 mWifiDisplayAdapter.requestStopScanLocked();
672 }
673 } else if (mWifiDisplayScanRequestCount < 0) {
Dianne Hackborn8d051722014-10-01 14:59:58 -0700674 Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: "
Jeff Brownce468a32013-11-21 16:42:03 -0800675 + mWifiDisplayScanRequestCount);
676 mWifiDisplayScanRequestCount = 0;
677 }
678 }
679 }
680
Jeff Brown4ccb8232014-01-16 22:16:42 -0800681 private void connectWifiDisplayInternal(String address) {
682 synchronized (mSyncRoot) {
683 if (mWifiDisplayAdapter != null) {
684 mWifiDisplayAdapter.requestConnectLocked(address);
Jeff Browne08ae382012-09-07 20:36:36 -0700685 }
Jeff Browne08ae382012-09-07 20:36:36 -0700686 }
687 }
688
Jeff Brown4ccb8232014-01-16 22:16:42 -0800689 private void pauseWifiDisplayInternal() {
690 synchronized (mSyncRoot) {
691 if (mWifiDisplayAdapter != null) {
692 mWifiDisplayAdapter.requestPauseLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700693 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700694 }
695 }
696
Jeff Brown4ccb8232014-01-16 22:16:42 -0800697 private void resumeWifiDisplayInternal() {
698 synchronized (mSyncRoot) {
699 if (mWifiDisplayAdapter != null) {
700 mWifiDisplayAdapter.requestResumeLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700701 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700702 }
703 }
704
Jeff Brown4ccb8232014-01-16 22:16:42 -0800705 private void disconnectWifiDisplayInternal() {
706 synchronized (mSyncRoot) {
707 if (mWifiDisplayAdapter != null) {
708 mWifiDisplayAdapter.requestDisconnectLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700709 }
Jeff Browne08ae382012-09-07 20:36:36 -0700710 }
711 }
712
Jeff Brown4ccb8232014-01-16 22:16:42 -0800713 private void renameWifiDisplayInternal(String address, String alias) {
714 synchronized (mSyncRoot) {
715 if (mWifiDisplayAdapter != null) {
716 mWifiDisplayAdapter.requestRenameLocked(address, alias);
Jeff Brown89d55462012-09-19 11:33:42 -0700717 }
Jeff Brown89d55462012-09-19 11:33:42 -0700718 }
719 }
720
Jeff Brown4ccb8232014-01-16 22:16:42 -0800721 private void forgetWifiDisplayInternal(String address) {
722 synchronized (mSyncRoot) {
723 if (mWifiDisplayAdapter != null) {
724 mWifiDisplayAdapter.requestForgetLocked(address);
Jeff Brown89d55462012-09-19 11:33:42 -0700725 }
Jeff Brown89d55462012-09-19 11:33:42 -0700726 }
727 }
728
Jeff Brown4ccb8232014-01-16 22:16:42 -0800729 private WifiDisplayStatus getWifiDisplayStatusInternal() {
730 synchronized (mSyncRoot) {
731 if (mWifiDisplayAdapter != null) {
732 return mWifiDisplayAdapter.getWifiDisplayStatusLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700733 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800734 return new WifiDisplayStatus();
Jeff Browne08ae382012-09-07 20:36:36 -0700735 }
736 }
737
Michael Wright1c9977b2016-07-12 13:30:10 -0700738 private void requestColorModeInternal(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +0100739 synchronized (mSyncRoot) {
740 LogicalDisplay display = mLogicalDisplays.get(displayId);
741 if (display != null &&
Michael Wright1c9977b2016-07-12 13:30:10 -0700742 display.getRequestedColorModeLocked() != colorMode) {
743 display.setRequestedColorModeLocked(colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100744 scheduleTraversalLocked(false);
745 }
746 }
747 }
748
Michael Wright75ee9fc2014-09-01 19:55:22 -0700749 private int createVirtualDisplayInternal(IVirtualDisplayCallback callback,
Santos Cordonee8931e2017-04-05 10:31:15 -0700750 IMediaProjection projection, int callingUid, String packageName, String name, int width,
751 int height, int densityDpi, Surface surface, int flags, String uniqueId) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800752 synchronized (mSyncRoot) {
753 if (mVirtualDisplayAdapter == null) {
754 Slog.w(TAG, "Rejecting request to create private virtual display "
755 + "because the virtual display adapter is not available.");
756 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700757 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800758
759 DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked(
Santos Cordonee8931e2017-04-05 10:31:15 -0700760 callback, projection, callingUid, packageName, name, width, height, densityDpi,
761 surface, flags, uniqueId);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800762 if (device == null) {
763 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700764 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700765
Jeff Brown4ccb8232014-01-16 22:16:42 -0800766 handleDisplayDeviceAddedLocked(device);
767 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
768 if (display != null) {
769 return display.getDisplayIdLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700770 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800771
772 // Something weird happened and the logical display was not created.
773 Slog.w(TAG, "Rejecting request to create virtual display "
774 + "because the logical display was not created.");
Michael Wright75ee9fc2014-09-01 19:55:22 -0700775 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800776 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700777 }
778 return -1;
779 }
780
Michael Wright01e840f2014-06-26 16:03:25 -0700781 private void resizeVirtualDisplayInternal(IBinder appToken,
782 int width, int height, int densityDpi) {
783 synchronized (mSyncRoot) {
784 if (mVirtualDisplayAdapter == null) {
785 return;
786 }
787
788 mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi);
789 }
790 }
791
Jeff Brown92207df2014-04-16 13:16:07 -0700792 private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) {
793 synchronized (mSyncRoot) {
794 if (mVirtualDisplayAdapter == null) {
795 return;
796 }
797
798 mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface);
799 }
800 }
801
Jeff Brown4ccb8232014-01-16 22:16:42 -0800802 private void releaseVirtualDisplayInternal(IBinder appToken) {
803 synchronized (mSyncRoot) {
804 if (mVirtualDisplayAdapter == null) {
805 return;
Jeff Browna506a6e2013-06-04 00:02:38 -0700806 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700807
Jeff Brown4ccb8232014-01-16 22:16:42 -0800808 DisplayDevice device =
809 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
810 if (device != null) {
811 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700812 }
813 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700814 }
815
chaviwda4c6942018-11-07 15:52:56 -0800816 private void setVirtualDisplayStateInternal(IBinder appToken, boolean isOn) {
817 synchronized (mSyncRoot) {
818 if (mVirtualDisplayAdapter == null) {
819 return;
820 }
821
822 mVirtualDisplayAdapter.setVirtualDisplayStateLocked(appToken, isOn);
823 }
824 }
825
Santos Cordonc22c5632017-06-21 16:03:49 -0700826 private void registerDefaultDisplayAdapters() {
827 // Register default display adapters.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700828 synchronized (mSyncRoot) {
Santos Cordonc22c5632017-06-21 16:03:49 -0700829 // main display adapter
Mike Lockwoode63f6f72013-11-15 11:01:47 -0800830 registerDisplayAdapterLocked(new LocalDisplayAdapter(
831 mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
Santos Cordonc22c5632017-06-21 16:03:49 -0700832
833 // Standalone VR devices rely on a virtual display as their primary display for
834 // 2D UI. We register virtual display adapter along side the main display adapter
835 // here so that it is ready by the time the system sends the home Intent for
836 // early apps like SetupWizard/Launcher. In particular, SUW is displayed using
837 // the virtual display inside VR before any VR-specific apps even run.
838 mVirtualDisplayAdapter = mInjector.getVirtualDisplayAdapter(mSyncRoot, mContext,
839 mHandler, mDisplayAdapterListener);
840 if (mVirtualDisplayAdapter != null) {
841 registerDisplayAdapterLocked(mVirtualDisplayAdapter);
842 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700843 }
844 }
845
846 private void registerAdditionalDisplayAdapters() {
847 synchronized (mSyncRoot) {
848 if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700849 registerOverlayDisplayAdapterLocked();
850 registerWifiDisplayAdapterLocked();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700851 }
852 }
853 }
854
Jeff Brown89d55462012-09-19 11:33:42 -0700855 private void registerOverlayDisplayAdapterLocked() {
856 registerDisplayAdapterLocked(new OverlayDisplayAdapter(
857 mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler));
858 }
859
860 private void registerWifiDisplayAdapterLocked() {
861 if (mContext.getResources().getBoolean(
Jeff Brownbbd28a22012-09-20 16:47:15 -0700862 com.android.internal.R.bool.config_enableWifiDisplay)
863 || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) {
Jeff Brown89d55462012-09-19 11:33:42 -0700864 mWifiDisplayAdapter = new WifiDisplayAdapter(
865 mSyncRoot, mContext, mHandler, mDisplayAdapterListener,
866 mPersistentDataStore);
867 registerDisplayAdapterLocked(mWifiDisplayAdapter);
868 }
869 }
870
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700871 private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
872 // In safe mode, we disable non-essential display adapters to give the user
873 // an opportunity to fix broken settings or other problems that might affect
874 // system stability.
875 // In only-core mode, we disable non-essential display adapters to minimize
876 // the number of dependencies that are started while in this mode and to
877 // prevent problems that might occur due to the device being encrypted.
878 return !mSafeMode && !mOnlyCore;
879 }
880
881 private void registerDisplayAdapterLocked(DisplayAdapter adapter) {
882 mDisplayAdapters.add(adapter);
883 adapter.registerLocked();
884 }
885
Jeff Brownbd6e1502012-08-28 03:27:37 -0700886 private void handleDisplayDeviceAdded(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700887 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700888 handleDisplayDeviceAddedLocked(device);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700889 }
890 }
891
Jeff Browna506a6e2013-06-04 00:02:38 -0700892 private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700893 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700894 if (mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700895 Slog.w(TAG, "Attempted to add already added display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700896 return;
897 }
898
Jeff Brown10acf6d2015-04-14 14:20:47 -0700899 Slog.i(TAG, "Display device added: " + info);
900 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700901
902 mDisplayDevices.add(device);
Michael Wright1c9977b2016-07-12 13:30:10 -0700903 LogicalDisplay display = addLogicalDisplayLocked(device);
Jeff Brown0033a862014-10-08 12:06:39 -0700904 Runnable work = updateDisplayStateLocked(device);
905 if (work != null) {
906 work.run();
907 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700908 scheduleTraversalLocked(false);
909 }
910
Jeff Brownbd6e1502012-08-28 03:27:37 -0700911 private void handleDisplayDeviceChanged(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700912 synchronized (mSyncRoot) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700913 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700914 if (!mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700915 Slog.w(TAG, "Attempted to change non-existent display device: " + info);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700916 return;
917 }
918
Jeff Brown10acf6d2015-04-14 14:20:47 -0700919 int diff = device.mDebugLastLoggedDeviceInfo.diff(info);
920 if (diff == DisplayDeviceInfo.DIFF_STATE) {
921 Slog.i(TAG, "Display device changed state: \"" + info.name
922 + "\", " + Display.stateToString(info.state));
923 } else if (diff != 0) {
924 Slog.i(TAG, "Display device changed: " + info);
925 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700926 if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) {
927 try {
928 mPersistentDataStore.setColorMode(device, info.colorMode);
929 } finally {
930 mPersistentDataStore.saveIfNeeded();
931 }
932 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700933 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browne87bf032012-09-20 18:30:13 -0700934
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700935 device.applyPendingDisplayDeviceInfoChangesLocked();
936 if (updateLogicalDisplaysLocked()) {
Craig Mautner65d11b32012-10-01 13:59:52 -0700937 scheduleTraversalLocked(false);
Jeff Brown64a55af2012-08-26 02:47:39 -0700938 }
939 }
940 }
941
Jeff Brownbd6e1502012-08-28 03:27:37 -0700942 private void handleDisplayDeviceRemoved(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700943 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700944 handleDisplayDeviceRemovedLocked(device);
945 }
946 }
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700947
Jeff Browna506a6e2013-06-04 00:02:38 -0700948 private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700949 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700950 if (!mDisplayDevices.remove(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700951 Slog.w(TAG, "Attempted to remove non-existent display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700952 return;
953 }
954
Jeff Brown10acf6d2015-04-14 14:20:47 -0700955 Slog.i(TAG, "Display device removed: " + info);
956 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700957
Jeff Browna506a6e2013-06-04 00:02:38 -0700958 updateLogicalDisplaysLocked();
959 scheduleTraversalLocked(false);
960 }
961
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200962 private void handleLogicalDisplayChanged(int displayId, @NonNull LogicalDisplay display) {
963 if (displayId == Display.DEFAULT_DISPLAY) {
964 recordTopInsetLocked(display);
965 }
966 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
967 }
968
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700969 private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700970 final int count = mDisplayDevices.size();
971 for (int i = 0; i < count; i++) {
972 DisplayDevice device = mDisplayDevices.get(i);
Jeff Browne75926d2014-09-18 15:24:49 -0700973 Runnable runnable = updateDisplayStateLocked(device);
974 if (runnable != null) {
975 workQueue.add(runnable);
976 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700977 }
978 }
979
Jeff Browne75926d2014-09-18 15:24:49 -0700980 private Runnable updateDisplayStateLocked(DisplayDevice device) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700981 // Blank or unblank the display immediately to match the state requested
Jeff Brown037c33e2014-04-09 00:31:55 -0700982 // by the display power controller (if known).
Jeff Browna506a6e2013-06-04 00:02:38 -0700983 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
984 if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700985 return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700986 }
Jeff Browne75926d2014-09-18 15:24:49 -0700987 return null;
Craig Mautner4f67ba62012-08-02 11:23:00 -0700988 }
989
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700990 // Adds a new logical display based on the given display device.
991 // Sends notifications if needed.
Michael Wright1c9977b2016-07-12 13:30:10 -0700992 private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700993 DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
994 boolean isDefault = (deviceInfo.flags
995 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
996 if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
997 Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
998 isDefault = false;
999 }
1000
Jeff Brown27f1d672012-10-17 18:32:34 -07001001 if (!isDefault && mSingleDisplayDemoMode) {
1002 Slog.i(TAG, "Not creating a logical display for a secondary display "
1003 + " because single display demo mode is enabled: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -07001004 return null;
Jeff Brown27f1d672012-10-17 18:32:34 -07001005 }
1006
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001007 final int displayId = assignDisplayIdLocked(isDefault);
1008 final int layerStack = assignLayerStackLocked(displayId);
1009
Jeff Brownd728bf52012-09-08 18:05:28 -07001010 LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001011 display.updateLocked(mDisplayDevices);
1012 if (!display.isValidLocked()) {
1013 // This should never happen currently.
1014 Slog.w(TAG, "Ignoring display device because the logical display "
1015 + "created from it was not considered valid: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -07001016 return null;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001017 }
1018
Michael Wrighteedcbf12017-08-16 23:14:54 +01001019 configureColorModeLocked(display, device);
1020 if (isDefault) {
1021 recordStableDisplayStatsIfNeededLocked(display);
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001022 recordTopInsetLocked(display);
Michael Wrighteedcbf12017-08-16 23:14:54 +01001023 }
1024
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001025 mLogicalDisplays.put(displayId, display);
1026
1027 // Wake up waitForDefaultDisplay.
1028 if (isDefault) {
1029 mSyncRoot.notifyAll();
1030 }
1031
1032 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
Michael Wright1c9977b2016-07-12 13:30:10 -07001033 return display;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001034 }
1035
1036 private int assignDisplayIdLocked(boolean isDefault) {
1037 return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++;
1038 }
1039
1040 private int assignLayerStackLocked(int displayId) {
1041 // Currently layer stacks and display ids are the same.
1042 // This need not be the case.
1043 return displayId;
1044 }
1045
Michael Wrighteedcbf12017-08-16 23:14:54 +01001046 private void configureColorModeLocked(LogicalDisplay display, DisplayDevice device) {
1047 if (display.getPrimaryDisplayDeviceLocked() == device) {
1048 int colorMode = mPersistentDataStore.getColorMode(device);
1049 if (colorMode == Display.COLOR_MODE_INVALID) {
1050 if ((device.getDisplayDeviceInfoLocked().flags
1051 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
1052 colorMode = mDefaultDisplayDefaultColorMode;
1053 } else {
1054 colorMode = Display.COLOR_MODE_DEFAULT;
1055 }
1056 }
1057 display.setRequestedColorModeLocked(colorMode);
1058 }
1059 }
1060
1061 // If we've never recorded stable device stats for this device before and they aren't
1062 // explicitly configured, go ahead and record the stable device stats now based on the status
1063 // of the default display at first boot.
1064 private void recordStableDisplayStatsIfNeededLocked(LogicalDisplay d) {
1065 if (mStableDisplaySize.x <= 0 && mStableDisplaySize.y <= 0) {
1066 DisplayInfo info = d.getDisplayInfoLocked();
1067 setStableDisplaySizeLocked(info.getNaturalWidth(), info.getNaturalHeight());
1068 }
1069 }
1070
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001071 private void recordTopInsetLocked(@Nullable LogicalDisplay d) {
Winson72dbe7e2019-04-29 14:55:30 -07001072 // We must only persist the inset after boot has completed, otherwise we will end up
1073 // overwriting the persisted value before the masking flag has been loaded from the
1074 // resource overlay.
1075 if (!mSystemReady || d == null) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001076 return;
1077 }
1078 int topInset = d.getInsets().top;
1079 if (topInset == mDefaultDisplayTopInset) {
1080 return;
1081 }
1082 mDefaultDisplayTopInset = topInset;
1083 SystemProperties.set(PROP_DEFAULT_DISPLAY_TOP_INSET, Integer.toString(topInset));
1084 }
1085
Michael Wrighteedcbf12017-08-16 23:14:54 +01001086 private void setStableDisplaySizeLocked(int width, int height) {
1087 mStableDisplaySize = new Point(width, height);
1088 try {
1089 mPersistentDataStore.setStableDisplaySize(mStableDisplaySize);
1090 } finally {
1091 mPersistentDataStore.saveIfNeeded();
1092 }
1093 }
1094
Dan Gittik122df862018-03-28 16:59:22 +01001095 @VisibleForTesting
1096 Curve getMinimumBrightnessCurveInternal() {
1097 return mMinimumBrightnessCurve;
1098 }
1099
Peiyong Lin277eaff2019-01-16 16:18:22 -08001100 int getPreferredWideGamutColorSpaceIdInternal() {
1101 return mWideColorSpace.getId();
1102 }
1103
Michael Wrighteef0e132017-11-21 17:57:52 +00001104 private void setBrightnessConfigurationForUserInternal(
Dan Gittik7a32fba2018-03-28 12:19:38 +01001105 @Nullable BrightnessConfiguration c, @UserIdInt int userId,
Kenny Guy05ce8092018-01-17 13:44:20 +00001106 @Nullable String packageName) {
Dan Gittik122df862018-03-28 16:59:22 +01001107 validateBrightnessConfiguration(c);
Michael Wrighteef0e132017-11-21 17:57:52 +00001108 final int userSerial = getUserManager().getUserSerialNumber(userId);
1109 synchronized (mSyncRoot) {
1110 try {
Kenny Guy05ce8092018-01-17 13:44:20 +00001111 mPersistentDataStore.setBrightnessConfigurationForUser(c, userSerial,
1112 packageName);
Michael Wrighteef0e132017-11-21 17:57:52 +00001113 } finally {
1114 mPersistentDataStore.saveIfNeeded();
1115 }
1116 if (userId == mCurrentUserId) {
1117 mDisplayPowerController.setBrightnessConfiguration(c);
1118 }
1119 }
1120 }
1121
Dan Gittik122df862018-03-28 16:59:22 +01001122 @VisibleForTesting
1123 void validateBrightnessConfiguration(BrightnessConfiguration config) {
1124 if (config == null) {
1125 return;
1126 }
1127 if (isBrightnessConfigurationTooDark(config)) {
1128 throw new IllegalArgumentException("brightness curve is too dark");
1129 }
1130 }
1131
1132 private boolean isBrightnessConfigurationTooDark(BrightnessConfiguration config) {
1133 Pair<float[], float[]> curve = config.getCurve();
1134 float[] lux = curve.first;
1135 float[] nits = curve.second;
1136 for (int i = 0; i < lux.length; i++) {
1137 if (nits[i] < mMinimumBrightnessSpline.interpolate(lux[i])) {
1138 return true;
1139 }
1140 }
1141 return false;
1142 }
1143
Michael Wrighteef0e132017-11-21 17:57:52 +00001144 private void loadBrightnessConfiguration() {
1145 synchronized (mSyncRoot) {
1146 final int userSerial = getUserManager().getUserSerialNumber(mCurrentUserId);
1147 BrightnessConfiguration config =
1148 mPersistentDataStore.getBrightnessConfiguration(userSerial);
1149 mDisplayPowerController.setBrightnessConfiguration(config);
1150 }
1151 }
1152
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001153 // Updates all existing logical displays given the current set of display devices.
1154 // Removes invalid logical displays.
1155 // Sends notifications if needed.
1156 private boolean updateLogicalDisplaysLocked() {
1157 boolean changed = false;
1158 for (int i = mLogicalDisplays.size(); i-- > 0; ) {
1159 final int displayId = mLogicalDisplays.keyAt(i);
1160 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1161
1162 mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
1163 display.updateLocked(mDisplayDevices);
1164 if (!display.isValidLocked()) {
1165 mLogicalDisplays.removeAt(i);
1166 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
1167 changed = true;
1168 } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001169 handleLogicalDisplayChanged(displayId, display);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001170 changed = true;
1171 }
1172 }
1173 return changed;
1174 }
1175
Robert Carrae606b42018-02-15 15:36:23 -08001176 private void performTraversalLocked(SurfaceControl.Transaction t) {
Jeff Brownd728bf52012-09-08 18:05:28 -07001177 // Clear all viewports before configuring displays so that we can keep
1178 // track of which ones we have configured.
1179 clearViewportsLocked();
1180
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001181 // Configure each display device.
1182 final int count = mDisplayDevices.size();
1183 for (int i = 0; i < count; i++) {
1184 DisplayDevice device = mDisplayDevices.get(i);
Robert Carrae606b42018-02-15 15:36:23 -08001185 configureDisplayLocked(t, device);
1186 device.performTraversalLocked(t);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001187 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001188
1189 // Tell the input system about these new viewports.
Jeff Brown4ccb8232014-01-16 22:16:42 -08001190 if (mInputManagerInternal != null) {
Jeff Brownd728bf52012-09-08 18:05:28 -07001191 mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
1192 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001193 }
1194
Michael Wright3f145a22014-07-22 19:46:03 -07001195 private void setDisplayPropertiesInternal(int displayId, boolean hasContent,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001196 float requestedRefreshRate, int requestedModeId, boolean requestedMinimalPostProcessing,
1197 boolean inTraversal) {
Craig Mautner722285e2012-09-07 13:55:58 -07001198 synchronized (mSyncRoot) {
1199 LogicalDisplay display = mLogicalDisplays.get(displayId);
Michael Wright3f145a22014-07-22 19:46:03 -07001200 if (display == null) {
1201 return;
1202 }
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001203
1204 boolean shouldScheduleTraversal = false;
1205
Michael Wright3f145a22014-07-22 19:46:03 -07001206 if (display.hasContentLocked() != hasContent) {
Jeff Brown33041bd2013-08-02 21:11:14 -07001207 if (DEBUG) {
1208 Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
1209 + "hasContent=" + hasContent + ", inTraversal=" + inTraversal);
1210 }
1211
Craig Mautner722285e2012-09-07 13:55:58 -07001212 display.setHasContentLocked(hasContent);
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001213 shouldScheduleTraversal = true;
Craig Mautner722285e2012-09-07 13:55:58 -07001214 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001215 if (requestedModeId == 0 && requestedRefreshRate != 0) {
1216 // Scan supported modes returned by display.getInfo() to find a mode with the same
1217 // size as the default display mode but with the specified refresh rate instead.
1218 requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate(
1219 requestedRefreshRate);
1220 }
Michael Wrighta3dab232019-02-22 16:54:21 +00001221 mDisplayModeDirector.getAppRequestObserver().setAppRequestedMode(
1222 displayId, requestedModeId);
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001223
1224
1225 if (display.getDisplayInfoLocked().minimalPostProcessingSupported
1226 && (display.getRequestedMinimalPostProcessingLocked()
1227 != requestedMinimalPostProcessing)) {
1228
1229 display.setRequestedMinimalPostProcessingLocked(requestedMinimalPostProcessing);
1230
1231 shouldScheduleTraversal = true;
1232 }
1233
1234 if (shouldScheduleTraversal) {
1235 scheduleTraversalLocked(inTraversal);
1236 }
Craig Mautner722285e2012-09-07 13:55:58 -07001237 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001238 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001239
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08001240 private void setDisplayOffsetsInternal(int displayId, int x, int y) {
1241 synchronized (mSyncRoot) {
1242 LogicalDisplay display = mLogicalDisplays.get(displayId);
1243 if (display == null) {
1244 return;
1245 }
1246 if (display.getDisplayOffsetXLocked() != x
1247 || display.getDisplayOffsetYLocked() != y) {
1248 if (DEBUG) {
1249 Slog.d(TAG, "Display " + displayId + " burn-in offset set to ("
1250 + x + ", " + y + ")");
1251 }
1252 display.setDisplayOffsetsLocked(x, y);
1253 scheduleTraversalLocked(false);
1254 }
1255 }
1256 }
1257
Sam Lin4c3ac2b2019-02-18 04:50:26 -08001258 private void setDisplayScalingDisabledInternal(int displayId, boolean disable) {
1259 synchronized (mSyncRoot) {
1260 final LogicalDisplay display = mLogicalDisplays.get(displayId);
1261 if (display == null) {
1262 return;
1263 }
1264 if (display.isDisplayScalingDisabled() != disable) {
1265 if (DEBUG) {
1266 Slog.d(TAG, "Display " + displayId + " content scaling disabled = " + disable);
1267 }
1268 display.setDisplayScalingDisabledLocked(disable);
1269 scheduleTraversalLocked(false);
1270 }
1271 }
1272 }
1273
Andrii Kulianfb1bf692017-01-17 11:17:34 -08001274 // Updates the lists of UIDs that are present on displays.
1275 private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) {
1276 synchronized (mSyncRoot) {
1277 mDisplayAccessUIDs.clear();
1278 for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) {
1279 mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i),
1280 newDisplayAccessUIDs.valueAt(i));
1281 }
1282 }
1283 }
1284
1285 // Checks if provided UID's content is present on the display and UID has access to it.
1286 private boolean isUidPresentOnDisplayInternal(int uid, int displayId) {
1287 synchronized (mSyncRoot) {
1288 final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId);
1289 return displayUIDs != null && displayUIDs.indexOf(uid) != -1;
1290 }
1291 }
1292
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001293 @Nullable
1294 private IBinder getDisplayToken(int displayId) {
1295 synchronized (mSyncRoot) {
1296 final LogicalDisplay display = mLogicalDisplays.get(displayId);
1297 if (display != null) {
1298 final DisplayDevice device = display.getPrimaryDisplayDeviceLocked();
1299 if (device != null) {
1300 return device.getDisplayTokenLocked();
1301 }
1302 }
1303 }
1304
1305 return null;
1306 }
1307
Robert Carr66b5664f2019-04-02 14:18:56 -07001308 private SurfaceControl.ScreenshotGraphicBuffer screenshotInternal(int displayId) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001309 final IBinder token = getDisplayToken(displayId);
1310 if (token == null) {
Robert Carr66b5664f2019-04-02 14:18:56 -07001311 return null;
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001312 }
Robert Carr66b5664f2019-04-02 14:18:56 -07001313 return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(
Peiyong Line3e5efd2019-03-21 20:59:47 +00001314 token, new Rect(), 0 /* width */, 0 /* height */,
1315 false /* useIdentityTransform */, 0 /* rotation */);
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001316 }
1317
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001318 @VisibleForTesting
1319 DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributesInternal(
1320 int displayId) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001321 final IBinder token = getDisplayToken(displayId);
1322 if (token == null) {
1323 return null;
1324 }
1325 return SurfaceControl.getDisplayedContentSamplingAttributes(token);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001326 }
1327
1328 @VisibleForTesting
1329 boolean setDisplayedContentSamplingEnabledInternal(
1330 int displayId, boolean enable, int componentMask, int maxFrames) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001331 final IBinder token = getDisplayToken(displayId);
1332 if (token == null) {
1333 return false;
1334 }
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001335 return SurfaceControl.setDisplayedContentSamplingEnabled(
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001336 token, enable, componentMask, maxFrames);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001337 }
1338
1339 @VisibleForTesting
1340 DisplayedContentSample getDisplayedContentSampleInternal(int displayId,
1341 long maxFrames, long timestamp) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001342 final IBinder token = getDisplayToken(displayId);
1343 if (token == null) {
1344 return null;
1345 }
1346 return SurfaceControl.getDisplayedContentSample(token, maxFrames, timestamp);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001347 }
1348
Ana Kruleca74a8642019-11-14 00:51:00 +01001349 private void onDesiredDisplayModeSpecsChangedInternal() {
Michael Wrighta3dab232019-02-22 16:54:21 +00001350 boolean changed = false;
1351 synchronized (mSyncRoot) {
1352 final int count = mLogicalDisplays.size();
1353 for (int i = 0; i < count; i++) {
1354 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1355 int displayId = mLogicalDisplays.keyAt(i);
Ana Kruleca74a8642019-11-14 00:51:00 +01001356 DisplayModeDirector.DesiredDisplayModeSpecs desiredDisplayModeSpecs =
1357 mDisplayModeDirector.getDesiredDisplayModeSpecs(displayId);
1358 DisplayModeDirector.DesiredDisplayModeSpecs existingDesiredDisplayModeSpecs =
1359 display.getDesiredDisplayModeSpecsLocked();
1360 if (DEBUG) {
1361 Slog.i(TAG,
1362 "Comparing display specs: " + desiredDisplayModeSpecs
1363 + ", existing: " + existingDesiredDisplayModeSpecs);
1364 }
1365 if (!desiredDisplayModeSpecs.equals(existingDesiredDisplayModeSpecs)) {
1366 display.setDesiredDisplayModeSpecsLocked(desiredDisplayModeSpecs);
Michael Wrighta3dab232019-02-22 16:54:21 +00001367 changed = true;
1368 }
1369 }
1370 if (changed) {
1371 scheduleTraversalLocked(false);
1372 }
1373 }
1374 }
1375
Jeff Brownd728bf52012-09-08 18:05:28 -07001376 private void clearViewportsLocked() {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001377 mViewports.clear();
Craig Mautner722285e2012-09-07 13:55:58 -07001378 }
1379
Robert Carrae606b42018-02-15 15:36:23 -08001380 private void configureDisplayLocked(SurfaceControl.Transaction t, DisplayDevice device) {
Jeff Brownd14c8c92014-01-07 18:13:09 -08001381 final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
1382 final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;
Jeff Browna506a6e2013-06-04 00:02:38 -07001383
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001384 // Find the logical display that the display device is showing.
Jeff Brownd14c8c92014-01-07 18:13:09 -08001385 // Certain displays only ever show their own content.
Craig Mautner722285e2012-09-07 13:55:58 -07001386 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
Jeff Brownd14c8c92014-01-07 18:13:09 -08001387 if (!ownContent) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001388 if (display != null && !display.hasContentLocked()) {
1389 // If the display does not have any content of its own, then
1390 // automatically mirror the default logical display contents.
1391 display = null;
1392 }
1393 if (display == null) {
1394 display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY);
1395 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001396 }
1397
1398 // Apply the logical display configuration to the display device.
1399 if (display == null) {
1400 // TODO: no logical display for the device, blank it
Jeff Brownd728bf52012-09-08 18:05:28 -07001401 Slog.w(TAG, "Missing logical display to use for physical display device: "
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001402 + device.getDisplayDeviceInfoLocked());
Jeff Brownd728bf52012-09-08 18:05:28 -07001403 return;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001404 }
Robert Carrae606b42018-02-15 15:36:23 -08001405 display.configureDisplayLocked(t, device, info.state == Display.STATE_OFF);
Arthur Hung41e81e72018-10-31 18:04:56 +08001406 final int viewportType;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001407 // Update the corresponding viewport.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001408 if ((info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
Arthur Hung41e81e72018-10-31 18:04:56 +08001409 viewportType = VIEWPORT_INTERNAL;
1410 } else if (info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
1411 viewportType = VIEWPORT_EXTERNAL;
1412 } else if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL
1413 && !TextUtils.isEmpty(info.uniqueId)) {
1414 viewportType = VIEWPORT_VIRTUAL;
1415 } else {
Arthur Hung46c4e582019-02-12 15:55:28 +08001416 Slog.i(TAG, "Display " + info + " does not support input device matching.");
Arthur Hung41e81e72018-10-31 18:04:56 +08001417 return;
Jeff Brownd728bf52012-09-08 18:05:28 -07001418 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001419
Arthur Hung41e81e72018-10-31 18:04:56 +08001420 populateViewportLocked(viewportType, display.getDisplayIdLocked(), device, info.uniqueId);
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001421 }
1422
1423 /**
1424 * Get internal or external viewport. Create it if does not currently exist.
1425 * @param viewportType - either INTERNAL or EXTERNAL
1426 * @return the viewport with the requested type
1427 */
Arthur Hung41e81e72018-10-31 18:04:56 +08001428 private DisplayViewport getViewportLocked(int viewportType, String uniqueId) {
1429 if (viewportType != VIEWPORT_INTERNAL && viewportType != VIEWPORT_EXTERNAL
1430 && viewportType != VIEWPORT_VIRTUAL) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001431 Slog.wtf(TAG, "Cannot call getViewportByTypeLocked for type "
1432 + DisplayViewport.typeToString(viewportType));
1433 return null;
1434 }
Arthur Hung41e81e72018-10-31 18:04:56 +08001435
1436 // Only allow a single INTERNAL or EXTERNAL viewport by forcing their uniqueIds
1437 // to be identical (in particular, empty).
1438 // TODO (b/116824030) allow multiple EXTERNAL viewports and remove this function.
1439 if (viewportType != VIEWPORT_VIRTUAL) {
1440 uniqueId = "";
1441 }
1442
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001443 DisplayViewport viewport;
1444 final int count = mViewports.size();
1445 for (int i = 0; i < count; i++) {
1446 viewport = mViewports.get(i);
Arthur Hung41e81e72018-10-31 18:04:56 +08001447 if (viewport.type == viewportType && uniqueId.equals(viewport.uniqueId)) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001448 return viewport;
1449 }
1450 }
1451
Arthur Hung41e81e72018-10-31 18:04:56 +08001452 // Creates the viewport if none exists.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001453 viewport = new DisplayViewport();
1454 viewport.type = viewportType;
Arthur Hung41e81e72018-10-31 18:04:56 +08001455 viewport.uniqueId = uniqueId;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001456 mViewports.add(viewport);
1457 return viewport;
1458 }
1459
Arthur Hung41e81e72018-10-31 18:04:56 +08001460 private void populateViewportLocked(int viewportType,
1461 int displayId, DisplayDevice device, String uniqueId) {
1462 final DisplayViewport viewport = getViewportLocked(viewportType, uniqueId);
Jeff Brownd728bf52012-09-08 18:05:28 -07001463 device.populateViewportLocked(viewport);
Arthur Hung41e81e72018-10-31 18:04:56 +08001464 viewport.valid = true;
1465 viewport.displayId = displayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001466 }
1467
1468 private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {
1469 final int count = mLogicalDisplays.size();
1470 for (int i = 0; i < count; i++) {
1471 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1472 if (display.getPrimaryDisplayDeviceLocked() == device) {
1473 return display;
1474 }
1475 }
1476 return null;
1477 }
1478
Jeff Brownbd6e1502012-08-28 03:27:37 -07001479 private void sendDisplayEventLocked(int displayId, int event) {
1480 Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
1481 mHandler.sendMessage(msg);
1482 }
1483
Robert Carrae606b42018-02-15 15:36:23 -08001484 // Requests that performTraversals be called at a
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001485 // later time to apply changes to surfaces and displays.
Craig Mautner65d11b32012-10-01 13:59:52 -07001486 private void scheduleTraversalLocked(boolean inTraversal) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001487 if (!mPendingTraversal && mWindowManagerInternal != null) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001488 mPendingTraversal = true;
Craig Mautner65d11b32012-10-01 13:59:52 -07001489 if (!inTraversal) {
1490 mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL);
1491 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001492 }
1493 }
1494
1495 // Runs on Handler thread.
1496 // Delivers display event notifications to callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001497 private void deliverDisplayEvent(int displayId, int event) {
1498 if (DEBUG) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001499 Slog.d(TAG, "Delivering display event: displayId="
1500 + displayId + ", event=" + event);
Jeff Brownfa25bf52012-07-23 19:26:30 -07001501 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001502
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001503 // Grab the lock and copy the callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001504 final int count;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001505 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001506 count = mCallbacks.size();
1507 mTempCallbacks.clear();
1508 for (int i = 0; i < count; i++) {
1509 mTempCallbacks.add(mCallbacks.valueAt(i));
Craig Mautner4f67ba62012-08-02 11:23:00 -07001510 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001511 }
Craig Mautner4f67ba62012-08-02 11:23:00 -07001512
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001513 // After releasing the lock, send the notifications out.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001514 for (int i = 0; i < count; i++) {
1515 mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event);
1516 }
1517 mTempCallbacks.clear();
Craig Mautner4f67ba62012-08-02 11:23:00 -07001518 }
1519
Michael Wrightc39d47a2014-07-08 18:07:36 -07001520 private IMediaProjectionManager getProjectionService() {
1521 if (mProjectionService == null) {
1522 IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE);
1523 mProjectionService = IMediaProjectionManager.Stub.asInterface(b);
1524 }
1525 return mProjectionService;
1526 }
1527
Michael Wrighteef0e132017-11-21 17:57:52 +00001528 private UserManager getUserManager() {
1529 return mContext.getSystemService(UserManager.class);
1530 }
1531
Jeff Brown4ccb8232014-01-16 22:16:42 -08001532 private void dumpInternal(PrintWriter pw) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001533 pw.println("DISPLAY MANAGER (dumpsys display)");
Jeff Brownfa25bf52012-07-23 19:26:30 -07001534
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001535 synchronized (mSyncRoot) {
Jeff Brown9e316a12012-10-08 19:17:06 -07001536 pw.println(" mOnlyCode=" + mOnlyCore);
1537 pw.println(" mSafeMode=" + mSafeMode);
1538 pw.println(" mPendingTraversal=" + mPendingTraversal);
Jeff Brown037c33e2014-04-09 00:31:55 -07001539 pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState));
Jeff Brown9e316a12012-10-08 19:17:06 -07001540 pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId);
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001541 pw.println(" mViewports=" + mViewports);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -07001542 pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode);
Jeff Brown27f1d672012-10-17 18:32:34 -07001543 pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
Jeff Brownce468a32013-11-21 16:42:03 -08001544 pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount);
Michael Wrighteedcbf12017-08-16 23:14:54 +01001545 pw.println(" mStableDisplaySize=" + mStableDisplaySize);
Kenny Guy2047db92019-02-21 13:04:05 +00001546 pw.println(" mMinimumBrightnessCurve=" + mMinimumBrightnessCurve);
Jeff Brown9e316a12012-10-08 19:17:06 -07001547
Jeff Brownbd6e1502012-08-28 03:27:37 -07001548 IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001549 ipw.increaseIndent();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001550
1551 pw.println();
1552 pw.println("Display Adapters: size=" + mDisplayAdapters.size());
Jeff Brown848c2dc2012-08-19 20:18:08 -07001553 for (DisplayAdapter adapter : mDisplayAdapters) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001554 pw.println(" " + adapter.getName());
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001555 adapter.dumpLocked(ipw);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001556 }
Craig Mautner9de49362012-08-02 14:30:30 -07001557
Jeff Brownbd6e1502012-08-28 03:27:37 -07001558 pw.println();
1559 pw.println("Display Devices: size=" + mDisplayDevices.size());
1560 for (DisplayDevice device : mDisplayDevices) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001561 pw.println(" " + device.getDisplayDeviceInfoLocked());
1562 device.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001563 }
1564
1565 final int logicalDisplayCount = mLogicalDisplays.size();
1566 pw.println();
1567 pw.println("Logical Displays: size=" + logicalDisplayCount);
1568 for (int i = 0; i < logicalDisplayCount; i++) {
1569 int displayId = mLogicalDisplays.keyAt(i);
1570 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1571 pw.println(" Display " + displayId + ":");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001572 display.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001573 }
Jeff Brownce468a32013-11-21 16:42:03 -08001574
Michael Wrighta3dab232019-02-22 16:54:21 +00001575 pw.println();
1576 mDisplayModeDirector.dump(pw);
1577
Jeff Brownce468a32013-11-21 16:42:03 -08001578 final int callbackCount = mCallbacks.size();
1579 pw.println();
1580 pw.println("Callbacks: size=" + callbackCount);
1581 for (int i = 0; i < callbackCount; i++) {
1582 CallbackRecord callback = mCallbacks.valueAt(i);
1583 pw.println(" " + i + ": mPid=" + callback.mPid
1584 + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
1585 }
Jeff Brownad9ef192014-04-08 17:26:30 -07001586
1587 if (mDisplayPowerController != null) {
1588 mDisplayPowerController.dump(pw);
1589 }
Michael Wright1c9977b2016-07-12 13:30:10 -07001590
1591 pw.println();
1592 mPersistentDataStore.dump(pw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001593 }
1594 }
1595
Dan Gittik122df862018-03-28 16:59:22 +01001596 private static float[] getFloatArray(TypedArray array) {
1597 int length = array.length();
1598 float[] floatArray = new float[length];
1599 for (int i = 0; i < length; i++) {
1600 floatArray[i] = array.getFloat(i, Float.NaN);
1601 }
1602 array.recycle();
1603 return floatArray;
1604 }
1605
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001606 /**
1607 * This is the object that everything in the display manager locks on.
1608 * We make it an inner class within the {@link DisplayManagerService} to so that it is
1609 * clear that the object belongs to the display manager service and that it is
1610 * a unique object with a special purpose.
1611 */
1612 public static final class SyncRoot {
1613 }
1614
Santos Cordonee8931e2017-04-05 10:31:15 -07001615 @VisibleForTesting
1616 static class Injector {
1617 VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context,
1618 Handler handler, DisplayAdapter.Listener displayAdapterListener) {
1619 return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener);
1620 }
Santos Cordonc22c5632017-06-21 16:03:49 -07001621
1622 long getDefaultDisplayDelayTimeout() {
1623 return WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
1624 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001625 }
1626
Alex Sakhartchouk879d24f2017-06-20 22:01:19 -04001627 @VisibleForTesting
1628 DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) {
1629 synchronized (mSyncRoot) {
1630 LogicalDisplay display = mLogicalDisplays.get(displayId);
1631 if (display != null) {
1632 DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked();
1633 return displayDevice.getDisplayDeviceInfoLocked();
1634 }
1635 return null;
1636 }
1637 }
1638
Jeff Brownbd6e1502012-08-28 03:27:37 -07001639 private final class DisplayManagerHandler extends Handler {
1640 public DisplayManagerHandler(Looper looper) {
1641 super(looper, null, true /*async*/);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001642 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001643
Jeff Brownbd6e1502012-08-28 03:27:37 -07001644 @Override
1645 public void handleMessage(Message msg) {
1646 switch (msg.what) {
Santos Cordonc22c5632017-06-21 16:03:49 -07001647 case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS:
1648 registerDefaultDisplayAdapters();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001649 break;
1650
1651 case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS:
1652 registerAdditionalDisplayAdapters();
1653 break;
1654
1655 case MSG_DELIVER_DISPLAY_EVENT:
1656 deliverDisplayEvent(msg.arg1, msg.arg2);
1657 break;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001658
1659 case MSG_REQUEST_TRAVERSAL:
Jeff Brown4ccb8232014-01-16 22:16:42 -08001660 mWindowManagerInternal.requestTraversalFromDisplayManager();
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001661 break;
Jeff Brownd728bf52012-09-08 18:05:28 -07001662
1663 case MSG_UPDATE_VIEWPORT: {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001664 final boolean changed;
Jeff Brownd728bf52012-09-08 18:05:28 -07001665 synchronized (mSyncRoot) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001666 changed = !mTempViewports.equals(mViewports);
1667 if (changed) {
1668 mTempViewports.clear();
1669 for (DisplayViewport d : mViewports) {
1670 mTempViewports.add(d.makeCopy());
1671 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001672 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001673 }
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001674 if (changed) {
1675 mInputManagerInternal.setDisplayViewports(mTempViewports);
1676 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001677 break;
1678 }
Kenny Guy22bd0442017-10-26 00:15:54 +01001679
Michael Wrighteef0e132017-11-21 17:57:52 +00001680 case MSG_LOAD_BRIGHTNESS_CONFIGURATION:
1681 loadBrightnessConfiguration();
1682 break;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001683 }
1684 }
1685 }
1686
1687 private final class DisplayAdapterListener implements DisplayAdapter.Listener {
1688 @Override
1689 public void onDisplayDeviceEvent(DisplayDevice device, int event) {
1690 switch (event) {
1691 case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED:
1692 handleDisplayDeviceAdded(device);
1693 break;
1694
1695 case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED:
1696 handleDisplayDeviceChanged(device);
1697 break;
1698
1699 case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED:
1700 handleDisplayDeviceRemoved(device);
1701 break;
1702 }
1703 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001704
1705 @Override
1706 public void onTraversalRequested() {
1707 synchronized (mSyncRoot) {
Craig Mautner65d11b32012-10-01 13:59:52 -07001708 scheduleTraversalLocked(false);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001709 }
1710 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001711 }
1712
1713 private final class CallbackRecord implements DeathRecipient {
Jeff Brownce468a32013-11-21 16:42:03 -08001714 public final int mPid;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001715 private final IDisplayManagerCallback mCallback;
1716
Jeff Brownce468a32013-11-21 16:42:03 -08001717 public boolean mWifiDisplayScanRequested;
1718
Jeff Brownbd6e1502012-08-28 03:27:37 -07001719 public CallbackRecord(int pid, IDisplayManagerCallback callback) {
1720 mPid = pid;
1721 mCallback = callback;
1722 }
1723
1724 @Override
1725 public void binderDied() {
1726 if (DEBUG) {
1727 Slog.d(TAG, "Display listener for pid " + mPid + " died.");
1728 }
Jeff Brownce468a32013-11-21 16:42:03 -08001729 onCallbackDied(this);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001730 }
1731
1732 public void notifyDisplayEventAsync(int displayId, int event) {
1733 try {
1734 mCallback.onDisplayEvent(displayId, event);
1735 } catch (RemoteException ex) {
1736 Slog.w(TAG, "Failed to notify process "
1737 + mPid + " that displays changed, assuming it died.", ex);
1738 binderDied();
1739 }
1740 }
1741 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001742
Santos Cordonee8931e2017-04-05 10:31:15 -07001743 @VisibleForTesting
1744 final class BinderService extends IDisplayManager.Stub {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001745 /**
1746 * Returns information about the specified logical display.
1747 *
1748 * @param displayId The logical display id.
lumarkec75b422019-01-07 15:58:38 +08001749 * @return The logical display info, return {@code null} if the display does not exist or
1750 * the calling UID isn't present on the display. The returned object must be treated as
1751 * immutable.
Jeff Brown4ccb8232014-01-16 22:16:42 -08001752 */
1753 @Override // Binder call
1754 public DisplayInfo getDisplayInfo(int displayId) {
1755 final int callingUid = Binder.getCallingUid();
1756 final long token = Binder.clearCallingIdentity();
1757 try {
1758 return getDisplayInfoInternal(displayId, callingUid);
1759 } finally {
1760 Binder.restoreCallingIdentity(token);
1761 }
1762 }
1763
1764 /**
1765 * Returns the list of all display ids.
1766 */
1767 @Override // Binder call
1768 public int[] getDisplayIds() {
1769 final int callingUid = Binder.getCallingUid();
1770 final long token = Binder.clearCallingIdentity();
1771 try {
1772 return getDisplayIdsInternal(callingUid);
1773 } finally {
1774 Binder.restoreCallingIdentity(token);
1775 }
1776 }
1777
lumarkec75b422019-01-07 15:58:38 +08001778 @Override // Binder call
1779 public boolean isUidPresentOnDisplay(int uid, int displayId) {
1780 final long token = Binder.clearCallingIdentity();
1781 try {
1782 return isUidPresentOnDisplayInternal(uid, displayId);
1783 } finally {
1784 Binder.restoreCallingIdentity(token);
1785 }
1786 }
1787
Michael Wrighteedcbf12017-08-16 23:14:54 +01001788 /**
1789 * Returns the stable device display size, in pixels.
1790 */
1791 @Override // Binder call
1792 public Point getStableDisplaySize() {
1793 final long token = Binder.clearCallingIdentity();
1794 try {
1795 return getStableDisplaySizeInternal();
1796 } finally {
1797 Binder.restoreCallingIdentity(token);
1798 }
1799 }
1800
Jeff Brown4ccb8232014-01-16 22:16:42 -08001801 @Override // Binder call
1802 public void registerCallback(IDisplayManagerCallback callback) {
1803 if (callback == null) {
1804 throw new IllegalArgumentException("listener must not be null");
1805 }
1806
1807 final int callingPid = Binder.getCallingPid();
1808 final long token = Binder.clearCallingIdentity();
1809 try {
1810 registerCallbackInternal(callback, callingPid);
1811 } finally {
1812 Binder.restoreCallingIdentity(token);
1813 }
1814 }
1815
1816 @Override // Binder call
1817 public void startWifiDisplayScan() {
1818 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1819 "Permission required to start wifi display scans");
1820
1821 final int callingPid = Binder.getCallingPid();
1822 final long token = Binder.clearCallingIdentity();
1823 try {
1824 startWifiDisplayScanInternal(callingPid);
1825 } finally {
1826 Binder.restoreCallingIdentity(token);
1827 }
1828 }
1829
1830 @Override // Binder call
1831 public void stopWifiDisplayScan() {
1832 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1833 "Permission required to stop wifi display scans");
1834
1835 final int callingPid = Binder.getCallingPid();
1836 final long token = Binder.clearCallingIdentity();
1837 try {
1838 stopWifiDisplayScanInternal(callingPid);
1839 } finally {
1840 Binder.restoreCallingIdentity(token);
1841 }
1842 }
1843
1844 @Override // Binder call
1845 public void connectWifiDisplay(String address) {
1846 if (address == null) {
1847 throw new IllegalArgumentException("address must not be null");
1848 }
1849 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1850 "Permission required to connect to a wifi display");
1851
1852 final long token = Binder.clearCallingIdentity();
1853 try {
1854 connectWifiDisplayInternal(address);
1855 } finally {
1856 Binder.restoreCallingIdentity(token);
1857 }
1858 }
1859
1860 @Override // Binder call
1861 public void disconnectWifiDisplay() {
1862 // This request does not require special permissions.
1863 // Any app can request disconnection from the currently active wifi display.
1864 // This exception should no longer be needed once wifi display control moves
1865 // to the media router service.
1866
1867 final long token = Binder.clearCallingIdentity();
1868 try {
1869 disconnectWifiDisplayInternal();
1870 } finally {
1871 Binder.restoreCallingIdentity(token);
1872 }
1873 }
1874
1875 @Override // Binder call
1876 public void renameWifiDisplay(String address, String alias) {
1877 if (address == null) {
1878 throw new IllegalArgumentException("address must not be null");
1879 }
1880 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1881 "Permission required to rename to a wifi display");
1882
1883 final long token = Binder.clearCallingIdentity();
1884 try {
1885 renameWifiDisplayInternal(address, alias);
1886 } finally {
1887 Binder.restoreCallingIdentity(token);
1888 }
1889 }
1890
1891 @Override // Binder call
1892 public void forgetWifiDisplay(String address) {
1893 if (address == null) {
1894 throw new IllegalArgumentException("address must not be null");
1895 }
1896 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1897 "Permission required to forget to a wifi display");
1898
1899 final long token = Binder.clearCallingIdentity();
1900 try {
1901 forgetWifiDisplayInternal(address);
1902 } finally {
1903 Binder.restoreCallingIdentity(token);
1904 }
1905 }
1906
1907 @Override // Binder call
1908 public void pauseWifiDisplay() {
1909 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1910 "Permission required to pause a wifi display session");
1911
1912 final long token = Binder.clearCallingIdentity();
1913 try {
1914 pauseWifiDisplayInternal();
1915 } finally {
1916 Binder.restoreCallingIdentity(token);
1917 }
1918 }
1919
1920 @Override // Binder call
1921 public void resumeWifiDisplay() {
1922 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1923 "Permission required to resume a wifi display session");
1924
1925 final long token = Binder.clearCallingIdentity();
1926 try {
1927 resumeWifiDisplayInternal();
1928 } finally {
1929 Binder.restoreCallingIdentity(token);
1930 }
1931 }
1932
1933 @Override // Binder call
1934 public WifiDisplayStatus getWifiDisplayStatus() {
1935 // This request does not require special permissions.
1936 // Any app can get information about available wifi displays.
1937
1938 final long token = Binder.clearCallingIdentity();
1939 try {
1940 return getWifiDisplayStatusInternal();
1941 } finally {
1942 Binder.restoreCallingIdentity(token);
1943 }
1944 }
1945
1946 @Override // Binder call
Michael Wright1c9977b2016-07-12 13:30:10 -07001947 public void requestColorMode(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +01001948 mContext.enforceCallingOrSelfPermission(
Michael Wright1c9977b2016-07-12 13:30:10 -07001949 Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE,
1950 "Permission required to change the display color mode");
Michael Wright58e829f2015-09-15 00:13:26 +01001951 final long token = Binder.clearCallingIdentity();
1952 try {
Michael Wright1c9977b2016-07-12 13:30:10 -07001953 requestColorModeInternal(displayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +01001954 } finally {
1955 Binder.restoreCallingIdentity(token);
1956 }
1957 }
1958
1959 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001960 public int createVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001961 IMediaProjection projection, String packageName, String name,
Santos Cordonee8931e2017-04-05 10:31:15 -07001962 int width, int height, int densityDpi, Surface surface, int flags,
1963 String uniqueId) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001964 final int callingUid = Binder.getCallingUid();
1965 if (!validatePackageName(callingUid, packageName)) {
1966 throw new SecurityException("packageName must match the calling uid");
1967 }
Michael Wright75ee9fc2014-09-01 19:55:22 -07001968 if (callback == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001969 throw new IllegalArgumentException("appToken must not be null");
1970 }
1971 if (TextUtils.isEmpty(name)) {
1972 throw new IllegalArgumentException("name must be non-null and non-empty");
1973 }
1974 if (width <= 0 || height <= 0 || densityDpi <= 0) {
1975 throw new IllegalArgumentException("width, height, and densityDpi must be "
1976 + "greater than 0");
1977 }
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07001978 if (surface != null && surface.isSingleBuffered()) {
Pablo Ceballosaff2f942016-07-29 14:49:55 -07001979 throw new IllegalArgumentException("Surface can't be single-buffered");
1980 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07001981
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001982 if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
1983 flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
1984
1985 // Public displays can't be allowed to show content when locked.
Andrii Kulian7211d2e2017-01-27 15:58:05 -08001986 if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001987 throw new IllegalArgumentException(
1988 "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE");
1989 }
Michael Wright6720be42014-07-29 19:14:16 -07001990 }
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08001991 if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) {
1992 flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
Michael Wright6720be42014-07-29 19:14:16 -07001993 }
1994
Michael Wrightc39d47a2014-07-08 18:07:36 -07001995 if (projection != null) {
1996 try {
1997 if (!getProjectionService().isValidMediaProjection(projection)) {
1998 throw new SecurityException("Invalid media projection");
1999 }
Michael Wright6720be42014-07-29 19:14:16 -07002000 flags = projection.applyVirtualDisplayFlags(flags);
Michael Wrightc39d47a2014-07-08 18:07:36 -07002001 } catch (RemoteException e) {
Michael Wright6720be42014-07-29 19:14:16 -07002002 throw new SecurityException("unable to validate media projection or flags");
Michael Wrightc39d47a2014-07-08 18:07:36 -07002003 }
2004 }
2005
Michael Wright6720be42014-07-29 19:14:16 -07002006 if (callingUid != Process.SYSTEM_UID &&
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002007 (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002008 if (!canProjectVideo(projection)) {
2009 throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
2010 + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate "
2011 + "MediaProjection token in order to create a screen sharing virtual "
2012 + "display.");
2013 }
2014 }
Santos Cordonb6992f22018-01-30 14:51:20 -08002015 if (callingUid != Process.SYSTEM_UID && (flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002016 if (!canProjectSecureVideo(projection)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002017 throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT "
Michael Wrightc39d47a2014-07-08 18:07:36 -07002018 + "or an appropriate MediaProjection token to create a "
2019 + "secure virtual display.");
Jeff Brown4ccb8232014-01-16 22:16:42 -08002020 }
2021 }
2022
Chilun67a379b2019-04-11 19:49:42 +08002023 // Sometimes users can have sensitive information in system decoration windows. An app
2024 // could create a virtual display with system decorations support and read the user info
2025 // from the surface.
2026 // We should only allow adding flag VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
2027 // to virtual displays that are owned by the system.
2028 if (callingUid != Process.SYSTEM_UID
2029 && (flags & VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0) {
2030 if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "createVirtualDisplay()")) {
2031 throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
2032 }
2033 }
2034
Jeff Brown4ccb8232014-01-16 22:16:42 -08002035 final long token = Binder.clearCallingIdentity();
2036 try {
Santos Cordonee8931e2017-04-05 10:31:15 -07002037 return createVirtualDisplayInternal(callback, projection, callingUid, packageName,
2038 name, width, height, densityDpi, surface, flags, uniqueId);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002039 } finally {
2040 Binder.restoreCallingIdentity(token);
2041 }
2042 }
2043
2044 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002045 public void resizeVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wright01e840f2014-06-26 16:03:25 -07002046 int width, int height, int densityDpi) {
Jeff Chang01baf6c2019-08-20 16:21:25 +08002047 if (width <= 0 || height <= 0 || densityDpi <= 0) {
2048 throw new IllegalArgumentException("width, height, and densityDpi must be "
2049 + "greater than 0");
2050 }
Michael Wright01e840f2014-06-26 16:03:25 -07002051 final long token = Binder.clearCallingIdentity();
2052 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002053 resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi);
Michael Wright01e840f2014-06-26 16:03:25 -07002054 } finally {
2055 Binder.restoreCallingIdentity(token);
2056 }
2057 }
2058
2059 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002060 public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) {
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07002061 if (surface != null && surface.isSingleBuffered()) {
2062 throw new IllegalArgumentException("Surface can't be single-buffered");
2063 }
Jeff Brown92207df2014-04-16 13:16:07 -07002064 final long token = Binder.clearCallingIdentity();
2065 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002066 setVirtualDisplaySurfaceInternal(callback.asBinder(), surface);
Jeff Brown92207df2014-04-16 13:16:07 -07002067 } finally {
2068 Binder.restoreCallingIdentity(token);
2069 }
2070 }
2071
2072 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002073 public void releaseVirtualDisplay(IVirtualDisplayCallback callback) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002074 final long token = Binder.clearCallingIdentity();
2075 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002076 releaseVirtualDisplayInternal(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -08002077 } finally {
2078 Binder.restoreCallingIdentity(token);
2079 }
2080 }
2081
2082 @Override // Binder call
chaviwda4c6942018-11-07 15:52:56 -08002083 public void setVirtualDisplayState(IVirtualDisplayCallback callback, boolean isOn) {
2084 final long token = Binder.clearCallingIdentity();
2085 try {
2086 setVirtualDisplayStateInternal(callback.asBinder(), isOn);
2087 } finally {
2088 Binder.restoreCallingIdentity(token);
2089 }
2090 }
2091
2092 @Override // Binder call
Jeff Brown4ccb8232014-01-16 22:16:42 -08002093 public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06002094 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jeff Brown4ccb8232014-01-16 22:16:42 -08002095
2096 final long token = Binder.clearCallingIdentity();
2097 try {
2098 dumpInternal(pw);
2099 } finally {
2100 Binder.restoreCallingIdentity(token);
2101 }
2102 }
2103
Kenny Guy22bd0442017-10-26 00:15:54 +01002104 @Override // Binder call
Kenny Guy29aa30e2017-11-30 13:43:46 +00002105 public ParceledListSlice<BrightnessChangeEvent> getBrightnessEvents(String callingPackage) {
Kenny Guy22bd0442017-10-26 00:15:54 +01002106 mContext.enforceCallingOrSelfPermission(
2107 Manifest.permission.BRIGHTNESS_SLIDER_USAGE,
2108 "Permission to read brightness events.");
Kenny Guy29aa30e2017-11-30 13:43:46 +00002109
2110 final int callingUid = Binder.getCallingUid();
2111 AppOpsManager appOpsManager = mContext.getSystemService(AppOpsManager.class);
Jeff Sharkeyd9311192018-04-16 16:50:34 +00002112 final int mode = appOpsManager.noteOp(AppOpsManager.OP_GET_USAGE_STATS,
Kenny Guy29aa30e2017-11-30 13:43:46 +00002113 callingUid, callingPackage);
2114 final boolean hasUsageStats;
2115 if (mode == AppOpsManager.MODE_DEFAULT) {
2116 // The default behavior here is to check if PackageManager has given the app
2117 // permission.
2118 hasUsageStats = mContext.checkCallingPermission(
2119 Manifest.permission.PACKAGE_USAGE_STATS)
2120 == PackageManager.PERMISSION_GRANTED;
2121 } else {
2122 hasUsageStats = mode == AppOpsManager.MODE_ALLOWED;
2123 }
2124
2125 final int userId = UserHandle.getUserId(callingUid);
Kenny Guy22bd0442017-10-26 00:15:54 +01002126 final long token = Binder.clearCallingIdentity();
2127 try {
Michael Wright144aac92017-12-21 18:37:41 +00002128 synchronized (mSyncRoot) {
2129 return mDisplayPowerController.getBrightnessEvents(userId, hasUsageStats);
2130 }
Kenny Guy22bd0442017-10-26 00:15:54 +01002131 } finally {
2132 Binder.restoreCallingIdentity(token);
2133 }
2134 }
2135
Michael Wrighteef0e132017-11-21 17:57:52 +00002136 @Override // Binder call
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002137 public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats() {
2138 mContext.enforceCallingOrSelfPermission(
2139 Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS,
2140 "Permission required to to access ambient light stats.");
2141 final int callingUid = Binder.getCallingUid();
2142 final int userId = UserHandle.getUserId(callingUid);
2143 final long token = Binder.clearCallingIdentity();
2144 try {
2145 synchronized (mSyncRoot) {
2146 return mDisplayPowerController.getAmbientBrightnessStats(userId);
2147 }
2148 } finally {
2149 Binder.restoreCallingIdentity(token);
2150 }
2151 }
2152
2153 @Override // Binder call
Michael Wrighteef0e132017-11-21 17:57:52 +00002154 public void setBrightnessConfigurationForUser(
Kenny Guy05ce8092018-01-17 13:44:20 +00002155 BrightnessConfiguration c, @UserIdInt int userId, String packageName) {
Michael Wrighteef0e132017-11-21 17:57:52 +00002156 mContext.enforceCallingOrSelfPermission(
2157 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2158 "Permission required to change the display's brightness configuration");
2159 if (userId != UserHandle.getCallingUserId()) {
2160 mContext.enforceCallingOrSelfPermission(
2161 Manifest.permission.INTERACT_ACROSS_USERS,
2162 "Permission required to change the display brightness"
2163 + " configuration of another user");
2164 }
Kenny Guy05ce8092018-01-17 13:44:20 +00002165 if (packageName != null && !validatePackageName(getCallingUid(), packageName)) {
2166 packageName = null;
2167 }
Michael Wrighteef0e132017-11-21 17:57:52 +00002168 final long token = Binder.clearCallingIdentity();
2169 try {
Kenny Guy05ce8092018-01-17 13:44:20 +00002170 setBrightnessConfigurationForUserInternal(c, userId, packageName);
Michael Wrighteef0e132017-11-21 17:57:52 +00002171 } finally {
2172 Binder.restoreCallingIdentity(token);
2173 }
2174 }
2175
Michael Wrightd8460232018-01-16 18:04:59 +00002176 @Override // Binder call
Kenny Guy6d1009f2018-03-14 14:28:23 +00002177 public BrightnessConfiguration getBrightnessConfigurationForUser(int userId) {
2178 mContext.enforceCallingOrSelfPermission(
2179 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2180 "Permission required to read the display's brightness configuration");
2181 if (userId != UserHandle.getCallingUserId()) {
2182 mContext.enforceCallingOrSelfPermission(
2183 Manifest.permission.INTERACT_ACROSS_USERS,
2184 "Permission required to read the display brightness"
2185 + " configuration of another user");
2186 }
2187 final long token = Binder.clearCallingIdentity();
2188 try {
2189 final int userSerial = getUserManager().getUserSerialNumber(userId);
2190 synchronized (mSyncRoot) {
2191 BrightnessConfiguration config =
2192 mPersistentDataStore.getBrightnessConfiguration(userSerial);
2193 if (config == null) {
2194 config = mDisplayPowerController.getDefaultBrightnessConfiguration();
2195 }
2196 return config;
2197 }
2198 } finally {
2199 Binder.restoreCallingIdentity(token);
2200 }
2201 }
2202
2203 @Override // Binder call
2204 public BrightnessConfiguration getDefaultBrightnessConfiguration() {
2205 mContext.enforceCallingOrSelfPermission(
2206 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2207 "Permission required to read the display's default brightness configuration");
2208 final long token = Binder.clearCallingIdentity();
2209 try {
2210 synchronized (mSyncRoot) {
2211 return mDisplayPowerController.getDefaultBrightnessConfiguration();
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(token);
2215 }
2216 }
2217
2218 @Override // Binder call
Michael Wrightd8460232018-01-16 18:04:59 +00002219 public void setTemporaryBrightness(int brightness) {
2220 mContext.enforceCallingOrSelfPermission(
2221 Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS,
2222 "Permission required to set the display's brightness");
2223 final long token = Binder.clearCallingIdentity();
2224 try {
2225 synchronized (mSyncRoot) {
2226 mDisplayPowerController.setTemporaryBrightness(brightness);
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(token);
2230 }
2231 }
2232
2233 @Override // Binder call
2234 public void setTemporaryAutoBrightnessAdjustment(float adjustment) {
2235 mContext.enforceCallingOrSelfPermission(
2236 Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS,
2237 "Permission required to set the display's auto brightness adjustment");
2238 final long token = Binder.clearCallingIdentity();
2239 try {
2240 synchronized (mSyncRoot) {
2241 mDisplayPowerController.setTemporaryAutoBrightnessAdjustment(adjustment);
2242 }
2243 } finally {
2244 Binder.restoreCallingIdentity(token);
2245 }
2246 }
2247
Dan Gittik7a32fba2018-03-28 12:19:38 +01002248 @Override // Binder call
2249 public void onShellCommand(FileDescriptor in, FileDescriptor out,
2250 FileDescriptor err, String[] args, ShellCallback callback,
2251 ResultReceiver resultReceiver) {
2252 final long token = Binder.clearCallingIdentity();
2253 try {
2254 DisplayManagerShellCommand command = new DisplayManagerShellCommand(this);
2255 command.exec(this, in, out, err, args, callback, resultReceiver);
2256 } finally {
2257 Binder.restoreCallingIdentity(token);
2258 }
2259 }
2260
Dan Gittik122df862018-03-28 16:59:22 +01002261 @Override // Binder call
2262 public Curve getMinimumBrightnessCurve() {
2263 final long token = Binder.clearCallingIdentity();
2264 try {
2265 return getMinimumBrightnessCurveInternal();
2266 } finally {
2267 Binder.restoreCallingIdentity(token);
2268 }
2269 }
2270
Peiyong Lin277eaff2019-01-16 16:18:22 -08002271 @Override // Binder call
2272 public int getPreferredWideGamutColorSpaceId() {
2273 final long token = Binder.clearCallingIdentity();
2274 try {
2275 return getPreferredWideGamutColorSpaceIdInternal();
2276 } finally {
2277 Binder.restoreCallingIdentity(token);
2278 }
2279 }
2280
Dan Gittik7a32fba2018-03-28 12:19:38 +01002281 void setBrightness(int brightness) {
2282 Settings.System.putIntForUser(mContext.getContentResolver(),
2283 Settings.System.SCREEN_BRIGHTNESS, brightness, UserHandle.USER_CURRENT);
2284 }
2285
2286 void resetBrightnessConfiguration() {
2287 setBrightnessConfigurationForUserInternal(null, mContext.getUserId(),
2288 mContext.getPackageName());
2289 }
2290
Dan Gittika5a2d632019-01-09 14:25:29 +00002291 void setAutoBrightnessLoggingEnabled(boolean enabled) {
2292 if (mDisplayPowerController != null) {
2293 synchronized (mSyncRoot) {
2294 mDisplayPowerController.setAutoBrightnessLoggingEnabled(enabled);
2295 }
2296 }
2297 }
2298
Dan Gittik8dbd7e92018-12-03 15:35:53 +00002299 void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) {
2300 if (mDisplayPowerController != null) {
2301 synchronized (mSyncRoot) {
2302 mDisplayPowerController.setDisplayWhiteBalanceLoggingEnabled(enabled);
2303 }
2304 }
2305 }
2306
2307 void setAmbientColorTemperatureOverride(float cct) {
2308 if (mDisplayPowerController != null) {
2309 synchronized (mSyncRoot) {
2310 mDisplayPowerController.setAmbientColorTemperatureOverride(cct);
2311 }
2312 }
2313 }
2314
Jeff Brown4ccb8232014-01-16 22:16:42 -08002315 private boolean validatePackageName(int uid, String packageName) {
2316 if (packageName != null) {
2317 String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
2318 if (packageNames != null) {
2319 for (String n : packageNames) {
2320 if (n.equals(packageName)) {
2321 return true;
2322 }
2323 }
2324 }
2325 }
2326 return false;
2327 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07002328
2329 private boolean canProjectVideo(IMediaProjection projection) {
2330 if (projection != null) {
2331 try {
2332 if (projection.canProjectVideo()) {
2333 return true;
2334 }
2335 } catch (RemoteException e) {
2336 Slog.e(TAG, "Unable to query projection service for permissions", e);
2337 }
2338 }
Chilun67a379b2019-04-11 19:49:42 +08002339 if (checkCallingPermission(CAPTURE_VIDEO_OUTPUT, "canProjectVideo()")) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002340 return true;
2341 }
2342 return canProjectSecureVideo(projection);
2343 }
2344
2345 private boolean canProjectSecureVideo(IMediaProjection projection) {
2346 if (projection != null) {
2347 try {
2348 if (projection.canProjectSecureVideo()){
2349 return true;
2350 }
2351 } catch (RemoteException e) {
2352 Slog.e(TAG, "Unable to query projection service for permissions", e);
2353 }
2354 }
Chilun67a379b2019-04-11 19:49:42 +08002355 return checkCallingPermission(CAPTURE_SECURE_VIDEO_OUTPUT, "canProjectSecureVideo()");
2356 }
2357
2358 private boolean checkCallingPermission(String permission, String func) {
2359 if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) {
2360 return true;
2361 }
2362 final String msg = "Permission Denial: " + func + " from pid=" + Binder.getCallingPid()
2363 + ", uid=" + Binder.getCallingUid() + " requires " + permission;
2364 Slog.w(TAG, msg);
2365 return false;
Michael Wrightc39d47a2014-07-08 18:07:36 -07002366 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08002367 }
2368
2369 private final class LocalService extends DisplayManagerInternal {
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002370
Jeff Brown4ccb8232014-01-16 22:16:42 -08002371 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07002372 public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler,
Jeff Brownad9ef192014-04-08 17:26:30 -07002373 SensorManager sensorManager) {
2374 synchronized (mSyncRoot) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002375 DisplayBlanker blanker = new DisplayBlanker() {
2376 @Override
Jeff Brown5d6443b2015-04-10 20:15:01 -07002377 public void requestDisplayState(int state, int brightness) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002378 // The order of operations is important for legacy reasons.
2379 if (state == Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07002380 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07002381 }
2382
2383 callbacks.onDisplayStateChange(state);
2384
2385 if (state != Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07002386 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07002387 }
2388 }
2389 };
Jeff Brownad9ef192014-04-08 17:26:30 -07002390 mDisplayPowerController = new DisplayPowerController(
Jeff Brown037c33e2014-04-09 00:31:55 -07002391 mContext, callbacks, handler, sensorManager, blanker);
Long Lingbc841b02019-07-03 16:43:15 -07002392 mSensorManager = sensorManager;
Jeff Brownad9ef192014-04-08 17:26:30 -07002393 }
Michael Wrighteef0e132017-11-21 17:57:52 +00002394
2395 mHandler.sendEmptyMessage(MSG_LOAD_BRIGHTNESS_CONFIGURATION);
Jeff Brownad9ef192014-04-08 17:26:30 -07002396 }
2397
2398 @Override
2399 public boolean requestPowerState(DisplayPowerRequest request,
2400 boolean waitForNegativeProximity) {
Michael Wrighteef0e132017-11-21 17:57:52 +00002401 synchronized (mSyncRoot) {
2402 return mDisplayPowerController.requestPowerState(request,
2403 waitForNegativeProximity);
2404 }
Jeff Brownad9ef192014-04-08 17:26:30 -07002405 }
2406
2407 @Override
2408 public boolean isProximitySensorAvailable() {
Michael Wrighteef0e132017-11-21 17:57:52 +00002409 synchronized (mSyncRoot) {
2410 return mDisplayPowerController.isProximitySensorAvailable();
2411 }
Jeff Brownad9ef192014-04-08 17:26:30 -07002412 }
2413
2414 @Override
Robert Carr66b5664f2019-04-02 14:18:56 -07002415 public SurfaceControl.ScreenshotGraphicBuffer screenshot(int displayId) {
2416 return screenshotInternal(displayId);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002417 }
2418
2419 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -08002420 public DisplayInfo getDisplayInfo(int displayId) {
2421 return getDisplayInfoInternal(displayId, Process.myUid());
2422 }
2423
2424 @Override
2425 public void registerDisplayTransactionListener(DisplayTransactionListener listener) {
2426 if (listener == null) {
2427 throw new IllegalArgumentException("listener must not be null");
2428 }
2429
2430 registerDisplayTransactionListenerInternal(listener);
2431 }
2432
2433 @Override
2434 public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) {
2435 if (listener == null) {
2436 throw new IllegalArgumentException("listener must not be null");
2437 }
2438
2439 unregisterDisplayTransactionListenerInternal(listener);
2440 }
2441
2442 @Override
2443 public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) {
2444 setDisplayInfoOverrideFromWindowManagerInternal(displayId, info);
2445 }
2446
2447 @Override
Andrii Kuliancd097992017-03-23 18:31:59 -07002448 public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) {
2449 getNonOverrideDisplayInfoInternal(displayId, outInfo);
2450 }
2451
2452 @Override
Robert Carrae606b42018-02-15 15:36:23 -08002453 public void performTraversal(SurfaceControl.Transaction t) {
2454 performTraversalInternal(t);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002455 }
2456
2457 @Override
Michael Wright3f145a22014-07-22 19:46:03 -07002458 public void setDisplayProperties(int displayId, boolean hasContent,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002459 float requestedRefreshRate, int requestedMode,
2460 boolean requestedMinimalPostProcessing, boolean inTraversal) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07002461 setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002462 requestedMode, requestedMinimalPostProcessing, inTraversal);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002463 }
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08002464
2465 @Override
2466 public void setDisplayOffsets(int displayId, int x, int y) {
2467 setDisplayOffsetsInternal(displayId, x, y);
2468 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002469
2470 @Override
Sam Lin4c3ac2b2019-02-18 04:50:26 -08002471 public void setDisplayScalingDisabled(int displayId, boolean disableScaling) {
2472 setDisplayScalingDisabledInternal(displayId, disableScaling);
2473 }
2474
2475 @Override
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002476 public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) {
2477 setDisplayAccessUIDsInternal(newDisplayAccessUIDs);
2478 }
2479
2480 @Override
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002481 public void persistBrightnessTrackerState() {
Michael Wright144aac92017-12-21 18:37:41 +00002482 synchronized (mSyncRoot) {
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002483 mDisplayPowerController.persistBrightnessTrackerState();
Michael Wright144aac92017-12-21 18:37:41 +00002484 }
Kenny Guycfe7b702017-11-14 21:04:58 +00002485 }
Adrian Roose1d68cd2018-01-17 12:54:50 +01002486
2487 @Override
2488 public void onOverlayChanged() {
2489 synchronized (mSyncRoot) {
Adrian Roos898ec382018-01-17 12:54:50 +01002490 for (int i = 0; i < mDisplayDevices.size(); i++) {
2491 mDisplayDevices.get(i).onOverlayChangedLocked();
Adrian Roose1d68cd2018-01-17 12:54:50 +01002492 }
2493 }
2494 }
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07002495
2496 @Override
2497 public DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes(
2498 int displayId) {
2499 return getDisplayedContentSamplingAttributesInternal(displayId);
2500 }
2501
2502 @Override
2503 public boolean setDisplayedContentSamplingEnabled(
2504 int displayId, boolean enable, int componentMask, int maxFrames) {
2505 return setDisplayedContentSamplingEnabledInternal(
2506 displayId, enable, componentMask, maxFrames);
2507 }
2508
2509 @Override
2510 public DisplayedContentSample getDisplayedContentSample(int displayId,
2511 long maxFrames, long timestamp) {
2512 return getDisplayedContentSampleInternal(displayId, maxFrames, timestamp);
2513 }
2514
Jeff Brown4ccb8232014-01-16 22:16:42 -08002515 }
Michael Wrighta3dab232019-02-22 16:54:21 +00002516
Ana Kruleca74a8642019-11-14 00:51:00 +01002517 class DesiredDisplayModeSpecsObserver
2518 implements DisplayModeDirector.DesiredDisplayModeSpecsListener {
2519 public void onDesiredDisplayModeSpecsChanged() {
2520 onDesiredDisplayModeSpecsChangedInternal();
Michael Wrighta3dab232019-02-22 16:54:21 +00002521 }
2522 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07002523}