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