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