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