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