blob: 34bb4b321db29d95d3926df94f96ef41de05958d [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;
Galia Peycheva088d7c02019-12-13 11:27:23 +010042import android.database.ContentObserver;
Peiyong Lin277eaff2019-01-16 16:18:22 -080043import android.graphics.ColorSpace;
Michael Wrighteedcbf12017-08-16 23:14:54 +010044import android.graphics.Point;
Robert Carr5c52b132019-02-15 15:48:11 -080045import android.graphics.Rect;
Jeff Brownad9ef192014-04-08 17:26:30 -070046import android.hardware.SensorManager;
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +000047import android.hardware.display.AmbientBrightnessDayStats;
Kenny Guy22bd0442017-10-26 00:15:54 +010048import android.hardware.display.BrightnessChangeEvent;
Michael Wrighteef0e132017-11-21 17:57:52 +000049import android.hardware.display.BrightnessConfiguration;
Dan Gittik122df862018-03-28 16:59:22 +010050import android.hardware.display.Curve;
Jeff Brownbd6e1502012-08-28 03:27:37 -070051import android.hardware.display.DisplayManagerGlobal;
Jeff Brown4ccb8232014-01-16 22:16:42 -080052import android.hardware.display.DisplayManagerInternal;
Jeff Brown4ccb8232014-01-16 22:16:42 -080053import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +010054import android.hardware.display.DisplayViewport;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070055import android.hardware.display.DisplayedContentSample;
56import android.hardware.display.DisplayedContentSamplingAttributes;
Jeff Brownfa25bf52012-07-23 19:26:30 -070057import android.hardware.display.IDisplayManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070058import android.hardware.display.IDisplayManagerCallback;
Michael Wright75ee9fc2014-09-01 19:55:22 -070059import android.hardware.display.IVirtualDisplayCallback;
Jeff Browne08ae382012-09-07 20:36:36 -070060import android.hardware.display.WifiDisplayStatus;
Jeff Brown4ccb8232014-01-16 22:16:42 -080061import android.hardware.input.InputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -070062import android.media.projection.IMediaProjection;
63import android.media.projection.IMediaProjectionManager;
Galia Peycheva088d7c02019-12-13 11:27:23 +010064import android.net.Uri;
Jeff Brownfa25bf52012-07-23 19:26:30 -070065import android.os.Binder;
Jeff Brownbd6e1502012-08-28 03:27:37 -070066import android.os.Handler;
Jeff Brown64a55af2012-08-26 02:47:39 -070067import android.os.IBinder;
Jeff Brown4ccb8232014-01-16 22:16:42 -080068import android.os.IBinder.DeathRecipient;
Jeff Brownbd6e1502012-08-28 03:27:37 -070069import android.os.Looper;
70import android.os.Message;
Jeff Brown5d6443b2015-04-10 20:15:01 -070071import android.os.PowerManager;
Craig Mautner4504de52013-12-20 09:06:56 -080072import android.os.Process;
Jeff Brownbd6e1502012-08-28 03:27:37 -070073import android.os.RemoteException;
Dan Gittik7a32fba2018-03-28 12:19:38 +010074import android.os.ResultReceiver;
Michael Wrightc39d47a2014-07-08 18:07:36 -070075import android.os.ServiceManager;
Dan Gittik7a32fba2018-03-28 12:19:38 +010076import android.os.ShellCallback;
Jeff Brownbd6e1502012-08-28 03:27:37 -070077import android.os.SystemClock;
Jeff Brownfa25bf52012-07-23 19:26:30 -070078import android.os.SystemProperties;
Jeff Brown5d6443b2015-04-10 20:15:01 -070079import android.os.Trace;
Kenny Guy22bd0442017-10-26 00:15:54 +010080import android.os.UserHandle;
Michael Wrighteef0e132017-11-21 17:57:52 +000081import android.os.UserManager;
Galia Peycheva088d7c02019-12-13 11:27:23 +010082import android.provider.Settings;
Jeff Browna506a6e2013-06-04 00:02:38 -070083import android.text.TextUtils;
Andrii Kulianfb1bf692017-01-17 11:17:34 -080084import android.util.IntArray;
Dan Gittik122df862018-03-28 16:59:22 +010085import android.util.Pair;
Jeff Brownbd6e1502012-08-28 03:27:37 -070086import android.util.Slog;
87import android.util.SparseArray;
Dan Gittik122df862018-03-28 16:59:22 +010088import android.util.Spline;
Jeff Brownfa25bf52012-07-23 19:26:30 -070089import android.view.Display;
90import android.view.DisplayInfo;
Jeff Browna506a6e2013-06-04 00:02:38 -070091import android.view.Surface;
Robert Carrae606b42018-02-15 15:36:23 -080092import android.view.SurfaceControl;
Jeff Browna506a6e2013-06-04 00:02:38 -070093
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +010094import com.android.internal.annotations.GuardedBy;
95import com.android.internal.annotations.VisibleForTesting;
96import com.android.internal.util.DumpUtils;
97import com.android.internal.util.IndentingPrintWriter;
Jorim Jaggied7993b2017-03-28 18:50:01 +010098import com.android.server.AnimationThread;
Jeff Brown4ccb8232014-01-16 22:16:42 -080099import com.android.server.DisplayThread;
100import com.android.server.LocalServices;
101import com.android.server.SystemService;
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700102import com.android.server.UiThread;
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200103import com.android.server.wm.SurfaceAnimationThread;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100104import com.android.server.wm.WindowManagerInternal;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700105
106import java.io.FileDescriptor;
107import java.io.PrintWriter;
108import java.util.ArrayList;
Jeff Browna506a6e2013-06-04 00:02:38 -0700109import java.util.Arrays;
Jeff Browne75926d2014-09-18 15:24:49 -0700110import java.util.List;
Jeff Brown7f3994e2012-12-04 14:04:28 -0800111import java.util.concurrent.CopyOnWriteArrayList;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700112
113/**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700114 * Manages attached displays.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700115 * <p>
Jeff Brownbd6e1502012-08-28 03:27:37 -0700116 * The {@link DisplayManagerService} manages the global lifecycle of displays,
117 * decides how to configure logical displays based on the physical display devices currently
118 * attached, sends notifications to the system and to applications when the state
119 * changes, and so on.
120 * </p><p>
121 * The display manager service relies on a collection of {@link DisplayAdapter} components,
122 * for discovering and configuring physical display devices attached to the system.
123 * There are separate display adapters for each manner that devices are attached:
124 * one display adapter for built-in local displays, one for simulated non-functional
125 * displays when the system is headless, one for simulated overlay displays used for
126 * development, one for wifi displays, etc.
127 * </p><p>
128 * Display adapters are only weakly coupled to the display manager service.
129 * Display adapters communicate changes in display device state to the display manager
Craig Mautner722285e2012-09-07 13:55:58 -0700130 * service asynchronously via a {@link DisplayAdapter.Listener} registered
Jeff Brownbd6e1502012-08-28 03:27:37 -0700131 * by the display manager service. This separation of concerns is important for
132 * two main reasons. First, it neatly encapsulates the responsibilities of these
133 * two classes: display adapters handle individual display devices whereas
134 * the display manager service handles the global state. Second, it eliminates
135 * the potential for deadlocks resulting from asynchronous display device discovery.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700136 * </p>
137 *
138 * <h3>Synchronization</h3>
139 * <p>
140 * Because the display manager may be accessed by multiple threads, the synchronization
141 * story gets a little complicated. In particular, the window manager may call into
142 * the display manager while holding a surface transaction with the expectation that
143 * it can apply changes immediately. Unfortunately, that means we can't just do
144 * everything asynchronously (*grump*).
Jeff Brownbd6e1502012-08-28 03:27:37 -0700145 * </p><p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700146 * To make this work, all of the objects that belong to the display manager must
147 * use the same lock. We call this lock the synchronization root and it has a unique
148 * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are
149 * named with the "Locked" suffix.
150 * </p><p>
151 * Where things get tricky is that the display manager is not allowed to make
152 * any potentially reentrant calls, especially into the window manager. We generally
153 * avoid this by making all potentially reentrant out-calls asynchronous.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700154 * </p>
155 */
Jeff Brown4ccb8232014-01-16 22:16:42 -0800156public final class DisplayManagerService extends SystemService {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700157 private static final String TAG = "DisplayManagerService";
Jeff Brownbd6e1502012-08-28 03:27:37 -0700158 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700159
Jeff Brownbbd28a22012-09-20 16:47:15 -0700160 // When this system property is set to 0, WFD is forcibly disabled on boot.
161 // When this system property is set to 1, WFD is forcibly enabled on boot.
162 // Otherwise WFD is enabled according to the value of config_enableWifiDisplay.
163 private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
164
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200165 private static final String PROP_DEFAULT_DISPLAY_TOP_INSET = "persist.sys.displayinset.top";
166
Jeff Brownbd6e1502012-08-28 03:27:37 -0700167 private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
168
Santos Cordonc22c5632017-06-21 16:03:49 -0700169 private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS = 1;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700170 private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2;
171 private static final int MSG_DELIVER_DISPLAY_EVENT = 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700172 private static final int MSG_REQUEST_TRAVERSAL = 4;
Jeff Brownd728bf52012-09-08 18:05:28 -0700173 private static final int MSG_UPDATE_VIEWPORT = 5;
Michael Wrighta3dab232019-02-22 16:54:21 +0000174 private static final int MSG_LOAD_BRIGHTNESS_CONFIGURATION = 6;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700175
Jeff Brownb880d882014-02-10 19:47:07 -0800176 private final Context mContext;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700177 private final DisplayManagerHandler mHandler;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700178 private final Handler mUiHandler;
179 private final DisplayAdapterListener mDisplayAdapterListener;
Michael Wrighta3dab232019-02-22 16:54:21 +0000180 private final DisplayModeDirector mDisplayModeDirector;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800181 private WindowManagerInternal mWindowManagerInternal;
182 private InputManagerInternal mInputManagerInternal;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700183 private IMediaProjectionManager mProjectionService;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700184
185 // The synchronization root for the display manager.
186 // This lock guards most of the display manager's state.
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800187 // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call
188 // into WindowManagerService methods that require mWindowMap while holding this unless you are
189 // very very sure that no deadlock can occur.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700190 private final SyncRoot mSyncRoot = new SyncRoot();
191
192 // True if in safe mode.
193 // This option may disable certain display adapters.
194 public boolean mSafeMode;
195
196 // True if we are in a special boot mode where only core applications and
197 // services should be started. This option may disable certain display adapters.
198 public boolean mOnlyCore;
199
Jeff Brown27f1d672012-10-17 18:32:34 -0700200 // True if the display manager service should pretend there is only one display
201 // and only tell applications about the existence of the default logical display.
202 // The display manager can still mirror content to secondary displays but applications
203 // cannot present unique content on those displays.
204 // Used for demonstration purposes only.
205 private final boolean mSingleDisplayDemoMode;
206
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700207 // All callback records indexed by calling process id.
208 public final SparseArray<CallbackRecord> mCallbacks =
Jeff Brownbd6e1502012-08-28 03:27:37 -0700209 new SparseArray<CallbackRecord>();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700210
Jeff Brownbd6e1502012-08-28 03:27:37 -0700211 // List of all currently registered display adapters.
212 private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
213
214 // List of all currently connected display devices.
215 private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>();
216
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700217 // List of all logical displays indexed by logical display id.
218 private final SparseArray<LogicalDisplay> mLogicalDisplays =
219 new SparseArray<LogicalDisplay>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700220 private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1;
221
Jeff Brown7f3994e2012-12-04 14:04:28 -0800222 // List of all display transaction listeners.
223 private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
224 new CopyOnWriteArrayList<DisplayTransactionListener>();
225
Jeff Brownad9ef192014-04-08 17:26:30 -0700226 // Display power controller.
227 private DisplayPowerController mDisplayPowerController;
228
Jeff Brown037c33e2014-04-09 00:31:55 -0700229 // The overall display state, independent of changes that might influence one
230 // display or another in particular.
Jeff Brown5d6443b2015-04-10 20:15:01 -0700231 private int mGlobalDisplayState = Display.STATE_ON;
232
233 // The overall display brightness.
234 // For now, this only applies to the built-in display but we may split it up eventually.
235 private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT;
Jeff Brown9e316a12012-10-08 19:17:06 -0700236
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700237 // Set to true when there are pending display changes that have yet to be applied
238 // to the surface flinger state.
239 private boolean mPendingTraversal;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700240
Jeff Browne08ae382012-09-07 20:36:36 -0700241 // The Wifi display adapter, or null if not registered.
242 private WifiDisplayAdapter mWifiDisplayAdapter;
243
Jeff Brownce468a32013-11-21 16:42:03 -0800244 // The number of active wifi display scan requests.
245 private int mWifiDisplayScanRequestCount;
246
Jeff Browna506a6e2013-06-04 00:02:38 -0700247 // The virtual display adapter, or null if not registered.
248 private VirtualDisplayAdapter mVirtualDisplayAdapter;
249
Michael Wrighteef0e132017-11-21 17:57:52 +0000250 // The User ID of the current user
251 private @UserIdInt int mCurrentUserId;
252
Michael Wrighteedcbf12017-08-16 23:14:54 +0100253 // The stable device screen height and width. These are not tied to a specific display, even
254 // the default display, because they need to be stable over the course of the device's entire
255 // life, even if the default display changes (e.g. a new monitor is plugged into a PC-like
256 // device).
257 private Point mStableDisplaySize = new Point();
258
Winson72dbe7e2019-04-29 14:55:30 -0700259 // Whether the system has finished booting or not.
260 private boolean mSystemReady;
261
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200262 // The top inset of the default display.
263 // This gets persisted so that the boot animation knows how to transition from the display's
264 // full size to the size configured by the user. Right now we only persist and animate the top
265 // inset, but theoretically we could do it for all of them.
266 private int mDefaultDisplayTopInset;
267
Jeff Brownd728bf52012-09-08 18:05:28 -0700268 // Viewports of the default display and the display that should receive touch
269 // input from an external source. Used by the input system.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100270 @GuardedBy("mSyncRoot")
271 private final ArrayList<DisplayViewport> mViewports = new ArrayList<>();
Jeff Brownd728bf52012-09-08 18:05:28 -0700272
Jeff Brown89d55462012-09-19 11:33:42 -0700273 // Persistent data store for all internal settings maintained by the display manager service.
274 private final PersistentDataStore mPersistentDataStore = new PersistentDataStore();
275
Jeff Brownbd6e1502012-08-28 03:27:37 -0700276 // Temporary callback list, used when sending display events to applications.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700277 // May be used outside of the lock but only on the handler thread.
278 private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700279
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700280 // Temporary display info, used for comparing display configurations.
281 private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
282
Jeff Brownd728bf52012-09-08 18:05:28 -0700283 // Temporary viewports, used when sending new viewport information to the
284 // input system. May be used outside of the lock but only on the handler thread.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100285 private final ArrayList<DisplayViewport> mTempViewports = new ArrayList<>();
Jeff Brownd728bf52012-09-08 18:05:28 -0700286
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700287 // The default color mode for default displays. Overrides the usual
288 // Display.Display.COLOR_MODE_DEFAULT for displays with the
289 // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set.
290 private final int mDefaultDisplayDefaultColorMode;
291
Jeff Browne75926d2014-09-18 15:24:49 -0700292 // Temporary list of deferred work to perform when setting the display state.
293 // Only used by requestDisplayState. The field is self-synchronized and only
294 // intended for use inside of the requestGlobalDisplayStateInternal function.
295 private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>();
296
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800297 // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs.
298 private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>();
299
Santos Cordonee8931e2017-04-05 10:31:15 -0700300 private final Injector mInjector;
301
Dan Gittik122df862018-03-28 16:59:22 +0100302 // The minimum brightness curve, which guarantess that any brightness curve that dips below it
303 // is rejected by the system.
304 private final Curve mMinimumBrightnessCurve;
305 private final Spline mMinimumBrightnessSpline;
Peiyong Lin277eaff2019-01-16 16:18:22 -0800306 private final ColorSpace mWideColorSpace;
Dan Gittik122df862018-03-28 16:59:22 +0100307
Long Lingbc841b02019-07-03 16:43:15 -0700308 private SensorManager mSensorManager;
309
Galia Peycheva088d7c02019-12-13 11:27:23 +0100310 // Whether minimal post processing is allowed by the user.
311 @GuardedBy("mSyncRoot")
312 private boolean mMinimalPostProcessingAllowed;
313
314 // Receives notifications about changes to Settings.
315 private SettingsObserver mSettingsObserver;
316
Jeff Brownb880d882014-02-10 19:47:07 -0800317 public DisplayManagerService(Context context) {
Santos Cordonee8931e2017-04-05 10:31:15 -0700318 this(context, new Injector());
319 }
320
321 @VisibleForTesting
322 DisplayManagerService(Context context, Injector injector) {
Jeff Brownb880d882014-02-10 19:47:07 -0800323 super(context);
Santos Cordonee8931e2017-04-05 10:31:15 -0700324 mInjector = injector;
Jeff Brownb880d882014-02-10 19:47:07 -0800325 mContext = context;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800326 mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700327 mUiHandler = UiThread.getHandler();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700328 mDisplayAdapterListener = new DisplayAdapterListener();
Michael Wrighta3dab232019-02-22 16:54:21 +0000329 mDisplayModeDirector = new DisplayModeDirector(context, mHandler);
Jeff Brown27f1d672012-10-17 18:32:34 -0700330 mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
Dan Gittik122df862018-03-28 16:59:22 +0100331 Resources resources = mContext.getResources();
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -0700332 mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger(
Michael Wrighteef0e132017-11-21 17:57:52 +0000333 com.android.internal.R.integer.config_defaultDisplayDefaultColorMode);
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200334 mDefaultDisplayTopInset = SystemProperties.getInt(PROP_DEFAULT_DISPLAY_TOP_INSET, -1);
Dan Gittik122df862018-03-28 16:59:22 +0100335 float[] lux = getFloatArray(resources.obtainTypedArray(
336 com.android.internal.R.array.config_minimumBrightnessCurveLux));
337 float[] nits = getFloatArray(resources.obtainTypedArray(
338 com.android.internal.R.array.config_minimumBrightnessCurveNits));
339 mMinimumBrightnessCurve = new Curve(lux, nits);
340 mMinimumBrightnessSpline = Spline.createSpline(lux, nits);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700341
Michael Wrighta3dab232019-02-22 16:54:21 +0000342 PowerManager pm = mContext.getSystemService(PowerManager.class);
Jeff Brown5d6443b2015-04-10 20:15:01 -0700343 mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting();
Michael Wrighteef0e132017-11-21 17:57:52 +0000344 mCurrentUserId = UserHandle.USER_SYSTEM;
Peiyong Lin277eaff2019-01-16 16:18:22 -0800345 ColorSpace[] colorSpaces = SurfaceControl.getCompositionColorSpaces();
346 mWideColorSpace = colorSpaces[1];
Winson72dbe7e2019-04-29 14:55:30 -0700347
348 mSystemReady = false;
Joel Fernandes2d314e12017-04-04 16:32:15 -0700349 }
350
351 public void setupSchedulerPolicies() {
Jorim Jaggied7993b2017-03-28 18:50:01 +0100352 // android.display and android.anim is critical to user experience and we should make sure
Michael Wrighteef0e132017-11-21 17:57:52 +0000353 // it is not in the default foregroup groups, add it to top-app to make sure it uses all
354 // the cores and scheduling settings for top-app when it runs.
Jorim Jaggied7993b2017-03-28 18:50:01 +0100355 Process.setThreadGroupAndCpuset(DisplayThread.get().getThreadId(),
356 Process.THREAD_GROUP_TOP_APP);
357 Process.setThreadGroupAndCpuset(AnimationThread.get().getThreadId(),
358 Process.THREAD_GROUP_TOP_APP);
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200359 Process.setThreadGroupAndCpuset(SurfaceAnimationThread.get().getThreadId(),
360 Process.THREAD_GROUP_TOP_APP);
Craig Mautner4f67ba62012-08-02 11:23:00 -0700361 }
362
Jeff Brown4ccb8232014-01-16 22:16:42 -0800363 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -0800364 public void onStart() {
Michael Wright1c9977b2016-07-12 13:30:10 -0700365 // We need to pre-load the persistent data store so it's ready before the default display
366 // adapter is up so that we have it's configuration. We could load it lazily, but since
367 // 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 -0700368 // we've waited for the display to register itself with us.
Michael Wrighta3dab232019-02-22 16:54:21 +0000369 synchronized (mSyncRoot) {
370 mPersistentDataStore.loadIfNeeded();
371 loadStableDisplayValuesLocked();
Michael Wrighteedcbf12017-08-16 23:14:54 +0100372 }
Santos Cordonc22c5632017-06-21 16:03:49 -0700373 mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800374
375 publishBinderService(Context.DISPLAY_SERVICE, new BinderService(),
376 true /*allowIsolated*/);
377 publishLocalService(DisplayManagerInternal.class, new LocalService());
378 }
379
380 @Override
381 public void onBootPhase(int phase) {
382 if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) {
383 synchronized (mSyncRoot) {
Santos Cordonc22c5632017-06-21 16:03:49 -0700384 long timeout = SystemClock.uptimeMillis()
385 + mInjector.getDefaultDisplayDelayTimeout();
386 while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null ||
387 mVirtualDisplayAdapter == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800388 long delay = timeout - SystemClock.uptimeMillis();
389 if (delay <= 0) {
390 throw new RuntimeException("Timeout waiting for default display "
Santos Cordonc22c5632017-06-21 16:03:49 -0700391 + "to be initialized. DefaultDisplay="
392 + mLogicalDisplays.get(Display.DEFAULT_DISPLAY)
393 + ", mVirtualDisplayAdapter=" + mVirtualDisplayAdapter);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800394 }
395 if (DEBUG) {
396 Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay);
397 }
398 try {
399 mSyncRoot.wait(delay);
400 } catch (InterruptedException ex) {
401 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700402 }
403 }
404 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700405 }
406
Michael Wrighteef0e132017-11-21 17:57:52 +0000407 @Override
408 public void onSwitchUser(@UserIdInt int newUserId) {
409 final int userSerial = getUserManager().getUserSerialNumber(newUserId);
410 synchronized (mSyncRoot) {
411 if (mCurrentUserId != newUserId) {
412 mCurrentUserId = newUserId;
413 BrightnessConfiguration config =
414 mPersistentDataStore.getBrightnessConfiguration(userSerial);
415 mDisplayPowerController.setBrightnessConfiguration(config);
Galia Peycheva088d7c02019-12-13 11:27:23 +0100416 handleSettingsChange();
Michael Wrighteef0e132017-11-21 17:57:52 +0000417 }
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +0000418 mDisplayPowerController.onSwitchUser(newUserId);
Michael Wrighteef0e132017-11-21 17:57:52 +0000419 }
420 }
421
Jeff Brown4ccb8232014-01-16 22:16:42 -0800422 // TODO: Use dependencies or a boot phase
423 public void windowManagerAndInputReady() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700424 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800425 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
426 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Craig Mautner65d11b32012-10-01 13:59:52 -0700427 scheduleTraversalLocked(false);
Jeff Brownd728bf52012-09-08 18:05:28 -0700428 }
429 }
430
431 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700432 * Called when the system is ready to go.
433 */
434 public void systemReady(boolean safeMode, boolean onlyCore) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700435 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700436 mSafeMode = safeMode;
437 mOnlyCore = onlyCore;
Winson72dbe7e2019-04-29 14:55:30 -0700438 mSystemReady = true;
439 // Just in case the top inset changed before the system was ready. At this point, any
440 // relevant configuration should be in place.
441 recordTopInsetLocked(mLogicalDisplays.get(Display.DEFAULT_DISPLAY));
Galia Peycheva088d7c02019-12-13 11:27:23 +0100442
443 updateSettingsLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700444 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700445
Ana Kruleca74a8642019-11-14 00:51:00 +0100446 mDisplayModeDirector.setDesiredDisplayModeSpecsListener(
447 new DesiredDisplayModeSpecsObserver());
Long Lingbc841b02019-07-03 16:43:15 -0700448 mDisplayModeDirector.start(mSensorManager);
Michael Wrighta3dab232019-02-22 16:54:21 +0000449
Jeff Brownbd6e1502012-08-28 03:27:37 -0700450 mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
Galia Peycheva088d7c02019-12-13 11:27:23 +0100451
452 mSettingsObserver = new SettingsObserver();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700453 }
454
Santos Cordonee8931e2017-04-05 10:31:15 -0700455 @VisibleForTesting
456 Handler getDisplayHandler() {
457 return mHandler;
458 }
459
Michael Wrighteedcbf12017-08-16 23:14:54 +0100460 private void loadStableDisplayValuesLocked() {
461 final Point size = mPersistentDataStore.getStableDisplaySize();
462 if (size.x > 0 && size.y > 0) {
463 // Just set these values directly so we don't write the display persistent data again
464 // unnecessarily
465 mStableDisplaySize.set(size.x, size.y);
466 } else {
467 final Resources res = mContext.getResources();
468 final int width = res.getInteger(
469 com.android.internal.R.integer.config_stableDeviceDisplayWidth);
470 final int height = res.getInteger(
471 com.android.internal.R.integer.config_stableDeviceDisplayHeight);
472 if (width > 0 && height > 0) {
473 setStableDisplaySizeLocked(width, height);
474 }
475 }
476 }
477
478 private Point getStableDisplaySizeInternal() {
479 Point r = new Point();
480 synchronized (mSyncRoot) {
481 if (mStableDisplaySize.x > 0 && mStableDisplaySize.y > 0) {
482 r.set(mStableDisplaySize.x, mStableDisplaySize.y);
483 }
484 }
485 return r;
486 }
487
Jeff Brown4ccb8232014-01-16 22:16:42 -0800488 private void registerDisplayTransactionListenerInternal(
489 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800490 // List is self-synchronized copy-on-write.
491 mDisplayTransactionListeners.add(listener);
492 }
493
Jeff Brown4ccb8232014-01-16 22:16:42 -0800494 private void unregisterDisplayTransactionListenerInternal(
495 DisplayTransactionListener listener) {
Jeff Brown7f3994e2012-12-04 14:04:28 -0800496 // List is self-synchronized copy-on-write.
497 mDisplayTransactionListeners.remove(listener);
498 }
499
Jeff Brown4ccb8232014-01-16 22:16:42 -0800500 private void setDisplayInfoOverrideFromWindowManagerInternal(
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700501 int displayId, DisplayInfo info) {
502 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700503 LogicalDisplay display = mLogicalDisplays.get(displayId);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700504 if (display != null) {
Jeff Brownef981a42013-08-07 14:13:37 -0700505 if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200506 handleLogicalDisplayChanged(displayId, display);
Craig Mautner65d11b32012-10-01 13:59:52 -0700507 scheduleTraversalLocked(false);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700508 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700509 }
510 }
511 }
512
Andrii Kuliancd097992017-03-23 18:31:59 -0700513 /**
514 * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo)
515 */
516 private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) {
517 synchronized (mSyncRoot) {
518 final LogicalDisplay display = mLogicalDisplays.get(displayId);
519 if (display != null) {
520 display.getNonOverrideDisplayInfoLocked(outInfo);
521 }
522 }
523 }
524
Santos Cordonee8931e2017-04-05 10:31:15 -0700525 @VisibleForTesting
Robert Carrae606b42018-02-15 15:36:23 -0800526 void performTraversalInternal(SurfaceControl.Transaction t) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700527 synchronized (mSyncRoot) {
528 if (!mPendingTraversal) {
529 return;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700530 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700531 mPendingTraversal = false;
532
Robert Carrae606b42018-02-15 15:36:23 -0800533 performTraversalLocked(t);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700534 }
Jeff Brown7f3994e2012-12-04 14:04:28 -0800535
536 // List is self-synchronized copy-on-write.
537 for (DisplayTransactionListener listener : mDisplayTransactionListeners) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800538 listener.onDisplayTransaction(t);
Jeff Brown7f3994e2012-12-04 14:04:28 -0800539 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700540 }
541
Jeff Brown5d6443b2015-04-10 20:15:01 -0700542 private void requestGlobalDisplayStateInternal(int state, int brightness) {
543 if (state == Display.STATE_UNKNOWN) {
544 state = Display.STATE_ON;
545 }
546 if (state == Display.STATE_OFF) {
547 brightness = PowerManager.BRIGHTNESS_OFF;
548 } else if (brightness < 0) {
549 brightness = PowerManager.BRIGHTNESS_DEFAULT;
550 } else if (brightness > PowerManager.BRIGHTNESS_ON) {
551 brightness = PowerManager.BRIGHTNESS_ON;
552 }
553
Jeff Browne75926d2014-09-18 15:24:49 -0700554 synchronized (mTempDisplayStateWorkQueue) {
555 try {
556 // Update the display state within the lock.
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700557 // Note that we do not need to schedule traversals here although it
558 // may happen as a side-effect of displays changing state.
Jeff Browne75926d2014-09-18 15:24:49 -0700559 synchronized (mSyncRoot) {
Jeff Brown5d6443b2015-04-10 20:15:01 -0700560 if (mGlobalDisplayState == state
561 && mGlobalDisplayBrightness == brightness) {
562 return; // no change
Jeff Browne75926d2014-09-18 15:24:49 -0700563 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700564
565 Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState("
566 + Display.stateToString(state)
567 + ", brightness=" + brightness + ")");
568 mGlobalDisplayState = state;
569 mGlobalDisplayBrightness = brightness;
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700570 applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue);
Jeff Browne75926d2014-09-18 15:24:49 -0700571 }
572
573 // Setting the display power state can take hundreds of milliseconds
574 // to complete so we defer the most expensive part of the work until
575 // after we have exited the critical section to avoid blocking other
576 // threads for a long time.
577 for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) {
578 mTempDisplayStateWorkQueue.get(i).run();
579 }
Jeff Brown5d6443b2015-04-10 20:15:01 -0700580 Trace.traceEnd(Trace.TRACE_TAG_POWER);
Jeff Browne75926d2014-09-18 15:24:49 -0700581 } finally {
582 mTempDisplayStateWorkQueue.clear();
Jeff Brown9e316a12012-10-08 19:17:06 -0700583 }
584 }
585 }
586
Galia Peycheva088d7c02019-12-13 11:27:23 +0100587 private class SettingsObserver extends ContentObserver {
588 SettingsObserver() {
589 super(mHandler);
590
591 mContext.getContentResolver().registerContentObserver(
592 Settings.Secure.getUriFor(
593 Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED), false, this);
594 }
595
596 @Override
597 public void onChange(boolean selfChange, Uri uri) {
598 handleSettingsChange();
599 }
600 }
601
602 private void handleSettingsChange() {
603 synchronized (mSyncRoot) {
604 updateSettingsLocked();
605 scheduleTraversalLocked(false);
606 }
607 }
608
609 private void updateSettingsLocked() {
610 mMinimalPostProcessingAllowed = Settings.Secure.getIntForUser(mContext.getContentResolver(),
611 Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED, 1, UserHandle.USER_CURRENT) != 0;
612 }
613
Jeff Brown4ccb8232014-01-16 22:16:42 -0800614 private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700615 synchronized (mSyncRoot) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800616 LogicalDisplay display = mLogicalDisplays.get(displayId);
617 if (display != null) {
618 DisplayInfo info = display.getDisplayInfoLocked();
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800619 if (info.hasAccess(callingUid)
620 || isUidPresentOnDisplayInternal(callingUid, displayId)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800621 return info;
622 }
623 }
624 return null;
625 }
626 }
627
628 private int[] getDisplayIdsInternal(int callingUid) {
629 synchronized (mSyncRoot) {
630 final int count = mLogicalDisplays.size();
631 int[] displayIds = new int[count];
632 int n = 0;
633 for (int i = 0; i < count; i++) {
634 LogicalDisplay display = mLogicalDisplays.valueAt(i);
635 DisplayInfo info = display.getDisplayInfoLocked();
636 if (info.hasAccess(callingUid)) {
637 displayIds[n++] = mLogicalDisplays.keyAt(i);
638 }
639 }
640 if (n != count) {
641 displayIds = Arrays.copyOfRange(displayIds, 0, n);
642 }
643 return displayIds;
644 }
645 }
646
647 private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) {
648 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700649 if (mCallbacks.get(callingPid) != null) {
650 throw new SecurityException("The calling process has already "
651 + "registered an IDisplayManagerCallback.");
Jeff Brown64a55af2012-08-26 02:47:39 -0700652 }
653
Jeff Brownbd6e1502012-08-28 03:27:37 -0700654 CallbackRecord record = new CallbackRecord(callingPid, callback);
655 try {
656 IBinder binder = callback.asBinder();
657 binder.linkToDeath(record, 0);
658 } catch (RemoteException ex) {
659 // give up
660 throw new RuntimeException(ex);
661 }
662
663 mCallbacks.put(callingPid, record);
664 }
665 }
666
Jeff Brownce468a32013-11-21 16:42:03 -0800667 private void onCallbackDied(CallbackRecord record) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700668 synchronized (mSyncRoot) {
Jeff Brownce468a32013-11-21 16:42:03 -0800669 mCallbacks.remove(record.mPid);
670 stopWifiDisplayScanLocked(record);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700671 }
672 }
673
Jeff Brown4ccb8232014-01-16 22:16:42 -0800674 private void startWifiDisplayScanInternal(int callingPid) {
675 synchronized (mSyncRoot) {
676 CallbackRecord record = mCallbacks.get(callingPid);
677 if (record == null) {
678 throw new IllegalStateException("The calling process has not "
679 + "registered an IDisplayManagerCallback.");
Jeff Browne08ae382012-09-07 20:36:36 -0700680 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800681 startWifiDisplayScanLocked(record);
Jeff Browne08ae382012-09-07 20:36:36 -0700682 }
683 }
684
Jeff Brownce468a32013-11-21 16:42:03 -0800685 private void startWifiDisplayScanLocked(CallbackRecord record) {
686 if (!record.mWifiDisplayScanRequested) {
687 record.mWifiDisplayScanRequested = true;
688 if (mWifiDisplayScanRequestCount++ == 0) {
689 if (mWifiDisplayAdapter != null) {
690 mWifiDisplayAdapter.requestStartScanLocked();
691 }
692 }
693 }
694 }
695
Jeff Brown4ccb8232014-01-16 22:16:42 -0800696 private void stopWifiDisplayScanInternal(int callingPid) {
697 synchronized (mSyncRoot) {
698 CallbackRecord record = mCallbacks.get(callingPid);
699 if (record == null) {
700 throw new IllegalStateException("The calling process has not "
701 + "registered an IDisplayManagerCallback.");
Jeff Brownce468a32013-11-21 16:42:03 -0800702 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800703 stopWifiDisplayScanLocked(record);
Jeff Brownce468a32013-11-21 16:42:03 -0800704 }
705 }
706
707 private void stopWifiDisplayScanLocked(CallbackRecord record) {
708 if (record.mWifiDisplayScanRequested) {
709 record.mWifiDisplayScanRequested = false;
710 if (--mWifiDisplayScanRequestCount == 0) {
711 if (mWifiDisplayAdapter != null) {
712 mWifiDisplayAdapter.requestStopScanLocked();
713 }
714 } else if (mWifiDisplayScanRequestCount < 0) {
Dianne Hackborn8d051722014-10-01 14:59:58 -0700715 Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: "
Jeff Brownce468a32013-11-21 16:42:03 -0800716 + mWifiDisplayScanRequestCount);
717 mWifiDisplayScanRequestCount = 0;
718 }
719 }
720 }
721
Jeff Brown4ccb8232014-01-16 22:16:42 -0800722 private void connectWifiDisplayInternal(String address) {
723 synchronized (mSyncRoot) {
724 if (mWifiDisplayAdapter != null) {
725 mWifiDisplayAdapter.requestConnectLocked(address);
Jeff Browne08ae382012-09-07 20:36:36 -0700726 }
Jeff Browne08ae382012-09-07 20:36:36 -0700727 }
728 }
729
Jeff Brown4ccb8232014-01-16 22:16:42 -0800730 private void pauseWifiDisplayInternal() {
731 synchronized (mSyncRoot) {
732 if (mWifiDisplayAdapter != null) {
733 mWifiDisplayAdapter.requestPauseLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700734 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700735 }
736 }
737
Jeff Brown4ccb8232014-01-16 22:16:42 -0800738 private void resumeWifiDisplayInternal() {
739 synchronized (mSyncRoot) {
740 if (mWifiDisplayAdapter != null) {
741 mWifiDisplayAdapter.requestResumeLocked();
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700742 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700743 }
744 }
745
Jeff Brown4ccb8232014-01-16 22:16:42 -0800746 private void disconnectWifiDisplayInternal() {
747 synchronized (mSyncRoot) {
748 if (mWifiDisplayAdapter != null) {
749 mWifiDisplayAdapter.requestDisconnectLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700750 }
Jeff Browne08ae382012-09-07 20:36:36 -0700751 }
752 }
753
Jeff Brown4ccb8232014-01-16 22:16:42 -0800754 private void renameWifiDisplayInternal(String address, String alias) {
755 synchronized (mSyncRoot) {
756 if (mWifiDisplayAdapter != null) {
757 mWifiDisplayAdapter.requestRenameLocked(address, alias);
Jeff Brown89d55462012-09-19 11:33:42 -0700758 }
Jeff Brown89d55462012-09-19 11:33:42 -0700759 }
760 }
761
Jeff Brown4ccb8232014-01-16 22:16:42 -0800762 private void forgetWifiDisplayInternal(String address) {
763 synchronized (mSyncRoot) {
764 if (mWifiDisplayAdapter != null) {
765 mWifiDisplayAdapter.requestForgetLocked(address);
Jeff Brown89d55462012-09-19 11:33:42 -0700766 }
Jeff Brown89d55462012-09-19 11:33:42 -0700767 }
768 }
769
Jeff Brown4ccb8232014-01-16 22:16:42 -0800770 private WifiDisplayStatus getWifiDisplayStatusInternal() {
771 synchronized (mSyncRoot) {
772 if (mWifiDisplayAdapter != null) {
773 return mWifiDisplayAdapter.getWifiDisplayStatusLocked();
Jeff Browne08ae382012-09-07 20:36:36 -0700774 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800775 return new WifiDisplayStatus();
Jeff Browne08ae382012-09-07 20:36:36 -0700776 }
777 }
778
Michael Wright1c9977b2016-07-12 13:30:10 -0700779 private void requestColorModeInternal(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +0100780 synchronized (mSyncRoot) {
781 LogicalDisplay display = mLogicalDisplays.get(displayId);
782 if (display != null &&
Michael Wright1c9977b2016-07-12 13:30:10 -0700783 display.getRequestedColorModeLocked() != colorMode) {
784 display.setRequestedColorModeLocked(colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100785 scheduleTraversalLocked(false);
786 }
787 }
788 }
789
Michael Wright75ee9fc2014-09-01 19:55:22 -0700790 private int createVirtualDisplayInternal(IVirtualDisplayCallback callback,
Santos Cordonee8931e2017-04-05 10:31:15 -0700791 IMediaProjection projection, int callingUid, String packageName, String name, int width,
792 int height, int densityDpi, Surface surface, int flags, String uniqueId) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800793 synchronized (mSyncRoot) {
794 if (mVirtualDisplayAdapter == null) {
795 Slog.w(TAG, "Rejecting request to create private virtual display "
796 + "because the virtual display adapter is not available.");
797 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700798 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800799
800 DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked(
Santos Cordonee8931e2017-04-05 10:31:15 -0700801 callback, projection, callingUid, packageName, name, width, height, densityDpi,
802 surface, flags, uniqueId);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800803 if (device == null) {
804 return -1;
Jeff Brown7d00aff2013-08-02 19:03:49 -0700805 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700806
Jeff Brown4ccb8232014-01-16 22:16:42 -0800807 handleDisplayDeviceAddedLocked(device);
808 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
809 if (display != null) {
810 return display.getDisplayIdLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700811 }
Jeff Brown4ccb8232014-01-16 22:16:42 -0800812
813 // Something weird happened and the logical display was not created.
814 Slog.w(TAG, "Rejecting request to create virtual display "
815 + "because the logical display was not created.");
Michael Wright75ee9fc2014-09-01 19:55:22 -0700816 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800817 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700818 }
819 return -1;
820 }
821
Michael Wright01e840f2014-06-26 16:03:25 -0700822 private void resizeVirtualDisplayInternal(IBinder appToken,
823 int width, int height, int densityDpi) {
824 synchronized (mSyncRoot) {
825 if (mVirtualDisplayAdapter == null) {
826 return;
827 }
828
829 mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi);
830 }
831 }
832
Jeff Brown92207df2014-04-16 13:16:07 -0700833 private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) {
834 synchronized (mSyncRoot) {
835 if (mVirtualDisplayAdapter == null) {
836 return;
837 }
838
839 mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface);
840 }
841 }
842
Jeff Brown4ccb8232014-01-16 22:16:42 -0800843 private void releaseVirtualDisplayInternal(IBinder appToken) {
844 synchronized (mSyncRoot) {
845 if (mVirtualDisplayAdapter == null) {
846 return;
Jeff Browna506a6e2013-06-04 00:02:38 -0700847 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700848
Jeff Brown4ccb8232014-01-16 22:16:42 -0800849 DisplayDevice device =
850 mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
851 if (device != null) {
852 handleDisplayDeviceRemovedLocked(device);
Jeff Browna506a6e2013-06-04 00:02:38 -0700853 }
854 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700855 }
856
chaviwda4c6942018-11-07 15:52:56 -0800857 private void setVirtualDisplayStateInternal(IBinder appToken, boolean isOn) {
858 synchronized (mSyncRoot) {
859 if (mVirtualDisplayAdapter == null) {
860 return;
861 }
862
863 mVirtualDisplayAdapter.setVirtualDisplayStateLocked(appToken, isOn);
864 }
865 }
866
Santos Cordonc22c5632017-06-21 16:03:49 -0700867 private void registerDefaultDisplayAdapters() {
868 // Register default display adapters.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700869 synchronized (mSyncRoot) {
Santos Cordonc22c5632017-06-21 16:03:49 -0700870 // main display adapter
Mike Lockwoode63f6f72013-11-15 11:01:47 -0800871 registerDisplayAdapterLocked(new LocalDisplayAdapter(
872 mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
Santos Cordonc22c5632017-06-21 16:03:49 -0700873
874 // Standalone VR devices rely on a virtual display as their primary display for
875 // 2D UI. We register virtual display adapter along side the main display adapter
876 // here so that it is ready by the time the system sends the home Intent for
877 // early apps like SetupWizard/Launcher. In particular, SUW is displayed using
878 // the virtual display inside VR before any VR-specific apps even run.
879 mVirtualDisplayAdapter = mInjector.getVirtualDisplayAdapter(mSyncRoot, mContext,
880 mHandler, mDisplayAdapterListener);
881 if (mVirtualDisplayAdapter != null) {
882 registerDisplayAdapterLocked(mVirtualDisplayAdapter);
883 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700884 }
885 }
886
887 private void registerAdditionalDisplayAdapters() {
888 synchronized (mSyncRoot) {
889 if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700890 registerOverlayDisplayAdapterLocked();
891 registerWifiDisplayAdapterLocked();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700892 }
893 }
894 }
895
Jeff Brown89d55462012-09-19 11:33:42 -0700896 private void registerOverlayDisplayAdapterLocked() {
897 registerDisplayAdapterLocked(new OverlayDisplayAdapter(
898 mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler));
899 }
900
901 private void registerWifiDisplayAdapterLocked() {
902 if (mContext.getResources().getBoolean(
Jeff Brownbbd28a22012-09-20 16:47:15 -0700903 com.android.internal.R.bool.config_enableWifiDisplay)
904 || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) {
Jeff Brown89d55462012-09-19 11:33:42 -0700905 mWifiDisplayAdapter = new WifiDisplayAdapter(
906 mSyncRoot, mContext, mHandler, mDisplayAdapterListener,
907 mPersistentDataStore);
908 registerDisplayAdapterLocked(mWifiDisplayAdapter);
909 }
910 }
911
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700912 private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
913 // In safe mode, we disable non-essential display adapters to give the user
914 // an opportunity to fix broken settings or other problems that might affect
915 // system stability.
916 // In only-core mode, we disable non-essential display adapters to minimize
917 // the number of dependencies that are started while in this mode and to
918 // prevent problems that might occur due to the device being encrypted.
919 return !mSafeMode && !mOnlyCore;
920 }
921
922 private void registerDisplayAdapterLocked(DisplayAdapter adapter) {
923 mDisplayAdapters.add(adapter);
924 adapter.registerLocked();
925 }
926
Jeff Brownbd6e1502012-08-28 03:27:37 -0700927 private void handleDisplayDeviceAdded(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700928 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700929 handleDisplayDeviceAddedLocked(device);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700930 }
931 }
932
Jeff Browna506a6e2013-06-04 00:02:38 -0700933 private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700934 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700935 if (mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700936 Slog.w(TAG, "Attempted to add already added display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700937 return;
938 }
939
Jeff Brown10acf6d2015-04-14 14:20:47 -0700940 Slog.i(TAG, "Display device added: " + info);
941 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700942
943 mDisplayDevices.add(device);
Michael Wright1c9977b2016-07-12 13:30:10 -0700944 LogicalDisplay display = addLogicalDisplayLocked(device);
Jeff Brown0033a862014-10-08 12:06:39 -0700945 Runnable work = updateDisplayStateLocked(device);
946 if (work != null) {
947 work.run();
948 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700949 scheduleTraversalLocked(false);
950 }
951
Jeff Brownbd6e1502012-08-28 03:27:37 -0700952 private void handleDisplayDeviceChanged(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700953 synchronized (mSyncRoot) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700954 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700955 if (!mDisplayDevices.contains(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700956 Slog.w(TAG, "Attempted to change non-existent display device: " + info);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700957 return;
958 }
959
Jeff Brown10acf6d2015-04-14 14:20:47 -0700960 int diff = device.mDebugLastLoggedDeviceInfo.diff(info);
961 if (diff == DisplayDeviceInfo.DIFF_STATE) {
962 Slog.i(TAG, "Display device changed state: \"" + info.name
963 + "\", " + Display.stateToString(info.state));
964 } else if (diff != 0) {
965 Slog.i(TAG, "Display device changed: " + info);
966 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700967 if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) {
968 try {
969 mPersistentDataStore.setColorMode(device, info.colorMode);
970 } finally {
971 mPersistentDataStore.saveIfNeeded();
972 }
973 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700974 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browne87bf032012-09-20 18:30:13 -0700975
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700976 device.applyPendingDisplayDeviceInfoChangesLocked();
977 if (updateLogicalDisplaysLocked()) {
Craig Mautner65d11b32012-10-01 13:59:52 -0700978 scheduleTraversalLocked(false);
Jeff Brown64a55af2012-08-26 02:47:39 -0700979 }
980 }
981 }
982
Jeff Brownbd6e1502012-08-28 03:27:37 -0700983 private void handleDisplayDeviceRemoved(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700984 synchronized (mSyncRoot) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700985 handleDisplayDeviceRemovedLocked(device);
986 }
987 }
Jeff Brown8e5d33e2015-06-10 13:05:50 -0700988
Jeff Browna506a6e2013-06-04 00:02:38 -0700989 private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700990 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
Jeff Browna506a6e2013-06-04 00:02:38 -0700991 if (!mDisplayDevices.remove(device)) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700992 Slog.w(TAG, "Attempted to remove non-existent display device: " + info);
Jeff Browna506a6e2013-06-04 00:02:38 -0700993 return;
994 }
995
Jeff Brown10acf6d2015-04-14 14:20:47 -0700996 Slog.i(TAG, "Display device removed: " + info);
997 device.mDebugLastLoggedDeviceInfo = info;
Jeff Browna506a6e2013-06-04 00:02:38 -0700998
Jeff Browna506a6e2013-06-04 00:02:38 -0700999 updateLogicalDisplaysLocked();
1000 scheduleTraversalLocked(false);
1001 }
1002
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001003 private void handleLogicalDisplayChanged(int displayId, @NonNull LogicalDisplay display) {
1004 if (displayId == Display.DEFAULT_DISPLAY) {
1005 recordTopInsetLocked(display);
1006 }
1007 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
1008 }
1009
Jeff Brown8e5d33e2015-06-10 13:05:50 -07001010 private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001011 final int count = mDisplayDevices.size();
1012 for (int i = 0; i < count; i++) {
1013 DisplayDevice device = mDisplayDevices.get(i);
Jeff Browne75926d2014-09-18 15:24:49 -07001014 Runnable runnable = updateDisplayStateLocked(device);
1015 if (runnable != null) {
1016 workQueue.add(runnable);
1017 }
Jeff Browna506a6e2013-06-04 00:02:38 -07001018 }
1019 }
1020
Jeff Browne75926d2014-09-18 15:24:49 -07001021 private Runnable updateDisplayStateLocked(DisplayDevice device) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001022 // Blank or unblank the display immediately to match the state requested
Jeff Brown037c33e2014-04-09 00:31:55 -07001023 // by the display power controller (if known).
Jeff Browna506a6e2013-06-04 00:02:38 -07001024 DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
1025 if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07001026 return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness);
Craig Mautner4f67ba62012-08-02 11:23:00 -07001027 }
Jeff Browne75926d2014-09-18 15:24:49 -07001028 return null;
Craig Mautner4f67ba62012-08-02 11:23:00 -07001029 }
1030
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001031 // Adds a new logical display based on the given display device.
1032 // Sends notifications if needed.
Michael Wright1c9977b2016-07-12 13:30:10 -07001033 private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001034 DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
1035 boolean isDefault = (deviceInfo.flags
1036 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
1037 if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
1038 Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
1039 isDefault = false;
1040 }
1041
Jeff Brown27f1d672012-10-17 18:32:34 -07001042 if (!isDefault && mSingleDisplayDemoMode) {
1043 Slog.i(TAG, "Not creating a logical display for a secondary display "
1044 + " because single display demo mode is enabled: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -07001045 return null;
Jeff Brown27f1d672012-10-17 18:32:34 -07001046 }
1047
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001048 final int displayId = assignDisplayIdLocked(isDefault);
1049 final int layerStack = assignLayerStackLocked(displayId);
1050
Jeff Brownd728bf52012-09-08 18:05:28 -07001051 LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001052 display.updateLocked(mDisplayDevices);
1053 if (!display.isValidLocked()) {
1054 // This should never happen currently.
1055 Slog.w(TAG, "Ignoring display device because the logical display "
1056 + "created from it was not considered valid: " + deviceInfo);
Michael Wright1c9977b2016-07-12 13:30:10 -07001057 return null;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001058 }
1059
Michael Wrighteedcbf12017-08-16 23:14:54 +01001060 configureColorModeLocked(display, device);
1061 if (isDefault) {
1062 recordStableDisplayStatsIfNeededLocked(display);
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001063 recordTopInsetLocked(display);
Michael Wrighteedcbf12017-08-16 23:14:54 +01001064 }
1065
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001066 mLogicalDisplays.put(displayId, display);
1067
1068 // Wake up waitForDefaultDisplay.
1069 if (isDefault) {
1070 mSyncRoot.notifyAll();
1071 }
1072
1073 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
Michael Wright1c9977b2016-07-12 13:30:10 -07001074 return display;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001075 }
1076
1077 private int assignDisplayIdLocked(boolean isDefault) {
1078 return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++;
1079 }
1080
1081 private int assignLayerStackLocked(int displayId) {
1082 // Currently layer stacks and display ids are the same.
1083 // This need not be the case.
1084 return displayId;
1085 }
1086
Michael Wrighteedcbf12017-08-16 23:14:54 +01001087 private void configureColorModeLocked(LogicalDisplay display, DisplayDevice device) {
1088 if (display.getPrimaryDisplayDeviceLocked() == device) {
1089 int colorMode = mPersistentDataStore.getColorMode(device);
1090 if (colorMode == Display.COLOR_MODE_INVALID) {
1091 if ((device.getDisplayDeviceInfoLocked().flags
1092 & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
1093 colorMode = mDefaultDisplayDefaultColorMode;
1094 } else {
1095 colorMode = Display.COLOR_MODE_DEFAULT;
1096 }
1097 }
1098 display.setRequestedColorModeLocked(colorMode);
1099 }
1100 }
1101
1102 // If we've never recorded stable device stats for this device before and they aren't
1103 // explicitly configured, go ahead and record the stable device stats now based on the status
1104 // of the default display at first boot.
1105 private void recordStableDisplayStatsIfNeededLocked(LogicalDisplay d) {
1106 if (mStableDisplaySize.x <= 0 && mStableDisplaySize.y <= 0) {
1107 DisplayInfo info = d.getDisplayInfoLocked();
1108 setStableDisplaySizeLocked(info.getNaturalWidth(), info.getNaturalHeight());
1109 }
1110 }
1111
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001112 private void recordTopInsetLocked(@Nullable LogicalDisplay d) {
Winson72dbe7e2019-04-29 14:55:30 -07001113 // We must only persist the inset after boot has completed, otherwise we will end up
1114 // overwriting the persisted value before the masking flag has been loaded from the
1115 // resource overlay.
1116 if (!mSystemReady || d == null) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001117 return;
1118 }
1119 int topInset = d.getInsets().top;
1120 if (topInset == mDefaultDisplayTopInset) {
1121 return;
1122 }
1123 mDefaultDisplayTopInset = topInset;
1124 SystemProperties.set(PROP_DEFAULT_DISPLAY_TOP_INSET, Integer.toString(topInset));
1125 }
1126
Michael Wrighteedcbf12017-08-16 23:14:54 +01001127 private void setStableDisplaySizeLocked(int width, int height) {
1128 mStableDisplaySize = new Point(width, height);
1129 try {
1130 mPersistentDataStore.setStableDisplaySize(mStableDisplaySize);
1131 } finally {
1132 mPersistentDataStore.saveIfNeeded();
1133 }
1134 }
1135
Dan Gittik122df862018-03-28 16:59:22 +01001136 @VisibleForTesting
1137 Curve getMinimumBrightnessCurveInternal() {
1138 return mMinimumBrightnessCurve;
1139 }
1140
Peiyong Lin277eaff2019-01-16 16:18:22 -08001141 int getPreferredWideGamutColorSpaceIdInternal() {
1142 return mWideColorSpace.getId();
1143 }
1144
Michael Wrighteef0e132017-11-21 17:57:52 +00001145 private void setBrightnessConfigurationForUserInternal(
Dan Gittik7a32fba2018-03-28 12:19:38 +01001146 @Nullable BrightnessConfiguration c, @UserIdInt int userId,
Kenny Guy05ce8092018-01-17 13:44:20 +00001147 @Nullable String packageName) {
Dan Gittik122df862018-03-28 16:59:22 +01001148 validateBrightnessConfiguration(c);
Michael Wrighteef0e132017-11-21 17:57:52 +00001149 final int userSerial = getUserManager().getUserSerialNumber(userId);
1150 synchronized (mSyncRoot) {
1151 try {
Kenny Guy05ce8092018-01-17 13:44:20 +00001152 mPersistentDataStore.setBrightnessConfigurationForUser(c, userSerial,
1153 packageName);
Michael Wrighteef0e132017-11-21 17:57:52 +00001154 } finally {
1155 mPersistentDataStore.saveIfNeeded();
1156 }
1157 if (userId == mCurrentUserId) {
1158 mDisplayPowerController.setBrightnessConfiguration(c);
1159 }
1160 }
1161 }
1162
Dan Gittik122df862018-03-28 16:59:22 +01001163 @VisibleForTesting
1164 void validateBrightnessConfiguration(BrightnessConfiguration config) {
1165 if (config == null) {
1166 return;
1167 }
1168 if (isBrightnessConfigurationTooDark(config)) {
1169 throw new IllegalArgumentException("brightness curve is too dark");
1170 }
1171 }
1172
1173 private boolean isBrightnessConfigurationTooDark(BrightnessConfiguration config) {
1174 Pair<float[], float[]> curve = config.getCurve();
1175 float[] lux = curve.first;
1176 float[] nits = curve.second;
1177 for (int i = 0; i < lux.length; i++) {
1178 if (nits[i] < mMinimumBrightnessSpline.interpolate(lux[i])) {
1179 return true;
1180 }
1181 }
1182 return false;
1183 }
1184
Michael Wrighteef0e132017-11-21 17:57:52 +00001185 private void loadBrightnessConfiguration() {
1186 synchronized (mSyncRoot) {
1187 final int userSerial = getUserManager().getUserSerialNumber(mCurrentUserId);
1188 BrightnessConfiguration config =
1189 mPersistentDataStore.getBrightnessConfiguration(userSerial);
1190 mDisplayPowerController.setBrightnessConfiguration(config);
1191 }
1192 }
1193
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001194 // Updates all existing logical displays given the current set of display devices.
1195 // Removes invalid logical displays.
1196 // Sends notifications if needed.
1197 private boolean updateLogicalDisplaysLocked() {
1198 boolean changed = false;
1199 for (int i = mLogicalDisplays.size(); i-- > 0; ) {
1200 final int displayId = mLogicalDisplays.keyAt(i);
1201 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1202
1203 mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
1204 display.updateLocked(mDisplayDevices);
1205 if (!display.isValidLocked()) {
1206 mLogicalDisplays.removeAt(i);
1207 sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
1208 changed = true;
1209 } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001210 handleLogicalDisplayChanged(displayId, display);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001211 changed = true;
1212 }
1213 }
1214 return changed;
1215 }
1216
Robert Carrae606b42018-02-15 15:36:23 -08001217 private void performTraversalLocked(SurfaceControl.Transaction t) {
Jeff Brownd728bf52012-09-08 18:05:28 -07001218 // Clear all viewports before configuring displays so that we can keep
1219 // track of which ones we have configured.
1220 clearViewportsLocked();
1221
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001222 // Configure each display device.
1223 final int count = mDisplayDevices.size();
1224 for (int i = 0; i < count; i++) {
1225 DisplayDevice device = mDisplayDevices.get(i);
Robert Carrae606b42018-02-15 15:36:23 -08001226 configureDisplayLocked(t, device);
1227 device.performTraversalLocked(t);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001228 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001229
1230 // Tell the input system about these new viewports.
Jeff Brown4ccb8232014-01-16 22:16:42 -08001231 if (mInputManagerInternal != null) {
Jeff Brownd728bf52012-09-08 18:05:28 -07001232 mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
1233 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001234 }
1235
Michael Wright3f145a22014-07-22 19:46:03 -07001236 private void setDisplayPropertiesInternal(int displayId, boolean hasContent,
Galia Peycheva088d7c02019-12-13 11:27:23 +01001237 float requestedRefreshRate, int requestedModeId, boolean preferMinimalPostProcessing,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001238 boolean inTraversal) {
Craig Mautner722285e2012-09-07 13:55:58 -07001239 synchronized (mSyncRoot) {
1240 LogicalDisplay display = mLogicalDisplays.get(displayId);
Michael Wright3f145a22014-07-22 19:46:03 -07001241 if (display == null) {
1242 return;
1243 }
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001244
1245 boolean shouldScheduleTraversal = false;
1246
Michael Wright3f145a22014-07-22 19:46:03 -07001247 if (display.hasContentLocked() != hasContent) {
Jeff Brown33041bd2013-08-02 21:11:14 -07001248 if (DEBUG) {
1249 Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
1250 + "hasContent=" + hasContent + ", inTraversal=" + inTraversal);
1251 }
1252
Craig Mautner722285e2012-09-07 13:55:58 -07001253 display.setHasContentLocked(hasContent);
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001254 shouldScheduleTraversal = true;
Craig Mautner722285e2012-09-07 13:55:58 -07001255 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001256 if (requestedModeId == 0 && requestedRefreshRate != 0) {
1257 // Scan supported modes returned by display.getInfo() to find a mode with the same
1258 // size as the default display mode but with the specified refresh rate instead.
1259 requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate(
1260 requestedRefreshRate);
1261 }
Michael Wrighta3dab232019-02-22 16:54:21 +00001262 mDisplayModeDirector.getAppRequestObserver().setAppRequestedMode(
1263 displayId, requestedModeId);
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001264
Galia Peycheva088d7c02019-12-13 11:27:23 +01001265 if (display.getDisplayInfoLocked().minimalPostProcessingSupported) {
1266 boolean mppRequest = mMinimalPostProcessingAllowed && preferMinimalPostProcessing;
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001267
Galia Peycheva088d7c02019-12-13 11:27:23 +01001268 if (display.getRequestedMinimalPostProcessingLocked() != mppRequest) {
1269 display.setRequestedMinimalPostProcessingLocked(mppRequest);
1270 shouldScheduleTraversal = true;
1271 }
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001272 }
1273
1274 if (shouldScheduleTraversal) {
1275 scheduleTraversalLocked(inTraversal);
1276 }
Craig Mautner722285e2012-09-07 13:55:58 -07001277 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001278 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001279
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08001280 private void setDisplayOffsetsInternal(int displayId, int x, int y) {
1281 synchronized (mSyncRoot) {
1282 LogicalDisplay display = mLogicalDisplays.get(displayId);
1283 if (display == null) {
1284 return;
1285 }
1286 if (display.getDisplayOffsetXLocked() != x
1287 || display.getDisplayOffsetYLocked() != y) {
1288 if (DEBUG) {
1289 Slog.d(TAG, "Display " + displayId + " burn-in offset set to ("
1290 + x + ", " + y + ")");
1291 }
1292 display.setDisplayOffsetsLocked(x, y);
1293 scheduleTraversalLocked(false);
1294 }
1295 }
1296 }
1297
Sam Lin4c3ac2b2019-02-18 04:50:26 -08001298 private void setDisplayScalingDisabledInternal(int displayId, boolean disable) {
1299 synchronized (mSyncRoot) {
1300 final LogicalDisplay display = mLogicalDisplays.get(displayId);
1301 if (display == null) {
1302 return;
1303 }
1304 if (display.isDisplayScalingDisabled() != disable) {
1305 if (DEBUG) {
1306 Slog.d(TAG, "Display " + displayId + " content scaling disabled = " + disable);
1307 }
1308 display.setDisplayScalingDisabledLocked(disable);
1309 scheduleTraversalLocked(false);
1310 }
1311 }
1312 }
1313
Andrii Kulianfb1bf692017-01-17 11:17:34 -08001314 // Updates the lists of UIDs that are present on displays.
1315 private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) {
1316 synchronized (mSyncRoot) {
1317 mDisplayAccessUIDs.clear();
1318 for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) {
1319 mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i),
1320 newDisplayAccessUIDs.valueAt(i));
1321 }
1322 }
1323 }
1324
1325 // Checks if provided UID's content is present on the display and UID has access to it.
1326 private boolean isUidPresentOnDisplayInternal(int uid, int displayId) {
1327 synchronized (mSyncRoot) {
1328 final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId);
1329 return displayUIDs != null && displayUIDs.indexOf(uid) != -1;
1330 }
1331 }
1332
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001333 @Nullable
1334 private IBinder getDisplayToken(int displayId) {
1335 synchronized (mSyncRoot) {
1336 final LogicalDisplay display = mLogicalDisplays.get(displayId);
1337 if (display != null) {
1338 final DisplayDevice device = display.getPrimaryDisplayDeviceLocked();
1339 if (device != null) {
1340 return device.getDisplayTokenLocked();
1341 }
1342 }
1343 }
1344
1345 return null;
1346 }
1347
Robert Carr66b5664f2019-04-02 14:18:56 -07001348 private SurfaceControl.ScreenshotGraphicBuffer screenshotInternal(int displayId) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001349 final IBinder token = getDisplayToken(displayId);
1350 if (token == null) {
Robert Carr66b5664f2019-04-02 14:18:56 -07001351 return null;
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001352 }
Robert Carr66b5664f2019-04-02 14:18:56 -07001353 return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(
Peiyong Line3e5efd2019-03-21 20:59:47 +00001354 token, new Rect(), 0 /* width */, 0 /* height */,
1355 false /* useIdentityTransform */, 0 /* rotation */);
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001356 }
1357
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001358 @VisibleForTesting
1359 DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributesInternal(
1360 int displayId) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001361 final IBinder token = getDisplayToken(displayId);
1362 if (token == null) {
1363 return null;
1364 }
1365 return SurfaceControl.getDisplayedContentSamplingAttributes(token);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001366 }
1367
1368 @VisibleForTesting
1369 boolean setDisplayedContentSamplingEnabledInternal(
1370 int displayId, boolean enable, int componentMask, int maxFrames) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001371 final IBinder token = getDisplayToken(displayId);
1372 if (token == null) {
1373 return false;
1374 }
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001375 return SurfaceControl.setDisplayedContentSamplingEnabled(
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001376 token, enable, componentMask, maxFrames);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001377 }
1378
1379 @VisibleForTesting
1380 DisplayedContentSample getDisplayedContentSampleInternal(int displayId,
1381 long maxFrames, long timestamp) {
Dominik Laskowskie912ae32019-01-26 11:19:36 -08001382 final IBinder token = getDisplayToken(displayId);
1383 if (token == null) {
1384 return null;
1385 }
1386 return SurfaceControl.getDisplayedContentSample(token, maxFrames, timestamp);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001387 }
1388
Santos Cordonc4fd8e62019-12-18 13:01:05 +00001389 void resetBrightnessConfiguration() {
1390 setBrightnessConfigurationForUserInternal(null, mContext.getUserId(),
1391 mContext.getPackageName());
1392 }
1393
1394 void setAutoBrightnessLoggingEnabled(boolean enabled) {
1395 if (mDisplayPowerController != null) {
1396 synchronized (mSyncRoot) {
1397 mDisplayPowerController.setAutoBrightnessLoggingEnabled(enabled);
1398 }
1399 }
1400 }
1401
1402 void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) {
1403 if (mDisplayPowerController != null) {
1404 synchronized (mSyncRoot) {
1405 mDisplayPowerController.setDisplayWhiteBalanceLoggingEnabled(enabled);
1406 }
1407 }
1408 }
1409
1410 void setAmbientColorTemperatureOverride(float cct) {
1411 if (mDisplayPowerController != null) {
1412 synchronized (mSyncRoot) {
1413 mDisplayPowerController.setAmbientColorTemperatureOverride(cct);
1414 }
1415 }
1416 }
1417
Ana Kruleca74a8642019-11-14 00:51:00 +01001418 private void onDesiredDisplayModeSpecsChangedInternal() {
Michael Wrighta3dab232019-02-22 16:54:21 +00001419 boolean changed = false;
1420 synchronized (mSyncRoot) {
1421 final int count = mLogicalDisplays.size();
1422 for (int i = 0; i < count; i++) {
1423 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1424 int displayId = mLogicalDisplays.keyAt(i);
Ana Kruleca74a8642019-11-14 00:51:00 +01001425 DisplayModeDirector.DesiredDisplayModeSpecs desiredDisplayModeSpecs =
1426 mDisplayModeDirector.getDesiredDisplayModeSpecs(displayId);
1427 DisplayModeDirector.DesiredDisplayModeSpecs existingDesiredDisplayModeSpecs =
1428 display.getDesiredDisplayModeSpecsLocked();
1429 if (DEBUG) {
1430 Slog.i(TAG,
1431 "Comparing display specs: " + desiredDisplayModeSpecs
1432 + ", existing: " + existingDesiredDisplayModeSpecs);
1433 }
1434 if (!desiredDisplayModeSpecs.equals(existingDesiredDisplayModeSpecs)) {
1435 display.setDesiredDisplayModeSpecsLocked(desiredDisplayModeSpecs);
Michael Wrighta3dab232019-02-22 16:54:21 +00001436 changed = true;
1437 }
1438 }
1439 if (changed) {
1440 scheduleTraversalLocked(false);
1441 }
1442 }
1443 }
1444
Jeff Brownd728bf52012-09-08 18:05:28 -07001445 private void clearViewportsLocked() {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001446 mViewports.clear();
Craig Mautner722285e2012-09-07 13:55:58 -07001447 }
1448
Robert Carrae606b42018-02-15 15:36:23 -08001449 private void configureDisplayLocked(SurfaceControl.Transaction t, DisplayDevice device) {
Jeff Brownd14c8c92014-01-07 18:13:09 -08001450 final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
1451 final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;
Jeff Browna506a6e2013-06-04 00:02:38 -07001452
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001453 // Find the logical display that the display device is showing.
Jeff Brownd14c8c92014-01-07 18:13:09 -08001454 // Certain displays only ever show their own content.
Craig Mautner722285e2012-09-07 13:55:58 -07001455 LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
Jeff Brownd14c8c92014-01-07 18:13:09 -08001456 if (!ownContent) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001457 if (display != null && !display.hasContentLocked()) {
1458 // If the display does not have any content of its own, then
1459 // automatically mirror the default logical display contents.
1460 display = null;
1461 }
1462 if (display == null) {
1463 display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY);
1464 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001465 }
1466
1467 // Apply the logical display configuration to the display device.
1468 if (display == null) {
1469 // TODO: no logical display for the device, blank it
Jeff Brownd728bf52012-09-08 18:05:28 -07001470 Slog.w(TAG, "Missing logical display to use for physical display device: "
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001471 + device.getDisplayDeviceInfoLocked());
Jeff Brownd728bf52012-09-08 18:05:28 -07001472 return;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001473 }
Robert Carrae606b42018-02-15 15:36:23 -08001474 display.configureDisplayLocked(t, device, info.state == Display.STATE_OFF);
Arthur Hung41e81e72018-10-31 18:04:56 +08001475 final int viewportType;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001476 // Update the corresponding viewport.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001477 if ((info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
Arthur Hung41e81e72018-10-31 18:04:56 +08001478 viewportType = VIEWPORT_INTERNAL;
1479 } else if (info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
1480 viewportType = VIEWPORT_EXTERNAL;
1481 } else if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL
1482 && !TextUtils.isEmpty(info.uniqueId)) {
1483 viewportType = VIEWPORT_VIRTUAL;
1484 } else {
Arthur Hung46c4e582019-02-12 15:55:28 +08001485 Slog.i(TAG, "Display " + info + " does not support input device matching.");
Arthur Hung41e81e72018-10-31 18:04:56 +08001486 return;
Jeff Brownd728bf52012-09-08 18:05:28 -07001487 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001488
Arthur Hung41e81e72018-10-31 18:04:56 +08001489 populateViewportLocked(viewportType, display.getDisplayIdLocked(), device, info.uniqueId);
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001490 }
1491
1492 /**
1493 * Get internal or external viewport. Create it if does not currently exist.
1494 * @param viewportType - either INTERNAL or EXTERNAL
1495 * @return the viewport with the requested type
1496 */
Arthur Hung41e81e72018-10-31 18:04:56 +08001497 private DisplayViewport getViewportLocked(int viewportType, String uniqueId) {
1498 if (viewportType != VIEWPORT_INTERNAL && viewportType != VIEWPORT_EXTERNAL
1499 && viewportType != VIEWPORT_VIRTUAL) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001500 Slog.wtf(TAG, "Cannot call getViewportByTypeLocked for type "
1501 + DisplayViewport.typeToString(viewportType));
1502 return null;
1503 }
Arthur Hung41e81e72018-10-31 18:04:56 +08001504
1505 // Only allow a single INTERNAL or EXTERNAL viewport by forcing their uniqueIds
1506 // to be identical (in particular, empty).
1507 // TODO (b/116824030) allow multiple EXTERNAL viewports and remove this function.
1508 if (viewportType != VIEWPORT_VIRTUAL) {
1509 uniqueId = "";
1510 }
1511
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001512 DisplayViewport viewport;
1513 final int count = mViewports.size();
1514 for (int i = 0; i < count; i++) {
1515 viewport = mViewports.get(i);
Arthur Hung41e81e72018-10-31 18:04:56 +08001516 if (viewport.type == viewportType && uniqueId.equals(viewport.uniqueId)) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001517 return viewport;
1518 }
1519 }
1520
Arthur Hung41e81e72018-10-31 18:04:56 +08001521 // Creates the viewport if none exists.
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001522 viewport = new DisplayViewport();
1523 viewport.type = viewportType;
Arthur Hung41e81e72018-10-31 18:04:56 +08001524 viewport.uniqueId = uniqueId;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001525 mViewports.add(viewport);
1526 return viewport;
1527 }
1528
Arthur Hung41e81e72018-10-31 18:04:56 +08001529 private void populateViewportLocked(int viewportType,
1530 int displayId, DisplayDevice device, String uniqueId) {
1531 final DisplayViewport viewport = getViewportLocked(viewportType, uniqueId);
Jeff Brownd728bf52012-09-08 18:05:28 -07001532 device.populateViewportLocked(viewport);
Arthur Hung41e81e72018-10-31 18:04:56 +08001533 viewport.valid = true;
1534 viewport.displayId = displayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001535 }
1536
1537 private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {
1538 final int count = mLogicalDisplays.size();
1539 for (int i = 0; i < count; i++) {
1540 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1541 if (display.getPrimaryDisplayDeviceLocked() == device) {
1542 return display;
1543 }
1544 }
1545 return null;
1546 }
1547
Jeff Brownbd6e1502012-08-28 03:27:37 -07001548 private void sendDisplayEventLocked(int displayId, int event) {
1549 Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
1550 mHandler.sendMessage(msg);
1551 }
1552
Robert Carrae606b42018-02-15 15:36:23 -08001553 // Requests that performTraversals be called at a
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001554 // later time to apply changes to surfaces and displays.
Craig Mautner65d11b32012-10-01 13:59:52 -07001555 private void scheduleTraversalLocked(boolean inTraversal) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001556 if (!mPendingTraversal && mWindowManagerInternal != null) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001557 mPendingTraversal = true;
Craig Mautner65d11b32012-10-01 13:59:52 -07001558 if (!inTraversal) {
1559 mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL);
1560 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001561 }
1562 }
1563
1564 // Runs on Handler thread.
1565 // Delivers display event notifications to callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001566 private void deliverDisplayEvent(int displayId, int event) {
1567 if (DEBUG) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001568 Slog.d(TAG, "Delivering display event: displayId="
1569 + displayId + ", event=" + event);
Jeff Brownfa25bf52012-07-23 19:26:30 -07001570 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001571
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001572 // Grab the lock and copy the callbacks.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001573 final int count;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001574 synchronized (mSyncRoot) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001575 count = mCallbacks.size();
1576 mTempCallbacks.clear();
1577 for (int i = 0; i < count; i++) {
1578 mTempCallbacks.add(mCallbacks.valueAt(i));
Craig Mautner4f67ba62012-08-02 11:23:00 -07001579 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001580 }
Craig Mautner4f67ba62012-08-02 11:23:00 -07001581
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001582 // After releasing the lock, send the notifications out.
Jeff Brownbd6e1502012-08-28 03:27:37 -07001583 for (int i = 0; i < count; i++) {
1584 mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event);
1585 }
1586 mTempCallbacks.clear();
Craig Mautner4f67ba62012-08-02 11:23:00 -07001587 }
1588
Michael Wrightc39d47a2014-07-08 18:07:36 -07001589 private IMediaProjectionManager getProjectionService() {
1590 if (mProjectionService == null) {
1591 IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE);
1592 mProjectionService = IMediaProjectionManager.Stub.asInterface(b);
1593 }
1594 return mProjectionService;
1595 }
1596
Michael Wrighteef0e132017-11-21 17:57:52 +00001597 private UserManager getUserManager() {
1598 return mContext.getSystemService(UserManager.class);
1599 }
1600
Jeff Brown4ccb8232014-01-16 22:16:42 -08001601 private void dumpInternal(PrintWriter pw) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001602 pw.println("DISPLAY MANAGER (dumpsys display)");
Jeff Brownfa25bf52012-07-23 19:26:30 -07001603
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001604 synchronized (mSyncRoot) {
Jeff Brown9e316a12012-10-08 19:17:06 -07001605 pw.println(" mOnlyCode=" + mOnlyCore);
1606 pw.println(" mSafeMode=" + mSafeMode);
1607 pw.println(" mPendingTraversal=" + mPendingTraversal);
Jeff Brown037c33e2014-04-09 00:31:55 -07001608 pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState));
Jeff Brown9e316a12012-10-08 19:17:06 -07001609 pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId);
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001610 pw.println(" mViewports=" + mViewports);
Damien Bargiacchi4364bbf2016-11-01 21:44:20 -07001611 pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode);
Jeff Brown27f1d672012-10-17 18:32:34 -07001612 pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
Jeff Brownce468a32013-11-21 16:42:03 -08001613 pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount);
Michael Wrighteedcbf12017-08-16 23:14:54 +01001614 pw.println(" mStableDisplaySize=" + mStableDisplaySize);
Kenny Guy2047db92019-02-21 13:04:05 +00001615 pw.println(" mMinimumBrightnessCurve=" + mMinimumBrightnessCurve);
Jeff Brown9e316a12012-10-08 19:17:06 -07001616
Jeff Brownbd6e1502012-08-28 03:27:37 -07001617 IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001618 ipw.increaseIndent();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001619
1620 pw.println();
1621 pw.println("Display Adapters: size=" + mDisplayAdapters.size());
Jeff Brown848c2dc2012-08-19 20:18:08 -07001622 for (DisplayAdapter adapter : mDisplayAdapters) {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001623 pw.println(" " + adapter.getName());
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001624 adapter.dumpLocked(ipw);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001625 }
Craig Mautner9de49362012-08-02 14:30:30 -07001626
Jeff Brownbd6e1502012-08-28 03:27:37 -07001627 pw.println();
1628 pw.println("Display Devices: size=" + mDisplayDevices.size());
1629 for (DisplayDevice device : mDisplayDevices) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001630 pw.println(" " + device.getDisplayDeviceInfoLocked());
1631 device.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001632 }
1633
1634 final int logicalDisplayCount = mLogicalDisplays.size();
1635 pw.println();
1636 pw.println("Logical Displays: size=" + logicalDisplayCount);
1637 for (int i = 0; i < logicalDisplayCount; i++) {
1638 int displayId = mLogicalDisplays.keyAt(i);
1639 LogicalDisplay display = mLogicalDisplays.valueAt(i);
1640 pw.println(" Display " + displayId + ":");
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001641 display.dumpLocked(ipw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001642 }
Jeff Brownce468a32013-11-21 16:42:03 -08001643
Michael Wrighta3dab232019-02-22 16:54:21 +00001644 pw.println();
1645 mDisplayModeDirector.dump(pw);
1646
Jeff Brownce468a32013-11-21 16:42:03 -08001647 final int callbackCount = mCallbacks.size();
1648 pw.println();
1649 pw.println("Callbacks: size=" + callbackCount);
1650 for (int i = 0; i < callbackCount; i++) {
1651 CallbackRecord callback = mCallbacks.valueAt(i);
1652 pw.println(" " + i + ": mPid=" + callback.mPid
1653 + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
1654 }
Jeff Brownad9ef192014-04-08 17:26:30 -07001655
1656 if (mDisplayPowerController != null) {
1657 mDisplayPowerController.dump(pw);
1658 }
Michael Wright1c9977b2016-07-12 13:30:10 -07001659
1660 pw.println();
1661 mPersistentDataStore.dump(pw);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001662 }
1663 }
1664
Dan Gittik122df862018-03-28 16:59:22 +01001665 private static float[] getFloatArray(TypedArray array) {
1666 int length = array.length();
1667 float[] floatArray = new float[length];
1668 for (int i = 0; i < length; i++) {
1669 floatArray[i] = array.getFloat(i, Float.NaN);
1670 }
1671 array.recycle();
1672 return floatArray;
1673 }
1674
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001675 /**
1676 * This is the object that everything in the display manager locks on.
1677 * We make it an inner class within the {@link DisplayManagerService} to so that it is
1678 * clear that the object belongs to the display manager service and that it is
1679 * a unique object with a special purpose.
1680 */
1681 public static final class SyncRoot {
1682 }
1683
Santos Cordonee8931e2017-04-05 10:31:15 -07001684 @VisibleForTesting
1685 static class Injector {
1686 VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context,
1687 Handler handler, DisplayAdapter.Listener displayAdapterListener) {
1688 return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener);
1689 }
Santos Cordonc22c5632017-06-21 16:03:49 -07001690
1691 long getDefaultDisplayDelayTimeout() {
1692 return WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
1693 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001694 }
1695
Alex Sakhartchouk879d24f2017-06-20 22:01:19 -04001696 @VisibleForTesting
1697 DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) {
1698 synchronized (mSyncRoot) {
1699 LogicalDisplay display = mLogicalDisplays.get(displayId);
1700 if (display != null) {
1701 DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked();
1702 return displayDevice.getDisplayDeviceInfoLocked();
1703 }
1704 return null;
1705 }
1706 }
1707
Jeff Brownbd6e1502012-08-28 03:27:37 -07001708 private final class DisplayManagerHandler extends Handler {
1709 public DisplayManagerHandler(Looper looper) {
1710 super(looper, null, true /*async*/);
Jeff Brown848c2dc2012-08-19 20:18:08 -07001711 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001712
Jeff Brownbd6e1502012-08-28 03:27:37 -07001713 @Override
1714 public void handleMessage(Message msg) {
1715 switch (msg.what) {
Santos Cordonc22c5632017-06-21 16:03:49 -07001716 case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS:
1717 registerDefaultDisplayAdapters();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001718 break;
1719
1720 case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS:
1721 registerAdditionalDisplayAdapters();
1722 break;
1723
1724 case MSG_DELIVER_DISPLAY_EVENT:
1725 deliverDisplayEvent(msg.arg1, msg.arg2);
1726 break;
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001727
1728 case MSG_REQUEST_TRAVERSAL:
Jeff Brown4ccb8232014-01-16 22:16:42 -08001729 mWindowManagerInternal.requestTraversalFromDisplayManager();
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001730 break;
Jeff Brownd728bf52012-09-08 18:05:28 -07001731
1732 case MSG_UPDATE_VIEWPORT: {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001733 final boolean changed;
Jeff Brownd728bf52012-09-08 18:05:28 -07001734 synchronized (mSyncRoot) {
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001735 changed = !mTempViewports.equals(mViewports);
1736 if (changed) {
1737 mTempViewports.clear();
1738 for (DisplayViewport d : mViewports) {
1739 mTempViewports.add(d.makeCopy());
1740 }
Santos Cordonee8931e2017-04-05 10:31:15 -07001741 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001742 }
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +01001743 if (changed) {
1744 mInputManagerInternal.setDisplayViewports(mTempViewports);
1745 }
Jeff Brownd728bf52012-09-08 18:05:28 -07001746 break;
1747 }
Kenny Guy22bd0442017-10-26 00:15:54 +01001748
Michael Wrighteef0e132017-11-21 17:57:52 +00001749 case MSG_LOAD_BRIGHTNESS_CONFIGURATION:
1750 loadBrightnessConfiguration();
1751 break;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001752 }
1753 }
1754 }
1755
1756 private final class DisplayAdapterListener implements DisplayAdapter.Listener {
1757 @Override
1758 public void onDisplayDeviceEvent(DisplayDevice device, int event) {
1759 switch (event) {
1760 case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED:
1761 handleDisplayDeviceAdded(device);
1762 break;
1763
1764 case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED:
1765 handleDisplayDeviceChanged(device);
1766 break;
1767
1768 case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED:
1769 handleDisplayDeviceRemoved(device);
1770 break;
1771 }
1772 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001773
1774 @Override
1775 public void onTraversalRequested() {
1776 synchronized (mSyncRoot) {
Craig Mautner65d11b32012-10-01 13:59:52 -07001777 scheduleTraversalLocked(false);
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001778 }
1779 }
Jeff Brownbd6e1502012-08-28 03:27:37 -07001780 }
1781
1782 private final class CallbackRecord implements DeathRecipient {
Jeff Brownce468a32013-11-21 16:42:03 -08001783 public final int mPid;
Jeff Brownbd6e1502012-08-28 03:27:37 -07001784 private final IDisplayManagerCallback mCallback;
1785
Jeff Brownce468a32013-11-21 16:42:03 -08001786 public boolean mWifiDisplayScanRequested;
1787
Jeff Brownbd6e1502012-08-28 03:27:37 -07001788 public CallbackRecord(int pid, IDisplayManagerCallback callback) {
1789 mPid = pid;
1790 mCallback = callback;
1791 }
1792
1793 @Override
1794 public void binderDied() {
1795 if (DEBUG) {
1796 Slog.d(TAG, "Display listener for pid " + mPid + " died.");
1797 }
Jeff Brownce468a32013-11-21 16:42:03 -08001798 onCallbackDied(this);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001799 }
1800
1801 public void notifyDisplayEventAsync(int displayId, int event) {
1802 try {
1803 mCallback.onDisplayEvent(displayId, event);
1804 } catch (RemoteException ex) {
1805 Slog.w(TAG, "Failed to notify process "
1806 + mPid + " that displays changed, assuming it died.", ex);
1807 binderDied();
1808 }
1809 }
1810 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001811
Santos Cordonee8931e2017-04-05 10:31:15 -07001812 @VisibleForTesting
1813 final class BinderService extends IDisplayManager.Stub {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001814 /**
1815 * Returns information about the specified logical display.
1816 *
1817 * @param displayId The logical display id.
lumarkec75b422019-01-07 15:58:38 +08001818 * @return The logical display info, return {@code null} if the display does not exist or
1819 * the calling UID isn't present on the display. The returned object must be treated as
1820 * immutable.
Jeff Brown4ccb8232014-01-16 22:16:42 -08001821 */
1822 @Override // Binder call
1823 public DisplayInfo getDisplayInfo(int displayId) {
1824 final int callingUid = Binder.getCallingUid();
1825 final long token = Binder.clearCallingIdentity();
1826 try {
1827 return getDisplayInfoInternal(displayId, callingUid);
1828 } finally {
1829 Binder.restoreCallingIdentity(token);
1830 }
1831 }
1832
1833 /**
1834 * Returns the list of all display ids.
1835 */
1836 @Override // Binder call
1837 public int[] getDisplayIds() {
1838 final int callingUid = Binder.getCallingUid();
1839 final long token = Binder.clearCallingIdentity();
1840 try {
1841 return getDisplayIdsInternal(callingUid);
1842 } finally {
1843 Binder.restoreCallingIdentity(token);
1844 }
1845 }
1846
lumarkec75b422019-01-07 15:58:38 +08001847 @Override // Binder call
1848 public boolean isUidPresentOnDisplay(int uid, int displayId) {
1849 final long token = Binder.clearCallingIdentity();
1850 try {
1851 return isUidPresentOnDisplayInternal(uid, displayId);
1852 } finally {
1853 Binder.restoreCallingIdentity(token);
1854 }
1855 }
1856
Michael Wrighteedcbf12017-08-16 23:14:54 +01001857 /**
1858 * Returns the stable device display size, in pixels.
1859 */
1860 @Override // Binder call
1861 public Point getStableDisplaySize() {
1862 final long token = Binder.clearCallingIdentity();
1863 try {
1864 return getStableDisplaySizeInternal();
1865 } finally {
1866 Binder.restoreCallingIdentity(token);
1867 }
1868 }
1869
Jeff Brown4ccb8232014-01-16 22:16:42 -08001870 @Override // Binder call
1871 public void registerCallback(IDisplayManagerCallback callback) {
1872 if (callback == null) {
1873 throw new IllegalArgumentException("listener must not be null");
1874 }
1875
1876 final int callingPid = Binder.getCallingPid();
1877 final long token = Binder.clearCallingIdentity();
1878 try {
1879 registerCallbackInternal(callback, callingPid);
1880 } finally {
1881 Binder.restoreCallingIdentity(token);
1882 }
1883 }
1884
1885 @Override // Binder call
1886 public void startWifiDisplayScan() {
1887 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1888 "Permission required to start wifi display scans");
1889
1890 final int callingPid = Binder.getCallingPid();
1891 final long token = Binder.clearCallingIdentity();
1892 try {
1893 startWifiDisplayScanInternal(callingPid);
1894 } finally {
1895 Binder.restoreCallingIdentity(token);
1896 }
1897 }
1898
1899 @Override // Binder call
1900 public void stopWifiDisplayScan() {
1901 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1902 "Permission required to stop wifi display scans");
1903
1904 final int callingPid = Binder.getCallingPid();
1905 final long token = Binder.clearCallingIdentity();
1906 try {
1907 stopWifiDisplayScanInternal(callingPid);
1908 } finally {
1909 Binder.restoreCallingIdentity(token);
1910 }
1911 }
1912
1913 @Override // Binder call
1914 public void connectWifiDisplay(String address) {
1915 if (address == null) {
1916 throw new IllegalArgumentException("address must not be null");
1917 }
1918 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1919 "Permission required to connect to a wifi display");
1920
1921 final long token = Binder.clearCallingIdentity();
1922 try {
1923 connectWifiDisplayInternal(address);
1924 } finally {
1925 Binder.restoreCallingIdentity(token);
1926 }
1927 }
1928
1929 @Override // Binder call
1930 public void disconnectWifiDisplay() {
1931 // This request does not require special permissions.
1932 // Any app can request disconnection from the currently active wifi display.
1933 // This exception should no longer be needed once wifi display control moves
1934 // to the media router service.
1935
1936 final long token = Binder.clearCallingIdentity();
1937 try {
1938 disconnectWifiDisplayInternal();
1939 } finally {
1940 Binder.restoreCallingIdentity(token);
1941 }
1942 }
1943
1944 @Override // Binder call
1945 public void renameWifiDisplay(String address, String alias) {
1946 if (address == null) {
1947 throw new IllegalArgumentException("address must not be null");
1948 }
1949 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1950 "Permission required to rename to a wifi display");
1951
1952 final long token = Binder.clearCallingIdentity();
1953 try {
1954 renameWifiDisplayInternal(address, alias);
1955 } finally {
1956 Binder.restoreCallingIdentity(token);
1957 }
1958 }
1959
1960 @Override // Binder call
1961 public void forgetWifiDisplay(String address) {
1962 if (address == null) {
1963 throw new IllegalArgumentException("address must not be null");
1964 }
1965 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1966 "Permission required to forget to a wifi display");
1967
1968 final long token = Binder.clearCallingIdentity();
1969 try {
1970 forgetWifiDisplayInternal(address);
1971 } finally {
1972 Binder.restoreCallingIdentity(token);
1973 }
1974 }
1975
1976 @Override // Binder call
1977 public void pauseWifiDisplay() {
1978 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1979 "Permission required to pause a wifi display session");
1980
1981 final long token = Binder.clearCallingIdentity();
1982 try {
1983 pauseWifiDisplayInternal();
1984 } finally {
1985 Binder.restoreCallingIdentity(token);
1986 }
1987 }
1988
1989 @Override // Binder call
1990 public void resumeWifiDisplay() {
1991 mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
1992 "Permission required to resume a wifi display session");
1993
1994 final long token = Binder.clearCallingIdentity();
1995 try {
1996 resumeWifiDisplayInternal();
1997 } finally {
1998 Binder.restoreCallingIdentity(token);
1999 }
2000 }
2001
2002 @Override // Binder call
2003 public WifiDisplayStatus getWifiDisplayStatus() {
2004 // This request does not require special permissions.
2005 // Any app can get information about available wifi displays.
2006
2007 final long token = Binder.clearCallingIdentity();
2008 try {
2009 return getWifiDisplayStatusInternal();
2010 } finally {
2011 Binder.restoreCallingIdentity(token);
2012 }
2013 }
2014
2015 @Override // Binder call
Michael Wright1c9977b2016-07-12 13:30:10 -07002016 public void requestColorMode(int displayId, int colorMode) {
Michael Wright58e829f2015-09-15 00:13:26 +01002017 mContext.enforceCallingOrSelfPermission(
Michael Wright1c9977b2016-07-12 13:30:10 -07002018 Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE,
2019 "Permission required to change the display color mode");
Michael Wright58e829f2015-09-15 00:13:26 +01002020 final long token = Binder.clearCallingIdentity();
2021 try {
Michael Wright1c9977b2016-07-12 13:30:10 -07002022 requestColorModeInternal(displayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +01002023 } finally {
2024 Binder.restoreCallingIdentity(token);
2025 }
2026 }
2027
2028 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002029 public int createVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wrightc39d47a2014-07-08 18:07:36 -07002030 IMediaProjection projection, String packageName, String name,
Santos Cordonee8931e2017-04-05 10:31:15 -07002031 int width, int height, int densityDpi, Surface surface, int flags,
2032 String uniqueId) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002033 final int callingUid = Binder.getCallingUid();
2034 if (!validatePackageName(callingUid, packageName)) {
2035 throw new SecurityException("packageName must match the calling uid");
2036 }
Michael Wright75ee9fc2014-09-01 19:55:22 -07002037 if (callback == null) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002038 throw new IllegalArgumentException("appToken must not be null");
2039 }
2040 if (TextUtils.isEmpty(name)) {
2041 throw new IllegalArgumentException("name must be non-null and non-empty");
2042 }
2043 if (width <= 0 || height <= 0 || densityDpi <= 0) {
2044 throw new IllegalArgumentException("width, height, and densityDpi must be "
2045 + "greater than 0");
2046 }
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07002047 if (surface != null && surface.isSingleBuffered()) {
Pablo Ceballosaff2f942016-07-29 14:49:55 -07002048 throw new IllegalArgumentException("Surface can't be single-buffered");
2049 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07002050
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002051 if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
2052 flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
2053
2054 // Public displays can't be allowed to show content when locked.
Andrii Kulian7211d2e2017-01-27 15:58:05 -08002055 if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002056 throw new IllegalArgumentException(
2057 "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE");
2058 }
Michael Wright6720be42014-07-29 19:14:16 -07002059 }
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002060 if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) {
2061 flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
Michael Wright6720be42014-07-29 19:14:16 -07002062 }
2063
Michael Wrightc39d47a2014-07-08 18:07:36 -07002064 if (projection != null) {
2065 try {
2066 if (!getProjectionService().isValidMediaProjection(projection)) {
2067 throw new SecurityException("Invalid media projection");
2068 }
Michael Wright6720be42014-07-29 19:14:16 -07002069 flags = projection.applyVirtualDisplayFlags(flags);
Michael Wrightc39d47a2014-07-08 18:07:36 -07002070 } catch (RemoteException e) {
Michael Wright6720be42014-07-29 19:14:16 -07002071 throw new SecurityException("unable to validate media projection or flags");
Michael Wrightc39d47a2014-07-08 18:07:36 -07002072 }
2073 }
2074
Michael Wright6720be42014-07-29 19:14:16 -07002075 if (callingUid != Process.SYSTEM_UID &&
Andrii Kulianfc8f82b2017-01-26 13:17:27 -08002076 (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002077 if (!canProjectVideo(projection)) {
2078 throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
2079 + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate "
2080 + "MediaProjection token in order to create a screen sharing virtual "
2081 + "display.");
2082 }
2083 }
Santos Cordonb6992f22018-01-30 14:51:20 -08002084 if (callingUid != Process.SYSTEM_UID && (flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002085 if (!canProjectSecureVideo(projection)) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002086 throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT "
Michael Wrightc39d47a2014-07-08 18:07:36 -07002087 + "or an appropriate MediaProjection token to create a "
2088 + "secure virtual display.");
Jeff Brown4ccb8232014-01-16 22:16:42 -08002089 }
2090 }
2091
Chilun67a379b2019-04-11 19:49:42 +08002092 // Sometimes users can have sensitive information in system decoration windows. An app
2093 // could create a virtual display with system decorations support and read the user info
2094 // from the surface.
2095 // We should only allow adding flag VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
2096 // to virtual displays that are owned by the system.
2097 if (callingUid != Process.SYSTEM_UID
2098 && (flags & VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0) {
2099 if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "createVirtualDisplay()")) {
2100 throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
2101 }
2102 }
2103
Jeff Brown4ccb8232014-01-16 22:16:42 -08002104 final long token = Binder.clearCallingIdentity();
2105 try {
Santos Cordonee8931e2017-04-05 10:31:15 -07002106 return createVirtualDisplayInternal(callback, projection, callingUid, packageName,
2107 name, width, height, densityDpi, surface, flags, uniqueId);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002108 } finally {
2109 Binder.restoreCallingIdentity(token);
2110 }
2111 }
2112
2113 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002114 public void resizeVirtualDisplay(IVirtualDisplayCallback callback,
Michael Wright01e840f2014-06-26 16:03:25 -07002115 int width, int height, int densityDpi) {
Jeff Chang01baf6c2019-08-20 16:21:25 +08002116 if (width <= 0 || height <= 0 || densityDpi <= 0) {
2117 throw new IllegalArgumentException("width, height, and densityDpi must be "
2118 + "greater than 0");
2119 }
Michael Wright01e840f2014-06-26 16:03:25 -07002120 final long token = Binder.clearCallingIdentity();
2121 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002122 resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi);
Michael Wright01e840f2014-06-26 16:03:25 -07002123 } finally {
2124 Binder.restoreCallingIdentity(token);
2125 }
2126 }
2127
2128 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002129 public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) {
Pablo Ceballoseb3370d2016-08-31 15:00:17 -07002130 if (surface != null && surface.isSingleBuffered()) {
2131 throw new IllegalArgumentException("Surface can't be single-buffered");
2132 }
Jeff Brown92207df2014-04-16 13:16:07 -07002133 final long token = Binder.clearCallingIdentity();
2134 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002135 setVirtualDisplaySurfaceInternal(callback.asBinder(), surface);
Jeff Brown92207df2014-04-16 13:16:07 -07002136 } finally {
2137 Binder.restoreCallingIdentity(token);
2138 }
2139 }
2140
2141 @Override // Binder call
Michael Wright75ee9fc2014-09-01 19:55:22 -07002142 public void releaseVirtualDisplay(IVirtualDisplayCallback callback) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08002143 final long token = Binder.clearCallingIdentity();
2144 try {
Michael Wright75ee9fc2014-09-01 19:55:22 -07002145 releaseVirtualDisplayInternal(callback.asBinder());
Jeff Brown4ccb8232014-01-16 22:16:42 -08002146 } finally {
2147 Binder.restoreCallingIdentity(token);
2148 }
2149 }
2150
2151 @Override // Binder call
chaviwda4c6942018-11-07 15:52:56 -08002152 public void setVirtualDisplayState(IVirtualDisplayCallback callback, boolean isOn) {
2153 final long token = Binder.clearCallingIdentity();
2154 try {
2155 setVirtualDisplayStateInternal(callback.asBinder(), isOn);
2156 } finally {
2157 Binder.restoreCallingIdentity(token);
2158 }
2159 }
2160
2161 @Override // Binder call
Jeff Brown4ccb8232014-01-16 22:16:42 -08002162 public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06002163 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jeff Brown4ccb8232014-01-16 22:16:42 -08002164
2165 final long token = Binder.clearCallingIdentity();
2166 try {
2167 dumpInternal(pw);
2168 } finally {
2169 Binder.restoreCallingIdentity(token);
2170 }
2171 }
2172
Kenny Guy22bd0442017-10-26 00:15:54 +01002173 @Override // Binder call
Kenny Guy29aa30e2017-11-30 13:43:46 +00002174 public ParceledListSlice<BrightnessChangeEvent> getBrightnessEvents(String callingPackage) {
Kenny Guy22bd0442017-10-26 00:15:54 +01002175 mContext.enforceCallingOrSelfPermission(
2176 Manifest.permission.BRIGHTNESS_SLIDER_USAGE,
2177 "Permission to read brightness events.");
Kenny Guy29aa30e2017-11-30 13:43:46 +00002178
2179 final int callingUid = Binder.getCallingUid();
2180 AppOpsManager appOpsManager = mContext.getSystemService(AppOpsManager.class);
Jeff Sharkeyd9311192018-04-16 16:50:34 +00002181 final int mode = appOpsManager.noteOp(AppOpsManager.OP_GET_USAGE_STATS,
Kenny Guy29aa30e2017-11-30 13:43:46 +00002182 callingUid, callingPackage);
2183 final boolean hasUsageStats;
2184 if (mode == AppOpsManager.MODE_DEFAULT) {
2185 // The default behavior here is to check if PackageManager has given the app
2186 // permission.
2187 hasUsageStats = mContext.checkCallingPermission(
2188 Manifest.permission.PACKAGE_USAGE_STATS)
2189 == PackageManager.PERMISSION_GRANTED;
2190 } else {
2191 hasUsageStats = mode == AppOpsManager.MODE_ALLOWED;
2192 }
2193
2194 final int userId = UserHandle.getUserId(callingUid);
Kenny Guy22bd0442017-10-26 00:15:54 +01002195 final long token = Binder.clearCallingIdentity();
2196 try {
Michael Wright144aac92017-12-21 18:37:41 +00002197 synchronized (mSyncRoot) {
2198 return mDisplayPowerController.getBrightnessEvents(userId, hasUsageStats);
2199 }
Kenny Guy22bd0442017-10-26 00:15:54 +01002200 } finally {
2201 Binder.restoreCallingIdentity(token);
2202 }
2203 }
2204
Michael Wrighteef0e132017-11-21 17:57:52 +00002205 @Override // Binder call
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002206 public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats() {
2207 mContext.enforceCallingOrSelfPermission(
2208 Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS,
2209 "Permission required to to access ambient light stats.");
2210 final int callingUid = Binder.getCallingUid();
2211 final int userId = UserHandle.getUserId(callingUid);
2212 final long token = Binder.clearCallingIdentity();
2213 try {
2214 synchronized (mSyncRoot) {
2215 return mDisplayPowerController.getAmbientBrightnessStats(userId);
2216 }
2217 } finally {
2218 Binder.restoreCallingIdentity(token);
2219 }
2220 }
2221
2222 @Override // Binder call
Michael Wrighteef0e132017-11-21 17:57:52 +00002223 public void setBrightnessConfigurationForUser(
Kenny Guy05ce8092018-01-17 13:44:20 +00002224 BrightnessConfiguration c, @UserIdInt int userId, String packageName) {
Michael Wrighteef0e132017-11-21 17:57:52 +00002225 mContext.enforceCallingOrSelfPermission(
2226 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2227 "Permission required to change the display's brightness configuration");
2228 if (userId != UserHandle.getCallingUserId()) {
2229 mContext.enforceCallingOrSelfPermission(
2230 Manifest.permission.INTERACT_ACROSS_USERS,
2231 "Permission required to change the display brightness"
2232 + " configuration of another user");
2233 }
Kenny Guy05ce8092018-01-17 13:44:20 +00002234 if (packageName != null && !validatePackageName(getCallingUid(), packageName)) {
2235 packageName = null;
2236 }
Michael Wrighteef0e132017-11-21 17:57:52 +00002237 final long token = Binder.clearCallingIdentity();
2238 try {
Kenny Guy05ce8092018-01-17 13:44:20 +00002239 setBrightnessConfigurationForUserInternal(c, userId, packageName);
Michael Wrighteef0e132017-11-21 17:57:52 +00002240 } finally {
2241 Binder.restoreCallingIdentity(token);
2242 }
2243 }
2244
Michael Wrightd8460232018-01-16 18:04:59 +00002245 @Override // Binder call
Kenny Guy6d1009f2018-03-14 14:28:23 +00002246 public BrightnessConfiguration getBrightnessConfigurationForUser(int userId) {
2247 mContext.enforceCallingOrSelfPermission(
2248 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2249 "Permission required to read the display's brightness configuration");
2250 if (userId != UserHandle.getCallingUserId()) {
2251 mContext.enforceCallingOrSelfPermission(
2252 Manifest.permission.INTERACT_ACROSS_USERS,
2253 "Permission required to read the display brightness"
2254 + " configuration of another user");
2255 }
2256 final long token = Binder.clearCallingIdentity();
2257 try {
2258 final int userSerial = getUserManager().getUserSerialNumber(userId);
2259 synchronized (mSyncRoot) {
2260 BrightnessConfiguration config =
2261 mPersistentDataStore.getBrightnessConfiguration(userSerial);
2262 if (config == null) {
2263 config = mDisplayPowerController.getDefaultBrightnessConfiguration();
2264 }
2265 return config;
2266 }
2267 } finally {
2268 Binder.restoreCallingIdentity(token);
2269 }
2270 }
2271
2272 @Override // Binder call
2273 public BrightnessConfiguration getDefaultBrightnessConfiguration() {
2274 mContext.enforceCallingOrSelfPermission(
2275 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS,
2276 "Permission required to read the display's default brightness configuration");
2277 final long token = Binder.clearCallingIdentity();
2278 try {
2279 synchronized (mSyncRoot) {
2280 return mDisplayPowerController.getDefaultBrightnessConfiguration();
2281 }
2282 } finally {
2283 Binder.restoreCallingIdentity(token);
2284 }
2285 }
2286
2287 @Override // Binder call
Michael Wrightd8460232018-01-16 18:04:59 +00002288 public void setTemporaryBrightness(int brightness) {
2289 mContext.enforceCallingOrSelfPermission(
2290 Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS,
2291 "Permission required to set the display's brightness");
2292 final long token = Binder.clearCallingIdentity();
2293 try {
2294 synchronized (mSyncRoot) {
2295 mDisplayPowerController.setTemporaryBrightness(brightness);
2296 }
2297 } finally {
2298 Binder.restoreCallingIdentity(token);
2299 }
2300 }
2301
2302 @Override // Binder call
2303 public void setTemporaryAutoBrightnessAdjustment(float adjustment) {
2304 mContext.enforceCallingOrSelfPermission(
2305 Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS,
2306 "Permission required to set the display's auto brightness adjustment");
2307 final long token = Binder.clearCallingIdentity();
2308 try {
2309 synchronized (mSyncRoot) {
2310 mDisplayPowerController.setTemporaryAutoBrightnessAdjustment(adjustment);
2311 }
2312 } finally {
2313 Binder.restoreCallingIdentity(token);
2314 }
2315 }
2316
Dan Gittik7a32fba2018-03-28 12:19:38 +01002317 @Override // Binder call
2318 public void onShellCommand(FileDescriptor in, FileDescriptor out,
2319 FileDescriptor err, String[] args, ShellCallback callback,
2320 ResultReceiver resultReceiver) {
Santos Cordonc4fd8e62019-12-18 13:01:05 +00002321 new DisplayManagerShellCommand(DisplayManagerService.this).exec(this, in, out, err,
2322 args, callback, resultReceiver);
Dan Gittik7a32fba2018-03-28 12:19:38 +01002323 }
2324
Dan Gittik122df862018-03-28 16:59:22 +01002325 @Override // Binder call
2326 public Curve getMinimumBrightnessCurve() {
2327 final long token = Binder.clearCallingIdentity();
2328 try {
2329 return getMinimumBrightnessCurveInternal();
2330 } finally {
2331 Binder.restoreCallingIdentity(token);
2332 }
2333 }
2334
Peiyong Lin277eaff2019-01-16 16:18:22 -08002335 @Override // Binder call
2336 public int getPreferredWideGamutColorSpaceId() {
2337 final long token = Binder.clearCallingIdentity();
2338 try {
2339 return getPreferredWideGamutColorSpaceIdInternal();
2340 } finally {
2341 Binder.restoreCallingIdentity(token);
2342 }
2343 }
2344
Jeff Brown4ccb8232014-01-16 22:16:42 -08002345 private boolean validatePackageName(int uid, String packageName) {
2346 if (packageName != null) {
2347 String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
2348 if (packageNames != null) {
2349 for (String n : packageNames) {
2350 if (n.equals(packageName)) {
2351 return true;
2352 }
2353 }
2354 }
2355 }
2356 return false;
2357 }
Michael Wrightc39d47a2014-07-08 18:07:36 -07002358
2359 private boolean canProjectVideo(IMediaProjection projection) {
2360 if (projection != null) {
2361 try {
2362 if (projection.canProjectVideo()) {
2363 return true;
2364 }
2365 } catch (RemoteException e) {
2366 Slog.e(TAG, "Unable to query projection service for permissions", e);
2367 }
2368 }
Chilun67a379b2019-04-11 19:49:42 +08002369 if (checkCallingPermission(CAPTURE_VIDEO_OUTPUT, "canProjectVideo()")) {
Michael Wrightc39d47a2014-07-08 18:07:36 -07002370 return true;
2371 }
2372 return canProjectSecureVideo(projection);
2373 }
2374
2375 private boolean canProjectSecureVideo(IMediaProjection projection) {
2376 if (projection != null) {
2377 try {
2378 if (projection.canProjectSecureVideo()){
2379 return true;
2380 }
2381 } catch (RemoteException e) {
2382 Slog.e(TAG, "Unable to query projection service for permissions", e);
2383 }
2384 }
Chilun67a379b2019-04-11 19:49:42 +08002385 return checkCallingPermission(CAPTURE_SECURE_VIDEO_OUTPUT, "canProjectSecureVideo()");
2386 }
2387
2388 private boolean checkCallingPermission(String permission, String func) {
2389 if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) {
2390 return true;
2391 }
2392 final String msg = "Permission Denial: " + func + " from pid=" + Binder.getCallingPid()
2393 + ", uid=" + Binder.getCallingUid() + " requires " + permission;
2394 Slog.w(TAG, msg);
2395 return false;
Michael Wrightc39d47a2014-07-08 18:07:36 -07002396 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08002397 }
2398
2399 private final class LocalService extends DisplayManagerInternal {
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002400
Jeff Brown4ccb8232014-01-16 22:16:42 -08002401 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07002402 public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler,
Jeff Brownad9ef192014-04-08 17:26:30 -07002403 SensorManager sensorManager) {
2404 synchronized (mSyncRoot) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002405 DisplayBlanker blanker = new DisplayBlanker() {
2406 @Override
Jeff Brown5d6443b2015-04-10 20:15:01 -07002407 public void requestDisplayState(int state, int brightness) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002408 // The order of operations is important for legacy reasons.
2409 if (state == Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07002410 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07002411 }
2412
2413 callbacks.onDisplayStateChange(state);
2414
2415 if (state != Display.STATE_OFF) {
Jeff Brown5d6443b2015-04-10 20:15:01 -07002416 requestGlobalDisplayStateInternal(state, brightness);
Jeff Brown037c33e2014-04-09 00:31:55 -07002417 }
2418 }
2419 };
Jeff Brownad9ef192014-04-08 17:26:30 -07002420 mDisplayPowerController = new DisplayPowerController(
Jeff Brown037c33e2014-04-09 00:31:55 -07002421 mContext, callbacks, handler, sensorManager, blanker);
Long Lingbc841b02019-07-03 16:43:15 -07002422 mSensorManager = sensorManager;
Jeff Brownad9ef192014-04-08 17:26:30 -07002423 }
Michael Wrighteef0e132017-11-21 17:57:52 +00002424
2425 mHandler.sendEmptyMessage(MSG_LOAD_BRIGHTNESS_CONFIGURATION);
Jeff Brownad9ef192014-04-08 17:26:30 -07002426 }
2427
2428 @Override
2429 public boolean requestPowerState(DisplayPowerRequest request,
2430 boolean waitForNegativeProximity) {
Michael Wrighteef0e132017-11-21 17:57:52 +00002431 synchronized (mSyncRoot) {
2432 return mDisplayPowerController.requestPowerState(request,
2433 waitForNegativeProximity);
2434 }
Jeff Brownad9ef192014-04-08 17:26:30 -07002435 }
2436
2437 @Override
2438 public boolean isProximitySensorAvailable() {
Michael Wrighteef0e132017-11-21 17:57:52 +00002439 synchronized (mSyncRoot) {
2440 return mDisplayPowerController.isProximitySensorAvailable();
2441 }
Jeff Brownad9ef192014-04-08 17:26:30 -07002442 }
2443
2444 @Override
Robert Carr66b5664f2019-04-02 14:18:56 -07002445 public SurfaceControl.ScreenshotGraphicBuffer screenshot(int displayId) {
2446 return screenshotInternal(displayId);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002447 }
2448
2449 @Override
Jeff Brown4ccb8232014-01-16 22:16:42 -08002450 public DisplayInfo getDisplayInfo(int displayId) {
2451 return getDisplayInfoInternal(displayId, Process.myUid());
2452 }
2453
2454 @Override
2455 public void registerDisplayTransactionListener(DisplayTransactionListener listener) {
2456 if (listener == null) {
2457 throw new IllegalArgumentException("listener must not be null");
2458 }
2459
2460 registerDisplayTransactionListenerInternal(listener);
2461 }
2462
2463 @Override
2464 public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) {
2465 if (listener == null) {
2466 throw new IllegalArgumentException("listener must not be null");
2467 }
2468
2469 unregisterDisplayTransactionListenerInternal(listener);
2470 }
2471
2472 @Override
2473 public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) {
2474 setDisplayInfoOverrideFromWindowManagerInternal(displayId, info);
2475 }
2476
2477 @Override
Andrii Kuliancd097992017-03-23 18:31:59 -07002478 public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) {
2479 getNonOverrideDisplayInfoInternal(displayId, outInfo);
2480 }
2481
2482 @Override
Robert Carrae606b42018-02-15 15:36:23 -08002483 public void performTraversal(SurfaceControl.Transaction t) {
2484 performTraversalInternal(t);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002485 }
2486
2487 @Override
Michael Wright3f145a22014-07-22 19:46:03 -07002488 public void setDisplayProperties(int displayId, boolean hasContent,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002489 float requestedRefreshRate, int requestedMode,
2490 boolean requestedMinimalPostProcessing, boolean inTraversal) {
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07002491 setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate,
Galia Peycheva056b3ee2019-06-26 14:05:12 +02002492 requestedMode, requestedMinimalPostProcessing, inTraversal);
Jeff Brown4ccb8232014-01-16 22:16:42 -08002493 }
Filip Gruszczynskid2e86402015-02-19 13:05:03 -08002494
2495 @Override
2496 public void setDisplayOffsets(int displayId, int x, int y) {
2497 setDisplayOffsetsInternal(displayId, x, y);
2498 }
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002499
2500 @Override
Sam Lin4c3ac2b2019-02-18 04:50:26 -08002501 public void setDisplayScalingDisabled(int displayId, boolean disableScaling) {
2502 setDisplayScalingDisabledInternal(displayId, disableScaling);
2503 }
2504
2505 @Override
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002506 public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) {
2507 setDisplayAccessUIDsInternal(newDisplayAccessUIDs);
2508 }
2509
2510 @Override
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002511 public void persistBrightnessTrackerState() {
Michael Wright144aac92017-12-21 18:37:41 +00002512 synchronized (mSyncRoot) {
Peeyush Agarwalcc155dd2018-01-10 11:51:33 +00002513 mDisplayPowerController.persistBrightnessTrackerState();
Michael Wright144aac92017-12-21 18:37:41 +00002514 }
Kenny Guycfe7b702017-11-14 21:04:58 +00002515 }
Adrian Roose1d68cd2018-01-17 12:54:50 +01002516
2517 @Override
2518 public void onOverlayChanged() {
2519 synchronized (mSyncRoot) {
Adrian Roos898ec382018-01-17 12:54:50 +01002520 for (int i = 0; i < mDisplayDevices.size(); i++) {
2521 mDisplayDevices.get(i).onOverlayChangedLocked();
Adrian Roose1d68cd2018-01-17 12:54:50 +01002522 }
2523 }
2524 }
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07002525
2526 @Override
2527 public DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes(
2528 int displayId) {
2529 return getDisplayedContentSamplingAttributesInternal(displayId);
2530 }
2531
2532 @Override
2533 public boolean setDisplayedContentSamplingEnabled(
2534 int displayId, boolean enable, int componentMask, int maxFrames) {
2535 return setDisplayedContentSamplingEnabledInternal(
2536 displayId, enable, componentMask, maxFrames);
2537 }
2538
2539 @Override
2540 public DisplayedContentSample getDisplayedContentSample(int displayId,
2541 long maxFrames, long timestamp) {
2542 return getDisplayedContentSampleInternal(displayId, maxFrames, timestamp);
2543 }
2544
Jeff Brown4ccb8232014-01-16 22:16:42 -08002545 }
Michael Wrighta3dab232019-02-22 16:54:21 +00002546
Ana Kruleca74a8642019-11-14 00:51:00 +01002547 class DesiredDisplayModeSpecsObserver
2548 implements DisplayModeDirector.DesiredDisplayModeSpecsListener {
2549 public void onDesiredDisplayModeSpecsChanged() {
2550 onDesiredDisplayModeSpecsChangedInternal();
Michael Wrighta3dab232019-02-22 16:54:21 +00002551 }
2552 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07002553}