Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.display; |
| 18 | |
Chilun | 67a379b | 2019-04-11 19:49:42 +0800 | [diff] [blame] | 19 | import static android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT; |
| 20 | import static android.Manifest.permission.CAPTURE_VIDEO_OUTPUT; |
| 21 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 22 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
Chilun | 67a379b | 2019-04-11 19:49:42 +0800 | [diff] [blame] | 23 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 24 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; |
| 25 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; |
| 26 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE; |
Chilun | 67a379b | 2019-04-11 19:49:42 +0800 | [diff] [blame] | 27 | import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 28 | import static android.hardware.display.DisplayViewport.VIEWPORT_EXTERNAL; |
| 29 | import static android.hardware.display.DisplayViewport.VIEWPORT_INTERNAL; |
| 30 | import static android.hardware.display.DisplayViewport.VIEWPORT_VIRTUAL; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 31 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 32 | import android.Manifest; |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 33 | import android.annotation.NonNull; |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 34 | import android.annotation.Nullable; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 35 | import android.annotation.UserIdInt; |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 36 | import android.app.AppOpsManager; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 37 | import android.content.Context; |
| 38 | import android.content.pm.PackageManager; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 39 | import android.content.pm.ParceledListSlice; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 40 | import android.content.res.Resources; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 41 | import android.content.res.TypedArray; |
Peiyong Lin | 277eaff | 2019-01-16 16:18:22 -0800 | [diff] [blame] | 42 | import android.graphics.ColorSpace; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 43 | import android.graphics.Point; |
Robert Carr | 5c52b13 | 2019-02-15 15:48:11 -0800 | [diff] [blame] | 44 | import android.graphics.Rect; |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 45 | import android.hardware.SensorManager; |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 46 | import android.hardware.display.AmbientBrightnessDayStats; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 47 | import android.hardware.display.BrightnessChangeEvent; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 48 | import android.hardware.display.BrightnessConfiguration; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 49 | import android.hardware.display.Curve; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 50 | import android.hardware.display.DisplayManagerGlobal; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 51 | import android.hardware.display.DisplayManagerInternal; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 52 | import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener; |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 53 | import android.hardware.display.DisplayViewport; |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 54 | import android.hardware.display.DisplayedContentSample; |
| 55 | import android.hardware.display.DisplayedContentSamplingAttributes; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 56 | import android.hardware.display.IDisplayManager; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 57 | import android.hardware.display.IDisplayManagerCallback; |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 58 | import android.hardware.display.IVirtualDisplayCallback; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 59 | import android.hardware.display.WifiDisplayStatus; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 60 | import android.hardware.input.InputManagerInternal; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 61 | import android.media.projection.IMediaProjection; |
| 62 | import android.media.projection.IMediaProjectionManager; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 63 | import android.os.Binder; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 64 | import android.os.Handler; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 65 | import android.os.IBinder; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 66 | import android.os.IBinder.DeathRecipient; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 67 | import android.os.Looper; |
| 68 | import android.os.Message; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 69 | import android.os.PowerManager; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 70 | import android.os.Process; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 71 | import android.os.RemoteException; |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 72 | import android.os.ResultReceiver; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 73 | import android.os.ServiceManager; |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 74 | import android.os.ShellCallback; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 75 | import android.os.SystemClock; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 76 | import android.os.SystemProperties; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 77 | import android.os.Trace; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 78 | import android.os.UserHandle; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 79 | import android.os.UserManager; |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 80 | import android.provider.Settings; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 81 | import android.text.TextUtils; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 82 | import android.util.IntArray; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 83 | import android.util.Pair; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 84 | import android.util.Slog; |
| 85 | import android.util.SparseArray; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 86 | import android.util.Spline; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 87 | import android.view.Display; |
| 88 | import android.view.DisplayInfo; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 89 | import android.view.Surface; |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 90 | import android.view.SurfaceControl; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 91 | |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 92 | import com.android.internal.annotations.GuardedBy; |
| 93 | import com.android.internal.annotations.VisibleForTesting; |
| 94 | import com.android.internal.util.DumpUtils; |
| 95 | import com.android.internal.util.IndentingPrintWriter; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 96 | import com.android.server.AnimationThread; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 97 | import com.android.server.DisplayThread; |
| 98 | import com.android.server.LocalServices; |
| 99 | import com.android.server.SystemService; |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 100 | import com.android.server.UiThread; |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 101 | import com.android.server.wm.SurfaceAnimationThread; |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 102 | import com.android.server.wm.WindowManagerInternal; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 103 | |
| 104 | import java.io.FileDescriptor; |
| 105 | import java.io.PrintWriter; |
| 106 | import java.util.ArrayList; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 107 | import java.util.Arrays; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 108 | import java.util.List; |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 109 | import java.util.concurrent.CopyOnWriteArrayList; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 112 | * Manages attached displays. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 113 | * <p> |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 114 | * The {@link DisplayManagerService} manages the global lifecycle of displays, |
| 115 | * decides how to configure logical displays based on the physical display devices currently |
| 116 | * attached, sends notifications to the system and to applications when the state |
| 117 | * changes, and so on. |
| 118 | * </p><p> |
| 119 | * The display manager service relies on a collection of {@link DisplayAdapter} components, |
| 120 | * for discovering and configuring physical display devices attached to the system. |
| 121 | * There are separate display adapters for each manner that devices are attached: |
| 122 | * one display adapter for built-in local displays, one for simulated non-functional |
| 123 | * displays when the system is headless, one for simulated overlay displays used for |
| 124 | * development, one for wifi displays, etc. |
| 125 | * </p><p> |
| 126 | * Display adapters are only weakly coupled to the display manager service. |
| 127 | * Display adapters communicate changes in display device state to the display manager |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 128 | * service asynchronously via a {@link DisplayAdapter.Listener} registered |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 129 | * by the display manager service. This separation of concerns is important for |
| 130 | * two main reasons. First, it neatly encapsulates the responsibilities of these |
| 131 | * two classes: display adapters handle individual display devices whereas |
| 132 | * the display manager service handles the global state. Second, it eliminates |
| 133 | * the potential for deadlocks resulting from asynchronous display device discovery. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 134 | * </p> |
| 135 | * |
| 136 | * <h3>Synchronization</h3> |
| 137 | * <p> |
| 138 | * Because the display manager may be accessed by multiple threads, the synchronization |
| 139 | * story gets a little complicated. In particular, the window manager may call into |
| 140 | * the display manager while holding a surface transaction with the expectation that |
| 141 | * it can apply changes immediately. Unfortunately, that means we can't just do |
| 142 | * everything asynchronously (*grump*). |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 143 | * </p><p> |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 144 | * To make this work, all of the objects that belong to the display manager must |
| 145 | * use the same lock. We call this lock the synchronization root and it has a unique |
| 146 | * type {@link DisplayManagerService.SyncRoot}. Methods that require this lock are |
| 147 | * named with the "Locked" suffix. |
| 148 | * </p><p> |
| 149 | * Where things get tricky is that the display manager is not allowed to make |
| 150 | * any potentially reentrant calls, especially into the window manager. We generally |
| 151 | * avoid this by making all potentially reentrant out-calls asynchronous. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 152 | * </p> |
| 153 | */ |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 154 | public final class DisplayManagerService extends SystemService { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 155 | private static final String TAG = "DisplayManagerService"; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 156 | private static final boolean DEBUG = false; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 157 | |
Jeff Brown | bbd28a2 | 2012-09-20 16:47:15 -0700 | [diff] [blame] | 158 | // When this system property is set to 0, WFD is forcibly disabled on boot. |
| 159 | // When this system property is set to 1, WFD is forcibly enabled on boot. |
| 160 | // Otherwise WFD is enabled according to the value of config_enableWifiDisplay. |
| 161 | private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable"; |
| 162 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 163 | private static final String PROP_DEFAULT_DISPLAY_TOP_INSET = "persist.sys.displayinset.top"; |
| 164 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 165 | private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000; |
| 166 | |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 167 | private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS = 1; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 168 | private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2; |
| 169 | private static final int MSG_DELIVER_DISPLAY_EVENT = 3; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 170 | private static final int MSG_REQUEST_TRAVERSAL = 4; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 171 | private static final int MSG_UPDATE_VIEWPORT = 5; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 172 | private static final int MSG_LOAD_BRIGHTNESS_CONFIGURATION = 6; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 173 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 174 | private final Context mContext; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 175 | private final DisplayManagerHandler mHandler; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 176 | private final Handler mUiHandler; |
| 177 | private final DisplayAdapterListener mDisplayAdapterListener; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 178 | private final DisplayModeDirector mDisplayModeDirector; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 179 | private WindowManagerInternal mWindowManagerInternal; |
| 180 | private InputManagerInternal mInputManagerInternal; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 181 | private IMediaProjectionManager mProjectionService; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 182 | |
| 183 | // The synchronization root for the display manager. |
| 184 | // This lock guards most of the display manager's state. |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 185 | // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call |
| 186 | // into WindowManagerService methods that require mWindowMap while holding this unless you are |
| 187 | // very very sure that no deadlock can occur. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 188 | private final SyncRoot mSyncRoot = new SyncRoot(); |
| 189 | |
| 190 | // True if in safe mode. |
| 191 | // This option may disable certain display adapters. |
| 192 | public boolean mSafeMode; |
| 193 | |
| 194 | // True if we are in a special boot mode where only core applications and |
| 195 | // services should be started. This option may disable certain display adapters. |
| 196 | public boolean mOnlyCore; |
| 197 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 198 | // True if the display manager service should pretend there is only one display |
| 199 | // and only tell applications about the existence of the default logical display. |
| 200 | // The display manager can still mirror content to secondary displays but applications |
| 201 | // cannot present unique content on those displays. |
| 202 | // Used for demonstration purposes only. |
| 203 | private final boolean mSingleDisplayDemoMode; |
| 204 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 205 | // All callback records indexed by calling process id. |
| 206 | public final SparseArray<CallbackRecord> mCallbacks = |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 207 | new SparseArray<CallbackRecord>(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 208 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 209 | // List of all currently registered display adapters. |
| 210 | private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>(); |
| 211 | |
| 212 | // List of all currently connected display devices. |
| 213 | private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>(); |
| 214 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 215 | // List of all logical displays indexed by logical display id. |
| 216 | private final SparseArray<LogicalDisplay> mLogicalDisplays = |
| 217 | new SparseArray<LogicalDisplay>(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 218 | private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1; |
| 219 | |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 220 | // List of all display transaction listeners. |
| 221 | private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners = |
| 222 | new CopyOnWriteArrayList<DisplayTransactionListener>(); |
| 223 | |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 224 | // Display power controller. |
| 225 | private DisplayPowerController mDisplayPowerController; |
| 226 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 227 | // The overall display state, independent of changes that might influence one |
| 228 | // display or another in particular. |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 229 | private int mGlobalDisplayState = Display.STATE_ON; |
| 230 | |
| 231 | // The overall display brightness. |
| 232 | // For now, this only applies to the built-in display but we may split it up eventually. |
| 233 | private int mGlobalDisplayBrightness = PowerManager.BRIGHTNESS_DEFAULT; |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 234 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 235 | // Set to true when there are pending display changes that have yet to be applied |
| 236 | // to the surface flinger state. |
| 237 | private boolean mPendingTraversal; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 238 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 239 | // The Wifi display adapter, or null if not registered. |
| 240 | private WifiDisplayAdapter mWifiDisplayAdapter; |
| 241 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 242 | // The number of active wifi display scan requests. |
| 243 | private int mWifiDisplayScanRequestCount; |
| 244 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 245 | // The virtual display adapter, or null if not registered. |
| 246 | private VirtualDisplayAdapter mVirtualDisplayAdapter; |
| 247 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 248 | // The User ID of the current user |
| 249 | private @UserIdInt int mCurrentUserId; |
| 250 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 251 | // The stable device screen height and width. These are not tied to a specific display, even |
| 252 | // the default display, because they need to be stable over the course of the device's entire |
| 253 | // life, even if the default display changes (e.g. a new monitor is plugged into a PC-like |
| 254 | // device). |
| 255 | private Point mStableDisplaySize = new Point(); |
| 256 | |
Winson | 72dbe7e | 2019-04-29 14:55:30 -0700 | [diff] [blame] | 257 | // Whether the system has finished booting or not. |
| 258 | private boolean mSystemReady; |
| 259 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 260 | // The top inset of the default display. |
| 261 | // This gets persisted so that the boot animation knows how to transition from the display's |
| 262 | // full size to the size configured by the user. Right now we only persist and animate the top |
| 263 | // inset, but theoretically we could do it for all of them. |
| 264 | private int mDefaultDisplayTopInset; |
| 265 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 266 | // Viewports of the default display and the display that should receive touch |
| 267 | // input from an external source. Used by the input system. |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 268 | @GuardedBy("mSyncRoot") |
| 269 | private final ArrayList<DisplayViewport> mViewports = new ArrayList<>(); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 270 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 271 | // Persistent data store for all internal settings maintained by the display manager service. |
| 272 | private final PersistentDataStore mPersistentDataStore = new PersistentDataStore(); |
| 273 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 274 | // Temporary callback list, used when sending display events to applications. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 275 | // May be used outside of the lock but only on the handler thread. |
| 276 | private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 277 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 278 | // Temporary display info, used for comparing display configurations. |
| 279 | private final DisplayInfo mTempDisplayInfo = new DisplayInfo(); |
| 280 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 281 | // Temporary viewports, used when sending new viewport information to the |
| 282 | // input system. May be used outside of the lock but only on the handler thread. |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 283 | private final ArrayList<DisplayViewport> mTempViewports = new ArrayList<>(); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 284 | |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 285 | // The default color mode for default displays. Overrides the usual |
| 286 | // Display.Display.COLOR_MODE_DEFAULT for displays with the |
| 287 | // DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY flag set. |
| 288 | private final int mDefaultDisplayDefaultColorMode; |
| 289 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 290 | // Temporary list of deferred work to perform when setting the display state. |
| 291 | // Only used by requestDisplayState. The field is self-synchronized and only |
| 292 | // intended for use inside of the requestGlobalDisplayStateInternal function. |
| 293 | private final ArrayList<Runnable> mTempDisplayStateWorkQueue = new ArrayList<Runnable>(); |
| 294 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 295 | // Lists of UIDs that are present on the displays. Maps displayId -> array of UIDs. |
| 296 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 297 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 298 | private final Injector mInjector; |
| 299 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 300 | // The minimum brightness curve, which guarantess that any brightness curve that dips below it |
| 301 | // is rejected by the system. |
| 302 | private final Curve mMinimumBrightnessCurve; |
| 303 | private final Spline mMinimumBrightnessSpline; |
Peiyong Lin | 277eaff | 2019-01-16 16:18:22 -0800 | [diff] [blame] | 304 | private final ColorSpace mWideColorSpace; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 305 | |
Long Ling | bc841b0 | 2019-07-03 16:43:15 -0700 | [diff] [blame] | 306 | private SensorManager mSensorManager; |
| 307 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 308 | public DisplayManagerService(Context context) { |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 309 | this(context, new Injector()); |
| 310 | } |
| 311 | |
| 312 | @VisibleForTesting |
| 313 | DisplayManagerService(Context context, Injector injector) { |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 314 | super(context); |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 315 | mInjector = injector; |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 316 | mContext = context; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 317 | mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper()); |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 318 | mUiHandler = UiThread.getHandler(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 319 | mDisplayAdapterListener = new DisplayAdapterListener(); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 320 | mDisplayModeDirector = new DisplayModeDirector(context, mHandler); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 321 | mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false); |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 322 | Resources resources = mContext.getResources(); |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 323 | mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger( |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 324 | com.android.internal.R.integer.config_defaultDisplayDefaultColorMode); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 325 | mDefaultDisplayTopInset = SystemProperties.getInt(PROP_DEFAULT_DISPLAY_TOP_INSET, -1); |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 326 | float[] lux = getFloatArray(resources.obtainTypedArray( |
| 327 | com.android.internal.R.array.config_minimumBrightnessCurveLux)); |
| 328 | float[] nits = getFloatArray(resources.obtainTypedArray( |
| 329 | com.android.internal.R.array.config_minimumBrightnessCurveNits)); |
| 330 | mMinimumBrightnessCurve = new Curve(lux, nits); |
| 331 | mMinimumBrightnessSpline = Spline.createSpline(lux, nits); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 332 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 333 | PowerManager pm = mContext.getSystemService(PowerManager.class); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 334 | mGlobalDisplayBrightness = pm.getDefaultScreenBrightnessSetting(); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 335 | mCurrentUserId = UserHandle.USER_SYSTEM; |
Peiyong Lin | 277eaff | 2019-01-16 16:18:22 -0800 | [diff] [blame] | 336 | ColorSpace[] colorSpaces = SurfaceControl.getCompositionColorSpaces(); |
| 337 | mWideColorSpace = colorSpaces[1]; |
Winson | 72dbe7e | 2019-04-29 14:55:30 -0700 | [diff] [blame] | 338 | |
| 339 | mSystemReady = false; |
Joel Fernandes | 2d314e1 | 2017-04-04 16:32:15 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | public void setupSchedulerPolicies() { |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 343 | // android.display and android.anim is critical to user experience and we should make sure |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 344 | // it is not in the default foregroup groups, add it to top-app to make sure it uses all |
| 345 | // the cores and scheduling settings for top-app when it runs. |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 346 | Process.setThreadGroupAndCpuset(DisplayThread.get().getThreadId(), |
| 347 | Process.THREAD_GROUP_TOP_APP); |
| 348 | Process.setThreadGroupAndCpuset(AnimationThread.get().getThreadId(), |
| 349 | Process.THREAD_GROUP_TOP_APP); |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 350 | Process.setThreadGroupAndCpuset(SurfaceAnimationThread.get().getThreadId(), |
| 351 | Process.THREAD_GROUP_TOP_APP); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 354 | @Override |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 355 | public void onStart() { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 356 | // We need to pre-load the persistent data store so it's ready before the default display |
| 357 | // adapter is up so that we have it's configuration. We could load it lazily, but since |
| 358 | // we're going to have to read it in eventually we may as well do it here rather than after |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 359 | // we've waited for the display to register itself with us. |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 360 | synchronized (mSyncRoot) { |
| 361 | mPersistentDataStore.loadIfNeeded(); |
| 362 | loadStableDisplayValuesLocked(); |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 363 | } |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 364 | mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 365 | |
| 366 | publishBinderService(Context.DISPLAY_SERVICE, new BinderService(), |
| 367 | true /*allowIsolated*/); |
| 368 | publishLocalService(DisplayManagerInternal.class, new LocalService()); |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public void onBootPhase(int phase) { |
| 373 | if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) { |
| 374 | synchronized (mSyncRoot) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 375 | long timeout = SystemClock.uptimeMillis() |
| 376 | + mInjector.getDefaultDisplayDelayTimeout(); |
| 377 | while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null || |
| 378 | mVirtualDisplayAdapter == null) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 379 | long delay = timeout - SystemClock.uptimeMillis(); |
| 380 | if (delay <= 0) { |
| 381 | throw new RuntimeException("Timeout waiting for default display " |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 382 | + "to be initialized. DefaultDisplay=" |
| 383 | + mLogicalDisplays.get(Display.DEFAULT_DISPLAY) |
| 384 | + ", mVirtualDisplayAdapter=" + mVirtualDisplayAdapter); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 385 | } |
| 386 | if (DEBUG) { |
| 387 | Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay); |
| 388 | } |
| 389 | try { |
| 390 | mSyncRoot.wait(delay); |
| 391 | } catch (InterruptedException ex) { |
| 392 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 398 | @Override |
| 399 | public void onSwitchUser(@UserIdInt int newUserId) { |
| 400 | final int userSerial = getUserManager().getUserSerialNumber(newUserId); |
| 401 | synchronized (mSyncRoot) { |
| 402 | if (mCurrentUserId != newUserId) { |
| 403 | mCurrentUserId = newUserId; |
| 404 | BrightnessConfiguration config = |
| 405 | mPersistentDataStore.getBrightnessConfiguration(userSerial); |
| 406 | mDisplayPowerController.setBrightnessConfiguration(config); |
| 407 | } |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 408 | mDisplayPowerController.onSwitchUser(newUserId); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 412 | // TODO: Use dependencies or a boot phase |
| 413 | public void windowManagerAndInputReady() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 414 | synchronized (mSyncRoot) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 415 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
| 416 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 417 | scheduleTraversalLocked(false); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 422 | * Called when the system is ready to go. |
| 423 | */ |
| 424 | public void systemReady(boolean safeMode, boolean onlyCore) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 425 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 426 | mSafeMode = safeMode; |
| 427 | mOnlyCore = onlyCore; |
Winson | 72dbe7e | 2019-04-29 14:55:30 -0700 | [diff] [blame] | 428 | mSystemReady = true; |
| 429 | // Just in case the top inset changed before the system was ready. At this point, any |
| 430 | // relevant configuration should be in place. |
| 431 | recordTopInsetLocked(mLogicalDisplays.get(Display.DEFAULT_DISPLAY)); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 432 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 433 | |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame^] | 434 | mDisplayModeDirector.setDesiredDisplayModeSpecsListener( |
| 435 | new DesiredDisplayModeSpecsObserver()); |
Long Ling | bc841b0 | 2019-07-03 16:43:15 -0700 | [diff] [blame] | 436 | mDisplayModeDirector.start(mSensorManager); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 437 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 438 | mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS); |
| 439 | } |
| 440 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 441 | @VisibleForTesting |
| 442 | Handler getDisplayHandler() { |
| 443 | return mHandler; |
| 444 | } |
| 445 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 446 | private void loadStableDisplayValuesLocked() { |
| 447 | final Point size = mPersistentDataStore.getStableDisplaySize(); |
| 448 | if (size.x > 0 && size.y > 0) { |
| 449 | // Just set these values directly so we don't write the display persistent data again |
| 450 | // unnecessarily |
| 451 | mStableDisplaySize.set(size.x, size.y); |
| 452 | } else { |
| 453 | final Resources res = mContext.getResources(); |
| 454 | final int width = res.getInteger( |
| 455 | com.android.internal.R.integer.config_stableDeviceDisplayWidth); |
| 456 | final int height = res.getInteger( |
| 457 | com.android.internal.R.integer.config_stableDeviceDisplayHeight); |
| 458 | if (width > 0 && height > 0) { |
| 459 | setStableDisplaySizeLocked(width, height); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | private Point getStableDisplaySizeInternal() { |
| 465 | Point r = new Point(); |
| 466 | synchronized (mSyncRoot) { |
| 467 | if (mStableDisplaySize.x > 0 && mStableDisplaySize.y > 0) { |
| 468 | r.set(mStableDisplaySize.x, mStableDisplaySize.y); |
| 469 | } |
| 470 | } |
| 471 | return r; |
| 472 | } |
| 473 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 474 | private void registerDisplayTransactionListenerInternal( |
| 475 | DisplayTransactionListener listener) { |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 476 | // List is self-synchronized copy-on-write. |
| 477 | mDisplayTransactionListeners.add(listener); |
| 478 | } |
| 479 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 480 | private void unregisterDisplayTransactionListenerInternal( |
| 481 | DisplayTransactionListener listener) { |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 482 | // List is self-synchronized copy-on-write. |
| 483 | mDisplayTransactionListeners.remove(listener); |
| 484 | } |
| 485 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 486 | private void setDisplayInfoOverrideFromWindowManagerInternal( |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 487 | int displayId, DisplayInfo info) { |
| 488 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 489 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 490 | if (display != null) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 491 | if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) { |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 492 | handleLogicalDisplayChanged(displayId, display); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 493 | scheduleTraversalLocked(false); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 494 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 499 | /** |
| 500 | * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo) |
| 501 | */ |
| 502 | private void getNonOverrideDisplayInfoInternal(int displayId, DisplayInfo outInfo) { |
| 503 | synchronized (mSyncRoot) { |
| 504 | final LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 505 | if (display != null) { |
| 506 | display.getNonOverrideDisplayInfoLocked(outInfo); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 511 | @VisibleForTesting |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 512 | void performTraversalInternal(SurfaceControl.Transaction t) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 513 | synchronized (mSyncRoot) { |
| 514 | if (!mPendingTraversal) { |
| 515 | return; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 516 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 517 | mPendingTraversal = false; |
| 518 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 519 | performTraversalLocked(t); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 520 | } |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 521 | |
| 522 | // List is self-synchronized copy-on-write. |
| 523 | for (DisplayTransactionListener listener : mDisplayTransactionListeners) { |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 524 | listener.onDisplayTransaction(t); |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 525 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 528 | private void requestGlobalDisplayStateInternal(int state, int brightness) { |
| 529 | if (state == Display.STATE_UNKNOWN) { |
| 530 | state = Display.STATE_ON; |
| 531 | } |
| 532 | if (state == Display.STATE_OFF) { |
| 533 | brightness = PowerManager.BRIGHTNESS_OFF; |
| 534 | } else if (brightness < 0) { |
| 535 | brightness = PowerManager.BRIGHTNESS_DEFAULT; |
| 536 | } else if (brightness > PowerManager.BRIGHTNESS_ON) { |
| 537 | brightness = PowerManager.BRIGHTNESS_ON; |
| 538 | } |
| 539 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 540 | synchronized (mTempDisplayStateWorkQueue) { |
| 541 | try { |
| 542 | // Update the display state within the lock. |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 543 | // Note that we do not need to schedule traversals here although it |
| 544 | // may happen as a side-effect of displays changing state. |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 545 | synchronized (mSyncRoot) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 546 | if (mGlobalDisplayState == state |
| 547 | && mGlobalDisplayBrightness == brightness) { |
| 548 | return; // no change |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 549 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 550 | |
| 551 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState(" |
| 552 | + Display.stateToString(state) |
| 553 | + ", brightness=" + brightness + ")"); |
| 554 | mGlobalDisplayState = state; |
| 555 | mGlobalDisplayBrightness = brightness; |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 556 | applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | // Setting the display power state can take hundreds of milliseconds |
| 560 | // to complete so we defer the most expensive part of the work until |
| 561 | // after we have exited the critical section to avoid blocking other |
| 562 | // threads for a long time. |
| 563 | for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) { |
| 564 | mTempDisplayStateWorkQueue.get(i).run(); |
| 565 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 566 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 567 | } finally { |
| 568 | mTempDisplayStateWorkQueue.clear(); |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
Galia Peycheva | ea94575 | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 573 | private void setPreferMinimalPostProcessingLocked(int displayId, boolean isPreferred) { |
| 574 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 575 | if (display != null) { |
| 576 | DisplayDeviceInfo info = |
| 577 | display.getPrimaryDisplayDeviceLocked().getDisplayDeviceInfoLocked(); |
| 578 | |
| 579 | if (info.allmSupported) { |
| 580 | display.setAutoLowLatencyMode(isPreferred); |
| 581 | } |
| 582 | if (info.gameContentTypeSupported) { |
| 583 | display.setGameContentType(isPreferred); |
| 584 | } |
| 585 | |
| 586 | scheduleTraversalLocked(false); |
| 587 | } |
| 588 | } |
| 589 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 590 | private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 591 | synchronized (mSyncRoot) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 592 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 593 | if (display != null) { |
| 594 | DisplayInfo info = display.getDisplayInfoLocked(); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 595 | if (info.hasAccess(callingUid) |
| 596 | || isUidPresentOnDisplayInternal(callingUid, displayId)) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 597 | return info; |
| 598 | } |
| 599 | } |
| 600 | return null; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | private int[] getDisplayIdsInternal(int callingUid) { |
| 605 | synchronized (mSyncRoot) { |
| 606 | final int count = mLogicalDisplays.size(); |
| 607 | int[] displayIds = new int[count]; |
| 608 | int n = 0; |
| 609 | for (int i = 0; i < count; i++) { |
| 610 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 611 | DisplayInfo info = display.getDisplayInfoLocked(); |
| 612 | if (info.hasAccess(callingUid)) { |
| 613 | displayIds[n++] = mLogicalDisplays.keyAt(i); |
| 614 | } |
| 615 | } |
| 616 | if (n != count) { |
| 617 | displayIds = Arrays.copyOfRange(displayIds, 0, n); |
| 618 | } |
| 619 | return displayIds; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) { |
| 624 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 625 | if (mCallbacks.get(callingPid) != null) { |
| 626 | throw new SecurityException("The calling process has already " |
| 627 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 630 | CallbackRecord record = new CallbackRecord(callingPid, callback); |
| 631 | try { |
| 632 | IBinder binder = callback.asBinder(); |
| 633 | binder.linkToDeath(record, 0); |
| 634 | } catch (RemoteException ex) { |
| 635 | // give up |
| 636 | throw new RuntimeException(ex); |
| 637 | } |
| 638 | |
| 639 | mCallbacks.put(callingPid, record); |
| 640 | } |
| 641 | } |
| 642 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 643 | private void onCallbackDied(CallbackRecord record) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 644 | synchronized (mSyncRoot) { |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 645 | mCallbacks.remove(record.mPid); |
| 646 | stopWifiDisplayScanLocked(record); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 650 | private void startWifiDisplayScanInternal(int callingPid) { |
| 651 | synchronized (mSyncRoot) { |
| 652 | CallbackRecord record = mCallbacks.get(callingPid); |
| 653 | if (record == null) { |
| 654 | throw new IllegalStateException("The calling process has not " |
| 655 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 656 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 657 | startWifiDisplayScanLocked(record); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 661 | private void startWifiDisplayScanLocked(CallbackRecord record) { |
| 662 | if (!record.mWifiDisplayScanRequested) { |
| 663 | record.mWifiDisplayScanRequested = true; |
| 664 | if (mWifiDisplayScanRequestCount++ == 0) { |
| 665 | if (mWifiDisplayAdapter != null) { |
| 666 | mWifiDisplayAdapter.requestStartScanLocked(); |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 672 | private void stopWifiDisplayScanInternal(int callingPid) { |
| 673 | synchronized (mSyncRoot) { |
| 674 | CallbackRecord record = mCallbacks.get(callingPid); |
| 675 | if (record == null) { |
| 676 | throw new IllegalStateException("The calling process has not " |
| 677 | + "registered an IDisplayManagerCallback."); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 678 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 679 | stopWifiDisplayScanLocked(record); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
| 683 | private void stopWifiDisplayScanLocked(CallbackRecord record) { |
| 684 | if (record.mWifiDisplayScanRequested) { |
| 685 | record.mWifiDisplayScanRequested = false; |
| 686 | if (--mWifiDisplayScanRequestCount == 0) { |
| 687 | if (mWifiDisplayAdapter != null) { |
| 688 | mWifiDisplayAdapter.requestStopScanLocked(); |
| 689 | } |
| 690 | } else if (mWifiDisplayScanRequestCount < 0) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 691 | Slog.wtf(TAG, "mWifiDisplayScanRequestCount became negative: " |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 692 | + mWifiDisplayScanRequestCount); |
| 693 | mWifiDisplayScanRequestCount = 0; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 698 | private void connectWifiDisplayInternal(String address) { |
| 699 | synchronized (mSyncRoot) { |
| 700 | if (mWifiDisplayAdapter != null) { |
| 701 | mWifiDisplayAdapter.requestConnectLocked(address); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 702 | } |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 706 | private void pauseWifiDisplayInternal() { |
| 707 | synchronized (mSyncRoot) { |
| 708 | if (mWifiDisplayAdapter != null) { |
| 709 | mWifiDisplayAdapter.requestPauseLocked(); |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 710 | } |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 714 | private void resumeWifiDisplayInternal() { |
| 715 | synchronized (mSyncRoot) { |
| 716 | if (mWifiDisplayAdapter != null) { |
| 717 | mWifiDisplayAdapter.requestResumeLocked(); |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 718 | } |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 722 | private void disconnectWifiDisplayInternal() { |
| 723 | synchronized (mSyncRoot) { |
| 724 | if (mWifiDisplayAdapter != null) { |
| 725 | mWifiDisplayAdapter.requestDisconnectLocked(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 726 | } |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 730 | private void renameWifiDisplayInternal(String address, String alias) { |
| 731 | synchronized (mSyncRoot) { |
| 732 | if (mWifiDisplayAdapter != null) { |
| 733 | mWifiDisplayAdapter.requestRenameLocked(address, alias); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 734 | } |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 738 | private void forgetWifiDisplayInternal(String address) { |
| 739 | synchronized (mSyncRoot) { |
| 740 | if (mWifiDisplayAdapter != null) { |
| 741 | mWifiDisplayAdapter.requestForgetLocked(address); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 742 | } |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 746 | private WifiDisplayStatus getWifiDisplayStatusInternal() { |
| 747 | synchronized (mSyncRoot) { |
| 748 | if (mWifiDisplayAdapter != null) { |
| 749 | return mWifiDisplayAdapter.getWifiDisplayStatusLocked(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 750 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 751 | return new WifiDisplayStatus(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 755 | private void requestColorModeInternal(int displayId, int colorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 756 | synchronized (mSyncRoot) { |
| 757 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 758 | if (display != null && |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 759 | display.getRequestedColorModeLocked() != colorMode) { |
| 760 | display.setRequestedColorModeLocked(colorMode); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 761 | scheduleTraversalLocked(false); |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 766 | private int createVirtualDisplayInternal(IVirtualDisplayCallback callback, |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 767 | IMediaProjection projection, int callingUid, String packageName, String name, int width, |
| 768 | int height, int densityDpi, Surface surface, int flags, String uniqueId) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 769 | synchronized (mSyncRoot) { |
| 770 | if (mVirtualDisplayAdapter == null) { |
| 771 | Slog.w(TAG, "Rejecting request to create private virtual display " |
| 772 | + "because the virtual display adapter is not available."); |
| 773 | return -1; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 774 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 775 | |
| 776 | DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked( |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 777 | callback, projection, callingUid, packageName, name, width, height, densityDpi, |
| 778 | surface, flags, uniqueId); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 779 | if (device == null) { |
| 780 | return -1; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 781 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 782 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 783 | handleDisplayDeviceAddedLocked(device); |
| 784 | LogicalDisplay display = findLogicalDisplayForDeviceLocked(device); |
| 785 | if (display != null) { |
| 786 | return display.getDisplayIdLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 787 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 788 | |
| 789 | // Something weird happened and the logical display was not created. |
| 790 | Slog.w(TAG, "Rejecting request to create virtual display " |
| 791 | + "because the logical display was not created."); |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 792 | mVirtualDisplayAdapter.releaseVirtualDisplayLocked(callback.asBinder()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 793 | handleDisplayDeviceRemovedLocked(device); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 794 | } |
| 795 | return -1; |
| 796 | } |
| 797 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 798 | private void resizeVirtualDisplayInternal(IBinder appToken, |
| 799 | int width, int height, int densityDpi) { |
| 800 | synchronized (mSyncRoot) { |
| 801 | if (mVirtualDisplayAdapter == null) { |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | mVirtualDisplayAdapter.resizeVirtualDisplayLocked(appToken, width, height, densityDpi); |
| 806 | } |
| 807 | } |
| 808 | |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 809 | private void setVirtualDisplaySurfaceInternal(IBinder appToken, Surface surface) { |
| 810 | synchronized (mSyncRoot) { |
| 811 | if (mVirtualDisplayAdapter == null) { |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | mVirtualDisplayAdapter.setVirtualDisplaySurfaceLocked(appToken, surface); |
| 816 | } |
| 817 | } |
| 818 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 819 | private void releaseVirtualDisplayInternal(IBinder appToken) { |
| 820 | synchronized (mSyncRoot) { |
| 821 | if (mVirtualDisplayAdapter == null) { |
| 822 | return; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 823 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 824 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 825 | DisplayDevice device = |
| 826 | mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken); |
| 827 | if (device != null) { |
| 828 | handleDisplayDeviceRemovedLocked(device); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 829 | } |
| 830 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 831 | } |
| 832 | |
chaviw | da4c694 | 2018-11-07 15:52:56 -0800 | [diff] [blame] | 833 | private void setVirtualDisplayStateInternal(IBinder appToken, boolean isOn) { |
| 834 | synchronized (mSyncRoot) { |
| 835 | if (mVirtualDisplayAdapter == null) { |
| 836 | return; |
| 837 | } |
| 838 | |
| 839 | mVirtualDisplayAdapter.setVirtualDisplayStateLocked(appToken, isOn); |
| 840 | } |
| 841 | } |
| 842 | |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 843 | private void registerDefaultDisplayAdapters() { |
| 844 | // Register default display adapters. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 845 | synchronized (mSyncRoot) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 846 | // main display adapter |
Mike Lockwood | e63f6f7 | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 847 | registerDisplayAdapterLocked(new LocalDisplayAdapter( |
| 848 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener)); |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 849 | |
| 850 | // Standalone VR devices rely on a virtual display as their primary display for |
| 851 | // 2D UI. We register virtual display adapter along side the main display adapter |
| 852 | // here so that it is ready by the time the system sends the home Intent for |
| 853 | // early apps like SetupWizard/Launcher. In particular, SUW is displayed using |
| 854 | // the virtual display inside VR before any VR-specific apps even run. |
| 855 | mVirtualDisplayAdapter = mInjector.getVirtualDisplayAdapter(mSyncRoot, mContext, |
| 856 | mHandler, mDisplayAdapterListener); |
| 857 | if (mVirtualDisplayAdapter != null) { |
| 858 | registerDisplayAdapterLocked(mVirtualDisplayAdapter); |
| 859 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
| 863 | private void registerAdditionalDisplayAdapters() { |
| 864 | synchronized (mSyncRoot) { |
| 865 | if (shouldRegisterNonEssentialDisplayAdaptersLocked()) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 866 | registerOverlayDisplayAdapterLocked(); |
| 867 | registerWifiDisplayAdapterLocked(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | } |
| 871 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 872 | private void registerOverlayDisplayAdapterLocked() { |
| 873 | registerDisplayAdapterLocked(new OverlayDisplayAdapter( |
| 874 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler)); |
| 875 | } |
| 876 | |
| 877 | private void registerWifiDisplayAdapterLocked() { |
| 878 | if (mContext.getResources().getBoolean( |
Jeff Brown | bbd28a2 | 2012-09-20 16:47:15 -0700 | [diff] [blame] | 879 | com.android.internal.R.bool.config_enableWifiDisplay) |
| 880 | || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 881 | mWifiDisplayAdapter = new WifiDisplayAdapter( |
| 882 | mSyncRoot, mContext, mHandler, mDisplayAdapterListener, |
| 883 | mPersistentDataStore); |
| 884 | registerDisplayAdapterLocked(mWifiDisplayAdapter); |
| 885 | } |
| 886 | } |
| 887 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 888 | private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() { |
| 889 | // In safe mode, we disable non-essential display adapters to give the user |
| 890 | // an opportunity to fix broken settings or other problems that might affect |
| 891 | // system stability. |
| 892 | // In only-core mode, we disable non-essential display adapters to minimize |
| 893 | // the number of dependencies that are started while in this mode and to |
| 894 | // prevent problems that might occur due to the device being encrypted. |
| 895 | return !mSafeMode && !mOnlyCore; |
| 896 | } |
| 897 | |
| 898 | private void registerDisplayAdapterLocked(DisplayAdapter adapter) { |
| 899 | mDisplayAdapters.add(adapter); |
| 900 | adapter.registerLocked(); |
| 901 | } |
| 902 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 903 | private void handleDisplayDeviceAdded(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 904 | synchronized (mSyncRoot) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 905 | handleDisplayDeviceAddedLocked(device); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 909 | private void handleDisplayDeviceAddedLocked(DisplayDevice device) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 910 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 911 | if (mDisplayDevices.contains(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 912 | Slog.w(TAG, "Attempted to add already added display device: " + info); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 913 | return; |
| 914 | } |
| 915 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 916 | Slog.i(TAG, "Display device added: " + info); |
| 917 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 918 | |
| 919 | mDisplayDevices.add(device); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 920 | LogicalDisplay display = addLogicalDisplayLocked(device); |
Jeff Brown | 0033a86 | 2014-10-08 12:06:39 -0700 | [diff] [blame] | 921 | Runnable work = updateDisplayStateLocked(device); |
| 922 | if (work != null) { |
| 923 | work.run(); |
| 924 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 925 | scheduleTraversalLocked(false); |
| 926 | } |
| 927 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 928 | private void handleDisplayDeviceChanged(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 929 | synchronized (mSyncRoot) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 930 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 931 | if (!mDisplayDevices.contains(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 932 | Slog.w(TAG, "Attempted to change non-existent display device: " + info); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 933 | return; |
| 934 | } |
| 935 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 936 | int diff = device.mDebugLastLoggedDeviceInfo.diff(info); |
| 937 | if (diff == DisplayDeviceInfo.DIFF_STATE) { |
| 938 | Slog.i(TAG, "Display device changed state: \"" + info.name |
| 939 | + "\", " + Display.stateToString(info.state)); |
| 940 | } else if (diff != 0) { |
| 941 | Slog.i(TAG, "Display device changed: " + info); |
| 942 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 943 | if ((diff & DisplayDeviceInfo.DIFF_COLOR_MODE) != 0) { |
| 944 | try { |
| 945 | mPersistentDataStore.setColorMode(device, info.colorMode); |
| 946 | } finally { |
| 947 | mPersistentDataStore.saveIfNeeded(); |
| 948 | } |
| 949 | } |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 950 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 951 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 952 | device.applyPendingDisplayDeviceInfoChangesLocked(); |
| 953 | if (updateLogicalDisplaysLocked()) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 954 | scheduleTraversalLocked(false); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | } |
| 958 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 959 | private void handleDisplayDeviceRemoved(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 960 | synchronized (mSyncRoot) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 961 | handleDisplayDeviceRemovedLocked(device); |
| 962 | } |
| 963 | } |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 964 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 965 | private void handleDisplayDeviceRemovedLocked(DisplayDevice device) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 966 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 967 | if (!mDisplayDevices.remove(device)) { |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 968 | Slog.w(TAG, "Attempted to remove non-existent display device: " + info); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 969 | return; |
| 970 | } |
| 971 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 972 | Slog.i(TAG, "Display device removed: " + info); |
| 973 | device.mDebugLastLoggedDeviceInfo = info; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 974 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 975 | updateLogicalDisplaysLocked(); |
| 976 | scheduleTraversalLocked(false); |
| 977 | } |
| 978 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 979 | private void handleLogicalDisplayChanged(int displayId, @NonNull LogicalDisplay display) { |
| 980 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 981 | recordTopInsetLocked(display); |
| 982 | } |
| 983 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED); |
| 984 | } |
| 985 | |
Jeff Brown | 8e5d33e | 2015-06-10 13:05:50 -0700 | [diff] [blame] | 986 | private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 987 | final int count = mDisplayDevices.size(); |
| 988 | for (int i = 0; i < count; i++) { |
| 989 | DisplayDevice device = mDisplayDevices.get(i); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 990 | Runnable runnable = updateDisplayStateLocked(device); |
| 991 | if (runnable != null) { |
| 992 | workQueue.add(runnable); |
| 993 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 997 | private Runnable updateDisplayStateLocked(DisplayDevice device) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 998 | // Blank or unblank the display immediately to match the state requested |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 999 | // by the display power controller (if known). |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1000 | DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
| 1001 | if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 1002 | return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1003 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 1004 | return null; |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1007 | // Adds a new logical display based on the given display device. |
| 1008 | // Sends notifications if needed. |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1009 | private LogicalDisplay addLogicalDisplayLocked(DisplayDevice device) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1010 | DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked(); |
| 1011 | boolean isDefault = (deviceInfo.flags |
| 1012 | & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0; |
| 1013 | if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) { |
| 1014 | Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo); |
| 1015 | isDefault = false; |
| 1016 | } |
| 1017 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1018 | if (!isDefault && mSingleDisplayDemoMode) { |
| 1019 | Slog.i(TAG, "Not creating a logical display for a secondary display " |
| 1020 | + " because single display demo mode is enabled: " + deviceInfo); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1021 | return null; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1024 | final int displayId = assignDisplayIdLocked(isDefault); |
| 1025 | final int layerStack = assignLayerStackLocked(displayId); |
| 1026 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1027 | LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1028 | display.updateLocked(mDisplayDevices); |
| 1029 | if (!display.isValidLocked()) { |
| 1030 | // This should never happen currently. |
| 1031 | Slog.w(TAG, "Ignoring display device because the logical display " |
| 1032 | + "created from it was not considered valid: " + deviceInfo); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1033 | return null; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1036 | configureColorModeLocked(display, device); |
| 1037 | if (isDefault) { |
| 1038 | recordStableDisplayStatsIfNeededLocked(display); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1039 | recordTopInsetLocked(display); |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1040 | } |
| 1041 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1042 | mLogicalDisplays.put(displayId, display); |
| 1043 | |
| 1044 | // Wake up waitForDefaultDisplay. |
| 1045 | if (isDefault) { |
| 1046 | mSyncRoot.notifyAll(); |
| 1047 | } |
| 1048 | |
| 1049 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1050 | return display; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | private int assignDisplayIdLocked(boolean isDefault) { |
| 1054 | return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++; |
| 1055 | } |
| 1056 | |
| 1057 | private int assignLayerStackLocked(int displayId) { |
| 1058 | // Currently layer stacks and display ids are the same. |
| 1059 | // This need not be the case. |
| 1060 | return displayId; |
| 1061 | } |
| 1062 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1063 | private void configureColorModeLocked(LogicalDisplay display, DisplayDevice device) { |
| 1064 | if (display.getPrimaryDisplayDeviceLocked() == device) { |
| 1065 | int colorMode = mPersistentDataStore.getColorMode(device); |
| 1066 | if (colorMode == Display.COLOR_MODE_INVALID) { |
| 1067 | if ((device.getDisplayDeviceInfoLocked().flags |
| 1068 | & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) { |
| 1069 | colorMode = mDefaultDisplayDefaultColorMode; |
| 1070 | } else { |
| 1071 | colorMode = Display.COLOR_MODE_DEFAULT; |
| 1072 | } |
| 1073 | } |
| 1074 | display.setRequestedColorModeLocked(colorMode); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | // If we've never recorded stable device stats for this device before and they aren't |
| 1079 | // explicitly configured, go ahead and record the stable device stats now based on the status |
| 1080 | // of the default display at first boot. |
| 1081 | private void recordStableDisplayStatsIfNeededLocked(LogicalDisplay d) { |
| 1082 | if (mStableDisplaySize.x <= 0 && mStableDisplaySize.y <= 0) { |
| 1083 | DisplayInfo info = d.getDisplayInfoLocked(); |
| 1084 | setStableDisplaySizeLocked(info.getNaturalWidth(), info.getNaturalHeight()); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1088 | private void recordTopInsetLocked(@Nullable LogicalDisplay d) { |
Winson | 72dbe7e | 2019-04-29 14:55:30 -0700 | [diff] [blame] | 1089 | // We must only persist the inset after boot has completed, otherwise we will end up |
| 1090 | // overwriting the persisted value before the masking flag has been loaded from the |
| 1091 | // resource overlay. |
| 1092 | if (!mSystemReady || d == null) { |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1093 | return; |
| 1094 | } |
| 1095 | int topInset = d.getInsets().top; |
| 1096 | if (topInset == mDefaultDisplayTopInset) { |
| 1097 | return; |
| 1098 | } |
| 1099 | mDefaultDisplayTopInset = topInset; |
| 1100 | SystemProperties.set(PROP_DEFAULT_DISPLAY_TOP_INSET, Integer.toString(topInset)); |
| 1101 | } |
| 1102 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1103 | private void setStableDisplaySizeLocked(int width, int height) { |
| 1104 | mStableDisplaySize = new Point(width, height); |
| 1105 | try { |
| 1106 | mPersistentDataStore.setStableDisplaySize(mStableDisplaySize); |
| 1107 | } finally { |
| 1108 | mPersistentDataStore.saveIfNeeded(); |
| 1109 | } |
| 1110 | } |
| 1111 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1112 | @VisibleForTesting |
| 1113 | Curve getMinimumBrightnessCurveInternal() { |
| 1114 | return mMinimumBrightnessCurve; |
| 1115 | } |
| 1116 | |
Peiyong Lin | 277eaff | 2019-01-16 16:18:22 -0800 | [diff] [blame] | 1117 | int getPreferredWideGamutColorSpaceIdInternal() { |
| 1118 | return mWideColorSpace.getId(); |
| 1119 | } |
| 1120 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1121 | private void setBrightnessConfigurationForUserInternal( |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 1122 | @Nullable BrightnessConfiguration c, @UserIdInt int userId, |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 1123 | @Nullable String packageName) { |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1124 | validateBrightnessConfiguration(c); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1125 | final int userSerial = getUserManager().getUserSerialNumber(userId); |
| 1126 | synchronized (mSyncRoot) { |
| 1127 | try { |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 1128 | mPersistentDataStore.setBrightnessConfigurationForUser(c, userSerial, |
| 1129 | packageName); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1130 | } finally { |
| 1131 | mPersistentDataStore.saveIfNeeded(); |
| 1132 | } |
| 1133 | if (userId == mCurrentUserId) { |
| 1134 | mDisplayPowerController.setBrightnessConfiguration(c); |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1139 | @VisibleForTesting |
| 1140 | void validateBrightnessConfiguration(BrightnessConfiguration config) { |
| 1141 | if (config == null) { |
| 1142 | return; |
| 1143 | } |
| 1144 | if (isBrightnessConfigurationTooDark(config)) { |
| 1145 | throw new IllegalArgumentException("brightness curve is too dark"); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | private boolean isBrightnessConfigurationTooDark(BrightnessConfiguration config) { |
| 1150 | Pair<float[], float[]> curve = config.getCurve(); |
| 1151 | float[] lux = curve.first; |
| 1152 | float[] nits = curve.second; |
| 1153 | for (int i = 0; i < lux.length; i++) { |
| 1154 | if (nits[i] < mMinimumBrightnessSpline.interpolate(lux[i])) { |
| 1155 | return true; |
| 1156 | } |
| 1157 | } |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1161 | private void loadBrightnessConfiguration() { |
| 1162 | synchronized (mSyncRoot) { |
| 1163 | final int userSerial = getUserManager().getUserSerialNumber(mCurrentUserId); |
| 1164 | BrightnessConfiguration config = |
| 1165 | mPersistentDataStore.getBrightnessConfiguration(userSerial); |
| 1166 | mDisplayPowerController.setBrightnessConfiguration(config); |
| 1167 | } |
| 1168 | } |
| 1169 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1170 | // Updates all existing logical displays given the current set of display devices. |
| 1171 | // Removes invalid logical displays. |
| 1172 | // Sends notifications if needed. |
| 1173 | private boolean updateLogicalDisplaysLocked() { |
| 1174 | boolean changed = false; |
| 1175 | for (int i = mLogicalDisplays.size(); i-- > 0; ) { |
| 1176 | final int displayId = mLogicalDisplays.keyAt(i); |
| 1177 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1178 | |
| 1179 | mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked()); |
| 1180 | display.updateLocked(mDisplayDevices); |
| 1181 | if (!display.isValidLocked()) { |
| 1182 | mLogicalDisplays.removeAt(i); |
| 1183 | sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED); |
| 1184 | changed = true; |
| 1185 | } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) { |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1186 | handleLogicalDisplayChanged(displayId, display); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1187 | changed = true; |
| 1188 | } |
| 1189 | } |
| 1190 | return changed; |
| 1191 | } |
| 1192 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1193 | private void performTraversalLocked(SurfaceControl.Transaction t) { |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1194 | // Clear all viewports before configuring displays so that we can keep |
| 1195 | // track of which ones we have configured. |
| 1196 | clearViewportsLocked(); |
| 1197 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1198 | // Configure each display device. |
| 1199 | final int count = mDisplayDevices.size(); |
| 1200 | for (int i = 0; i < count; i++) { |
| 1201 | DisplayDevice device = mDisplayDevices.get(i); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1202 | configureDisplayLocked(t, device); |
| 1203 | device.performTraversalLocked(t); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1204 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1205 | |
| 1206 | // Tell the input system about these new viewports. |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1207 | if (mInputManagerInternal != null) { |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1208 | mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT); |
| 1209 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1212 | private void setDisplayPropertiesInternal(int displayId, boolean hasContent, |
Galia Peycheva | ea94575 | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 1213 | float requestedRefreshRate, int requestedModeId, boolean preferMinimalPostProcessing, |
| 1214 | boolean inTraversal) { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1215 | synchronized (mSyncRoot) { |
| 1216 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1217 | if (display == null) { |
| 1218 | return; |
| 1219 | } |
| 1220 | if (display.hasContentLocked() != hasContent) { |
Jeff Brown | 33041bd | 2013-08-02 21:11:14 -0700 | [diff] [blame] | 1221 | if (DEBUG) { |
| 1222 | Slog.d(TAG, "Display " + displayId + " hasContent flag changed: " |
| 1223 | + "hasContent=" + hasContent + ", inTraversal=" + inTraversal); |
| 1224 | } |
| 1225 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1226 | display.setHasContentLocked(hasContent); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1227 | scheduleTraversalLocked(inTraversal); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1228 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1229 | if (requestedModeId == 0 && requestedRefreshRate != 0) { |
| 1230 | // Scan supported modes returned by display.getInfo() to find a mode with the same |
| 1231 | // size as the default display mode but with the specified refresh rate instead. |
| 1232 | requestedModeId = display.getDisplayInfoLocked().findDefaultModeByRefreshRate( |
| 1233 | requestedRefreshRate); |
| 1234 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 1235 | mDisplayModeDirector.getAppRequestObserver().setAppRequestedMode( |
| 1236 | displayId, requestedModeId); |
Galia Peycheva | ea94575 | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 1237 | |
| 1238 | setPreferMinimalPostProcessingLocked(displayId, preferMinimalPostProcessing); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1239 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1240 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1241 | |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 1242 | private void setDisplayOffsetsInternal(int displayId, int x, int y) { |
| 1243 | synchronized (mSyncRoot) { |
| 1244 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1245 | if (display == null) { |
| 1246 | return; |
| 1247 | } |
| 1248 | if (display.getDisplayOffsetXLocked() != x |
| 1249 | || display.getDisplayOffsetYLocked() != y) { |
| 1250 | if (DEBUG) { |
| 1251 | Slog.d(TAG, "Display " + displayId + " burn-in offset set to (" |
| 1252 | + x + ", " + y + ")"); |
| 1253 | } |
| 1254 | display.setDisplayOffsetsLocked(x, y); |
| 1255 | scheduleTraversalLocked(false); |
| 1256 | } |
| 1257 | } |
| 1258 | } |
| 1259 | |
Sam Lin | 4c3ac2b | 2019-02-18 04:50:26 -0800 | [diff] [blame] | 1260 | private void setDisplayScalingDisabledInternal(int displayId, boolean disable) { |
| 1261 | synchronized (mSyncRoot) { |
| 1262 | final LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1263 | if (display == null) { |
| 1264 | return; |
| 1265 | } |
| 1266 | if (display.isDisplayScalingDisabled() != disable) { |
| 1267 | if (DEBUG) { |
| 1268 | Slog.d(TAG, "Display " + displayId + " content scaling disabled = " + disable); |
| 1269 | } |
| 1270 | display.setDisplayScalingDisabledLocked(disable); |
| 1271 | scheduleTraversalLocked(false); |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1276 | // Updates the lists of UIDs that are present on displays. |
| 1277 | private void setDisplayAccessUIDsInternal(SparseArray<IntArray> newDisplayAccessUIDs) { |
| 1278 | synchronized (mSyncRoot) { |
| 1279 | mDisplayAccessUIDs.clear(); |
| 1280 | for (int i = newDisplayAccessUIDs.size() - 1; i >= 0; i--) { |
| 1281 | mDisplayAccessUIDs.append(newDisplayAccessUIDs.keyAt(i), |
| 1282 | newDisplayAccessUIDs.valueAt(i)); |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | // Checks if provided UID's content is present on the display and UID has access to it. |
| 1288 | private boolean isUidPresentOnDisplayInternal(int uid, int displayId) { |
| 1289 | synchronized (mSyncRoot) { |
| 1290 | final IntArray displayUIDs = mDisplayAccessUIDs.get(displayId); |
| 1291 | return displayUIDs != null && displayUIDs.indexOf(uid) != -1; |
| 1292 | } |
| 1293 | } |
| 1294 | |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1295 | @Nullable |
| 1296 | private IBinder getDisplayToken(int displayId) { |
| 1297 | synchronized (mSyncRoot) { |
| 1298 | final LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1299 | if (display != null) { |
| 1300 | final DisplayDevice device = display.getPrimaryDisplayDeviceLocked(); |
| 1301 | if (device != null) { |
| 1302 | return device.getDisplayTokenLocked(); |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | return null; |
| 1308 | } |
| 1309 | |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 1310 | private SurfaceControl.ScreenshotGraphicBuffer screenshotInternal(int displayId) { |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1311 | final IBinder token = getDisplayToken(displayId); |
| 1312 | if (token == null) { |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 1313 | return null; |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1314 | } |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 1315 | return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe( |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 1316 | token, new Rect(), 0 /* width */, 0 /* height */, |
| 1317 | false /* useIdentityTransform */, 0 /* rotation */); |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1318 | } |
| 1319 | |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1320 | @VisibleForTesting |
| 1321 | DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributesInternal( |
| 1322 | int displayId) { |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1323 | final IBinder token = getDisplayToken(displayId); |
| 1324 | if (token == null) { |
| 1325 | return null; |
| 1326 | } |
| 1327 | return SurfaceControl.getDisplayedContentSamplingAttributes(token); |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | @VisibleForTesting |
| 1331 | boolean setDisplayedContentSamplingEnabledInternal( |
| 1332 | int displayId, boolean enable, int componentMask, int maxFrames) { |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1333 | final IBinder token = getDisplayToken(displayId); |
| 1334 | if (token == null) { |
| 1335 | return false; |
| 1336 | } |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1337 | return SurfaceControl.setDisplayedContentSamplingEnabled( |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1338 | token, enable, componentMask, maxFrames); |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | @VisibleForTesting |
| 1342 | DisplayedContentSample getDisplayedContentSampleInternal(int displayId, |
| 1343 | long maxFrames, long timestamp) { |
Dominik Laskowski | e912ae3 | 2019-01-26 11:19:36 -0800 | [diff] [blame] | 1344 | final IBinder token = getDisplayToken(displayId); |
| 1345 | if (token == null) { |
| 1346 | return null; |
| 1347 | } |
| 1348 | return SurfaceControl.getDisplayedContentSample(token, maxFrames, timestamp); |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame^] | 1351 | private void onDesiredDisplayModeSpecsChangedInternal() { |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 1352 | boolean changed = false; |
| 1353 | synchronized (mSyncRoot) { |
| 1354 | final int count = mLogicalDisplays.size(); |
| 1355 | for (int i = 0; i < count; i++) { |
| 1356 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1357 | int displayId = mLogicalDisplays.keyAt(i); |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame^] | 1358 | DisplayModeDirector.DesiredDisplayModeSpecs desiredDisplayModeSpecs = |
| 1359 | mDisplayModeDirector.getDesiredDisplayModeSpecs(displayId); |
| 1360 | DisplayModeDirector.DesiredDisplayModeSpecs existingDesiredDisplayModeSpecs = |
| 1361 | display.getDesiredDisplayModeSpecsLocked(); |
| 1362 | if (DEBUG) { |
| 1363 | Slog.i(TAG, |
| 1364 | "Comparing display specs: " + desiredDisplayModeSpecs |
| 1365 | + ", existing: " + existingDesiredDisplayModeSpecs); |
| 1366 | } |
| 1367 | if (!desiredDisplayModeSpecs.equals(existingDesiredDisplayModeSpecs)) { |
| 1368 | display.setDesiredDisplayModeSpecsLocked(desiredDisplayModeSpecs); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 1369 | changed = true; |
| 1370 | } |
| 1371 | } |
| 1372 | if (changed) { |
| 1373 | scheduleTraversalLocked(false); |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1378 | private void clearViewportsLocked() { |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1379 | mViewports.clear(); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1382 | private void configureDisplayLocked(SurfaceControl.Transaction t, DisplayDevice device) { |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1383 | final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); |
| 1384 | final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1385 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1386 | // Find the logical display that the display device is showing. |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1387 | // Certain displays only ever show their own content. |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1388 | LogicalDisplay display = findLogicalDisplayForDeviceLocked(device); |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 1389 | if (!ownContent) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1390 | if (display != null && !display.hasContentLocked()) { |
| 1391 | // If the display does not have any content of its own, then |
| 1392 | // automatically mirror the default logical display contents. |
| 1393 | display = null; |
| 1394 | } |
| 1395 | if (display == null) { |
| 1396 | display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY); |
| 1397 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | // Apply the logical display configuration to the display device. |
| 1401 | if (display == null) { |
| 1402 | // TODO: no logical display for the device, blank it |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1403 | Slog.w(TAG, "Missing logical display to use for physical display device: " |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1404 | + device.getDisplayDeviceInfoLocked()); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1405 | return; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1406 | } |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1407 | display.configureDisplayLocked(t, device, info.state == Display.STATE_OFF); |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1408 | final int viewportType; |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1409 | // Update the corresponding viewport. |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1410 | if ((info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) { |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1411 | viewportType = VIEWPORT_INTERNAL; |
| 1412 | } else if (info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) { |
| 1413 | viewportType = VIEWPORT_EXTERNAL; |
| 1414 | } else if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL |
| 1415 | && !TextUtils.isEmpty(info.uniqueId)) { |
| 1416 | viewportType = VIEWPORT_VIRTUAL; |
| 1417 | } else { |
Arthur Hung | 46c4e58 | 2019-02-12 15:55:28 +0800 | [diff] [blame] | 1418 | Slog.i(TAG, "Display " + info + " does not support input device matching."); |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1419 | return; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1420 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1421 | |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1422 | populateViewportLocked(viewportType, display.getDisplayIdLocked(), device, info.uniqueId); |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | /** |
| 1426 | * Get internal or external viewport. Create it if does not currently exist. |
| 1427 | * @param viewportType - either INTERNAL or EXTERNAL |
| 1428 | * @return the viewport with the requested type |
| 1429 | */ |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1430 | private DisplayViewport getViewportLocked(int viewportType, String uniqueId) { |
| 1431 | if (viewportType != VIEWPORT_INTERNAL && viewportType != VIEWPORT_EXTERNAL |
| 1432 | && viewportType != VIEWPORT_VIRTUAL) { |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1433 | Slog.wtf(TAG, "Cannot call getViewportByTypeLocked for type " |
| 1434 | + DisplayViewport.typeToString(viewportType)); |
| 1435 | return null; |
| 1436 | } |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1437 | |
| 1438 | // Only allow a single INTERNAL or EXTERNAL viewport by forcing their uniqueIds |
| 1439 | // to be identical (in particular, empty). |
| 1440 | // TODO (b/116824030) allow multiple EXTERNAL viewports and remove this function. |
| 1441 | if (viewportType != VIEWPORT_VIRTUAL) { |
| 1442 | uniqueId = ""; |
| 1443 | } |
| 1444 | |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1445 | DisplayViewport viewport; |
| 1446 | final int count = mViewports.size(); |
| 1447 | for (int i = 0; i < count; i++) { |
| 1448 | viewport = mViewports.get(i); |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1449 | if (viewport.type == viewportType && uniqueId.equals(viewport.uniqueId)) { |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1450 | return viewport; |
| 1451 | } |
| 1452 | } |
| 1453 | |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1454 | // Creates the viewport if none exists. |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1455 | viewport = new DisplayViewport(); |
| 1456 | viewport.type = viewportType; |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1457 | viewport.uniqueId = uniqueId; |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1458 | mViewports.add(viewport); |
| 1459 | return viewport; |
| 1460 | } |
| 1461 | |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1462 | private void populateViewportLocked(int viewportType, |
| 1463 | int displayId, DisplayDevice device, String uniqueId) { |
| 1464 | final DisplayViewport viewport = getViewportLocked(viewportType, uniqueId); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1465 | device.populateViewportLocked(viewport); |
Arthur Hung | 41e81e7 | 2018-10-31 18:04:56 +0800 | [diff] [blame] | 1466 | viewport.valid = true; |
| 1467 | viewport.displayId = displayId; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) { |
| 1471 | final int count = mLogicalDisplays.size(); |
| 1472 | for (int i = 0; i < count; i++) { |
| 1473 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1474 | if (display.getPrimaryDisplayDeviceLocked() == device) { |
| 1475 | return display; |
| 1476 | } |
| 1477 | } |
| 1478 | return null; |
| 1479 | } |
| 1480 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1481 | private void sendDisplayEventLocked(int displayId, int event) { |
| 1482 | Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event); |
| 1483 | mHandler.sendMessage(msg); |
| 1484 | } |
| 1485 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1486 | // Requests that performTraversals be called at a |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1487 | // later time to apply changes to surfaces and displays. |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1488 | private void scheduleTraversalLocked(boolean inTraversal) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1489 | if (!mPendingTraversal && mWindowManagerInternal != null) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1490 | mPendingTraversal = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1491 | if (!inTraversal) { |
| 1492 | mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL); |
| 1493 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | // Runs on Handler thread. |
| 1498 | // Delivers display event notifications to callbacks. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1499 | private void deliverDisplayEvent(int displayId, int event) { |
| 1500 | if (DEBUG) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1501 | Slog.d(TAG, "Delivering display event: displayId=" |
| 1502 | + displayId + ", event=" + event); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1503 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1504 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1505 | // Grab the lock and copy the callbacks. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1506 | final int count; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1507 | synchronized (mSyncRoot) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1508 | count = mCallbacks.size(); |
| 1509 | mTempCallbacks.clear(); |
| 1510 | for (int i = 0; i < count; i++) { |
| 1511 | mTempCallbacks.add(mCallbacks.valueAt(i)); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1512 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1513 | } |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1514 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1515 | // After releasing the lock, send the notifications out. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1516 | for (int i = 0; i < count; i++) { |
| 1517 | mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event); |
| 1518 | } |
| 1519 | mTempCallbacks.clear(); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1522 | private IMediaProjectionManager getProjectionService() { |
| 1523 | if (mProjectionService == null) { |
| 1524 | IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE); |
| 1525 | mProjectionService = IMediaProjectionManager.Stub.asInterface(b); |
| 1526 | } |
| 1527 | return mProjectionService; |
| 1528 | } |
| 1529 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1530 | private UserManager getUserManager() { |
| 1531 | return mContext.getSystemService(UserManager.class); |
| 1532 | } |
| 1533 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1534 | private void dumpInternal(PrintWriter pw) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1535 | pw.println("DISPLAY MANAGER (dumpsys display)"); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1536 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1537 | synchronized (mSyncRoot) { |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1538 | pw.println(" mOnlyCode=" + mOnlyCore); |
| 1539 | pw.println(" mSafeMode=" + mSafeMode); |
| 1540 | pw.println(" mPendingTraversal=" + mPendingTraversal); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1541 | pw.println(" mGlobalDisplayState=" + Display.stateToString(mGlobalDisplayState)); |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1542 | pw.println(" mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId); |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1543 | pw.println(" mViewports=" + mViewports); |
Damien Bargiacchi | 4364bbf | 2016-11-01 21:44:20 -0700 | [diff] [blame] | 1544 | pw.println(" mDefaultDisplayDefaultColorMode=" + mDefaultDisplayDefaultColorMode); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1545 | pw.println(" mSingleDisplayDemoMode=" + mSingleDisplayDemoMode); |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1546 | pw.println(" mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount); |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1547 | pw.println(" mStableDisplaySize=" + mStableDisplaySize); |
Kenny Guy | 2047db9 | 2019-02-21 13:04:05 +0000 | [diff] [blame] | 1548 | pw.println(" mMinimumBrightnessCurve=" + mMinimumBrightnessCurve); |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 1549 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1550 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1551 | ipw.increaseIndent(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1552 | |
| 1553 | pw.println(); |
| 1554 | pw.println("Display Adapters: size=" + mDisplayAdapters.size()); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1555 | for (DisplayAdapter adapter : mDisplayAdapters) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1556 | pw.println(" " + adapter.getName()); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1557 | adapter.dumpLocked(ipw); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1558 | } |
Craig Mautner | 9de4936 | 2012-08-02 14:30:30 -0700 | [diff] [blame] | 1559 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1560 | pw.println(); |
| 1561 | pw.println("Display Devices: size=" + mDisplayDevices.size()); |
| 1562 | for (DisplayDevice device : mDisplayDevices) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1563 | pw.println(" " + device.getDisplayDeviceInfoLocked()); |
| 1564 | device.dumpLocked(ipw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | final int logicalDisplayCount = mLogicalDisplays.size(); |
| 1568 | pw.println(); |
| 1569 | pw.println("Logical Displays: size=" + logicalDisplayCount); |
| 1570 | for (int i = 0; i < logicalDisplayCount; i++) { |
| 1571 | int displayId = mLogicalDisplays.keyAt(i); |
| 1572 | LogicalDisplay display = mLogicalDisplays.valueAt(i); |
| 1573 | pw.println(" Display " + displayId + ":"); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1574 | display.dumpLocked(ipw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1575 | } |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1576 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 1577 | pw.println(); |
| 1578 | mDisplayModeDirector.dump(pw); |
| 1579 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1580 | final int callbackCount = mCallbacks.size(); |
| 1581 | pw.println(); |
| 1582 | pw.println("Callbacks: size=" + callbackCount); |
| 1583 | for (int i = 0; i < callbackCount; i++) { |
| 1584 | CallbackRecord callback = mCallbacks.valueAt(i); |
| 1585 | pw.println(" " + i + ": mPid=" + callback.mPid |
| 1586 | + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested); |
| 1587 | } |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 1588 | |
| 1589 | if (mDisplayPowerController != null) { |
| 1590 | mDisplayPowerController.dump(pw); |
| 1591 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1592 | |
| 1593 | pw.println(); |
| 1594 | mPersistentDataStore.dump(pw); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 1598 | private static float[] getFloatArray(TypedArray array) { |
| 1599 | int length = array.length(); |
| 1600 | float[] floatArray = new float[length]; |
| 1601 | for (int i = 0; i < length; i++) { |
| 1602 | floatArray[i] = array.getFloat(i, Float.NaN); |
| 1603 | } |
| 1604 | array.recycle(); |
| 1605 | return floatArray; |
| 1606 | } |
| 1607 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1608 | /** |
| 1609 | * This is the object that everything in the display manager locks on. |
| 1610 | * We make it an inner class within the {@link DisplayManagerService} to so that it is |
| 1611 | * clear that the object belongs to the display manager service and that it is |
| 1612 | * a unique object with a special purpose. |
| 1613 | */ |
| 1614 | public static final class SyncRoot { |
| 1615 | } |
| 1616 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1617 | @VisibleForTesting |
| 1618 | static class Injector { |
| 1619 | VirtualDisplayAdapter getVirtualDisplayAdapter(SyncRoot syncRoot, Context context, |
| 1620 | Handler handler, DisplayAdapter.Listener displayAdapterListener) { |
| 1621 | return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener); |
| 1622 | } |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 1623 | |
| 1624 | long getDefaultDisplayDelayTimeout() { |
| 1625 | return WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT; |
| 1626 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Alex Sakhartchouk | 879d24f | 2017-06-20 22:01:19 -0400 | [diff] [blame] | 1629 | @VisibleForTesting |
| 1630 | DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) { |
| 1631 | synchronized (mSyncRoot) { |
| 1632 | LogicalDisplay display = mLogicalDisplays.get(displayId); |
| 1633 | if (display != null) { |
| 1634 | DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked(); |
| 1635 | return displayDevice.getDisplayDeviceInfoLocked(); |
| 1636 | } |
| 1637 | return null; |
| 1638 | } |
| 1639 | } |
| 1640 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1641 | private final class DisplayManagerHandler extends Handler { |
| 1642 | public DisplayManagerHandler(Looper looper) { |
| 1643 | super(looper, null, true /*async*/); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 1644 | } |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 1645 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1646 | @Override |
| 1647 | public void handleMessage(Message msg) { |
| 1648 | switch (msg.what) { |
Santos Cordon | c22c563 | 2017-06-21 16:03:49 -0700 | [diff] [blame] | 1649 | case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTERS: |
| 1650 | registerDefaultDisplayAdapters(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1651 | break; |
| 1652 | |
| 1653 | case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS: |
| 1654 | registerAdditionalDisplayAdapters(); |
| 1655 | break; |
| 1656 | |
| 1657 | case MSG_DELIVER_DISPLAY_EVENT: |
| 1658 | deliverDisplayEvent(msg.arg1, msg.arg2); |
| 1659 | break; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1660 | |
| 1661 | case MSG_REQUEST_TRAVERSAL: |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1662 | mWindowManagerInternal.requestTraversalFromDisplayManager(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1663 | break; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1664 | |
| 1665 | case MSG_UPDATE_VIEWPORT: { |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1666 | final boolean changed; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1667 | synchronized (mSyncRoot) { |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1668 | changed = !mTempViewports.equals(mViewports); |
| 1669 | if (changed) { |
| 1670 | mTempViewports.clear(); |
| 1671 | for (DisplayViewport d : mViewports) { |
| 1672 | mTempViewports.add(d.makeCopy()); |
| 1673 | } |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1674 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1675 | } |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 1676 | if (changed) { |
| 1677 | mInputManagerInternal.setDisplayViewports(mTempViewports); |
| 1678 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1679 | break; |
| 1680 | } |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 1681 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 1682 | case MSG_LOAD_BRIGHTNESS_CONFIGURATION: |
| 1683 | loadBrightnessConfiguration(); |
| 1684 | break; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | private final class DisplayAdapterListener implements DisplayAdapter.Listener { |
| 1690 | @Override |
| 1691 | public void onDisplayDeviceEvent(DisplayDevice device, int event) { |
| 1692 | switch (event) { |
| 1693 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED: |
| 1694 | handleDisplayDeviceAdded(device); |
| 1695 | break; |
| 1696 | |
| 1697 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED: |
| 1698 | handleDisplayDeviceChanged(device); |
| 1699 | break; |
| 1700 | |
| 1701 | case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED: |
| 1702 | handleDisplayDeviceRemoved(device); |
| 1703 | break; |
| 1704 | } |
| 1705 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1706 | |
| 1707 | @Override |
| 1708 | public void onTraversalRequested() { |
| 1709 | synchronized (mSyncRoot) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1710 | scheduleTraversalLocked(false); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1711 | } |
| 1712 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | private final class CallbackRecord implements DeathRecipient { |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1716 | public final int mPid; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1717 | private final IDisplayManagerCallback mCallback; |
| 1718 | |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1719 | public boolean mWifiDisplayScanRequested; |
| 1720 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1721 | public CallbackRecord(int pid, IDisplayManagerCallback callback) { |
| 1722 | mPid = pid; |
| 1723 | mCallback = callback; |
| 1724 | } |
| 1725 | |
| 1726 | @Override |
| 1727 | public void binderDied() { |
| 1728 | if (DEBUG) { |
| 1729 | Slog.d(TAG, "Display listener for pid " + mPid + " died."); |
| 1730 | } |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 1731 | onCallbackDied(this); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | public void notifyDisplayEventAsync(int displayId, int event) { |
| 1735 | try { |
| 1736 | mCallback.onDisplayEvent(displayId, event); |
| 1737 | } catch (RemoteException ex) { |
| 1738 | Slog.w(TAG, "Failed to notify process " |
| 1739 | + mPid + " that displays changed, assuming it died.", ex); |
| 1740 | binderDied(); |
| 1741 | } |
| 1742 | } |
| 1743 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1744 | |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1745 | @VisibleForTesting |
| 1746 | final class BinderService extends IDisplayManager.Stub { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1747 | /** |
| 1748 | * Returns information about the specified logical display. |
| 1749 | * |
| 1750 | * @param displayId The logical display id. |
lumark | ec75b42 | 2019-01-07 15:58:38 +0800 | [diff] [blame] | 1751 | * @return The logical display info, return {@code null} if the display does not exist or |
| 1752 | * the calling UID isn't present on the display. The returned object must be treated as |
| 1753 | * immutable. |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1754 | */ |
| 1755 | @Override // Binder call |
| 1756 | public DisplayInfo getDisplayInfo(int displayId) { |
| 1757 | final int callingUid = Binder.getCallingUid(); |
| 1758 | final long token = Binder.clearCallingIdentity(); |
| 1759 | try { |
| 1760 | return getDisplayInfoInternal(displayId, callingUid); |
| 1761 | } finally { |
| 1762 | Binder.restoreCallingIdentity(token); |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | /** |
| 1767 | * Returns the list of all display ids. |
| 1768 | */ |
| 1769 | @Override // Binder call |
| 1770 | public int[] getDisplayIds() { |
| 1771 | final int callingUid = Binder.getCallingUid(); |
| 1772 | final long token = Binder.clearCallingIdentity(); |
| 1773 | try { |
| 1774 | return getDisplayIdsInternal(callingUid); |
| 1775 | } finally { |
| 1776 | Binder.restoreCallingIdentity(token); |
| 1777 | } |
| 1778 | } |
| 1779 | |
lumark | ec75b42 | 2019-01-07 15:58:38 +0800 | [diff] [blame] | 1780 | @Override // Binder call |
| 1781 | public boolean isUidPresentOnDisplay(int uid, int displayId) { |
| 1782 | final long token = Binder.clearCallingIdentity(); |
| 1783 | try { |
| 1784 | return isUidPresentOnDisplayInternal(uid, displayId); |
| 1785 | } finally { |
| 1786 | Binder.restoreCallingIdentity(token); |
| 1787 | } |
| 1788 | } |
| 1789 | |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 1790 | /** |
| 1791 | * Returns the stable device display size, in pixels. |
| 1792 | */ |
| 1793 | @Override // Binder call |
| 1794 | public Point getStableDisplaySize() { |
| 1795 | final long token = Binder.clearCallingIdentity(); |
| 1796 | try { |
| 1797 | return getStableDisplaySizeInternal(); |
| 1798 | } finally { |
| 1799 | Binder.restoreCallingIdentity(token); |
| 1800 | } |
| 1801 | } |
| 1802 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1803 | @Override // Binder call |
| 1804 | public void registerCallback(IDisplayManagerCallback callback) { |
| 1805 | if (callback == null) { |
| 1806 | throw new IllegalArgumentException("listener must not be null"); |
| 1807 | } |
| 1808 | |
| 1809 | final int callingPid = Binder.getCallingPid(); |
| 1810 | final long token = Binder.clearCallingIdentity(); |
| 1811 | try { |
| 1812 | registerCallbackInternal(callback, callingPid); |
| 1813 | } finally { |
| 1814 | Binder.restoreCallingIdentity(token); |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | @Override // Binder call |
| 1819 | public void startWifiDisplayScan() { |
| 1820 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1821 | "Permission required to start wifi display scans"); |
| 1822 | |
| 1823 | final int callingPid = Binder.getCallingPid(); |
| 1824 | final long token = Binder.clearCallingIdentity(); |
| 1825 | try { |
| 1826 | startWifiDisplayScanInternal(callingPid); |
| 1827 | } finally { |
| 1828 | Binder.restoreCallingIdentity(token); |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | @Override // Binder call |
| 1833 | public void stopWifiDisplayScan() { |
| 1834 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1835 | "Permission required to stop wifi display scans"); |
| 1836 | |
| 1837 | final int callingPid = Binder.getCallingPid(); |
| 1838 | final long token = Binder.clearCallingIdentity(); |
| 1839 | try { |
| 1840 | stopWifiDisplayScanInternal(callingPid); |
| 1841 | } finally { |
| 1842 | Binder.restoreCallingIdentity(token); |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | @Override // Binder call |
| 1847 | public void connectWifiDisplay(String address) { |
| 1848 | if (address == null) { |
| 1849 | throw new IllegalArgumentException("address must not be null"); |
| 1850 | } |
| 1851 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1852 | "Permission required to connect to a wifi display"); |
| 1853 | |
| 1854 | final long token = Binder.clearCallingIdentity(); |
| 1855 | try { |
| 1856 | connectWifiDisplayInternal(address); |
| 1857 | } finally { |
| 1858 | Binder.restoreCallingIdentity(token); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | @Override // Binder call |
| 1863 | public void disconnectWifiDisplay() { |
| 1864 | // This request does not require special permissions. |
| 1865 | // Any app can request disconnection from the currently active wifi display. |
| 1866 | // This exception should no longer be needed once wifi display control moves |
| 1867 | // to the media router service. |
| 1868 | |
| 1869 | final long token = Binder.clearCallingIdentity(); |
| 1870 | try { |
| 1871 | disconnectWifiDisplayInternal(); |
| 1872 | } finally { |
| 1873 | Binder.restoreCallingIdentity(token); |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | @Override // Binder call |
| 1878 | public void renameWifiDisplay(String address, String alias) { |
| 1879 | if (address == null) { |
| 1880 | throw new IllegalArgumentException("address must not be null"); |
| 1881 | } |
| 1882 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1883 | "Permission required to rename to a wifi display"); |
| 1884 | |
| 1885 | final long token = Binder.clearCallingIdentity(); |
| 1886 | try { |
| 1887 | renameWifiDisplayInternal(address, alias); |
| 1888 | } finally { |
| 1889 | Binder.restoreCallingIdentity(token); |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | @Override // Binder call |
| 1894 | public void forgetWifiDisplay(String address) { |
| 1895 | if (address == null) { |
| 1896 | throw new IllegalArgumentException("address must not be null"); |
| 1897 | } |
| 1898 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1899 | "Permission required to forget to a wifi display"); |
| 1900 | |
| 1901 | final long token = Binder.clearCallingIdentity(); |
| 1902 | try { |
| 1903 | forgetWifiDisplayInternal(address); |
| 1904 | } finally { |
| 1905 | Binder.restoreCallingIdentity(token); |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | @Override // Binder call |
| 1910 | public void pauseWifiDisplay() { |
| 1911 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1912 | "Permission required to pause a wifi display session"); |
| 1913 | |
| 1914 | final long token = Binder.clearCallingIdentity(); |
| 1915 | try { |
| 1916 | pauseWifiDisplayInternal(); |
| 1917 | } finally { |
| 1918 | Binder.restoreCallingIdentity(token); |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | @Override // Binder call |
| 1923 | public void resumeWifiDisplay() { |
| 1924 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY, |
| 1925 | "Permission required to resume a wifi display session"); |
| 1926 | |
| 1927 | final long token = Binder.clearCallingIdentity(); |
| 1928 | try { |
| 1929 | resumeWifiDisplayInternal(); |
| 1930 | } finally { |
| 1931 | Binder.restoreCallingIdentity(token); |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | @Override // Binder call |
| 1936 | public WifiDisplayStatus getWifiDisplayStatus() { |
| 1937 | // This request does not require special permissions. |
| 1938 | // Any app can get information about available wifi displays. |
| 1939 | |
| 1940 | final long token = Binder.clearCallingIdentity(); |
| 1941 | try { |
| 1942 | return getWifiDisplayStatusInternal(); |
| 1943 | } finally { |
| 1944 | Binder.restoreCallingIdentity(token); |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | @Override // Binder call |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1949 | public void requestColorMode(int displayId, int colorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1950 | mContext.enforceCallingOrSelfPermission( |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1951 | Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE, |
| 1952 | "Permission required to change the display color mode"); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1953 | final long token = Binder.clearCallingIdentity(); |
| 1954 | try { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1955 | requestColorModeInternal(displayId, colorMode); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1956 | } finally { |
| 1957 | Binder.restoreCallingIdentity(token); |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1962 | public int createVirtualDisplay(IVirtualDisplayCallback callback, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1963 | IMediaProjection projection, String packageName, String name, |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 1964 | int width, int height, int densityDpi, Surface surface, int flags, |
| 1965 | String uniqueId) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1966 | final int callingUid = Binder.getCallingUid(); |
| 1967 | if (!validatePackageName(callingUid, packageName)) { |
| 1968 | throw new SecurityException("packageName must match the calling uid"); |
| 1969 | } |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 1970 | if (callback == null) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1971 | throw new IllegalArgumentException("appToken must not be null"); |
| 1972 | } |
| 1973 | if (TextUtils.isEmpty(name)) { |
| 1974 | throw new IllegalArgumentException("name must be non-null and non-empty"); |
| 1975 | } |
| 1976 | if (width <= 0 || height <= 0 || densityDpi <= 0) { |
| 1977 | throw new IllegalArgumentException("width, height, and densityDpi must be " |
| 1978 | + "greater than 0"); |
| 1979 | } |
Pablo Ceballos | eb3370d | 2016-08-31 15:00:17 -0700 | [diff] [blame] | 1980 | if (surface != null && surface.isSingleBuffered()) { |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 1981 | throw new IllegalArgumentException("Surface can't be single-buffered"); |
| 1982 | } |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1983 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1984 | if ((flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) { |
| 1985 | flags |= VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
| 1986 | |
| 1987 | // Public displays can't be allowed to show content when locked. |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 1988 | if ((flags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) { |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1989 | throw new IllegalArgumentException( |
| 1990 | "Public display must not be marked as SHOW_WHEN_LOCKED_INSECURE"); |
| 1991 | } |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1992 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1993 | if ((flags & VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) { |
| 1994 | flags &= ~VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1997 | if (projection != null) { |
| 1998 | try { |
| 1999 | if (!getProjectionService().isValidMediaProjection(projection)) { |
| 2000 | throw new SecurityException("Invalid media projection"); |
| 2001 | } |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 2002 | flags = projection.applyVirtualDisplayFlags(flags); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2003 | } catch (RemoteException e) { |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 2004 | throw new SecurityException("unable to validate media projection or flags"); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2005 | } |
| 2006 | } |
| 2007 | |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 2008 | if (callingUid != Process.SYSTEM_UID && |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2009 | (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2010 | if (!canProjectVideo(projection)) { |
| 2011 | throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or " |
| 2012 | + "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate " |
| 2013 | + "MediaProjection token in order to create a screen sharing virtual " |
| 2014 | + "display."); |
| 2015 | } |
| 2016 | } |
Santos Cordon | b6992f2 | 2018-01-30 14:51:20 -0800 | [diff] [blame] | 2017 | if (callingUid != Process.SYSTEM_UID && (flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2018 | if (!canProjectSecureVideo(projection)) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2019 | throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT " |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2020 | + "or an appropriate MediaProjection token to create a " |
| 2021 | + "secure virtual display."); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | |
Chilun | 67a379b | 2019-04-11 19:49:42 +0800 | [diff] [blame] | 2025 | // Sometimes users can have sensitive information in system decoration windows. An app |
| 2026 | // could create a virtual display with system decorations support and read the user info |
| 2027 | // from the surface. |
| 2028 | // We should only allow adding flag VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS |
| 2029 | // to virtual displays that are owned by the system. |
| 2030 | if (callingUid != Process.SYSTEM_UID |
| 2031 | && (flags & VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0) { |
| 2032 | if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "createVirtualDisplay()")) { |
| 2033 | throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission"); |
| 2034 | } |
| 2035 | } |
| 2036 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2037 | final long token = Binder.clearCallingIdentity(); |
| 2038 | try { |
Santos Cordon | ee8931e | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 2039 | return createVirtualDisplayInternal(callback, projection, callingUid, packageName, |
| 2040 | name, width, height, densityDpi, surface, flags, uniqueId); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2041 | } finally { |
| 2042 | Binder.restoreCallingIdentity(token); |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 2047 | public void resizeVirtualDisplay(IVirtualDisplayCallback callback, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 2048 | int width, int height, int densityDpi) { |
Jeff Chang | 01baf6c | 2019-08-20 16:21:25 +0800 | [diff] [blame] | 2049 | if (width <= 0 || height <= 0 || densityDpi <= 0) { |
| 2050 | throw new IllegalArgumentException("width, height, and densityDpi must be " |
| 2051 | + "greater than 0"); |
| 2052 | } |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 2053 | final long token = Binder.clearCallingIdentity(); |
| 2054 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 2055 | resizeVirtualDisplayInternal(callback.asBinder(), width, height, densityDpi); |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 2056 | } finally { |
| 2057 | Binder.restoreCallingIdentity(token); |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 2062 | public void setVirtualDisplaySurface(IVirtualDisplayCallback callback, Surface surface) { |
Pablo Ceballos | eb3370d | 2016-08-31 15:00:17 -0700 | [diff] [blame] | 2063 | if (surface != null && surface.isSingleBuffered()) { |
| 2064 | throw new IllegalArgumentException("Surface can't be single-buffered"); |
| 2065 | } |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 2066 | final long token = Binder.clearCallingIdentity(); |
| 2067 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 2068 | setVirtualDisplaySurfaceInternal(callback.asBinder(), surface); |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 2069 | } finally { |
| 2070 | Binder.restoreCallingIdentity(token); |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | @Override // Binder call |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 2075 | public void releaseVirtualDisplay(IVirtualDisplayCallback callback) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2076 | final long token = Binder.clearCallingIdentity(); |
| 2077 | try { |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 2078 | releaseVirtualDisplayInternal(callback.asBinder()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2079 | } finally { |
| 2080 | Binder.restoreCallingIdentity(token); |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | @Override // Binder call |
chaviw | da4c694 | 2018-11-07 15:52:56 -0800 | [diff] [blame] | 2085 | public void setVirtualDisplayState(IVirtualDisplayCallback callback, boolean isOn) { |
| 2086 | final long token = Binder.clearCallingIdentity(); |
| 2087 | try { |
| 2088 | setVirtualDisplayStateInternal(callback.asBinder(), isOn); |
| 2089 | } finally { |
| 2090 | Binder.restoreCallingIdentity(token); |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | @Override // Binder call |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2095 | public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 2096 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2097 | |
| 2098 | final long token = Binder.clearCallingIdentity(); |
| 2099 | try { |
| 2100 | dumpInternal(pw); |
| 2101 | } finally { |
| 2102 | Binder.restoreCallingIdentity(token); |
| 2103 | } |
| 2104 | } |
| 2105 | |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 2106 | @Override // Binder call |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 2107 | public ParceledListSlice<BrightnessChangeEvent> getBrightnessEvents(String callingPackage) { |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 2108 | mContext.enforceCallingOrSelfPermission( |
| 2109 | Manifest.permission.BRIGHTNESS_SLIDER_USAGE, |
| 2110 | "Permission to read brightness events."); |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 2111 | |
| 2112 | final int callingUid = Binder.getCallingUid(); |
| 2113 | AppOpsManager appOpsManager = mContext.getSystemService(AppOpsManager.class); |
Jeff Sharkey | d931119 | 2018-04-16 16:50:34 +0000 | [diff] [blame] | 2114 | final int mode = appOpsManager.noteOp(AppOpsManager.OP_GET_USAGE_STATS, |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 2115 | callingUid, callingPackage); |
| 2116 | final boolean hasUsageStats; |
| 2117 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 2118 | // The default behavior here is to check if PackageManager has given the app |
| 2119 | // permission. |
| 2120 | hasUsageStats = mContext.checkCallingPermission( |
| 2121 | Manifest.permission.PACKAGE_USAGE_STATS) |
| 2122 | == PackageManager.PERMISSION_GRANTED; |
| 2123 | } else { |
| 2124 | hasUsageStats = mode == AppOpsManager.MODE_ALLOWED; |
| 2125 | } |
| 2126 | |
| 2127 | final int userId = UserHandle.getUserId(callingUid); |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 2128 | final long token = Binder.clearCallingIdentity(); |
| 2129 | try { |
Michael Wright | 144aac9 | 2017-12-21 18:37:41 +0000 | [diff] [blame] | 2130 | synchronized (mSyncRoot) { |
| 2131 | return mDisplayPowerController.getBrightnessEvents(userId, hasUsageStats); |
| 2132 | } |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 2133 | } finally { |
| 2134 | Binder.restoreCallingIdentity(token); |
| 2135 | } |
| 2136 | } |
| 2137 | |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2138 | @Override // Binder call |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 2139 | public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats() { |
| 2140 | mContext.enforceCallingOrSelfPermission( |
| 2141 | Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS, |
| 2142 | "Permission required to to access ambient light stats."); |
| 2143 | final int callingUid = Binder.getCallingUid(); |
| 2144 | final int userId = UserHandle.getUserId(callingUid); |
| 2145 | final long token = Binder.clearCallingIdentity(); |
| 2146 | try { |
| 2147 | synchronized (mSyncRoot) { |
| 2148 | return mDisplayPowerController.getAmbientBrightnessStats(userId); |
| 2149 | } |
| 2150 | } finally { |
| 2151 | Binder.restoreCallingIdentity(token); |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | @Override // Binder call |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2156 | public void setBrightnessConfigurationForUser( |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 2157 | BrightnessConfiguration c, @UserIdInt int userId, String packageName) { |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2158 | mContext.enforceCallingOrSelfPermission( |
| 2159 | Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS, |
| 2160 | "Permission required to change the display's brightness configuration"); |
| 2161 | if (userId != UserHandle.getCallingUserId()) { |
| 2162 | mContext.enforceCallingOrSelfPermission( |
| 2163 | Manifest.permission.INTERACT_ACROSS_USERS, |
| 2164 | "Permission required to change the display brightness" |
| 2165 | + " configuration of another user"); |
| 2166 | } |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 2167 | if (packageName != null && !validatePackageName(getCallingUid(), packageName)) { |
| 2168 | packageName = null; |
| 2169 | } |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2170 | final long token = Binder.clearCallingIdentity(); |
| 2171 | try { |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 2172 | setBrightnessConfigurationForUserInternal(c, userId, packageName); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2173 | } finally { |
| 2174 | Binder.restoreCallingIdentity(token); |
| 2175 | } |
| 2176 | } |
| 2177 | |
Michael Wright | d846023 | 2018-01-16 18:04:59 +0000 | [diff] [blame] | 2178 | @Override // Binder call |
Kenny Guy | 6d1009f | 2018-03-14 14:28:23 +0000 | [diff] [blame] | 2179 | public BrightnessConfiguration getBrightnessConfigurationForUser(int userId) { |
| 2180 | mContext.enforceCallingOrSelfPermission( |
| 2181 | Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS, |
| 2182 | "Permission required to read the display's brightness configuration"); |
| 2183 | if (userId != UserHandle.getCallingUserId()) { |
| 2184 | mContext.enforceCallingOrSelfPermission( |
| 2185 | Manifest.permission.INTERACT_ACROSS_USERS, |
| 2186 | "Permission required to read the display brightness" |
| 2187 | + " configuration of another user"); |
| 2188 | } |
| 2189 | final long token = Binder.clearCallingIdentity(); |
| 2190 | try { |
| 2191 | final int userSerial = getUserManager().getUserSerialNumber(userId); |
| 2192 | synchronized (mSyncRoot) { |
| 2193 | BrightnessConfiguration config = |
| 2194 | mPersistentDataStore.getBrightnessConfiguration(userSerial); |
| 2195 | if (config == null) { |
| 2196 | config = mDisplayPowerController.getDefaultBrightnessConfiguration(); |
| 2197 | } |
| 2198 | return config; |
| 2199 | } |
| 2200 | } finally { |
| 2201 | Binder.restoreCallingIdentity(token); |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | @Override // Binder call |
| 2206 | public BrightnessConfiguration getDefaultBrightnessConfiguration() { |
| 2207 | mContext.enforceCallingOrSelfPermission( |
| 2208 | Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS, |
| 2209 | "Permission required to read the display's default brightness configuration"); |
| 2210 | final long token = Binder.clearCallingIdentity(); |
| 2211 | try { |
| 2212 | synchronized (mSyncRoot) { |
| 2213 | return mDisplayPowerController.getDefaultBrightnessConfiguration(); |
| 2214 | } |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(token); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | @Override // Binder call |
Michael Wright | d846023 | 2018-01-16 18:04:59 +0000 | [diff] [blame] | 2221 | public void setTemporaryBrightness(int brightness) { |
| 2222 | mContext.enforceCallingOrSelfPermission( |
| 2223 | Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS, |
| 2224 | "Permission required to set the display's brightness"); |
| 2225 | final long token = Binder.clearCallingIdentity(); |
| 2226 | try { |
| 2227 | synchronized (mSyncRoot) { |
| 2228 | mDisplayPowerController.setTemporaryBrightness(brightness); |
| 2229 | } |
| 2230 | } finally { |
| 2231 | Binder.restoreCallingIdentity(token); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | @Override // Binder call |
| 2236 | public void setTemporaryAutoBrightnessAdjustment(float adjustment) { |
| 2237 | mContext.enforceCallingOrSelfPermission( |
| 2238 | Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS, |
| 2239 | "Permission required to set the display's auto brightness adjustment"); |
| 2240 | final long token = Binder.clearCallingIdentity(); |
| 2241 | try { |
| 2242 | synchronized (mSyncRoot) { |
| 2243 | mDisplayPowerController.setTemporaryAutoBrightnessAdjustment(adjustment); |
| 2244 | } |
| 2245 | } finally { |
| 2246 | Binder.restoreCallingIdentity(token); |
| 2247 | } |
| 2248 | } |
| 2249 | |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 2250 | @Override // Binder call |
| 2251 | public void onShellCommand(FileDescriptor in, FileDescriptor out, |
| 2252 | FileDescriptor err, String[] args, ShellCallback callback, |
| 2253 | ResultReceiver resultReceiver) { |
| 2254 | final long token = Binder.clearCallingIdentity(); |
| 2255 | try { |
| 2256 | DisplayManagerShellCommand command = new DisplayManagerShellCommand(this); |
| 2257 | command.exec(this, in, out, err, args, callback, resultReceiver); |
| 2258 | } finally { |
| 2259 | Binder.restoreCallingIdentity(token); |
| 2260 | } |
| 2261 | } |
| 2262 | |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 2263 | @Override // Binder call |
| 2264 | public Curve getMinimumBrightnessCurve() { |
| 2265 | final long token = Binder.clearCallingIdentity(); |
| 2266 | try { |
| 2267 | return getMinimumBrightnessCurveInternal(); |
| 2268 | } finally { |
| 2269 | Binder.restoreCallingIdentity(token); |
| 2270 | } |
| 2271 | } |
| 2272 | |
Peiyong Lin | 277eaff | 2019-01-16 16:18:22 -0800 | [diff] [blame] | 2273 | @Override // Binder call |
| 2274 | public int getPreferredWideGamutColorSpaceId() { |
| 2275 | final long token = Binder.clearCallingIdentity(); |
| 2276 | try { |
| 2277 | return getPreferredWideGamutColorSpaceIdInternal(); |
| 2278 | } finally { |
| 2279 | Binder.restoreCallingIdentity(token); |
| 2280 | } |
| 2281 | } |
| 2282 | |
Dan Gittik | 7a32fba | 2018-03-28 12:19:38 +0100 | [diff] [blame] | 2283 | void setBrightness(int brightness) { |
| 2284 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2285 | Settings.System.SCREEN_BRIGHTNESS, brightness, UserHandle.USER_CURRENT); |
| 2286 | } |
| 2287 | |
| 2288 | void resetBrightnessConfiguration() { |
| 2289 | setBrightnessConfigurationForUserInternal(null, mContext.getUserId(), |
| 2290 | mContext.getPackageName()); |
| 2291 | } |
| 2292 | |
Dan Gittik | a5a2d63 | 2019-01-09 14:25:29 +0000 | [diff] [blame] | 2293 | void setAutoBrightnessLoggingEnabled(boolean enabled) { |
| 2294 | if (mDisplayPowerController != null) { |
| 2295 | synchronized (mSyncRoot) { |
| 2296 | mDisplayPowerController.setAutoBrightnessLoggingEnabled(enabled); |
| 2297 | } |
| 2298 | } |
| 2299 | } |
| 2300 | |
Dan Gittik | 8dbd7e9 | 2018-12-03 15:35:53 +0000 | [diff] [blame] | 2301 | void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) { |
| 2302 | if (mDisplayPowerController != null) { |
| 2303 | synchronized (mSyncRoot) { |
| 2304 | mDisplayPowerController.setDisplayWhiteBalanceLoggingEnabled(enabled); |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | void setAmbientColorTemperatureOverride(float cct) { |
| 2310 | if (mDisplayPowerController != null) { |
| 2311 | synchronized (mSyncRoot) { |
| 2312 | mDisplayPowerController.setAmbientColorTemperatureOverride(cct); |
| 2313 | } |
| 2314 | } |
| 2315 | } |
| 2316 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2317 | private boolean validatePackageName(int uid, String packageName) { |
| 2318 | if (packageName != null) { |
| 2319 | String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); |
| 2320 | if (packageNames != null) { |
| 2321 | for (String n : packageNames) { |
| 2322 | if (n.equals(packageName)) { |
| 2323 | return true; |
| 2324 | } |
| 2325 | } |
| 2326 | } |
| 2327 | } |
| 2328 | return false; |
| 2329 | } |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2330 | |
| 2331 | private boolean canProjectVideo(IMediaProjection projection) { |
| 2332 | if (projection != null) { |
| 2333 | try { |
| 2334 | if (projection.canProjectVideo()) { |
| 2335 | return true; |
| 2336 | } |
| 2337 | } catch (RemoteException e) { |
| 2338 | Slog.e(TAG, "Unable to query projection service for permissions", e); |
| 2339 | } |
| 2340 | } |
Chilun | 67a379b | 2019-04-11 19:49:42 +0800 | [diff] [blame] | 2341 | if (checkCallingPermission(CAPTURE_VIDEO_OUTPUT, "canProjectVideo()")) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2342 | return true; |
| 2343 | } |
| 2344 | return canProjectSecureVideo(projection); |
| 2345 | } |
| 2346 | |
| 2347 | private boolean canProjectSecureVideo(IMediaProjection projection) { |
| 2348 | if (projection != null) { |
| 2349 | try { |
| 2350 | if (projection.canProjectSecureVideo()){ |
| 2351 | return true; |
| 2352 | } |
| 2353 | } catch (RemoteException e) { |
| 2354 | Slog.e(TAG, "Unable to query projection service for permissions", e); |
| 2355 | } |
| 2356 | } |
Chilun | 67a379b | 2019-04-11 19:49:42 +0800 | [diff] [blame] | 2357 | return checkCallingPermission(CAPTURE_SECURE_VIDEO_OUTPUT, "canProjectSecureVideo()"); |
| 2358 | } |
| 2359 | |
| 2360 | private boolean checkCallingPermission(String permission, String func) { |
| 2361 | if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) { |
| 2362 | return true; |
| 2363 | } |
| 2364 | final String msg = "Permission Denial: " + func + " from pid=" + Binder.getCallingPid() |
| 2365 | + ", uid=" + Binder.getCallingUid() + " requires " + permission; |
| 2366 | Slog.w(TAG, msg); |
| 2367 | return false; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2368 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | private final class LocalService extends DisplayManagerInternal { |
Galia Peycheva | ea94575 | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 2372 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2373 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2374 | public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler, |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2375 | SensorManager sensorManager) { |
| 2376 | synchronized (mSyncRoot) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2377 | DisplayBlanker blanker = new DisplayBlanker() { |
| 2378 | @Override |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 2379 | public void requestDisplayState(int state, int brightness) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2380 | // The order of operations is important for legacy reasons. |
| 2381 | if (state == Display.STATE_OFF) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 2382 | requestGlobalDisplayStateInternal(state, brightness); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | callbacks.onDisplayStateChange(state); |
| 2386 | |
| 2387 | if (state != Display.STATE_OFF) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 2388 | requestGlobalDisplayStateInternal(state, brightness); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | }; |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2392 | mDisplayPowerController = new DisplayPowerController( |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2393 | mContext, callbacks, handler, sensorManager, blanker); |
Long Ling | bc841b0 | 2019-07-03 16:43:15 -0700 | [diff] [blame] | 2394 | mSensorManager = sensorManager; |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2395 | } |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2396 | |
| 2397 | mHandler.sendEmptyMessage(MSG_LOAD_BRIGHTNESS_CONFIGURATION); |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | @Override |
| 2401 | public boolean requestPowerState(DisplayPowerRequest request, |
| 2402 | boolean waitForNegativeProximity) { |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2403 | synchronized (mSyncRoot) { |
| 2404 | return mDisplayPowerController.requestPowerState(request, |
| 2405 | waitForNegativeProximity); |
| 2406 | } |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | @Override |
| 2410 | public boolean isProximitySensorAvailable() { |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 2411 | synchronized (mSyncRoot) { |
| 2412 | return mDisplayPowerController.isProximitySensorAvailable(); |
| 2413 | } |
Jeff Brown | ad9ef19 | 2014-04-08 17:26:30 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | @Override |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 2417 | public SurfaceControl.ScreenshotGraphicBuffer screenshot(int displayId) { |
| 2418 | return screenshotInternal(displayId); |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | @Override |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2422 | public DisplayInfo getDisplayInfo(int displayId) { |
| 2423 | return getDisplayInfoInternal(displayId, Process.myUid()); |
| 2424 | } |
| 2425 | |
| 2426 | @Override |
| 2427 | public void registerDisplayTransactionListener(DisplayTransactionListener listener) { |
| 2428 | if (listener == null) { |
| 2429 | throw new IllegalArgumentException("listener must not be null"); |
| 2430 | } |
| 2431 | |
| 2432 | registerDisplayTransactionListenerInternal(listener); |
| 2433 | } |
| 2434 | |
| 2435 | @Override |
| 2436 | public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) { |
| 2437 | if (listener == null) { |
| 2438 | throw new IllegalArgumentException("listener must not be null"); |
| 2439 | } |
| 2440 | |
| 2441 | unregisterDisplayTransactionListenerInternal(listener); |
| 2442 | } |
| 2443 | |
| 2444 | @Override |
| 2445 | public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) { |
| 2446 | setDisplayInfoOverrideFromWindowManagerInternal(displayId, info); |
| 2447 | } |
| 2448 | |
| 2449 | @Override |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2450 | public void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo) { |
| 2451 | getNonOverrideDisplayInfoInternal(displayId, outInfo); |
| 2452 | } |
| 2453 | |
| 2454 | @Override |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 2455 | public void performTraversal(SurfaceControl.Transaction t) { |
| 2456 | performTraversalInternal(t); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | @Override |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 2460 | public void setDisplayProperties(int displayId, boolean hasContent, |
Galia Peycheva | ea94575 | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 2461 | float requestedRefreshRate, int requestedMode, boolean preferMinimalPostProcessing, |
| 2462 | boolean inTraversal) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 2463 | setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate, |
Galia Peycheva | ea94575 | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 2464 | requestedMode, preferMinimalPostProcessing, inTraversal); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2465 | } |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 2466 | |
| 2467 | @Override |
| 2468 | public void setDisplayOffsets(int displayId, int x, int y) { |
| 2469 | setDisplayOffsetsInternal(displayId, x, y); |
| 2470 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2471 | |
| 2472 | @Override |
Sam Lin | 4c3ac2b | 2019-02-18 04:50:26 -0800 | [diff] [blame] | 2473 | public void setDisplayScalingDisabled(int displayId, boolean disableScaling) { |
| 2474 | setDisplayScalingDisabledInternal(displayId, disableScaling); |
| 2475 | } |
| 2476 | |
| 2477 | @Override |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2478 | public void setDisplayAccessUIDs(SparseArray<IntArray> newDisplayAccessUIDs) { |
| 2479 | setDisplayAccessUIDsInternal(newDisplayAccessUIDs); |
| 2480 | } |
| 2481 | |
| 2482 | @Override |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 2483 | public void persistBrightnessTrackerState() { |
Michael Wright | 144aac9 | 2017-12-21 18:37:41 +0000 | [diff] [blame] | 2484 | synchronized (mSyncRoot) { |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 2485 | mDisplayPowerController.persistBrightnessTrackerState(); |
Michael Wright | 144aac9 | 2017-12-21 18:37:41 +0000 | [diff] [blame] | 2486 | } |
Kenny Guy | cfe7b70 | 2017-11-14 21:04:58 +0000 | [diff] [blame] | 2487 | } |
Adrian Roos | e1d68cd | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 2488 | |
| 2489 | @Override |
| 2490 | public void onOverlayChanged() { |
| 2491 | synchronized (mSyncRoot) { |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 2492 | for (int i = 0; i < mDisplayDevices.size(); i++) { |
| 2493 | mDisplayDevices.get(i).onOverlayChangedLocked(); |
Adrian Roos | e1d68cd | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 2494 | } |
| 2495 | } |
| 2496 | } |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 2497 | |
| 2498 | @Override |
| 2499 | public DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes( |
| 2500 | int displayId) { |
| 2501 | return getDisplayedContentSamplingAttributesInternal(displayId); |
| 2502 | } |
| 2503 | |
| 2504 | @Override |
| 2505 | public boolean setDisplayedContentSamplingEnabled( |
| 2506 | int displayId, boolean enable, int componentMask, int maxFrames) { |
| 2507 | return setDisplayedContentSamplingEnabledInternal( |
| 2508 | displayId, enable, componentMask, maxFrames); |
| 2509 | } |
| 2510 | |
| 2511 | @Override |
| 2512 | public DisplayedContentSample getDisplayedContentSample(int displayId, |
| 2513 | long maxFrames, long timestamp) { |
| 2514 | return getDisplayedContentSampleInternal(displayId, maxFrames, timestamp); |
| 2515 | } |
| 2516 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 2517 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 2518 | |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame^] | 2519 | class DesiredDisplayModeSpecsObserver |
| 2520 | implements DisplayModeDirector.DesiredDisplayModeSpecsListener { |
| 2521 | public void onDesiredDisplayModeSpecsChanged() { |
| 2522 | onDesiredDisplayModeSpecsChangedInternal(); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 2523 | } |
| 2524 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2525 | } |