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