blob: e39d6d5389e304b16752ceb9027ba8ecc536328c [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;
Jeff Browna506a6e2013-06-04 00:02:38 -070080import android.text.TextUtils;
Andrii Kulianfb1bf692017-01-17 11:17:34 -080081import android.util.IntArray;
Dan Gittik122df862018-03-28 16:59:22 +010082import android.util.Pair;
Jeff Brownbd6e1502012-08-28 03:27:37 -070083import android.util.Slog;
84import android.util.SparseArray;
Dan Gittik122df862018-03-28 16:59:22 +010085import android.util.Spline;
Jeff Brownfa25bf52012-07-23 19:26:30 -070086import android.view.Display;
87import android.view.DisplayInfo;
Jeff Browna506a6e2013-06-04 00:02:38 -070088import android.view.Surface;
Robert Carrae606b42018-02-15 15:36:23 -080089import android.view.SurfaceControl;
Jeff Browna506a6e2013-06-04 00:02:38 -070090
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +010091import com.android.internal.annotations.GuardedBy;
92import com.android.internal.annotations.VisibleForTesting;
93import com.android.internal.util.DumpUtils;
94import com.android.internal.util.IndentingPrintWriter;
Jorim Jaggied7993b2017-03-28 18:50:01 +010095import com.android.server.AnimationThread;
Jeff Brown4ccb8232014-01-16 22:16:42 -080096import com.android.server.DisplayThread;
97import com.android.server.LocalServices;
98import com.android.server.SystemService;
Dianne Hackborn8d044e82013-04-30 17:24:15 -070099import com.android.server.UiThread;
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200100import com.android.server.wm.SurfaceAnimationThread;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100101import com.android.server.wm.WindowManagerInternal;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700102
103import java.io.FileDescriptor;
104import java.io.PrintWriter;
105import java.util.ArrayList;
Jeff Browna506a6e2013-06-04 00:02:38 -0700106import java.util.Arrays;
Jeff Browne75926d2014-09-18 15:24:49 -0700107import java.util.List;
Jeff Brown7f3994e2012-12-04 14:04:28 -0800108import java.util.concurrent.CopyOnWriteArrayList;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700109
110/**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700111 * Manages attached displays.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700112 * <p>
Jeff Brownbd6e1502012-08-28 03:27:37 -0700113 * The {@link DisplayManagerService} manages the global lifecycle of displays,
114 * decides how to configure logical displays based on the physical display devices currently
115 * attached, sends notifications to the system and to applications when the state
116 * changes, and so on.
117 * </p><p>
118 * The display manager service relies on a collection of {@link DisplayAdapter} components,
119 * for discovering and configuring physical display devices attached to the system.
120 * There are separate display adapters for each manner that devices are attached:
121 * one display adapter for built-in local displays, one for simulated non-functional
122 * displays when the system is headless, one for simulated overlay displays used for
123 * development, one for wifi displays, etc.
124 * </p><p>
125 * Display adapters are only weakly coupled to the display manager service.
126 * Display adapters communicate changes in display device state to the display manager
Craig Mautner722285e2012-09-07 13:55:58 -0700127 * service asynchronously via a {@link DisplayAdapter.Listener} registered
Jeff Brownbd6e1502012-08-28 03:27:37 -0700128 * by the display manager service. This separation of concerns is important for
129 * two main reasons. First, it neatly encapsulates the responsibilities of these
130 * two classes: display adapters handle individual display devices whereas
131 * the display manager service handles the global state. Second, it eliminates
132 * the potential for deadlocks resulting from asynchronous display device discovery.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700133 * </p>
134 *
135 * <h3>Synchronization</h3>
136 * <p>
137 * Because the display manager may be accessed by multiple threads, the synchronization
138 * story gets a little complicated. In particular, the window manager may call into
139 * the display manager while holding a surface transaction with the expectation that
140 * it can apply changes immediately. Unfortunately, that means we can't just do
141 * everything asynchronously (*grump*).
Jeff Brownbd6e1502012-08-28 03:27:37 -0700142 * </p><p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700143 * To make this work, all of the objects that belong to the display manager must
144 * use the same lock. We call this lock the synchronization root and it has a unique
145 * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are
146 * named with the "Locked" suffix.
147 * </p><p>
148 * Where things get tricky is that the display manager is not allowed to make
149 * any potentially reentrant calls, especially into the window manager. We generally
150 * avoid this by making all potentially reentrant out-calls asynchronous.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700151 * </p>
152 */
Jeff Brown4ccb8232014-01-16 22:16:42 -0800153public final class DisplayManagerService extends SystemService {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700154 private static final String TAG = "DisplayManagerService";
Jeff Brownbd6e1502012-08-28 03:27:37 -0700155 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700156
Jeff Brownbbd28a22012-09-20 16:47:15 -0700157 // When this system property is set to 0, WFD is forcibly disabled on boot.
158 // When this system property is set to 1, WFD is forcibly enabled on boot.
159 // Otherwise WFD is enabled according to the value of config_enableWifiDisplay.
160 private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
161
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200162 private static final String PROP_DEFAULT_DISPLAY_TOP_INSET = "persist.sys.displayinset.top";
163
Jeff Brownbd6e1502012-08-28 03:27:37 -0700164 private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
165
Santos Cordonc22c5632017-06-21 16:03:49 -0700166 private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS = 1;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700167 private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2;
168 private static final int MSG_DELIVER_DISPLAY_EVENT = 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700169 private static final int MSG_REQUEST_TRAVERSAL = 4;
Jeff Brownd728bf52012-09-08 18:05:28 -0700170 private static final int MSG_UPDATE_VIEWPORT = 5;
Michael Wrighta3dab232019-02-22 16:54:21 +0000171 private static final int MSG_LOAD_BRIGHTNESS_CONFIGURATION = 6;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700172
Jeff Brownb880d882014-02-10 19:47:07 -0800173 private final Context mContext;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700174 private final DisplayManagerHandler mHandler;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700175 private final Handler mUiHandler;
176 private final DisplayAdapterListener mDisplayAdapterListener;
Michael Wrighta3dab232019-02-22 16:54:21 +0000177 private final DisplayModeDirector mDisplayModeDirector;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800178 private WindowManagerInternal mWindowManagerInternal;
179 private InputManagerInternal mInputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700180 private IMediaProjectionManager mProjectionService;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700181
182 // The synchronization root for the display manager.
183 // This lock guards most of the display manager's state.
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800184 // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call
185 // into WindowManagerService methods that require mWindowMap while holding this unless you are
186 // very very sure that no deadlock can occur.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700187 private final SyncRoot mSyncRoot = new SyncRoot();
188
189 // True if in safe mode.
190 // This option may disable certain display adapters.
191 public boolean mSafeMode;
192
193 // True if we are in a special boot mode where only core applications and
194 // services should be started. This option may disable certain display adapters.
195 public boolean mOnlyCore;
196
Jeff Brown27f1d672012-10-17 18:32:34 -0700197 // True if the display manager service should pretend there is only one display
198 // and only tell applications about the existence of the default logical display.
199 // The display manager can still mirror content to secondary displays but applications
200 // cannot present unique content on those displays.
201 // Used for demonstration purposes only.
202 private final boolean mSingleDisplayDemoMode;
203
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700204 // All callback records indexed by calling process id.
205 public final SparseArray<CallbackRecord> mCallbacks =
Jeff Brownbd6e1502012-08-28 03:27:37 -0700206 new SparseArray<CallbackRecord>();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700207
Jeff Brownbd6e1502012-08-28 03:27:37 -0700208 // List of all currently registered display adapters.
209 private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
210
211 // List of all currently connected display devices.
212 private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>();
213
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700214 // List of all logical displays indexed by logical display id.
215 private final SparseArray<LogicalDisplay> mLogicalDisplays =
216 new SparseArray<LogicalDisplay>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700217 private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1;
218
Jeff Brown7f3994e2012-12-04 14:04:28 -0800219 // List of all display transaction listeners.
220 private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
221 new CopyOnWriteArrayList<DisplayTransactionListener>();
222
Jeff Brownad9ef192014-04-08 17:26:30 -0700223 // Display power controller.
224 private DisplayPowerController mDisplayPowerController;
225
Jeff Brown037c33e2014-04-09 00:31:55 -0700226 // The overall display state, independent of changes that might influence one
227 // display or another in particular.
Jeff Brown5d6443b2015-04-10 20:15:01 -0700228 private int mGlobalDisplayState = Display.STATE_ON;
229
230 // The overall display brightness.
231 // For now, this only applies to the built-in display but we may split it up eventually.
232 private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT;
Jeff Brown9e316a12012-10-08 19:17:06 -0700233
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700234 // Set to true when there are pending display changes that have yet to be applied
235 // to the surface flinger state.
236 private boolean mPendingTraversal;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700237
Jeff Browne08ae382012-09-07 20:36:36 -0700238 // The Wifi display adapter, or null if not registered.
239 private WifiDisplayAdapter mWifiDisplayAdapter;
240
Jeff Brownce468a32013-11-21 16:42:03 -0800241 // The number of active wifi display scan requests.
242 private int mWifiDisplayScanRequestCount;
243
Jeff Browna506a6e2013-06-04 00:02:38 -0700244 // The virtual display adapter, or null if not registered.
245 private VirtualDisplayAdapter mVirtualDisplayAdapter;
246
Michael Wrighteef0e132017-11-21 17:57:52 +0000247 // The User ID of the current user
248 private @UserIdInt int mCurrentUserId;
249
Michael Wrighteedcbf12017-08-16 23:14:54 +0100250 // The stable device screen height and width. These are not tied to a specific display, even
251 // the default display, because they need to be stable over the course of the device's entire
252 // life, even if the default display changes (e.g. a new monitor is plugged into a PC-like
253 // device).
254 private Point mStableDisplaySize = new Point();
255
Winson72dbe7e2019-04-29 14:55:30 -0700256 // Whether the system has finished booting or not.
257 private boolean mSystemReady;
258
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200259 // The top inset of the default display.
260 // This gets persisted so that the boot animation knows how to transition from the display's
261 // full size to the size configured by the user. Right now we only persist and animate the top
262 // inset, but theoretically we could do it for all of them.
263 private int mDefaultDisplayTopInset;
264
Jeff Brownd728bf52012-09-08 18:05:28 -0700265 // Viewports of the default display and the display that should receive touch
266 // input from an external source. Used by the input system.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100267 @GuardedBy("mSyncRoot")
268 private final ArrayList<DisplayViewport> mViewports = new ArrayList<>();
Jeff Brownd728bf52012-09-08 18:05:28 -0700269
Jeff Brown89d55462012-09-19 11:33:42 -0700270 // Persistent data store for all internal settings maintained by the display manager service.
271 private final PersistentDataStore mPersistentDataStore = new PersistentDataStore();
272
Jeff Brownbd6e1502012-08-28 03:27:37 -0700273 // Temporary callback list, used when sending display events to applications.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700274 // May be used outside of the lock but only on the handler thread.
275 private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700276
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700277 // Temporary display info, used for comparing display configurations.
278 private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
279
Jeff Brownd728bf52012-09-08 18:05:28 -0700280 // Temporary viewports, used when sending new viewport information to the
281 // input system. May be used outside of the lock but only on the handler thread.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100282 private final ArrayList<DisplayViewport> mTempViewports = new ArrayList<>();
Jeff Brownd728bf52012-09-08 18:05:28 -0700283
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700284 // The default color mode for default displays. Overrides the usual
285 // Display.Display.COLOR_MODE_DEFAULT for displays with the
286 // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set.
287 private final int mDefaultDisplayDefaultColorMode;
288
Jeff Browne75926d2014-09-18 15:24:49 -0700289 // Temporary list of deferred work to perform when setting the display state.
290 // Only used by requestDisplayState. The field is self-synchronized and only
291 // intended for use inside of the requestGlobalDisplayStateInternal function.
292 private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>();
293
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800294 // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs.
295 private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>();
296
Santos Cordonee8931e2017-04-05 10:31:15 -0700297 private final Injector mInjector;
298
Dan Gittik122df862018-03-28 16:59:22 +0100299 // The minimum brightness curve, which guarantess that any brightness curve that dips below it
300 // is rejected by the system.
301 private final Curve mMinimumBrightnessCurve;
302 private final Spline mMinimumBrightnessSpline;
Peiyong Lin277eaff2019-01-16 16:18:22 -0800303 private final ColorSpace mWideColorSpace;
Dan Gittik122df862018-03-28 16:59:22 +0100304
Long Lingbc841b02019-07-03 16:43:15 -0700305 private SensorManager mSensorManager;
306
Jeff Brownb880d882014-02-10 19:47:07 -0800307 public DisplayManagerService(Context context) {
Santos Cordonee8931e2017-04-05 10:31:15 -0700308 this(context, new Injector());
309 }
310
311 @VisibleForTesting
312 DisplayManagerService(Context context, Injector injector) {
Jeff Brownb880d882014-02-10 19:47:07 -0800313 super(context);
Santos Cordonee8931e2017-04-05 10:31:15 -0700314 mInjector = injector;
Jeff Brownb880d882014-02-10 19:47:07 -0800315 mContext = context;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800316 mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700317 mUiHandler = UiThread.getHandler();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700318 mDisplayAdapterListener = new DisplayAdapterListener();
Michael Wrighta3dab232019-02-22 16:54:21 +0000319 mDisplayModeDirector = new DisplayModeDirector(context, mHandler);
Jeff Brown27f1d672012-10-17 18:32:34 -0700320 mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
Dan Gittik122df862018-03-28 16:59:22 +0100321 Resources resources = mContext.getResources();
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700322 mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger(
Michael Wrighteef0e132017-11-21 17:57:52 +0000323 com.android.internal.R.integer.config_defaultDisplayDefaultColorMode);
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200324 mDefaultDisplayTopInset = SystemProperties.getInt(PROP_DEFAULT_DISPLAY_TOP_INSET, -1);
Dan Gittik122df862018-03-28 16:59:22 +0100325 float[] lux = getFloatArray(resources.obtainTypedArray(
326 com.android.internal.R.array.config_minimumBrightnessCurveLux));
327 float[] nits = getFloatArray(resources.obtainTypedArray(
328 com.android.internal.R.array.config_minimumBrightnessCurveNits));
329 mMinimumBrightnessCurve = new Curve(lux, nits);
330 mMinimumBrightnessSpline = Spline.createSpline(lux, nits);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700331
Michael Wrighta3dab232019-02-22 16:54:21 +0000332 PowerManager pm = mContext.getSystemService(PowerManager.class);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700333 mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting();
Michael Wrighteef0e132017-11-21 17:57:52 +0000334 mCurrentUserId = UserHandle.USER_SYSTEM;
Peiyong Lin277eaff2019-01-16 16:18:22 -0800335 ColorSpace[] colorSpaces = SurfaceControl.getCompositionColorSpaces();
336 mWideColorSpace = colorSpaces[1];
Winson72dbe7e2019-04-29 14:55:30 -0700337
338 mSystemReady = false;
Joel Fernandes2d314e12017-04-04 16:32:15 -0700339 }
340
341 public void setupSchedulerPolicies() {
Jorim Jaggied7993b2017-03-28 18:50:01 +0100342 // android.display and android.anim is critical to user experience and we should make sure
Michael Wrighteef0e132017-11-21 17:57:52 +0000343 // it is not in the default foregroup groups, add it to top-app to make sure it uses all
344 // the cores and scheduling settings for top-app when it runs.
Jorim Jaggied7993b2017-03-28 18:50:01 +0100345 Process.setThreadGroupAndCpuset(DisplayThread.get().getThreadId(),
346 Process.THREAD_GROUP_TOP_APP);
347 Process.setThreadGroupAndCpuset(AnimationThread.get().getThreadId(),
348 Process.THREAD_GROUP_TOP_APP);
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200349 Process.setThreadGroupAndCpuset(SurfaceAnimationThread.get().getThreadId(),
350 Process.THREAD_GROUP_TOP_APP);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700351 }
352
Jeff Brown4ccb8232014-01-16 22:16:42 -0800353 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -0800354 public void onStart() {
Michael Wright1c9977b2016-07-12 13:30:10 -0700355 // We need to pre-load the persistent data store so it's ready before the default display
356 // adapter is up so that we have it's configuration. We could load it lazily, but since
357 // 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 -0700358 // we've waited for the display to register itself with us.
Michael Wrighta3dab232019-02-22 16:54:21 +0000359 synchronized (mSyncRoot) {
360 mPersistentDataStore.loadIfNeeded();
361 loadStableDisplayValuesLocked();
Michael Wrighteedcbf12017-08-16 23:14:54 +0100362 }
Santos Cordonc22c5632017-06-21 16:03:49 -0700363 mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800364
365 publishBinderService(Context.DISPLAY_SERVICE, new BinderService(),
366 true /*allowIsolated*/);
367 publishLocalService(DisplayManagerInternal.class, new LocalService());
368 }
369
370 @Override
371 public void onBootPhase(int phase) {
372 if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) {
373 synchronized (mSyncRoot) {
Santos Cordonc22c5632017-06-21 16:03:49 -0700374 long timeout = SystemClock.uptimeMillis()
375 + mInjector.getDefaultDisplayDelayTimeout();
376 while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null ||
377 mVirtualDisplayAdapter == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800378 long delay = timeout - SystemClock.uptimeMillis();
379 if (delay <= 0) {
380 throw new RuntimeException("Timeout waiting for default display "
Santos Cordonc22c5632017-06-21 16:03:49 -0700381 + "to be initialized. DefaultDisplay="
382 + mLogicalDisplays.get(Display.DEFAULT_DISPLAY)
383 + ", mVirtualDisplayAdapter=" + mVirtualDisplayAdapter);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800384 }
385 if (DEBUG) {
386 Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay);
387 }
388 try {
389 mSyncRoot.wait(delay);
390 } catch (InterruptedException ex) {
391 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700392 }
393 }
394 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700395 }
396
Michael Wrighteef0e132017-11-21 17:57:52 +0000397 @Override
398 public void onSwitchUser(@UserIdInt int newUserId) {
399 final int userSerial = getUserManager().getUserSerialNumber(newUserId);
400 synchronized (mSyncRoot) {
401 if (mCurrentUserId != newUserId) {
402 mCurrentUserId = newUserId;
403 BrightnessConfiguration config =
404 mPersistentDataStore.getBrightnessConfiguration(userSerial);
405 mDisplayPowerController.setBrightnessConfiguration(config);
406 }
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +0000407 mDisplayPowerController.onSwitchUser(newUserId);
Michael Wrighteef0e132017-11-21 17:57:52 +0000408 }
409 }
410
Jeff Brown4ccb8232014-01-16 22:16:42 -0800411 // TODO: Use dependencies or a boot phase
412 public void windowManagerAndInputReady() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700413 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800414 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
415 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Craig Mautner65d11b32012-10-01 13:59:52 -0700416 scheduleTraversalLocked(false);
Jeff Brownd728bf52012-09-08 18:05:28 -0700417 }
418 }
419
420 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700421 * Called when the system is ready to go.
422 */
423 public void systemReady(boolean safeMode, boolean onlyCore) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700424 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700425 mSafeMode = safeMode;
426 mOnlyCore = onlyCore;
Winson72dbe7e2019-04-29 14:55:30 -0700427 mSystemReady = true;
428 // Just in case the top inset changed before the system was ready. At this point, any
429 // relevant configuration should be in place.
430 recordTopInsetLocked(mLogicalDisplays.get(Display.DEFAULT_DISPLAY));
Jeff Brownbd6e1502012-08-28 03:27:37 -0700431 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700432
Ana Kruleca74a8642019-11-14 00:51:00 +0100433 mDisplayModeDirector.setDesiredDisplayModeSpecsListener(
434 new DesiredDisplayModeSpecsObserver());
Long Lingbc841b02019-07-03 16:43:15 -0700435 mDisplayModeDirector.start(mSensorManager);
Michael Wrighta3dab232019-02-22 16:54:21 +0000436
Jeff Brownbd6e1502012-08-28 03:27:37 -0700437 mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
438 }
439
Santos Cordonee8931e2017-04-05 10:31:15 -0700440 @VisibleForTesting
441 Handler getDisplayHandler() {
442 return mHandler;
443 }
444
Michael Wrighteedcbf12017-08-16 23:14:54 +0100445 private void loadStableDisplayValuesLocked() {
446 final Point size = mPersistentDataStore.getStableDisplaySize();
447 if (size.x > 0 && size.y > 0) {
448 // Just set these values directly so we don't write the display persistent data again
449 // unnecessarily
450 mStableDisplaySize.set(size.x, size.y);
451 } else {
452 final Resources res = mContext.getResources();
453 final int width = res.getInteger(
454 com.android.internal.R.integer.config_stableDeviceDisplayWidth);
455 final int height = res.getInteger(
456 com.android.internal.R.integer.config_stableDeviceDisplayHeight);
457 if (width > 0 && height > 0) {
458 setStableDisplaySizeLocked(width, height);
459 }
460 }
461 }
462
463 private Point getStableDisplaySizeInternal() {
464 Point r = new Point();
465 synchronized (mSyncRoot) {
466 if (mStableDisplaySize.x > 0 && mStableDisplaySize.y > 0) {
467 r.set(mStableDisplaySize.x, mStableDisplaySize.y);
468 }
469 }
470 return r;
471 }
472
Jeff Brown4ccb8232014-01-16 22:16:42 -0800473 private void registerDisplayTransactionListenerInternal(
474 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800475 // List is self-synchronized copy-on-write.
476 mDisplayTransactionListeners.add(listener);
477 }
478
Jeff Brown4ccb8232014-01-16 22:16:42 -0800479 private void unregisterDisplayTransactionListenerInternal(
480 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800481 // List is self-synchronized copy-on-write.
482 mDisplayTransactionListeners.remove(listener);
483 }
484
Jeff Brown4ccb8232014-01-16 22:16:42 -0800485 private void setDisplayInfoOverrideFromWindowManagerInternal(
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700486 int displayId, DisplayInfo info) {
487 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700488 LogicalDisplay display = mLogicalDisplays.get(displayId);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700489 if (display != null) {
Jeff Brownef981a42013-08-07 14:13:37 -0700490 if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200491 handleLogicalDisplayChanged(displayId, display);
Craig Mautner65d11b32012-10-01 13:59:52 -0700492 scheduleTraversalLocked(false);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700493 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700494 }
495 }
496 }
497
Andrii Kuliancd097992017-03-23 18:31:59 -0700498 /**
499 * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo)
500 */
501 private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) {
502 synchronized (mSyncRoot) {
503 final LogicalDisplay display = mLogicalDisplays.get(displayId);
504 if (display != null) {
505 display.getNonOverrideDisplayInfoLocked(outInfo);
506 }
507 }
508 }
509
Santos Cordonee8931e2017-04-05 10:31:15 -0700510 @VisibleForTesting
Robert Carrae606b42018-02-15 15:36:23 -0800511 void performTraversalInternal(SurfaceControl.Transaction t) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700512 synchronized (mSyncRoot) {
513 if (!mPendingTraversal) {
514 return;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700515 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700516 mPendingTraversal = false;
517
Robert Carrae606b42018-02-15 15:36:23 -0800518 performTraversalLocked(t);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700519 }
Jeff Brown7f3994e2012-12-04 14:04:28 -0800520
521 // List is self-synchronized copy-on-write.
522 for (DisplayTransactionListener listener : mDisplayTransactionListeners) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800523 listener.onDisplayTransaction(t);
Jeff Brown7f3994e2012-12-04 14:04:28 -0800524 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700525 }
526
Jeff Brown5d6443b2015-04-10 20:15:01 -0700527 private void requestGlobalDisplayStateInternal(int state, int brightness) {
528 if (state == Display.STATE_UNKNOWN) {
529 state = Display.STATE_ON;
530 }
531 if (state == Display.STATE_OFF) {
532 brightness = PowerManager.BRIGHTNESS_OFF;
533 } else if (brightness < 0) {
534 brightness = PowerManager.BRIGHTNESS_DEFAULT;
535 } else if (brightness > PowerManager.BRIGHTNESS_ON) {
536 brightness = PowerManager.BRIGHTNESS_ON;
537 }
538
Jeff Browne75926d2014-09-18 15:24:49 -0700539 synchronized (mTempDisplayStateWorkQueue) {
540 try {
541 // Update the display state within the lock.
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700542 // Note that we do not need to schedule traversals here although it
543 // may happen as a side-effect of displays changing state.
Jeff Browne75926d2014-09-18 15:24:49 -0700544 synchronized (mSyncRoot) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700545 if (mGlobalDisplayState == state
546 && mGlobalDisplayBrightness == brightness) {
547 return; // no change
Jeff Browne75926d2014-09-18 15:24:49 -0700548 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700549
550 Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState("
551 + Display.stateToString(state)
552 + ", brightness=" + brightness + ")");
553 mGlobalDisplayState = state;
554 mGlobalDisplayBrightness = brightness;
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700555 applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue);
Jeff Browne75926d2014-09-18 15:24:49 -0700556 }
557
558 // Setting the display power state can take hundreds of milliseconds
559 // to complete so we defer the most expensive part of the work until
560 // after we have exited the critical section to avoid blocking other
561 // threads for a long time.
562 for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) {
563 mTempDisplayStateWorkQueue.get(i).run();
564 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700565 Trace.traceEnd(Trace.TRACE_TAG_POWER);
Jeff Browne75926d2014-09-18 15:24:49 -0700566 } finally {
567 mTempDisplayStateWorkQueue.clear();
Jeff Brown9e316a12012-10-08 19:17:06 -0700568 }
569 }
570 }
571
Jeff Brown4ccb8232014-01-16 22:16:42 -0800572 private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700573 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800574 LogicalDisplay display = mLogicalDisplays.get(displayId);
575 if (display != null) {
576 DisplayInfo info = display.getDisplayInfoLocked();
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800577 if (info.hasAccess(callingUid)
578 || isUidPresentOnDisplayInternal(callingUid, displayId)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800579 return info;
580 }
581 }
582 return null;
583 }
584 }
585
586 private int[] getDisplayIdsInternal(int callingUid) {
587 synchronized (mSyncRoot) {
588 final int count = mLogicalDisplays.size();
589 int[] displayIds = new int[count];
590 int n = 0;
591 for (int i = 0; i < count; i++) {
592 LogicalDisplay display = mLogicalDisplays.valueAt(i);
593 DisplayInfo info = display.getDisplayInfoLocked();
594 if (info.hasAccess(callingUid)) {
595 displayIds[n++] = mLogicalDisplays.keyAt(i);
596 }
597 }
598 if (n != count) {
599 displayIds = Arrays.copyOfRange(displayIds, 0, n);
600 }
601 return displayIds;
602 }
603 }
604
605 private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) {
606 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700607 if (mCallbacks.get(callingPid) != null) {
608 throw new SecurityException("The calling process has already "
609 + "registered an IDisplayManagerCallback.");
Jeff Brown64a55af2012-08-26 02:47:39 -0700610 }
611
Jeff Brownbd6e1502012-08-28 03:27:37 -0700612 CallbackRecord record = new CallbackRecord(callingPid, callback);
613 try {
614 IBinder binder = callback.asBinder();
615 binder.linkToDeath(record, 0);
616 } catch (RemoteException ex) {
617 // give up
618 throw new RuntimeException(ex);
619 }
620
621 mCallbacks.put(callingPid, record);
622 }
623 }
624
Jeff Brownce468a32013-11-21 16:42:03 -0800625 private void onCallbackDied(CallbackRecord record) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700626 synchronized (mSyncRoot) {
Jeff Brownce468a32013-11-21 16:42:03 -0800627 mCallbacks.remove(record.mPid);
628 stopWifiDisplayScanLocked(record);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700629 }
630 }
631
Jeff Brown4ccb8232014-01-16 22:16:42 -0800632 private void startWifiDisplayScanInternal(int callingPid) {
633 synchronized (mSyncRoot) {
634 CallbackRecord record = mCallbacks.get(callingPid);
635 if (record == null) {
636 throw new IllegalStateException("The calling process has not "
637 + "registered an IDisplayManagerCallback.");
Jeff Browne08ae382012-09-07 20:36:36 -0700638 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800639 startWifiDisplayScanLocked(record);
Jeff Browne08ae382012-09-07 20:36:36 -0700640 }
641 }
642
Jeff Brownce468a32013-11-21 16:42:03 -0800643 private void startWifiDisplayScanLocked(CallbackRecord record) {
644 if (!record.mWifiDisplayScanRequested) {
645 record.mWifiDisplayScanRequested = true;
646 if (mWifiDisplayScanRequestCount++ == 0) {
647 if (mWifiDisplayAdapter != null) {
648 mWifiDisplayAdapter.requestStartScanLocked();
649 }
650 }
651 }
652 }
653
Jeff Brown4ccb8232014-01-16 22:16:42 -0800654 private void stopWifiDisplayScanInternal(int callingPid) {
655 synchronized (mSyncRoot) {
656 CallbackRecord record = mCallbacks.get(callingPid);
657 if (record == null) {
658 throw new IllegalStateException("The calling process has not "
659 + "registered an IDisplayManagerCallback.");
Jeff Brownce468a32013-11-21 16:42:03 -0800660 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800661 stopWifiDisplayScanLocked(record);
Jeff Brownce468a32013-11-21 16:42:03 -0800662 }
663 }
664
665 private void stopWifiDisplayScanLocked(CallbackRecord record) {
666 if (record.mWifiDisplayScanRequested) {
667 record.mWifiDisplayScanRequested = false;
668 if (--mWifiDisplayScanRequestCount == 0) {
669 if (mWifiDisplayAdapter != null) {
670 mWifiDisplayAdapter.requestStopScanLocked();
671 }
672 } else if (mWifiDisplayScanRequestCount < 0) {
Dianne Hackborn8d051722014-10-01 14:59:58 -0700673 Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: "
Jeff Brownce468a32013-11-21 16:42:03 -0800674 + mWifiDisplayScanRequestCount);
675 mWifiDisplayScanRequestCount = 0;
676 }
677 }
678 }
679
Jeff Brown4ccb8232014-01-16 22:16:42 -0800680 private void connectWifiDisplayInternal(String address) {
681 synchronized (mSyncRoot) {
682 if (mWifiDisplayAdapter != null) {
683 mWifiDisplayAdapter.requestConnectLocked(address);
Jeff Browne08ae382012-09-07 20:36:36 -0700684 }
Jeff Browne08ae382012-09-07 20:36:36 -0700685 }
686 }
687
Jeff Brown4ccb8232014-01-16 22:16:42 -0800688 private void pauseWifiDisplayInternal() {
689 synchronized (mSyncRoot) {
690 if (mWifiDisplayAdapter != null) {
691 mWifiDisplayAdapter.requestPauseLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700692 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700693 }
694 }
695
Jeff Brown4ccb8232014-01-16 22:16:42 -0800696 private void resumeWifiDisplayInternal() {
697 synchronized (mSyncRoot) {
698 if (mWifiDisplayAdapter != null) {
699 mWifiDisplayAdapter.requestResumeLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700700 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700701 }
702 }
703
Jeff Brown4ccb8232014-01-16 22:16:42 -0800704 private void disconnectWifiDisplayInternal() {
705 synchronized (mSyncRoot) {
706 if (mWifiDisplayAdapter != null) {
707 mWifiDisplayAdapter.requestDisconnectLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700708 }
Jeff Browne08ae382012-09-07 20:36:36 -0700709 }
710 }
711
Jeff Brown4ccb8232014-01-16 22:16:42 -0800712 private void renameWifiDisplayInternal(String address, String alias) {
713 synchronized (mSyncRoot) {
714 if (mWifiDisplayAdapter != null) {
715 mWifiDisplayAdapter.requestRenameLocked(address, alias);
Jeff Brown89d55462012-09-19 11:33:42 -0700716 }
Jeff Brown89d55462012-09-19 11:33:42 -0700717 }
718 }
719
Jeff Brown4ccb8232014-01-16 22:16:42 -0800720 private void forgetWifiDisplayInternal(String address) {
721 synchronized (mSyncRoot) {
722 if (mWifiDisplayAdapter != null) {
723 mWifiDisplayAdapter.requestForgetLocked(address);
Jeff Brown89d55462012-09-19 11:33:42 -0700724 }
Jeff Brown89d55462012-09-19 11:33:42 -0700725 }
726 }
727
Jeff Brown4ccb8232014-01-16 22:16:42 -0800728 private WifiDisplayStatus getWifiDisplayStatusInternal() {
729 synchronized (mSyncRoot) {
730 if (mWifiDisplayAdapter != null) {
731 return mWifiDisplayAdapter.getWifiDisplayStatusLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700732 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800733 return new WifiDisplayStatus();
Jeff Browne08ae382012-09-07 20:36:36 -0700734 }
735 }
736
Michael Wright1c9977b2016-07-12 13:30:10 -0700737 private void requestColorModeInternal(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +0100738 synchronized (mSyncRoot) {
739 LogicalDisplay display = mLogicalDisplays.get(displayId);
740 if (display != null &&
Michael Wright1c9977b2016-07-12 13:30:10 -0700741 display.getRequestedColorModeLocked() != colorMode) {
742 display.setRequestedColorModeLocked(colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100743 scheduleTraversalLocked(false);
744 }
745 }
746 }
747
Michael Wright75ee9fc2014-09-01 19:55:22 -0700748 private int createVirtualDisplayInternal(IVirtualDisplayCallback callback,
Santos Cordonee8931e2017-04-05 10:31:15 -0700749 IMediaProjection projection, int callingUid, String packageName, String name, int width,
750 int height, int densityDpi, Surface surface, int flags, String uniqueId) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800751 synchronized (mSyncRoot) {
752 if (mVirtualDisplayAdapter == null) {
753 Slog.w(TAG, "Rejecting request to create private virtual display "
754 + "because the virtual display adapter is not available.");
755 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700756 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800757
758 DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked(
Santos Cordonee8931e2017-04-05 10:31:15 -0700759 callback, projection, callingUid, packageName, name, width, height, densityDpi,
760 surface, flags, uniqueId);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800761 if (device == null) {
762 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700763 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700764
Jeff Brown4ccb8232014-01-16 22:16:42 -0800765 handleDisplayDeviceAddedLocked(device);
766 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
767 if (display != null) {
768 return display.getDisplayIdLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700769 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800770
771 // Something weird happened and the logical display was not created.
772 Slog.w(TAG, "Rejecting request to create virtual display "
773 + "because the logical display was not created.");
Michael Wright75ee9fc2014-09-01 19:55:22 -0700774 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800775 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700776 }
777 return -1;
778 }
779
Michael Wright01e840f2014-06-26 16:03:25 -0700780 private void resizeVirtualDisplayInternal(IBinder appToken,
781 int width, int height, int densityDpi) {
782 synchronized (mSyncRoot) {
783 if (mVirtualDisplayAdapter == null) {
784 return;
785 }
786
787 mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi);
788 }
789 }
790
Jeff Brown92207df2014-04-16 13:16:07 -0700791 private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) {
792 synchronized (mSyncRoot) {
793 if (mVirtualDisplayAdapter == null) {
794 return;
795 }
796
797 mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface);
798 }
799 }
800
Jeff Brown4ccb8232014-01-16 22:16:42 -0800801 private void releaseVirtualDisplayInternal(IBinder appToken) {
802 synchronized (mSyncRoot) {
803 if (mVirtualDisplayAdapter == null) {
804 return;
Jeff Browna506a6e2013-06-04 00:02:38 -0700805 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700806
Jeff Brown4ccb8232014-01-16 22:16:42 -0800807 DisplayDevice device =
808 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
809 if (device != null) {
810 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700811 }
812 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700813 }
814
chaviwda4c6942018-11-07 15:52:56 -0800815 private void setVirtualDisplayStateInternal(IBinder appToken, boolean isOn) {
816 synchronized (mSyncRoot) {
817 if (mVirtualDisplayAdapter == null) {
818 return;
819 }
820
821 mVirtualDisplayAdapter.setVirtualDisplayStateLocked(appToken, isOn);
822 }
823 }
824
Santos Cordonc22c5632017-06-21 16:03:49 -0700825 private void registerDefaultDisplayAdapters() {
826 // Register default display adapters.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700827 synchronized (mSyncRoot) {
Santos Cordonc22c5632017-06-21 16:03:49 -0700828 // main display adapter
Mike Lockwoode63f6f72013-11-15 11:01:47 -0800829 registerDisplayAdapterLocked(new LocalDisplayAdapter(
830 mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
Santos Cordonc22c5632017-06-21 16:03:49 -0700831
832 // Standalone VR devices rely on a virtual display as their primary display for
833 // 2D UI. We register virtual display adapter along side the main display adapter
834 // here so that it is ready by the time the system sends the home Intent for
835 // early apps like SetupWizard/Launcher. In particular, SUW is displayed using
836 // the virtual display inside VR before any VR-specific apps even run.
837 mVirtualDisplayAdapter = mInjector.getVirtualDisplayAdapter(mSyncRoot, mContext,
838 mHandler, mDisplayAdapterListener);
839 if (mVirtualDisplayAdapter != null) {
840 registerDisplayAdapterLocked(mVirtualDisplayAdapter);
841 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700842 }
843 }
844
845 private void registerAdditionalDisplayAdapters() {
846 synchronized (mSyncRoot) {
847 if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700848 registerOverlayDisplayAdapterLocked();
849 registerWifiDisplayAdapterLocked();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700850 }
851 }
852 }
853
Jeff Brown89d55462012-09-19 11:33:42 -0700854 private void registerOverlayDisplayAdapterLocked() {
855 registerDisplayAdapterLocked(new OverlayDisplayAdapter(
856 mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler));
857 }
858
859 private void registerWifiDisplayAdapterLocked() {
860 if (mContext.getResources().getBoolean(
Jeff Brownbbd28a22012-09-20 16:47:15 -0700861 com.android.internal.R.bool.config_enableWifiDisplay)
862 || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) {
Jeff Brown89d55462012-09-19 11:33:42 -0700863 mWifiDisplayAdapter = new WifiDisplayAdapter(
864 mSyncRoot, mContext, mHandler, mDisplayAdapterListener,
865 mPersistentDataStore);
866 registerDisplayAdapterLocked(mWifiDisplayAdapter);
867 }
868 }
869
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700870 private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
871 // In safe mode, we disable non-essential display adapters to give the user
872 // an opportunity to fix broken settings or other problems that might affect
873 // system stability.
874 // In only-core mode, we disable non-essential display adapters to minimize
875 // the number of dependencies that are started while in this mode and to
876 // prevent problems that might occur due to the device being encrypted.
877 return !mSafeMode && !mOnlyCore;
878 }
879
880 private void registerDisplayAdapterLocked(DisplayAdapter adapter) {
881 mDisplayAdapters.add(adapter);
882 adapter.registerLocked();
883 }
884
Jeff Brownbd6e1502012-08-28 03:27:37 -0700885 private void handleDisplayDeviceAdded(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700886 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700887 handleDisplayDeviceAddedLocked(device);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700888 }
889 }
890
Jeff Browna506a6e2013-06-04 00:02:38 -0700891 private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700892 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700893 if (mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700894 Slog.w(TAG, "Attempted to add already added display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700895 return;
896 }
897
Jeff Brown10acf6d2015-04-14 14:20:47 -0700898 Slog.i(TAG, "Display device added: " + info);
899 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700900
901 mDisplayDevices.add(device);
Michael Wright1c9977b2016-07-12 13:30:10 -0700902 LogicalDisplay display = addLogicalDisplayLocked(device);
Jeff Brown0033a862014-10-08 12:06:39 -0700903 Runnable work = updateDisplayStateLocked(device);
904 if (work != null) {
905 work.run();
906 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700907 scheduleTraversalLocked(false);
908 }
909
Jeff Brownbd6e1502012-08-28 03:27:37 -0700910 private void handleDisplayDeviceChanged(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700911 synchronized (mSyncRoot) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700912 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700913 if (!mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700914 Slog.w(TAG, "Attempted to change non-existent display device: " + info);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700915 return;
916 }
917
Jeff Brown10acf6d2015-04-14 14:20:47 -0700918 int diff = device.mDebugLastLoggedDeviceInfo.diff(info);
919 if (diff == DisplayDeviceInfo.DIFF_STATE) {
920 Slog.i(TAG, "Display device changed state: \"" + info.name
921 + "\", " + Display.stateToString(info.state));
922 } else if (diff != 0) {
923 Slog.i(TAG, "Display device changed: " + info);
924 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700925 if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) {
926 try {
927 mPersistentDataStore.setColorMode(device, info.colorMode);
928 } finally {
929 mPersistentDataStore.saveIfNeeded();
930 }
931 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700932 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browne87bf032012-09-20 18:30:13 -0700933
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700934 device.applyPendingDisplayDeviceInfoChangesLocked();
935 if (updateLogicalDisplaysLocked()) {
Craig Mautner65d11b32012-10-01 13:59:52 -0700936 scheduleTraversalLocked(false);
Jeff Brown64a55af2012-08-26 02:47:39 -0700937 }
938 }
939 }
940
Jeff Brownbd6e1502012-08-28 03:27:37 -0700941 private void handleDisplayDeviceRemoved(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700942 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700943 handleDisplayDeviceRemovedLocked(device);
944 }
945 }
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700946
Jeff Browna506a6e2013-06-04 00:02:38 -0700947 private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700948 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700949 if (!mDisplayDevices.remove(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700950 Slog.w(TAG, "Attempted to remove non-existent display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700951 return;
952 }
953
Jeff Brown10acf6d2015-04-14 14:20:47 -0700954 Slog.i(TAG, "Display device removed: " + info);
955 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700956
Jeff Browna506a6e2013-06-04 00:02:38 -0700957 updateLogicalDisplaysLocked();
958 scheduleTraversalLocked(false);
959 }
960
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200961 private void handleLogicalDisplayChanged(int displayId, @NonNull LogicalDisplay display) {
962 if (displayId == Display.DEFAULT_DISPLAY) {
963 recordTopInsetLocked(display);
964 }
965 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
966 }
967
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700968 private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700969 final int count = mDisplayDevices.size();
970 for (int i = 0; i < count; i++) {
971 DisplayDevice device = mDisplayDevices.get(i);
Jeff Browne75926d2014-09-18 15:24:49 -0700972 Runnable runnable = updateDisplayStateLocked(device);
973 if (runnable != null) {
974 workQueue.add(runnable);
975 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700976 }
977 }
978
Jeff Browne75926d2014-09-18 15:24:49 -0700979 private Runnable updateDisplayStateLocked(DisplayDevice device) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700980 // Blank or unblank the display immediately to match the state requested
Jeff Brown037c33e2014-04-09 00:31:55 -0700981 // by the display power controller (if known).
Jeff Browna506a6e2013-06-04 00:02:38 -0700982 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
983 if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700984 return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700985 }
Jeff Browne75926d2014-09-18 15:24:49 -0700986 return null;
Craig Mautner4f67ba62012-08-02 11:23:00 -0700987 }
988
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700989 // Adds a new logical display based on the given display device.
990 // Sends notifications if needed.
Michael Wright1c9977b2016-07-12 13:30:10 -0700991 private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700992 DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
993 boolean isDefault = (deviceInfo.flags
994 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
995 if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
996 Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
997 isDefault = false;
998 }
999
Jeff Brown27f1d672012-10-17 18:32:34 -07001000 if (!isDefault && mSingleDisplayDemoMode) {
1001 Slog.i(TAG, "Not creating a logical display for a secondary display "
1002 + " because single display demo mode is enabled: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -07001003 return null;
Jeff Brown27f1d672012-10-17 18:32:34 -07001004 }
1005
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001006 final int displayId = assignDisplayIdLocked(isDefault);
1007 final int layerStack = assignLayerStackLocked(displayId);
1008
Jeff Brownd728bf52012-09-08 18:05:28 -07001009 LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001010 display.updateLocked(mDisplayDevices);
1011 if (!display.isValidLocked()) {
1012 // This should never happen currently.
1013 Slog.w(TAG, "Ignoring display device because the logical display "
1014 + "created from it was not considered valid: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -07001015 return null;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001016 }
1017
Michael Wrighteedcbf12017-08-16 23:14:54 +01001018 configureColorModeLocked(display, device);
1019 if (isDefault) {
1020 recordStableDisplayStatsIfNeededLocked(display);
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001021 recordTopInsetLocked(display);
Michael Wrighteedcbf12017-08-16 23:14:54 +01001022 }
1023
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001024 mLogicalDisplays.put(displayId, display);
1025
1026 // Wake up waitForDefaultDisplay.
1027 if (isDefault) {
1028 mSyncRoot.notifyAll();
1029 }
1030
1031 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
Michael Wright1c9977b2016-07-12 13:30:10 -07001032 return display;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001033 }
1034
1035 private int assignDisplayIdLocked(boolean isDefault) {
1036 return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++;
1037 }
1038
1039 private int assignLayerStackLocked(int displayId) {
1040 // Currently layer stacks and display ids are the same.
1041 // This need not be the case.
1042 return displayId;
1043 }
1044
Michael Wrighteedcbf12017-08-16 23:14:54 +01001045 private void configureColorModeLocked(LogicalDisplay display, DisplayDevice device) {
1046 if (display.getPrimaryDisplayDeviceLocked() == device) {
1047 int colorMode = mPersistentDataStore.getColorMode(device);
1048 if (colorMode == Display.COLOR_MODE_INVALID) {
1049 if ((device.getDisplayDeviceInfoLocked().flags
1050 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
1051 colorMode = mDefaultDisplayDefaultColorMode;
1052 } else {
1053 colorMode = Display.COLOR_MODE_DEFAULT;
1054 }
1055 }
1056 display.setRequestedColorModeLocked(colorMode);
1057 }
1058 }
1059
1060 // If we've never recorded stable device stats for this device before and they aren't
1061 // explicitly configured, go ahead and record the stable device stats now based on the status
1062 // of the default display at first boot.
1063 private void recordStableDisplayStatsIfNeededLocked(LogicalDisplay d) {
1064 if (mStableDisplaySize.x <= 0 && mStableDisplaySize.y <= 0) {
1065 DisplayInfo info = d.getDisplayInfoLocked();
1066 setStableDisplaySizeLocked(info.getNaturalWidth(), info.getNaturalHeight());
1067 }
1068 }
1069
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001070 private void recordTopInsetLocked(@Nullable LogicalDisplay d) {
Winson72dbe7e2019-04-29 14:55:30 -07001071 // We must only persist the inset after boot has completed, otherwise we will end up
1072 // overwriting the persisted value before the masking flag has been loaded from the
1073 // resource overlay.
1074 if (!mSystemReady || d == null) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001075 return;
1076 }
1077 int topInset = d.getInsets().top;
1078 if (topInset == mDefaultDisplayTopInset) {
1079 return;
1080 }
1081 mDefaultDisplayTopInset = topInset;
1082 SystemProperties.set(PROP_DEFAULT_DISPLAY_TOP_INSET, Integer.toString(topInset));
1083 }
1084
Michael Wrighteedcbf12017-08-16 23:14:54 +01001085 private void setStableDisplaySizeLocked(int width, int height) {
1086 mStableDisplaySize = new Point(width, height);
1087 try {
1088 mPersistentDataStore.setStableDisplaySize(mStableDisplaySize);
1089 } finally {
1090 mPersistentDataStore.saveIfNeeded();
1091 }
1092 }
1093
Dan Gittik122df862018-03-28 16:59:22 +01001094 @VisibleForTesting
1095 Curve getMinimumBrightnessCurveInternal() {
1096 return mMinimumBrightnessCurve;
1097 }
1098
Peiyong Lin277eaff2019-01-16 16:18:22 -08001099 int getPreferredWideGamutColorSpaceIdInternal() {
1100 return mWideColorSpace.getId();
1101 }
1102
Michael Wrighteef0e132017-11-21 17:57:52 +00001103 private void setBrightnessConfigurationForUserInternal(
Dan Gittik7a32fba2018-03-28 12:19:38 +01001104 @Nullable BrightnessConfiguration c, @UserIdInt int userId,
Kenny Guy05ce8092018-01-17 13:44:20 +00001105 @Nullable String packageName) {
Dan Gittik122df862018-03-28 16:59:22 +01001106 validateBrightnessConfiguration(c);
Michael Wrighteef0e132017-11-21 17:57:52 +00001107 final int userSerial = getUserManager().getUserSerialNumber(userId);
1108 synchronized (mSyncRoot) {
1109 try {
Kenny Guy05ce8092018-01-17 13:44:20 +00001110 mPersistentDataStore.setBrightnessConfigurationForUser(c, userSerial,
1111 packageName);
Michael Wrighteef0e132017-11-21 17:57:52 +00001112 } finally {
1113 mPersistentDataStore.saveIfNeeded();
1114 }
1115 if (userId == mCurrentUserId) {
1116 mDisplayPowerController.setBrightnessConfiguration(c);
1117 }
1118 }
1119 }
1120
Dan Gittik122df862018-03-28 16:59:22 +01001121 @VisibleForTesting
1122 void validateBrightnessConfiguration(BrightnessConfiguration config) {
1123 if (config == null) {
1124 return;
1125 }
1126 if (isBrightnessConfigurationTooDark(config)) {
1127 throw new IllegalArgumentException("brightness curve is too dark");
1128 }
1129 }
1130
1131 private boolean isBrightnessConfigurationTooDark(BrightnessConfiguration config) {
1132 Pair<float[], float[]> curve = config.getCurve();
1133 float[] lux = curve.first;
1134 float[] nits = curve.second;
1135 for (int i = 0; i < lux.length; i++) {
1136 if (nits[i] < mMinimumBrightnessSpline.interpolate(lux[i])) {
1137 return true;
1138 }
1139 }
1140 return false;
1141 }
1142
Michael Wrighteef0e132017-11-21 17:57:52 +00001143 private void loadBrightnessConfiguration() {
1144 synchronized (mSyncRoot) {
1145 final int userSerial = getUserManager().getUserSerialNumber(mCurrentUserId);
1146 BrightnessConfiguration config =
1147 mPersistentDataStore.getBrightnessConfiguration(userSerial);
1148 mDisplayPowerController.setBrightnessConfiguration(config);
1149 }
1150 }
1151
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001152 // Updates all existing logical displays given the current set of display devices.
1153 // Removes invalid logical displays.
1154 // Sends notifications if needed.
1155 private boolean updateLogicalDisplaysLocked() {
1156 boolean changed = false;
1157 for (int i = mLogicalDisplays.size(); i-- > 0; ) {
1158 final int displayId = mLogicalDisplays.keyAt(i);
1159 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1160
1161 mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
1162 display.updateLocked(mDisplayDevices);
1163 if (!display.isValidLocked()) {
1164 mLogicalDisplays.removeAt(i);
1165 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
1166 changed = true;
1167 } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001168 handleLogicalDisplayChanged(displayId, display);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001169 changed = true;
1170 }
1171 }
1172 return changed;
1173 }
1174
Robert Carrae606b42018-02-15 15:36:23 -08001175 private void performTraversalLocked(SurfaceControl.Transaction t) {
Jeff Brownd728bf52012-09-08 18:05:28 -07001176 // Clear all viewports before configuring displays so that we can keep
1177 // track of which ones we have configured.
1178 clearViewportsLocked();
1179
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001180 // Configure each display device.
1181 final int count = mDisplayDevices.size();
1182 for (int i = 0; i < count; i++) {
1183 DisplayDevice device = mDisplayDevices.get(i);
Robert Carrae606b42018-02-15 15:36:23 -08001184 configureDisplayLocked(t, device);
1185 device.performTraversalLocked(t);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001186 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001187
1188 // Tell the input system about these new viewports.
Jeff Brown4ccb8232014-01-16 22:16:42 -08001189 if (mInputManagerInternal != null) {
Jeff Brownd728bf52012-09-08 18:05:28 -07001190 mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
1191 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001192 }
1193
Michael Wright3f145a22014-07-22 19:46:03 -07001194 private void setDisplayPropertiesInternal(int displayId, boolean hasContent,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001195 float requestedRefreshRate, int requestedModeId, boolean requestedMinimalPostProcessing,
1196 boolean inTraversal) {
Craig Mautner722285e2012-09-07 13:55:58 -07001197 synchronized (mSyncRoot) {
1198 LogicalDisplay display = mLogicalDisplays.get(displayId);
Michael Wright3f145a22014-07-22 19:46:03 -07001199 if (display == null) {
1200 return;
1201 }
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001202
1203 boolean shouldScheduleTraversal = false;
1204
Michael Wright3f145a22014-07-22 19:46:03 -07001205 if (display.hasContentLocked() != hasContent) {
Jeff Brown33041bd2013-08-02 21:11:14 -07001206 if (DEBUG) {
1207 Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
1208 + "hasContent=" + hasContent + ", inTraversal=" + inTraversal);
1209 }
1210
Craig Mautner722285e2012-09-07 13:55:58 -07001211 display.setHasContentLocked(hasContent);
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001212 shouldScheduleTraversal = true;
Craig Mautner722285e2012-09-07 13:55:58 -07001213 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001214 if (requestedModeId == 0 && requestedRefreshRate != 0) {
1215 // Scan supported modes returned by display.getInfo() to find a mode with the same
1216 // size as the default display mode but with the specified refresh rate instead.
1217 requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate(
1218 requestedRefreshRate);
1219 }
Michael Wrighta3dab232019-02-22 16:54:21 +00001220 mDisplayModeDirector.getAppRequestObserver().setAppRequestedMode(
1221 displayId, requestedModeId);
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001222
1223
1224 if (display.getDisplayInfoLocked().minimalPostProcessingSupported
1225 && (display.getRequestedMinimalPostProcessingLocked()
1226 != requestedMinimalPostProcessing)) {
1227
1228 display.setRequestedMinimalPostProcessingLocked(requestedMinimalPostProcessing);
1229
1230 shouldScheduleTraversal = true;
1231 }
1232
1233 if (shouldScheduleTraversal) {
1234 scheduleTraversalLocked(inTraversal);
1235 }
Craig Mautner722285e2012-09-07 13:55:58 -07001236 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001237 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001238
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08001239 private void setDisplayOffsetsInternal(int displayId, int x, int y) {
1240 synchronized (mSyncRoot) {
1241 LogicalDisplay display = mLogicalDisplays.get(displayId);
1242 if (display == null) {
1243 return;
1244 }
1245 if (display.getDisplayOffsetXLocked() != x
1246 || display.getDisplayOffsetYLocked() != y) {
1247 if (DEBUG) {
1248 Slog.d(TAG, "Display " + displayId + " burn-in offset set to ("
1249 + x + ", " + y + ")");
1250 }
1251 display.setDisplayOffsetsLocked(x, y);
1252 scheduleTraversalLocked(false);
1253 }
1254 }
1255 }
1256
Sam Lin4c3ac2b2019-02-18 04:50:26 -08001257 private void setDisplayScalingDisabledInternal(int displayId, boolean disable) {
1258 synchronized (mSyncRoot) {
1259 final LogicalDisplay display = mLogicalDisplays.get(displayId);
1260 if (display == null) {
1261 return;
1262 }
1263 if (display.isDisplayScalingDisabled() != disable) {
1264 if (DEBUG) {
1265 Slog.d(TAG, "Display " + displayId + " content scaling disabled = " + disable);
1266 }
1267 display.setDisplayScalingDisabledLocked(disable);
1268 scheduleTraversalLocked(false);
1269 }
1270 }
1271 }
1272
Andrii Kulianfb1bf692017-01-17 11:17:34 -08001273 // Updates the lists of UIDs that are present on displays.
1274 private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) {
1275 synchronized (mSyncRoot) {
1276 mDisplayAccessUIDs.clear();
1277 for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) {
1278 mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i),
1279 newDisplayAccessUIDs.valueAt(i));
1280 }
1281 }
1282 }
1283
1284 // Checks if provided UID's content is present on the display and UID has access to it.
1285 private boolean isUidPresentOnDisplayInternal(int uid, int displayId) {
1286 synchronized (mSyncRoot) {
1287 final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId);
1288 return displayUIDs != null && displayUIDs.indexOf(uid) != -1;
1289 }
1290 }
1291
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001292 @Nullable
1293 private IBinder getDisplayToken(int displayId) {
1294 synchronized (mSyncRoot) {
1295 final LogicalDisplay display = mLogicalDisplays.get(displayId);
1296 if (display != null) {
1297 final DisplayDevice device = display.getPrimaryDisplayDeviceLocked();
1298 if (device != null) {
1299 return device.getDisplayTokenLocked();
1300 }
1301 }
1302 }
1303
1304 return null;
1305 }
1306
Robert Carr66b5664f2019-04-02 14:18:56 -07001307 private SurfaceControl.ScreenshotGraphicBuffer screenshotInternal(int displayId) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001308 final IBinder token = getDisplayToken(displayId);
1309 if (token == null) {
Robert Carr66b5664f2019-04-02 14:18:56 -07001310 return null;
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001311 }
Robert Carr66b5664f2019-04-02 14:18:56 -07001312 return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(
Peiyong Line3e5efd2019-03-21 20:59:47 +00001313 token, new Rect(), 0 /* width */, 0 /* height */,
1314 false /* useIdentityTransform */, 0 /* rotation */);
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001315 }
1316
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001317 @VisibleForTesting
1318 DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributesInternal(
1319 int displayId) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001320 final IBinder token = getDisplayToken(displayId);
1321 if (token == null) {
1322 return null;
1323 }
1324 return SurfaceControl.getDisplayedContentSamplingAttributes(token);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001325 }
1326
1327 @VisibleForTesting
1328 boolean setDisplayedContentSamplingEnabledInternal(
1329 int displayId, boolean enable, int componentMask, int maxFrames) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001330 final IBinder token = getDisplayToken(displayId);
1331 if (token == null) {
1332 return false;
1333 }
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001334 return SurfaceControl.setDisplayedContentSamplingEnabled(
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001335 token, enable, componentMask, maxFrames);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001336 }
1337
1338 @VisibleForTesting
1339 DisplayedContentSample getDisplayedContentSampleInternal(int displayId,
1340 long maxFrames, long timestamp) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001341 final IBinder token = getDisplayToken(displayId);
1342 if (token == null) {
1343 return null;
1344 }
1345 return SurfaceControl.getDisplayedContentSample(token, maxFrames, timestamp);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001346 }
1347
Santos Cordonc4fd8e62019-12-18 13:01:05 +00001348 void resetBrightnessConfiguration() {
1349 setBrightnessConfigurationForUserInternal(null, mContext.getUserId(),
1350 mContext.getPackageName());
1351 }
1352
1353 void setAutoBrightnessLoggingEnabled(boolean enabled) {
1354 if (mDisplayPowerController != null) {
1355 synchronized (mSyncRoot) {
1356 mDisplayPowerController.setAutoBrightnessLoggingEnabled(enabled);
1357 }
1358 }
1359 }
1360
1361 void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) {
1362 if (mDisplayPowerController != null) {
1363 synchronized (mSyncRoot) {
1364 mDisplayPowerController.setDisplayWhiteBalanceLoggingEnabled(enabled);
1365 }
1366 }
1367 }
1368
1369 void setAmbientColorTemperatureOverride(float cct) {
1370 if (mDisplayPowerController != null) {
1371 synchronized (mSyncRoot) {
1372 mDisplayPowerController.setAmbientColorTemperatureOverride(cct);
1373 }
1374 }
1375 }
1376
Ana Kruleca74a8642019-11-14 00:51:00 +01001377 private void onDesiredDisplayModeSpecsChangedInternal() {
Michael Wrighta3dab232019-02-22 16:54:21 +00001378 boolean changed = false;
1379 synchronized (mSyncRoot) {
1380 final int count = mLogicalDisplays.size();
1381 for (int i = 0; i < count; i++) {
1382 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1383 int displayId = mLogicalDisplays.keyAt(i);
Ana Kruleca74a8642019-11-14 00:51:00 +01001384 DisplayModeDirector.DesiredDisplayModeSpecs desiredDisplayModeSpecs =
1385 mDisplayModeDirector.getDesiredDisplayModeSpecs(displayId);
1386 DisplayModeDirector.DesiredDisplayModeSpecs existingDesiredDisplayModeSpecs =
1387 display.getDesiredDisplayModeSpecsLocked();
1388 if (DEBUG) {
1389 Slog.i(TAG,
1390 "Comparing display specs: " + desiredDisplayModeSpecs
1391 + ", existing: " + existingDesiredDisplayModeSpecs);
1392 }
1393 if (!desiredDisplayModeSpecs.equals(existingDesiredDisplayModeSpecs)) {
1394 display.setDesiredDisplayModeSpecsLocked(desiredDisplayModeSpecs);
Michael Wrighta3dab232019-02-22 16:54:21 +00001395 changed = true;
1396 }
1397 }
1398 if (changed) {
1399 scheduleTraversalLocked(false);
1400 }
1401 }
1402 }
1403
Jeff Brownd728bf52012-09-08 18:05:28 -07001404 private void clearViewportsLocked() {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001405 mViewports.clear();
Craig Mautner722285e2012-09-07 13:55:58 -07001406 }
1407
Robert Carrae606b42018-02-15 15:36:23 -08001408 private void configureDisplayLocked(SurfaceControl.Transaction t, DisplayDevice device) {
Jeff Brownd14c8c92014-01-07 18:13:09 -08001409 final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
1410 final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;
Jeff Browna506a6e2013-06-04 00:02:38 -07001411
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001412 // Find the logical display that the display device is showing.
Jeff Brownd14c8c92014-01-07 18:13:09 -08001413 // Certain displays only ever show their own content.
Craig Mautner722285e2012-09-07 13:55:58 -07001414 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
Jeff Brownd14c8c92014-01-07 18:13:09 -08001415 if (!ownContent) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001416 if (display != null && !display.hasContentLocked()) {
1417 // If the display does not have any content of its own, then
1418 // automatically mirror the default logical display contents.
1419 display = null;
1420 }
1421 if (display == null) {
1422 display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY);
1423 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001424 }
1425
1426 // Apply the logical display configuration to the display device.
1427 if (display == null) {
1428 // TODO: no logical display for the device, blank it
Jeff Brownd728bf52012-09-08 18:05:28 -07001429 Slog.w(TAG, "Missing logical display to use for physical display device: "
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001430 + device.getDisplayDeviceInfoLocked());
Jeff Brownd728bf52012-09-08 18:05:28 -07001431 return;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001432 }
Robert Carrae606b42018-02-15 15:36:23 -08001433 display.configureDisplayLocked(t, device, info.state == Display.STATE_OFF);
Arthur Hung41e81e72018-10-31 18:04:56 +08001434 final int viewportType;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001435 // Update the corresponding viewport.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001436 if ((info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
Arthur Hung41e81e72018-10-31 18:04:56 +08001437 viewportType = VIEWPORT_INTERNAL;
1438 } else if (info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
1439 viewportType = VIEWPORT_EXTERNAL;
1440 } else if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL
1441 && !TextUtils.isEmpty(info.uniqueId)) {
1442 viewportType = VIEWPORT_VIRTUAL;
1443 } else {
Arthur Hung46c4e582019-02-12 15:55:28 +08001444 Slog.i(TAG, "Display " + info + " does not support input device matching.");
Arthur Hung41e81e72018-10-31 18:04:56 +08001445 return;
Jeff Brownd728bf52012-09-08 18:05:28 -07001446 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001447
Arthur Hung41e81e72018-10-31 18:04:56 +08001448 populateViewportLocked(viewportType, display.getDisplayIdLocked(), device, info.uniqueId);
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001449 }
1450
1451 /**
1452 * Get internal or external viewport. Create it if does not currently exist.
1453 * @param viewportType - either INTERNAL or EXTERNAL
1454 * @return the viewport with the requested type
1455 */
Arthur Hung41e81e72018-10-31 18:04:56 +08001456 private DisplayViewport getViewportLocked(int viewportType, String uniqueId) {
1457 if (viewportType != VIEWPORT_INTERNAL && viewportType != VIEWPORT_EXTERNAL
1458 && viewportType != VIEWPORT_VIRTUAL) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001459 Slog.wtf(TAG, "Cannot call getViewportByTypeLocked for type "
1460 + DisplayViewport.typeToString(viewportType));
1461 return null;
1462 }
Arthur Hung41e81e72018-10-31 18:04:56 +08001463
1464 // Only allow a single INTERNAL or EXTERNAL viewport by forcing their uniqueIds
1465 // to be identical (in particular, empty).
1466 // TODO (b/116824030) allow multiple EXTERNAL viewports and remove this function.
1467 if (viewportType != VIEWPORT_VIRTUAL) {
1468 uniqueId = "";
1469 }
1470
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001471 DisplayViewport viewport;
1472 final int count = mViewports.size();
1473 for (int i = 0; i < count; i++) {
1474 viewport = mViewports.get(i);
Arthur Hung41e81e72018-10-31 18:04:56 +08001475 if (viewport.type == viewportType && uniqueId.equals(viewport.uniqueId)) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001476 return viewport;
1477 }
1478 }
1479
Arthur Hung41e81e72018-10-31 18:04:56 +08001480 // Creates the viewport if none exists.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001481 viewport = new DisplayViewport();
1482 viewport.type = viewportType;
Arthur Hung41e81e72018-10-31 18:04:56 +08001483 viewport.uniqueId = uniqueId;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001484 mViewports.add(viewport);
1485 return viewport;
1486 }
1487
Arthur Hung41e81e72018-10-31 18:04:56 +08001488 private void populateViewportLocked(int viewportType,
1489 int displayId, DisplayDevice device, String uniqueId) {
1490 final DisplayViewport viewport = getViewportLocked(viewportType, uniqueId);
Jeff Brownd728bf52012-09-08 18:05:28 -07001491 device.populateViewportLocked(viewport);
Arthur Hung41e81e72018-10-31 18:04:56 +08001492 viewport.valid = true;
1493 viewport.displayId = displayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001494 }
1495
1496 private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {
1497 final int count = mLogicalDisplays.size();
1498 for (int i = 0; i < count; i++) {
1499 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1500 if (display.getPrimaryDisplayDeviceLocked() == device) {
1501 return display;
1502 }
1503 }
1504 return null;
1505 }
1506
Jeff Brownbd6e1502012-08-28 03:27:37 -07001507 private void sendDisplayEventLocked(int displayId, int event) {
1508 Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
1509 mHandler.sendMessage(msg);
1510 }
1511
Robert Carrae606b42018-02-15 15:36:23 -08001512 // Requests that performTraversals be called at a
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001513 // later time to apply changes to surfaces and displays.
Craig Mautner65d11b32012-10-01 13:59:52 -07001514 private void scheduleTraversalLocked(boolean inTraversal) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001515 if (!mPendingTraversal && mWindowManagerInternal != null) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001516 mPendingTraversal = true;
Craig Mautner65d11b32012-10-01 13:59:52 -07001517 if (!inTraversal) {
1518 mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL);
1519 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001520 }
1521 }
1522
1523 // Runs on Handler thread.
1524 // Delivers display event notifications to callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001525 private void deliverDisplayEvent(int displayId, int event) {
1526 if (DEBUG) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001527 Slog.d(TAG, "Delivering display event: displayId="
1528 + displayId + ", event=" + event);
Jeff Brownfa25bf52012-07-23 19:26:30 -07001529 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001530
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001531 // Grab the lock and copy the callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001532 final int count;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001533 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001534 count = mCallbacks.size();
1535 mTempCallbacks.clear();
1536 for (int i = 0; i < count; i++) {
1537 mTempCallbacks.add(mCallbacks.valueAt(i));
Craig Mautner4f67ba62012-08-02 11:23:00 -07001538 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001539 }
Craig Mautner4f67ba62012-08-02 11:23:00 -07001540
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001541 // After releasing the lock, send the notifications out.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001542 for (int i = 0; i < count; i++) {
1543 mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event);
1544 }
1545 mTempCallbacks.clear();
Craig Mautner4f67ba62012-08-02 11:23:00 -07001546 }
1547
Michael Wrightc39d47a2014-07-08 18:07:36 -07001548 private IMediaProjectionManager getProjectionService() {
1549 if (mProjectionService == null) {
1550 IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE);
1551 mProjectionService = IMediaProjectionManager.Stub.asInterface(b);
1552 }
1553 return mProjectionService;
1554 }
1555
Michael Wrighteef0e132017-11-21 17:57:52 +00001556 private UserManager getUserManager() {
1557 return mContext.getSystemService(UserManager.class);
1558 }
1559
Jeff Brown4ccb8232014-01-16 22:16:42 -08001560 private void dumpInternal(PrintWriter pw) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001561 pw.println("DISPLAY MANAGER (dumpsys display)");
Jeff Brownfa25bf52012-07-23 19:26:30 -07001562
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001563 synchronized (mSyncRoot) {
Jeff Brown9e316a12012-10-08 19:17:06 -07001564 pw.println(" mOnlyCode=" + mOnlyCore);
1565 pw.println(" mSafeMode=" + mSafeMode);
1566 pw.println(" mPendingTraversal=" + mPendingTraversal);
Jeff Brown037c33e2014-04-09 00:31:55 -07001567 pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState));
Jeff Brown9e316a12012-10-08 19:17:06 -07001568 pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId);
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001569 pw.println(" mViewports=" + mViewports);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -07001570 pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode);
Jeff Brown27f1d672012-10-17 18:32:34 -07001571 pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
Jeff Brownce468a32013-11-21 16:42:03 -08001572 pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount);
Michael Wrighteedcbf12017-08-16 23:14:54 +01001573 pw.println(" mStableDisplaySize=" + mStableDisplaySize);
Kenny Guy2047db92019-02-21 13:04:05 +00001574 pw.println(" mMinimumBrightnessCurve=" + mMinimumBrightnessCurve);
Jeff Brown9e316a12012-10-08 19:17:06 -07001575
Jeff Brownbd6e1502012-08-28 03:27:37 -07001576 IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001577 ipw.increaseIndent();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001578
1579 pw.println();
1580 pw.println("Display Adapters: size=" + mDisplayAdapters.size());
Jeff Brown848c2dc2012-08-19 20:18:08 -07001581 for (DisplayAdapter adapter : mDisplayAdapters) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001582 pw.println(" " + adapter.getName());
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001583 adapter.dumpLocked(ipw);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001584 }
Craig Mautner9de49362012-08-02 14:30:30 -07001585
Jeff Brownbd6e1502012-08-28 03:27:37 -07001586 pw.println();
1587 pw.println("Display Devices: size=" + mDisplayDevices.size());
1588 for (DisplayDevice device : mDisplayDevices) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001589 pw.println(" " + device.getDisplayDeviceInfoLocked());
1590 device.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001591 }
1592
1593 final int logicalDisplayCount = mLogicalDisplays.size();
1594 pw.println();
1595 pw.println("Logical Displays: size=" + logicalDisplayCount);
1596 for (int i = 0; i < logicalDisplayCount; i++) {
1597 int displayId = mLogicalDisplays.keyAt(i);
1598 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1599 pw.println(" Display " + displayId + ":");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001600 display.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001601 }
Jeff Brownce468a32013-11-21 16:42:03 -08001602
Michael Wrighta3dab232019-02-22 16:54:21 +00001603 pw.println();
1604 mDisplayModeDirector.dump(pw);
1605
Jeff Brownce468a32013-11-21 16:42:03 -08001606 final int callbackCount = mCallbacks.size();
1607 pw.println();
1608 pw.println("Callbacks: size=" + callbackCount);
1609 for (int i = 0; i < callbackCount; i++) {
1610 CallbackRecord callback = mCallbacks.valueAt(i);
1611 pw.println(" " + i + ": mPid=" + callback.mPid
1612 + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
1613 }
Jeff Brownad9ef192014-04-08 17:26:30 -07001614
1615 if (mDisplayPowerController != null) {
1616 mDisplayPowerController.dump(pw);
1617 }
Michael Wright1c9977b2016-07-12 13:30:10 -07001618
1619 pw.println();
1620 mPersistentDataStore.dump(pw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001621 }
1622 }
1623
Dan Gittik122df862018-03-28 16:59:22 +01001624 private static float[] getFloatArray(TypedArray array) {
1625 int length = array.length();
1626 float[] floatArray = new float[length];
1627 for (int i = 0; i < length; i++) {
1628 floatArray[i] = array.getFloat(i, Float.NaN);
1629 }
1630 array.recycle();
1631 return floatArray;
1632 }
1633
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001634 /**
1635 * This is the object that everything in the display manager locks on.
1636 * We make it an inner class within the {@link DisplayManagerService} to so that it is
1637 * clear that the object belongs to the display manager service and that it is
1638 * a unique object with a special purpose.
1639 */
1640 public static final class SyncRoot {
1641 }
1642
Santos Cordonee8931e2017-04-05 10:31:15 -07001643 @VisibleForTesting
1644 static class Injector {
1645 VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context,
1646 Handler handler, DisplayAdapter.Listener displayAdapterListener) {
1647 return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener);
1648 }
Santos Cordonc22c5632017-06-21 16:03:49 -07001649
1650 long getDefaultDisplayDelayTimeout() {
1651 return WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
1652 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001653 }
1654
Alex Sakhartchouk879d24f2017-06-20 22:01:19 -04001655 @VisibleForTesting
1656 DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) {
1657 synchronized (mSyncRoot) {
1658 LogicalDisplay display = mLogicalDisplays.get(displayId);
1659 if (display != null) {
1660 DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked();
1661 return displayDevice.getDisplayDeviceInfoLocked();
1662 }
1663 return null;
1664 }
1665 }
1666
Jeff Brownbd6e1502012-08-28 03:27:37 -07001667 private final class DisplayManagerHandler extends Handler {
1668 public DisplayManagerHandler(Looper looper) {
1669 super(looper, null, true /*async*/);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001670 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001671
Jeff Brownbd6e1502012-08-28 03:27:37 -07001672 @Override
1673 public void handleMessage(Message msg) {
1674 switch (msg.what) {
Santos Cordonc22c5632017-06-21 16:03:49 -07001675 case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS:
1676 registerDefaultDisplayAdapters();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001677 break;
1678
1679 case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS:
1680 registerAdditionalDisplayAdapters();
1681 break;
1682
1683 case MSG_DELIVER_DISPLAY_EVENT:
1684 deliverDisplayEvent(msg.arg1, msg.arg2);
1685 break;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001686
1687 case MSG_REQUEST_TRAVERSAL:
Jeff Brown4ccb8232014-01-16 22:16:42 -08001688 mWindowManagerInternal.requestTraversalFromDisplayManager();
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001689 break;
Jeff Brownd728bf52012-09-08 18:05:28 -07001690
1691 case MSG_UPDATE_VIEWPORT: {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001692 final boolean changed;
Jeff Brownd728bf52012-09-08 18:05:28 -07001693 synchronized (mSyncRoot) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001694 changed = !mTempViewports.equals(mViewports);
1695 if (changed) {
1696 mTempViewports.clear();
1697 for (DisplayViewport d : mViewports) {
1698 mTempViewports.add(d.makeCopy());
1699 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001700 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001701 }
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001702 if (changed) {
1703 mInputManagerInternal.setDisplayViewports(mTempViewports);
1704 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001705 break;
1706 }
Kenny Guy22bd0442017-10-26 00:15:54 +01001707
Michael Wrighteef0e132017-11-21 17:57:52 +00001708 case MSG_LOAD_BRIGHTNESS_CONFIGURATION:
1709 loadBrightnessConfiguration();
1710 break;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001711 }
1712 }
1713 }
1714
1715 private final class DisplayAdapterListener implements DisplayAdapter.Listener {
1716 @Override
1717 public void onDisplayDeviceEvent(DisplayDevice device, int event) {
1718 switch (event) {
1719 case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED:
1720 handleDisplayDeviceAdded(device);
1721 break;
1722
1723 case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED:
1724 handleDisplayDeviceChanged(device);
1725 break;
1726
1727 case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED:
1728 handleDisplayDeviceRemoved(device);
1729 break;
1730 }
1731 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001732
1733 @Override
1734 public void onTraversalRequested() {
1735 synchronized (mSyncRoot) {
Craig Mautner65d11b32012-10-01 13:59:52 -07001736 scheduleTraversalLocked(false);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001737 }
1738 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001739 }
1740
1741 private final class CallbackRecord implements DeathRecipient {
Jeff Brownce468a32013-11-21 16:42:03 -08001742 public final int mPid;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001743 private final IDisplayManagerCallback mCallback;
1744
Jeff Brownce468a32013-11-21 16:42:03 -08001745 public boolean mWifiDisplayScanRequested;
1746
Jeff Brownbd6e1502012-08-28 03:27:37 -07001747 public CallbackRecord(int pid, IDisplayManagerCallback callback) {
1748 mPid = pid;
1749 mCallback = callback;
1750 }
1751
1752 @Override
1753 public void binderDied() {
1754 if (DEBUG) {
1755 Slog.d(TAG, "Display listener for pid " + mPid + " died.");
1756 }
Jeff Brownce468a32013-11-21 16:42:03 -08001757 onCallbackDied(this);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001758 }
1759
1760 public void notifyDisplayEventAsync(int displayId, int event) {
1761 try {
1762 mCallback.onDisplayEvent(displayId, event);
1763 } catch (RemoteException ex) {
1764 Slog.w(TAG, "Failed to notify process "
1765 + mPid + " that displays changed, assuming it died.", ex);
1766 binderDied();
1767 }
1768 }
1769 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001770
Santos Cordonee8931e2017-04-05 10:31:15 -07001771 @VisibleForTesting
1772 final class BinderService extends IDisplayManager.Stub {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001773 /**
1774 * Returns information about the specified logical display.
1775 *
1776 * @param displayId The logical display id.
lumarkec75b422019-01-07 15:58:38 +08001777 * @return The logical display info, return {@code null} if the display does not exist or
1778 * the calling UID isn't present on the display. The returned object must be treated as
1779 * immutable.
Jeff Brown4ccb8232014-01-16 22:16:42 -08001780 */
1781 @Override // Binder call
1782 public DisplayInfo getDisplayInfo(int displayId) {
1783 final int callingUid = Binder.getCallingUid();
1784 final long token = Binder.clearCallingIdentity();
1785 try {
1786 return getDisplayInfoInternal(displayId, callingUid);
1787 } finally {
1788 Binder.restoreCallingIdentity(token);
1789 }
1790 }
1791
1792 /**
1793 * Returns the list of all display ids.
1794 */
1795 @Override // Binder call
1796 public int[] getDisplayIds() {
1797 final int callingUid = Binder.getCallingUid();
1798 final long token = Binder.clearCallingIdentity();
1799 try {
1800 return getDisplayIdsInternal(callingUid);
1801 } finally {
1802 Binder.restoreCallingIdentity(token);
1803 }
1804 }
1805
lumarkec75b422019-01-07 15:58:38 +08001806 @Override // Binder call
1807 public boolean isUidPresentOnDisplay(int uid, int displayId) {
1808 final long token = Binder.clearCallingIdentity();
1809 try {
1810 return isUidPresentOnDisplayInternal(uid, displayId);
1811 } finally {
1812 Binder.restoreCallingIdentity(token);
1813 }
1814 }
1815
Michael Wrighteedcbf12017-08-16 23:14:54 +01001816 /**
1817 * Returns the stable device display size, in pixels.
1818 */
1819 @Override // Binder call
1820 public Point getStableDisplaySize() {
1821 final long token = Binder.clearCallingIdentity();
1822 try {
1823 return getStableDisplaySizeInternal();
1824 } finally {
1825 Binder.restoreCallingIdentity(token);
1826 }
1827 }
1828
Jeff Brown4ccb8232014-01-16 22:16:42 -08001829 @Override // Binder call
1830 public void registerCallback(IDisplayManagerCallback callback) {
1831 if (callback == null) {
1832 throw new IllegalArgumentException("listener must not be null");
1833 }
1834
1835 final int callingPid = Binder.getCallingPid();
1836 final long token = Binder.clearCallingIdentity();
1837 try {
1838 registerCallbackInternal(callback, callingPid);
1839 } finally {
1840 Binder.restoreCallingIdentity(token);
1841 }
1842 }
1843
1844 @Override // Binder call
1845 public void startWifiDisplayScan() {
1846 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1847 "Permission required to start wifi display scans");
1848
1849 final int callingPid = Binder.getCallingPid();
1850 final long token = Binder.clearCallingIdentity();
1851 try {
1852 startWifiDisplayScanInternal(callingPid);
1853 } finally {
1854 Binder.restoreCallingIdentity(token);
1855 }
1856 }
1857
1858 @Override // Binder call
1859 public void stopWifiDisplayScan() {
1860 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1861 "Permission required to stop wifi display scans");
1862
1863 final int callingPid = Binder.getCallingPid();
1864 final long token = Binder.clearCallingIdentity();
1865 try {
1866 stopWifiDisplayScanInternal(callingPid);
1867 } finally {
1868 Binder.restoreCallingIdentity(token);
1869 }
1870 }
1871
1872 @Override // Binder call
1873 public void connectWifiDisplay(String address) {
1874 if (address == null) {
1875 throw new IllegalArgumentException("address must not be null");
1876 }
1877 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1878 "Permission required to connect to a wifi display");
1879
1880 final long token = Binder.clearCallingIdentity();
1881 try {
1882 connectWifiDisplayInternal(address);
1883 } finally {
1884 Binder.restoreCallingIdentity(token);
1885 }
1886 }
1887
1888 @Override // Binder call
1889 public void disconnectWifiDisplay() {
1890 // This request does not require special permissions.
1891 // Any app can request disconnection from the currently active wifi display.
1892 // This exception should no longer be needed once wifi display control moves
1893 // to the media router service.
1894
1895 final long token = Binder.clearCallingIdentity();
1896 try {
1897 disconnectWifiDisplayInternal();
1898 } finally {
1899 Binder.restoreCallingIdentity(token);
1900 }
1901 }
1902
1903 @Override // Binder call
1904 public void renameWifiDisplay(String address, String alias) {
1905 if (address == null) {
1906 throw new IllegalArgumentException("address must not be null");
1907 }
1908 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1909 "Permission required to rename to a wifi display");
1910
1911 final long token = Binder.clearCallingIdentity();
1912 try {
1913 renameWifiDisplayInternal(address, alias);
1914 } finally {
1915 Binder.restoreCallingIdentity(token);
1916 }
1917 }
1918
1919 @Override // Binder call
1920 public void forgetWifiDisplay(String address) {
1921 if (address == null) {
1922 throw new IllegalArgumentException("address must not be null");
1923 }
1924 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1925 "Permission required to forget to a wifi display");
1926
1927 final long token = Binder.clearCallingIdentity();
1928 try {
1929 forgetWifiDisplayInternal(address);
1930 } finally {
1931 Binder.restoreCallingIdentity(token);
1932 }
1933 }
1934
1935 @Override // Binder call
1936 public void pauseWifiDisplay() {
1937 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1938 "Permission required to pause a wifi display session");
1939
1940 final long token = Binder.clearCallingIdentity();
1941 try {
1942 pauseWifiDisplayInternal();
1943 } finally {
1944 Binder.restoreCallingIdentity(token);
1945 }
1946 }
1947
1948 @Override // Binder call
1949 public void resumeWifiDisplay() {
1950 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1951 "Permission required to resume a wifi display session");
1952
1953 final long token = Binder.clearCallingIdentity();
1954 try {
1955 resumeWifiDisplayInternal();
1956 } finally {
1957 Binder.restoreCallingIdentity(token);
1958 }
1959 }
1960
1961 @Override // Binder call
1962 public WifiDisplayStatus getWifiDisplayStatus() {
1963 // This request does not require special permissions.
1964 // Any app can get information about available wifi displays.
1965
1966 final long token = Binder.clearCallingIdentity();
1967 try {
1968 return getWifiDisplayStatusInternal();
1969 } finally {
1970 Binder.restoreCallingIdentity(token);
1971 }
1972 }
1973
1974 @Override // Binder call
Michael Wright1c9977b2016-07-12 13:30:10 -07001975 public void requestColorMode(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +01001976 mContext.enforceCallingOrSelfPermission(
Michael Wright1c9977b2016-07-12 13:30:10 -07001977 Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE,
1978 "Permission required to change the display color mode");
Michael Wright58e829f2015-09-15 00:13:26 +01001979 final long token = Binder.clearCallingIdentity();
1980 try {
Michael Wright1c9977b2016-07-12 13:30:10 -07001981 requestColorModeInternal(displayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +01001982 } finally {
1983 Binder.restoreCallingIdentity(token);
1984 }
1985 }
1986
1987 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07001988 public int createVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001989 IMediaProjection projection, String packageName, String name,
Santos Cordonee8931e2017-04-05 10:31:15 -07001990 int width, int height, int densityDpi, Surface surface, int flags,
1991 String uniqueId) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001992 final int callingUid = Binder.getCallingUid();
1993 if (!validatePackageName(callingUid, packageName)) {
1994 throw new SecurityException("packageName must match the calling uid");
1995 }
Michael Wright75ee9fc2014-09-01 19:55:22 -07001996 if (callback == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001997 throw new IllegalArgumentException("appToken must not be null");
1998 }
1999 if (TextUtils.isEmpty(name)) {
2000 throw new IllegalArgumentException("name must be non-null and non-empty");
2001 }
2002 if (width <= 0 || height <= 0 || densityDpi <= 0) {
2003 throw new IllegalArgumentException("width, height, and densityDpi must be "
2004 + "greater than 0");
2005 }
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07002006 if (surface != null && surface.isSingleBuffered()) {
Pablo Ceballosaff2f942016-07-29 14:49:55 -07002007 throw new IllegalArgumentException("Surface can't be single-buffered");
2008 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07002009
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002010 if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
2011 flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
2012
2013 // Public displays can't be allowed to show content when locked.
Andrii Kulian7211d2e2017-01-27 15:58:05 -08002014 if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002015 throw new IllegalArgumentException(
2016 "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE");
2017 }
Michael Wright6720be42014-07-29 19:14:16 -07002018 }
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002019 if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) {
2020 flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
Michael Wright6720be42014-07-29 19:14:16 -07002021 }
2022
Michael Wrightc39d47a2014-07-08 18:07:36 -07002023 if (projection != null) {
2024 try {
2025 if (!getProjectionService().isValidMediaProjection(projection)) {
2026 throw new SecurityException("Invalid media projection");
2027 }
Michael Wright6720be42014-07-29 19:14:16 -07002028 flags = projection.applyVirtualDisplayFlags(flags);
Michael Wrightc39d47a2014-07-08 18:07:36 -07002029 } catch (RemoteException e) {
Michael Wright6720be42014-07-29 19:14:16 -07002030 throw new SecurityException("unable to validate media projection or flags");
Michael Wrightc39d47a2014-07-08 18:07:36 -07002031 }
2032 }
2033
Michael Wright6720be42014-07-29 19:14:16 -07002034 if (callingUid != Process.SYSTEM_UID &&
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002035 (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002036 if (!canProjectVideo(projection)) {
2037 throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
2038 + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate "
2039 + "MediaProjection token in order to create a screen sharing virtual "
2040 + "display.");
2041 }
2042 }
Santos Cordonb6992f22018-01-30 14:51:20 -08002043 if (callingUid != Process.SYSTEM_UID && (flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002044 if (!canProjectSecureVideo(projection)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002045 throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT "
Michael Wrightc39d47a2014-07-08 18:07:36 -07002046 + "or an appropriate MediaProjection token to create a "
2047 + "secure virtual display.");
Jeff Brown4ccb8232014-01-16 22:16:42 -08002048 }
2049 }
2050
Chilun67a379b2019-04-11 19:49:42 +08002051 // Sometimes users can have sensitive information in system decoration windows. An app
2052 // could create a virtual display with system decorations support and read the user info
2053 // from the surface.
2054 // We should only allow adding flag VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
2055 // to virtual displays that are owned by the system.
2056 if (callingUid != Process.SYSTEM_UID
2057 && (flags & VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0) {
2058 if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "createVirtualDisplay()")) {
2059 throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
2060 }
2061 }
2062
Jeff Brown4ccb8232014-01-16 22:16:42 -08002063 final long token = Binder.clearCallingIdentity();
2064 try {
Santos Cordonee8931e2017-04-05 10:31:15 -07002065 return createVirtualDisplayInternal(callback, projection, callingUid, packageName,
2066 name, width, height, densityDpi, surface, flags, uniqueId);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002067 } finally {
2068 Binder.restoreCallingIdentity(token);
2069 }
2070 }
2071
2072 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002073 public void resizeVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wright01e840f2014-06-26 16:03:25 -07002074 int width, int height, int densityDpi) {
Jeff Chang01baf6c2019-08-20 16:21:25 +08002075 if (width <= 0 || height <= 0 || densityDpi <= 0) {
2076 throw new IllegalArgumentException("width, height, and densityDpi must be "
2077 + "greater than 0");
2078 }
Michael Wright01e840f2014-06-26 16:03:25 -07002079 final long token = Binder.clearCallingIdentity();
2080 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002081 resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi);
Michael Wright01e840f2014-06-26 16:03:25 -07002082 } finally {
2083 Binder.restoreCallingIdentity(token);
2084 }
2085 }
2086
2087 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002088 public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) {
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07002089 if (surface != null && surface.isSingleBuffered()) {
2090 throw new IllegalArgumentException("Surface can't be single-buffered");
2091 }
Jeff Brown92207df2014-04-16 13:16:07 -07002092 final long token = Binder.clearCallingIdentity();
2093 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002094 setVirtualDisplaySurfaceInternal(callback.asBinder(), surface);
Jeff Brown92207df2014-04-16 13:16:07 -07002095 } finally {
2096 Binder.restoreCallingIdentity(token);
2097 }
2098 }
2099
2100 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002101 public void releaseVirtualDisplay(IVirtualDisplayCallback callback) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002102 final long token = Binder.clearCallingIdentity();
2103 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002104 releaseVirtualDisplayInternal(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -08002105 } finally {
2106 Binder.restoreCallingIdentity(token);
2107 }
2108 }
2109
2110 @Override // Binder call
chaviwda4c6942018-11-07 15:52:56 -08002111 public void setVirtualDisplayState(IVirtualDisplayCallback callback, boolean isOn) {
2112 final long token = Binder.clearCallingIdentity();
2113 try {
2114 setVirtualDisplayStateInternal(callback.asBinder(), isOn);
2115 } finally {
2116 Binder.restoreCallingIdentity(token);
2117 }
2118 }
2119
2120 @Override // Binder call
Jeff Brown4ccb8232014-01-16 22:16:42 -08002121 public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06002122 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jeff Brown4ccb8232014-01-16 22:16:42 -08002123
2124 final long token = Binder.clearCallingIdentity();
2125 try {
2126 dumpInternal(pw);
2127 } finally {
2128 Binder.restoreCallingIdentity(token);
2129 }
2130 }
2131
Kenny Guy22bd0442017-10-26 00:15:54 +01002132 @Override // Binder call
Kenny Guy29aa30e2017-11-30 13:43:46 +00002133 public ParceledListSlice<BrightnessChangeEvent> getBrightnessEvents(String callingPackage) {
Kenny Guy22bd0442017-10-26 00:15:54 +01002134 mContext.enforceCallingOrSelfPermission(
2135 Manifest.permission.BRIGHTNESS_SLIDER_USAGE,
2136 "Permission to read brightness events.");
Kenny Guy29aa30e2017-11-30 13:43:46 +00002137
2138 final int callingUid = Binder.getCallingUid();
2139 AppOpsManager appOpsManager = mContext.getSystemService(AppOpsManager.class);
Jeff Sharkeyd9311192018-04-16 16:50:34 +00002140 final int mode = appOpsManager.noteOp(AppOpsManager.OP_GET_USAGE_STATS,
Kenny Guy29aa30e2017-11-30 13:43:46 +00002141 callingUid, callingPackage);
2142 final boolean hasUsageStats;
2143 if (mode == AppOpsManager.MODE_DEFAULT) {
2144 // The default behavior here is to check if PackageManager has given the app
2145 // permission.
2146 hasUsageStats = mContext.checkCallingPermission(
2147 Manifest.permission.PACKAGE_USAGE_STATS)
2148 == PackageManager.PERMISSION_GRANTED;
2149 } else {
2150 hasUsageStats = mode == AppOpsManager.MODE_ALLOWED;
2151 }
2152
2153 final int userId = UserHandle.getUserId(callingUid);
Kenny Guy22bd0442017-10-26 00:15:54 +01002154 final long token = Binder.clearCallingIdentity();
2155 try {
Michael Wright144aac92017-12-21 18:37:41 +00002156 synchronized (mSyncRoot) {
2157 return mDisplayPowerController.getBrightnessEvents(userId, hasUsageStats);
2158 }
Kenny Guy22bd0442017-10-26 00:15:54 +01002159 } finally {
2160 Binder.restoreCallingIdentity(token);
2161 }
2162 }
2163
Michael Wrighteef0e132017-11-21 17:57:52 +00002164 @Override // Binder call
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002165 public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats() {
2166 mContext.enforceCallingOrSelfPermission(
2167 Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS,
2168 "Permission required to to access ambient light stats.");
2169 final int callingUid = Binder.getCallingUid();
2170 final int userId = UserHandle.getUserId(callingUid);
2171 final long token = Binder.clearCallingIdentity();
2172 try {
2173 synchronized (mSyncRoot) {
2174 return mDisplayPowerController.getAmbientBrightnessStats(userId);
2175 }
2176 } finally {
2177 Binder.restoreCallingIdentity(token);
2178 }
2179 }
2180
2181 @Override // Binder call
Michael Wrighteef0e132017-11-21 17:57:52 +00002182 public void setBrightnessConfigurationForUser(
Kenny Guy05ce8092018-01-17 13:44:20 +00002183 BrightnessConfiguration c, @UserIdInt int userId, String packageName) {
Michael Wrighteef0e132017-11-21 17:57:52 +00002184 mContext.enforceCallingOrSelfPermission(
2185 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2186 "Permission required to change the display's brightness configuration");
2187 if (userId != UserHandle.getCallingUserId()) {
2188 mContext.enforceCallingOrSelfPermission(
2189 Manifest.permission.INTERACT_ACROSS_USERS,
2190 "Permission required to change the display brightness"
2191 + " configuration of another user");
2192 }
Kenny Guy05ce8092018-01-17 13:44:20 +00002193 if (packageName != null && !validatePackageName(getCallingUid(), packageName)) {
2194 packageName = null;
2195 }
Michael Wrighteef0e132017-11-21 17:57:52 +00002196 final long token = Binder.clearCallingIdentity();
2197 try {
Kenny Guy05ce8092018-01-17 13:44:20 +00002198 setBrightnessConfigurationForUserInternal(c, userId, packageName);
Michael Wrighteef0e132017-11-21 17:57:52 +00002199 } finally {
2200 Binder.restoreCallingIdentity(token);
2201 }
2202 }
2203
Michael Wrightd8460232018-01-16 18:04:59 +00002204 @Override // Binder call
Kenny Guy6d1009f2018-03-14 14:28:23 +00002205 public BrightnessConfiguration getBrightnessConfigurationForUser(int userId) {
2206 mContext.enforceCallingOrSelfPermission(
2207 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2208 "Permission required to read the display's brightness configuration");
2209 if (userId != UserHandle.getCallingUserId()) {
2210 mContext.enforceCallingOrSelfPermission(
2211 Manifest.permission.INTERACT_ACROSS_USERS,
2212 "Permission required to read the display brightness"
2213 + " configuration of another user");
2214 }
2215 final long token = Binder.clearCallingIdentity();
2216 try {
2217 final int userSerial = getUserManager().getUserSerialNumber(userId);
2218 synchronized (mSyncRoot) {
2219 BrightnessConfiguration config =
2220 mPersistentDataStore.getBrightnessConfiguration(userSerial);
2221 if (config == null) {
2222 config = mDisplayPowerController.getDefaultBrightnessConfiguration();
2223 }
2224 return config;
2225 }
2226 } finally {
2227 Binder.restoreCallingIdentity(token);
2228 }
2229 }
2230
2231 @Override // Binder call
2232 public BrightnessConfiguration getDefaultBrightnessConfiguration() {
2233 mContext.enforceCallingOrSelfPermission(
2234 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2235 "Permission required to read the display's default brightness configuration");
2236 final long token = Binder.clearCallingIdentity();
2237 try {
2238 synchronized (mSyncRoot) {
2239 return mDisplayPowerController.getDefaultBrightnessConfiguration();
2240 }
2241 } finally {
2242 Binder.restoreCallingIdentity(token);
2243 }
2244 }
2245
2246 @Override // Binder call
Michael Wrightd8460232018-01-16 18:04:59 +00002247 public void setTemporaryBrightness(int brightness) {
2248 mContext.enforceCallingOrSelfPermission(
2249 Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS,
2250 "Permission required to set the display's brightness");
2251 final long token = Binder.clearCallingIdentity();
2252 try {
2253 synchronized (mSyncRoot) {
2254 mDisplayPowerController.setTemporaryBrightness(brightness);
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(token);
2258 }
2259 }
2260
2261 @Override // Binder call
2262 public void setTemporaryAutoBrightnessAdjustment(float adjustment) {
2263 mContext.enforceCallingOrSelfPermission(
2264 Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS,
2265 "Permission required to set the display's auto brightness adjustment");
2266 final long token = Binder.clearCallingIdentity();
2267 try {
2268 synchronized (mSyncRoot) {
2269 mDisplayPowerController.setTemporaryAutoBrightnessAdjustment(adjustment);
2270 }
2271 } finally {
2272 Binder.restoreCallingIdentity(token);
2273 }
2274 }
2275
Dan Gittik7a32fba2018-03-28 12:19:38 +01002276 @Override // Binder call
2277 public void onShellCommand(FileDescriptor in, FileDescriptor out,
2278 FileDescriptor err, String[] args, ShellCallback callback,
2279 ResultReceiver resultReceiver) {
Santos Cordonc4fd8e62019-12-18 13:01:05 +00002280 new DisplayManagerShellCommand(DisplayManagerService.this).exec(this, in, out, err,
2281 args, callback, resultReceiver);
Dan Gittik7a32fba2018-03-28 12:19:38 +01002282 }
2283
Dan Gittik122df862018-03-28 16:59:22 +01002284 @Override // Binder call
2285 public Curve getMinimumBrightnessCurve() {
2286 final long token = Binder.clearCallingIdentity();
2287 try {
2288 return getMinimumBrightnessCurveInternal();
2289 } finally {
2290 Binder.restoreCallingIdentity(token);
2291 }
2292 }
2293
Peiyong Lin277eaff2019-01-16 16:18:22 -08002294 @Override // Binder call
2295 public int getPreferredWideGamutColorSpaceId() {
2296 final long token = Binder.clearCallingIdentity();
2297 try {
2298 return getPreferredWideGamutColorSpaceIdInternal();
2299 } finally {
2300 Binder.restoreCallingIdentity(token);
2301 }
2302 }
2303
Jeff Brown4ccb8232014-01-16 22:16:42 -08002304 private boolean validatePackageName(int uid, String packageName) {
2305 if (packageName != null) {
2306 String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
2307 if (packageNames != null) {
2308 for (String n : packageNames) {
2309 if (n.equals(packageName)) {
2310 return true;
2311 }
2312 }
2313 }
2314 }
2315 return false;
2316 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07002317
2318 private boolean canProjectVideo(IMediaProjection projection) {
2319 if (projection != null) {
2320 try {
2321 if (projection.canProjectVideo()) {
2322 return true;
2323 }
2324 } catch (RemoteException e) {
2325 Slog.e(TAG, "Unable to query projection service for permissions", e);
2326 }
2327 }
Chilun67a379b2019-04-11 19:49:42 +08002328 if (checkCallingPermission(CAPTURE_VIDEO_OUTPUT, "canProjectVideo()")) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002329 return true;
2330 }
2331 return canProjectSecureVideo(projection);
2332 }
2333
2334 private boolean canProjectSecureVideo(IMediaProjection projection) {
2335 if (projection != null) {
2336 try {
2337 if (projection.canProjectSecureVideo()){
2338 return true;
2339 }
2340 } catch (RemoteException e) {
2341 Slog.e(TAG, "Unable to query projection service for permissions", e);
2342 }
2343 }
Chilun67a379b2019-04-11 19:49:42 +08002344 return checkCallingPermission(CAPTURE_SECURE_VIDEO_OUTPUT, "canProjectSecureVideo()");
2345 }
2346
2347 private boolean checkCallingPermission(String permission, String func) {
2348 if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) {
2349 return true;
2350 }
2351 final String msg = "Permission Denial: " + func + " from pid=" + Binder.getCallingPid()
2352 + ", uid=" + Binder.getCallingUid() + " requires " + permission;
2353 Slog.w(TAG, msg);
2354 return false;
Michael Wrightc39d47a2014-07-08 18:07:36 -07002355 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08002356 }
2357
2358 private final class LocalService extends DisplayManagerInternal {
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002359
Jeff Brown4ccb8232014-01-16 22:16:42 -08002360 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07002361 public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler,
Jeff Brownad9ef192014-04-08 17:26:30 -07002362 SensorManager sensorManager) {
2363 synchronized (mSyncRoot) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002364 DisplayBlanker blanker = new DisplayBlanker() {
2365 @Override
Jeff Brown5d6443b2015-04-10 20:15:01 -07002366 public void requestDisplayState(int state, int brightness) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002367 // The order of operations is important for legacy reasons.
2368 if (state == Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07002369 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07002370 }
2371
2372 callbacks.onDisplayStateChange(state);
2373
2374 if (state != Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07002375 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07002376 }
2377 }
2378 };
Jeff Brownad9ef192014-04-08 17:26:30 -07002379 mDisplayPowerController = new DisplayPowerController(
Jeff Brown037c33e2014-04-09 00:31:55 -07002380 mContext, callbacks, handler, sensorManager, blanker);
Long Lingbc841b02019-07-03 16:43:15 -07002381 mSensorManager = sensorManager;
Jeff Brownad9ef192014-04-08 17:26:30 -07002382 }
Michael Wrighteef0e132017-11-21 17:57:52 +00002383
2384 mHandler.sendEmptyMessage(MSG_LOAD_BRIGHTNESS_CONFIGURATION);
Jeff Brownad9ef192014-04-08 17:26:30 -07002385 }
2386
2387 @Override
2388 public boolean requestPowerState(DisplayPowerRequest request,
2389 boolean waitForNegativeProximity) {
Michael Wrighteef0e132017-11-21 17:57:52 +00002390 synchronized (mSyncRoot) {
2391 return mDisplayPowerController.requestPowerState(request,
2392 waitForNegativeProximity);
2393 }
Jeff Brownad9ef192014-04-08 17:26:30 -07002394 }
2395
2396 @Override
2397 public boolean isProximitySensorAvailable() {
Michael Wrighteef0e132017-11-21 17:57:52 +00002398 synchronized (mSyncRoot) {
2399 return mDisplayPowerController.isProximitySensorAvailable();
2400 }
Jeff Brownad9ef192014-04-08 17:26:30 -07002401 }
2402
2403 @Override
Robert Carr66b5664f2019-04-02 14:18:56 -07002404 public SurfaceControl.ScreenshotGraphicBuffer screenshot(int displayId) {
2405 return screenshotInternal(displayId);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002406 }
2407
2408 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -08002409 public DisplayInfo getDisplayInfo(int displayId) {
2410 return getDisplayInfoInternal(displayId, Process.myUid());
2411 }
2412
2413 @Override
2414 public void registerDisplayTransactionListener(DisplayTransactionListener listener) {
2415 if (listener == null) {
2416 throw new IllegalArgumentException("listener must not be null");
2417 }
2418
2419 registerDisplayTransactionListenerInternal(listener);
2420 }
2421
2422 @Override
2423 public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) {
2424 if (listener == null) {
2425 throw new IllegalArgumentException("listener must not be null");
2426 }
2427
2428 unregisterDisplayTransactionListenerInternal(listener);
2429 }
2430
2431 @Override
2432 public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) {
2433 setDisplayInfoOverrideFromWindowManagerInternal(displayId, info);
2434 }
2435
2436 @Override
Andrii Kuliancd097992017-03-23 18:31:59 -07002437 public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) {
2438 getNonOverrideDisplayInfoInternal(displayId, outInfo);
2439 }
2440
2441 @Override
Robert Carrae606b42018-02-15 15:36:23 -08002442 public void performTraversal(SurfaceControl.Transaction t) {
2443 performTraversalInternal(t);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002444 }
2445
2446 @Override
Michael Wright3f145a22014-07-22 19:46:03 -07002447 public void setDisplayProperties(int displayId, boolean hasContent,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002448 float requestedRefreshRate, int requestedMode,
2449 boolean requestedMinimalPostProcessing, boolean inTraversal) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07002450 setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002451 requestedMode, requestedMinimalPostProcessing, inTraversal);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002452 }
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08002453
2454 @Override
2455 public void setDisplayOffsets(int displayId, int x, int y) {
2456 setDisplayOffsetsInternal(displayId, x, y);
2457 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002458
2459 @Override
Sam Lin4c3ac2b2019-02-18 04:50:26 -08002460 public void setDisplayScalingDisabled(int displayId, boolean disableScaling) {
2461 setDisplayScalingDisabledInternal(displayId, disableScaling);
2462 }
2463
2464 @Override
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002465 public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) {
2466 setDisplayAccessUIDsInternal(newDisplayAccessUIDs);
2467 }
2468
2469 @Override
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002470 public void persistBrightnessTrackerState() {
Michael Wright144aac92017-12-21 18:37:41 +00002471 synchronized (mSyncRoot) {
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002472 mDisplayPowerController.persistBrightnessTrackerState();
Michael Wright144aac92017-12-21 18:37:41 +00002473 }
Kenny Guycfe7b702017-11-14 21:04:58 +00002474 }
Adrian Roose1d68cd2018-01-17 12:54:50 +01002475
2476 @Override
2477 public void onOverlayChanged() {
2478 synchronized (mSyncRoot) {
Adrian Roos898ec382018-01-17 12:54:50 +01002479 for (int i = 0; i < mDisplayDevices.size(); i++) {
2480 mDisplayDevices.get(i).onOverlayChangedLocked();
Adrian Roose1d68cd2018-01-17 12:54:50 +01002481 }
2482 }
2483 }
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07002484
2485 @Override
2486 public DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes(
2487 int displayId) {
2488 return getDisplayedContentSamplingAttributesInternal(displayId);
2489 }
2490
2491 @Override
2492 public boolean setDisplayedContentSamplingEnabled(
2493 int displayId, boolean enable, int componentMask, int maxFrames) {
2494 return setDisplayedContentSamplingEnabledInternal(
2495 displayId, enable, componentMask, maxFrames);
2496 }
2497
2498 @Override
2499 public DisplayedContentSample getDisplayedContentSample(int displayId,
2500 long maxFrames, long timestamp) {
2501 return getDisplayedContentSampleInternal(displayId, maxFrames, timestamp);
2502 }
2503
Jeff Brown4ccb8232014-01-16 22:16:42 -08002504 }
Michael Wrighta3dab232019-02-22 16:54:21 +00002505
Ana Kruleca74a8642019-11-14 00:51:00 +01002506 class DesiredDisplayModeSpecsObserver
2507 implements DisplayModeDirector.DesiredDisplayModeSpecsListener {
2508 public void onDesiredDisplayModeSpecsChanged() {
2509 onDesiredDisplayModeSpecsChangedInternal();
Michael Wrighta3dab232019-02-22 16:54:21 +00002510 }
2511 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07002512}