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 android.hardware.display; |
| 18 | |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 19 | import android.Manifest; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 22 | import android.annotation.RequiresPermission; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 24 | import android.annotation.SystemService; |
Kenny Guy | 0ff4489 | 2018-01-10 14:06:42 +0000 | [diff] [blame] | 25 | import android.annotation.TestApi; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 26 | import android.app.KeyguardManager; |
Artur Satayev | 2695800 | 2019-12-10 17:47:52 +0000 | [diff] [blame^] | 27 | import android.compat.annotation.UnsupportedAppUsage; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 28 | import android.content.Context; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 29 | import android.graphics.Point; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 30 | import android.media.projection.MediaProjection; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 32 | import android.util.Pair; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 33 | import android.util.SparseArray; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 34 | import android.view.Display; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 35 | import android.view.Surface; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 36 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 37 | import java.util.ArrayList; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 38 | import java.util.List; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 39 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 40 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 41 | * Manages the properties of attached displays. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 42 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 43 | @SystemService(Context.DISPLAY_SERVICE) |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 44 | public final class DisplayManager { |
| 45 | private static final String TAG = "DisplayManager"; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 46 | private static final boolean DEBUG = false; |
| 47 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 48 | private final Context mContext; |
| 49 | private final DisplayManagerGlobal mGlobal; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 50 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 51 | private final Object mLock = new Object(); |
| 52 | private final SparseArray<Display> mDisplays = new SparseArray<Display>(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 53 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 54 | private final ArrayList<Display> mTempDisplays = new ArrayList<Display>(); |
| 55 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Broadcast receiver that indicates when the Wifi display status changes. |
| 58 | * <p> |
| 59 | * The status is provided as a {@link WifiDisplayStatus} object in the |
| 60 | * {@link #EXTRA_WIFI_DISPLAY_STATUS} extra. |
| 61 | * </p><p> |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 62 | * This broadcast is only sent to registered receivers and can only be sent by the system. |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 63 | * </p> |
| 64 | * @hide |
| 65 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 66 | @UnsupportedAppUsage |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 67 | public static final String ACTION_WIFI_DISPLAY_STATUS_CHANGED = |
| 68 | "android.hardware.display.action.WIFI_DISPLAY_STATUS_CHANGED"; |
| 69 | |
| 70 | /** |
| 71 | * Contains a {@link WifiDisplayStatus} object. |
| 72 | * @hide |
| 73 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 74 | @UnsupportedAppUsage |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 75 | public static final String EXTRA_WIFI_DISPLAY_STATUS = |
| 76 | "android.hardware.display.extra.WIFI_DISPLAY_STATUS"; |
| 77 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 78 | /** |
| 79 | * Display category: Presentation displays. |
| 80 | * <p> |
| 81 | * This category can be used to identify secondary displays that are suitable for |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 82 | * use as presentation displays such as HDMI or Wireless displays. Applications |
| 83 | * may automatically project their content to presentation displays to provide |
| 84 | * richer second screen experiences. |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 85 | * </p> |
| 86 | * |
Jeff Brown | 511cd35 | 2013-08-23 17:43:37 -0700 | [diff] [blame] | 87 | * @see android.app.Presentation |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 88 | * @see Display#FLAG_PRESENTATION |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 89 | * @see #getDisplays(String) |
| 90 | */ |
| 91 | public static final String DISPLAY_CATEGORY_PRESENTATION = |
| 92 | "android.hardware.display.category.PRESENTATION"; |
| 93 | |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Virtual display flag: Create a public display. |
| 96 | * |
| 97 | * <h3>Public virtual displays</h3> |
| 98 | * <p> |
| 99 | * When this flag is set, the virtual display is public. |
| 100 | * </p><p> |
| 101 | * A public virtual display behaves just like most any other display that is connected |
| 102 | * to the system such as an HDMI or Wireless display. Applications can open |
| 103 | * windows on the display and the system may mirror the contents of other displays |
| 104 | * onto it. |
| 105 | * </p><p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 106 | * Creating a public virtual display that isn't restricted to own-content only implicitly |
| 107 | * creates an auto-mirroring display. See {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} for |
| 108 | * restrictions on who is allowed to create an auto-mirroring display. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 109 | * </p> |
| 110 | * |
| 111 | * <h3>Private virtual displays</h3> |
| 112 | * <p> |
| 113 | * When this flag is not set, the virtual display is private as defined by the |
| 114 | * {@link Display#FLAG_PRIVATE} display flag. |
| 115 | * </p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 116 | * |
| 117 | * <p> |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 118 | * A private virtual display belongs to the application that created it. Only the a owner of a |
| 119 | * private virtual display and the apps that are already on that display are allowed to place |
| 120 | * windows upon it. The private virtual display also does not participate in display mirroring: |
| 121 | * it will neither receive mirrored content from another display nor allow its own content to be |
| 122 | * mirrored elsewhere. More precisely, the only processes that are allowed to enumerate or |
| 123 | * interact with the private display are those that have the same UID as the application that |
| 124 | * originally created the private virtual display or as the activities that are already on that |
| 125 | * display. |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 126 | * </p> |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 127 | * |
| 128 | * @see #createVirtualDisplay |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 129 | * @see #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 130 | * @see #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 131 | */ |
| 132 | public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1 << 0; |
| 133 | |
| 134 | /** |
| 135 | * Virtual display flag: Create a presentation display. |
| 136 | * |
| 137 | * <h3>Presentation virtual displays</h3> |
| 138 | * <p> |
| 139 | * When this flag is set, the virtual display is registered as a presentation |
| 140 | * display in the {@link #DISPLAY_CATEGORY_PRESENTATION presentation display category}. |
| 141 | * Applications may automatically project their content to presentation displays |
| 142 | * to provide richer second screen experiences. |
| 143 | * </p> |
| 144 | * |
| 145 | * <h3>Non-presentation virtual displays</h3> |
| 146 | * <p> |
| 147 | * When this flag is not set, the virtual display is not registered as a presentation |
| 148 | * display. Applications can still project their content on the display but they |
| 149 | * will typically not do so automatically. This option is appropriate for |
| 150 | * more special-purpose displays. |
| 151 | * </p> |
| 152 | * |
Jeff Brown | 511cd35 | 2013-08-23 17:43:37 -0700 | [diff] [blame] | 153 | * @see android.app.Presentation |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 154 | * @see #createVirtualDisplay |
| 155 | * @see #DISPLAY_CATEGORY_PRESENTATION |
| 156 | * @see Display#FLAG_PRESENTATION |
| 157 | */ |
| 158 | public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 1 << 1; |
| 159 | |
| 160 | /** |
| 161 | * Virtual display flag: Create a secure display. |
| 162 | * |
| 163 | * <h3>Secure virtual displays</h3> |
| 164 | * <p> |
| 165 | * When this flag is set, the virtual display is considered secure as defined |
| 166 | * by the {@link Display#FLAG_SECURE} display flag. The caller promises to take |
| 167 | * reasonable measures, such as over-the-air encryption, to prevent the contents |
| 168 | * of the display from being intercepted or recorded on a persistent medium. |
| 169 | * </p><p> |
Michael Wright | ca022f6 | 2018-08-28 16:58:59 +0100 | [diff] [blame] | 170 | * Creating a secure virtual display requires the CAPTURE_SECURE_VIDEO_OUTPUT permission. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 171 | * This permission is reserved for use by system components and is not available to |
| 172 | * third-party applications. |
| 173 | * </p> |
| 174 | * |
| 175 | * <h3>Non-secure virtual displays</h3> |
| 176 | * <p> |
| 177 | * When this flag is not set, the virtual display is considered unsecure. |
| 178 | * The content of secure windows will be blanked if shown on this display. |
| 179 | * </p> |
| 180 | * |
Jeff Brown | 511cd35 | 2013-08-23 17:43:37 -0700 | [diff] [blame] | 181 | * @see Display#FLAG_SECURE |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 182 | * @see #createVirtualDisplay |
| 183 | */ |
| 184 | public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 1 << 2; |
| 185 | |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 186 | /** |
| 187 | * Virtual display flag: Only show this display's own content; do not mirror |
| 188 | * the content of another display. |
| 189 | * |
| 190 | * <p> |
| 191 | * This flag is used in conjunction with {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}. |
| 192 | * Ordinarily public virtual displays will automatically mirror the content of the |
| 193 | * default display if they have no windows of their own. When this flag is |
| 194 | * specified, the virtual display will only ever show its own content and |
| 195 | * will be blanked instead if it has no windows. |
| 196 | * </p> |
| 197 | * |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 198 | * <p> |
| 199 | * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. If both |
| 200 | * flags are specified then the own-content only behavior will be applied. |
| 201 | * </p> |
| 202 | * |
| 203 | * <p> |
| 204 | * This behavior of this flag is implied whenever neither {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC} |
| 205 | * nor {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} have been set. This flag is only required to |
| 206 | * override the default behavior when creating a public display. |
| 207 | * </p> |
| 208 | * |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 209 | * @see #createVirtualDisplay |
| 210 | */ |
| 211 | public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 1 << 3; |
| 212 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 213 | |
| 214 | /** |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 215 | * Virtual display flag: Allows content to be mirrored on private displays when no content is |
| 216 | * being shown. |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 217 | * |
Michael Wright | 9469cdd | 2014-07-29 13:03:56 -0700 | [diff] [blame] | 218 | * <p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 219 | * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}. |
| 220 | * If both flags are specified then the own-content only behavior will be applied. |
Michael Wright | 9469cdd | 2014-07-29 13:03:56 -0700 | [diff] [blame] | 221 | * </p> |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 222 | * |
Michael Wright | 9469cdd | 2014-07-29 13:03:56 -0700 | [diff] [blame] | 223 | * <p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 224 | * The behavior of this flag is implied whenever {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC} is set |
| 225 | * and {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY} has not been set. This flag is only |
| 226 | * required to override the default behavior when creating a private display. |
| 227 | * </p> |
| 228 | * |
| 229 | * <p> |
Michael Wright | ca022f6 | 2018-08-28 16:58:59 +0100 | [diff] [blame] | 230 | * Creating an auto-mirroing virtual display requires the CAPTURE_VIDEO_OUTPUT |
| 231 | * or CAPTURE_SECURE_VIDEO_OUTPUT permission. |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 232 | * These permissions are reserved for use by system components and are not available to |
| 233 | * third-party applications. |
| 234 | * |
| 235 | * Alternatively, an appropriate {@link MediaProjection} may be used to create an |
| 236 | * auto-mirroring virtual display. |
Michael Wright | 9469cdd | 2014-07-29 13:03:56 -0700 | [diff] [blame] | 237 | * </p> |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 238 | * |
| 239 | * @see #createVirtualDisplay |
| 240 | */ |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 241 | public static final int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 1 << 4; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 242 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 243 | /** |
| 244 | * Virtual display flag: Allows content to be displayed on private virtual displays when |
| 245 | * keyguard is shown but is insecure. |
| 246 | * |
| 247 | * <p> |
Andrii Kulian | 732a90a | 2017-08-17 17:21:20 -0700 | [diff] [blame] | 248 | * This might be used in a case when the content of a virtual display is captured and sent to an |
| 249 | * external hardware display that is not visible to the system directly. This flag will allow |
| 250 | * the continued display of content while other displays will be covered by a keyguard which |
| 251 | * doesn't require providing credentials to unlock. This means that there is either no password |
| 252 | * or other authentication method set, or the device is in a trusted state - |
| 253 | * {@link android.service.trust.TrustAgentService} has available and active trust agent. |
| 254 | * </p><p> |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 255 | * This flag can only be applied to private displays as defined by the |
| 256 | * {@link Display#FLAG_PRIVATE} display flag. It is mutually exclusive with |
| 257 | * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}. If both flags are specified then this flag's behavior |
| 258 | * will not be applied. |
| 259 | * </p> |
| 260 | * |
| 261 | * @see #createVirtualDisplay |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 262 | * @see KeyguardManager#isDeviceSecure() |
| 263 | * @see KeyguardManager#isDeviceLocked() |
Andrii Kulian | 22512e8 | 2017-04-13 11:34:43 -0700 | [diff] [blame] | 264 | * @hide |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 265 | */ |
Chilun | 8753ad3 | 2018-10-09 15:56:45 +0800 | [diff] [blame] | 266 | // TODO (b/114338689): Remove the flag and use IWindowManager#shouldShowWithInsecureKeyguard |
Andrii Kulian | 732a90a | 2017-08-17 17:21:20 -0700 | [diff] [blame] | 267 | // TODO: Update name and documentation and un-hide the flag. Don't change the value before that. |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 268 | public static final int VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 269 | |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Virtual display flag: Specifies that the virtual display can be associated with a |
| 272 | * touchpad device that matches its uniqueId. |
| 273 | * |
| 274 | * @see #createVirtualDisplay |
| 275 | * @hide |
| 276 | */ |
| 277 | public static final int VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH = 1 << 6; |
| 278 | |
Alex Sakhartchouk | 879d24f | 2017-06-20 22:01:19 -0400 | [diff] [blame] | 279 | /** |
| 280 | * Virtual display flag: Indicates that the orientation of this display device is coupled to |
| 281 | * the rotation of its associated logical display. |
| 282 | * |
| 283 | * @see #createVirtualDisplay |
| 284 | * @hide |
| 285 | */ |
| 286 | public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 1 << 7; |
| 287 | |
rongliu | 1e90fc3 | 2017-10-04 17:30:30 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Virtual display flag: Indicates that the contents will be destroyed once |
| 290 | * the display is removed. |
| 291 | * |
rongliu | 3e9f972 | 2017-10-06 11:01:02 -0700 | [diff] [blame] | 292 | * Public virtual displays without this flag will move their content to main display |
| 293 | * stack once they're removed. Private vistual displays will always destroy their |
| 294 | * content on removal even without this flag. |
| 295 | * |
rongliu | 1e90fc3 | 2017-10-04 17:30:30 -0700 | [diff] [blame] | 296 | * @see #createVirtualDisplay |
| 297 | * @hide |
| 298 | */ |
Chilun | 8753ad3 | 2018-10-09 15:56:45 +0800 | [diff] [blame] | 299 | // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY |
rongliu | 1e90fc3 | 2017-10-04 17:30:30 -0700 | [diff] [blame] | 300 | public static final int VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL = 1 << 8; |
| 301 | |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 302 | /** |
| 303 | * Virtual display flag: Indicates that the display should support system decorations. Virtual |
| 304 | * displays without this flag shouldn't show home, IME or any other system decorations. |
| 305 | * |
| 306 | * @see #createVirtualDisplay |
| 307 | * @hide |
| 308 | */ |
Chilun | 8753ad3 | 2018-10-09 15:56:45 +0800 | [diff] [blame] | 309 | // TODO (b/114338689): Remove the flag and use IWindowManager#setShouldShowSystemDecors |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 310 | public static final int VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS = 1 << 9; |
| 311 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 312 | /** @hide */ |
| 313 | public DisplayManager(Context context) { |
| 314 | mContext = context; |
| 315 | mGlobal = DisplayManagerGlobal.getInstance(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 319 | * Gets information about a logical display. |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 320 | * |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 321 | * The display metrics may be adjusted to provide compatibility |
| 322 | * for legacy applications. |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 323 | * |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 324 | * @param displayId The logical display id. |
| 325 | * @return The display object, or null if there is no valid display with the given id. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 326 | */ |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 327 | public Display getDisplay(int displayId) { |
| 328 | synchronized (mLock) { |
| 329 | return getOrCreateDisplayLocked(displayId, false /*assumeValid*/); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Gets all currently valid logical displays. |
| 335 | * |
| 336 | * @return An array containing all displays. |
| 337 | */ |
| 338 | public Display[] getDisplays() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 339 | return getDisplays(null); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Gets all currently valid logical displays of the specified category. |
| 344 | * <p> |
| 345 | * When there are multiple displays in a category the returned displays are sorted |
| 346 | * of preference. For example, if the requested category is |
| 347 | * {@link #DISPLAY_CATEGORY_PRESENTATION} and there are multiple presentation displays |
| 348 | * then the displays are sorted so that the first display in the returned array |
| 349 | * is the most preferred presentation display. The application may simply |
| 350 | * use the first display or allow the user to choose. |
| 351 | * </p> |
| 352 | * |
| 353 | * @param category The requested display category or null to return all displays. |
| 354 | * @return An array containing all displays sorted by order of preference. |
| 355 | * |
| 356 | * @see #DISPLAY_CATEGORY_PRESENTATION |
| 357 | */ |
| 358 | public Display[] getDisplays(String category) { |
| 359 | final int[] displayIds = mGlobal.getDisplayIds(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 360 | synchronized (mLock) { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 361 | try { |
| 362 | if (category == null) { |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 363 | addAllDisplaysLocked(mTempDisplays, displayIds); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 364 | } else if (category.equals(DISPLAY_CATEGORY_PRESENTATION)) { |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 365 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_WIFI); |
| 366 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_HDMI); |
| 367 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_OVERLAY); |
| 368 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_VIRTUAL); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 369 | } |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 370 | return mTempDisplays.toArray(new Display[mTempDisplays.size()]); |
| 371 | } finally { |
| 372 | mTempDisplays.clear(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 373 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 374 | } |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 377 | private void addAllDisplaysLocked(ArrayList<Display> displays, int[] displayIds) { |
| 378 | for (int i = 0; i < displayIds.length; i++) { |
| 379 | Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/); |
| 380 | if (display != null) { |
| 381 | displays.add(display); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | private void addPresentationDisplaysLocked( |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 387 | ArrayList<Display> displays, int[] displayIds, int matchType) { |
| 388 | for (int i = 0; i < displayIds.length; i++) { |
| 389 | Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/); |
| 390 | if (display != null |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 391 | && (display.getFlags() & Display.FLAG_PRESENTATION) != 0 |
| 392 | && display.getType() == matchType) { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 393 | displays.add(display); |
| 394 | } |
| 395 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 398 | private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) { |
| 399 | Display display = mDisplays.get(displayId); |
| 400 | if (display == null) { |
Bryce Lee | c406152 | 2017-05-09 10:40:23 -0700 | [diff] [blame] | 401 | // TODO: We cannot currently provide any override configurations for metrics on displays |
| 402 | // other than the display the context is associated with. |
Yohei Yukawa | 5281b6b | 2018-10-15 07:38:25 +0800 | [diff] [blame] | 403 | final Context context = mContext.getDisplayId() == displayId |
Bryce Lee | c406152 | 2017-05-09 10:40:23 -0700 | [diff] [blame] | 404 | ? mContext : mContext.getApplicationContext(); |
| 405 | |
| 406 | display = mGlobal.getCompatibleDisplay(displayId, context.getResources()); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 407 | if (display != null) { |
| 408 | mDisplays.put(displayId, display); |
| 409 | } |
| 410 | } else if (!assumeValid && !display.isValid()) { |
| 411 | display = null; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 412 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 413 | return display; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 414 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 415 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 416 | /** |
| 417 | * Registers an display listener to receive notifications about when |
| 418 | * displays are added, removed or changed. |
| 419 | * |
| 420 | * @param listener The listener to register. |
| 421 | * @param handler The handler on which the listener should be invoked, or null |
| 422 | * if the listener should be invoked on the calling thread's looper. |
| 423 | * |
| 424 | * @see #unregisterDisplayListener |
| 425 | */ |
| 426 | public void registerDisplayListener(DisplayListener listener, Handler handler) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 427 | mGlobal.registerDisplayListener(listener, handler); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /** |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 431 | * Unregisters a display listener. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 432 | * |
| 433 | * @param listener The listener to unregister. |
| 434 | * |
| 435 | * @see #registerDisplayListener |
| 436 | */ |
| 437 | public void unregisterDisplayListener(DisplayListener listener) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 438 | mGlobal.unregisterDisplayListener(listener); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /** |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 442 | * Starts scanning for available Wifi displays. |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 443 | * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast. |
Jeff Brown | af57418 | 2013-11-14 18:16:08 -0800 | [diff] [blame] | 444 | * <p> |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 445 | * Calls to this method nest and must be matched by an equal number of calls to |
| 446 | * {@link #stopWifiDisplayScan()}. |
| 447 | * </p><p> |
| 448 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
| 449 | * </p> |
| 450 | * |
| 451 | * @hide |
| 452 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 453 | @UnsupportedAppUsage |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 454 | public void startWifiDisplayScan() { |
| 455 | mGlobal.startWifiDisplayScan(); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Stops scanning for available Wifi displays. |
| 460 | * <p> |
Jeff Brown | af57418 | 2013-11-14 18:16:08 -0800 | [diff] [blame] | 461 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
| 462 | * </p> |
| 463 | * |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 464 | * @hide |
| 465 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 466 | @UnsupportedAppUsage |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 467 | public void stopWifiDisplayScan() { |
| 468 | mGlobal.stopWifiDisplayScan(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Connects to a Wifi display. |
| 473 | * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast. |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 474 | * <p> |
| 475 | * Automatically remembers the display after a successful connection, if not |
| 476 | * already remembered. |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 477 | * </p><p> |
Jeff Brown | af57418 | 2013-11-14 18:16:08 -0800 | [diff] [blame] | 478 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 479 | * </p> |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 480 | * |
| 481 | * @param deviceAddress The MAC address of the device to which we should connect. |
| 482 | * @hide |
| 483 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 484 | @UnsupportedAppUsage |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 485 | public void connectWifiDisplay(String deviceAddress) { |
| 486 | mGlobal.connectWifiDisplay(deviceAddress); |
| 487 | } |
| 488 | |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 489 | /** @hide */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 490 | @UnsupportedAppUsage |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 491 | public void pauseWifiDisplay() { |
| 492 | mGlobal.pauseWifiDisplay(); |
| 493 | } |
| 494 | |
| 495 | /** @hide */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 496 | @UnsupportedAppUsage |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 497 | public void resumeWifiDisplay() { |
| 498 | mGlobal.resumeWifiDisplay(); |
| 499 | } |
| 500 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 501 | /** |
| 502 | * Disconnects from the current Wifi display. |
| 503 | * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast. |
| 504 | * @hide |
| 505 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 506 | @UnsupportedAppUsage |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 507 | public void disconnectWifiDisplay() { |
| 508 | mGlobal.disconnectWifiDisplay(); |
| 509 | } |
| 510 | |
| 511 | /** |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 512 | * Renames a Wifi display. |
| 513 | * <p> |
| 514 | * The display must already be remembered for this call to succeed. In other words, |
| 515 | * we must already have successfully connected to the display at least once and then |
| 516 | * not forgotten it. |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 517 | * </p><p> |
| 518 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 519 | * </p> |
| 520 | * |
| 521 | * @param deviceAddress The MAC address of the device to rename. |
| 522 | * @param alias The alias name by which to remember the device, or null |
| 523 | * or empty if no alias should be used. |
| 524 | * @hide |
| 525 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 526 | @UnsupportedAppUsage |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 527 | public void renameWifiDisplay(String deviceAddress, String alias) { |
| 528 | mGlobal.renameWifiDisplay(deviceAddress, alias); |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Forgets a previously remembered Wifi display. |
| 533 | * <p> |
| 534 | * Automatically disconnects from the display if currently connected to it. |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 535 | * </p><p> |
| 536 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 537 | * </p> |
| 538 | * |
| 539 | * @param deviceAddress The MAC address of the device to forget. |
| 540 | * @hide |
| 541 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 542 | @UnsupportedAppUsage |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 543 | public void forgetWifiDisplay(String deviceAddress) { |
| 544 | mGlobal.forgetWifiDisplay(deviceAddress); |
| 545 | } |
| 546 | |
| 547 | /** |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 548 | * Gets the current Wifi display status. |
| 549 | * Watch for changes in the status by registering a broadcast receiver for |
| 550 | * {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED}. |
| 551 | * |
| 552 | * @return The current Wifi display status. |
| 553 | * @hide |
| 554 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 555 | @UnsupportedAppUsage |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 556 | public WifiDisplayStatus getWifiDisplayStatus() { |
| 557 | return mGlobal.getWifiDisplayStatus(); |
| 558 | } |
| 559 | |
| 560 | /** |
Bryan Mawhinney | 462e29d | 2018-03-22 15:52:41 +0000 | [diff] [blame] | 561 | * Set the level of color saturation to apply to the display. |
| 562 | * @param level The amount of saturation to apply, between 0 and 1 inclusive. |
| 563 | * 0 produces a grayscale image, 1 is normal. |
| 564 | * |
| 565 | * @hide |
Christine Franks | 8a08a92 | 2019-02-15 15:02:32 -0800 | [diff] [blame] | 566 | * @deprecated use {@link ColorDisplayManager#setSaturationLevel(int)} instead. The level passed |
| 567 | * as a parameter here will be rounded to the nearest hundredth. |
Bryan Mawhinney | 462e29d | 2018-03-22 15:52:41 +0000 | [diff] [blame] | 568 | */ |
| 569 | @SystemApi |
| 570 | @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_SATURATION) |
| 571 | public void setSaturationLevel(float level) { |
Christine Franks | 09c229e | 2018-12-14 10:37:40 -0800 | [diff] [blame] | 572 | if (level < 0f || level > 1f) { |
| 573 | throw new IllegalArgumentException("Saturation level must be between 0 and 1"); |
| 574 | } |
| 575 | final ColorDisplayManager cdm = mContext.getSystemService(ColorDisplayManager.class); |
| 576 | cdm.setSaturationLevel(Math.round(level * 100f)); |
Bryan Mawhinney | 462e29d | 2018-03-22 15:52:41 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /** |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 580 | * Creates a virtual display. |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 581 | * |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 582 | * @see #createVirtualDisplay(String, int, int, int, Surface, int, |
| 583 | * VirtualDisplay.Callback, Handler) |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 584 | */ |
| 585 | public VirtualDisplay createVirtualDisplay(@NonNull String name, |
| 586 | int width, int height, int densityDpi, @Nullable Surface surface, int flags) { |
| 587 | return createVirtualDisplay(name, width, height, densityDpi, surface, flags, null, null); |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Creates a virtual display. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 592 | * <p> |
| 593 | * The content of a virtual display is rendered to a {@link Surface} provided |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 594 | * by the application. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 595 | * </p><p> |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 596 | * The virtual display should be {@link VirtualDisplay#release released} |
| 597 | * when no longer needed. Because a virtual display renders to a surface |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 598 | * provided by the application, it will be released automatically when the |
| 599 | * process terminates and all remaining windows on it will be forcibly removed. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 600 | * </p><p> |
| 601 | * The behavior of the virtual display depends on the flags that are provided |
| 602 | * to this method. By default, virtual displays are created to be private, |
| 603 | * non-presentation and unsecure. Permissions may be required to use certain flags. |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 604 | * </p><p> |
| 605 | * As of {@link android.os.Build.VERSION_CODES#KITKAT_WATCH}, the surface may |
| 606 | * be attached or detached dynamically using {@link VirtualDisplay#setSurface}. |
| 607 | * Previously, the surface had to be non-null when {@link #createVirtualDisplay} |
| 608 | * was called and could not be changed for the lifetime of the display. |
| 609 | * </p><p> |
| 610 | * Detaching the surface that backs a virtual display has a similar effect to |
| 611 | * turning off the screen. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 612 | * </p> |
| 613 | * |
| 614 | * @param name The name of the virtual display, must be non-empty. |
| 615 | * @param width The width of the virtual display in pixels, must be greater than 0. |
| 616 | * @param height The height of the virtual display in pixels, must be greater than 0. |
| 617 | * @param densityDpi The density of the virtual display in dpi, must be greater than 0. |
| 618 | * @param surface The surface to which the content of the virtual display should |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 619 | * be rendered, or null if there is none initially. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 620 | * @param flags A combination of virtual display flags: |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 621 | * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION}, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 622 | * {@link #VIRTUAL_DISPLAY_FLAG_SECURE}, {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}, |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 623 | * or {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 624 | * @param callback Callback to call when the state of the {@link VirtualDisplay} changes |
Michael Wright | 5438e4e | 2014-07-25 14:05:42 -0700 | [diff] [blame] | 625 | * @param handler The handler on which the listener should be invoked, or null |
| 626 | * if the listener should be invoked on the calling thread's looper. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 627 | * @return The newly created virtual display, or null if the application could |
| 628 | * not create the virtual display. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 629 | * |
| 630 | * @throws SecurityException if the caller does not have permission to create |
| 631 | * a virtual display with the specified flags. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 632 | */ |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 633 | public VirtualDisplay createVirtualDisplay(@NonNull String name, |
| 634 | int width, int height, int densityDpi, @Nullable Surface surface, int flags, |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 635 | @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) { |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 636 | return createVirtualDisplay(null /* projection */, name, width, height, densityDpi, surface, |
| 637 | flags, callback, handler, null /* uniqueId */); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** @hide */ |
| 641 | public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection, |
| 642 | @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface, |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 643 | int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler, |
| 644 | @Nullable String uniqueId) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 645 | return mGlobal.createVirtualDisplay(mContext, projection, |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 646 | name, width, height, densityDpi, surface, flags, callback, handler, uniqueId); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /** |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 650 | * Gets the stable device display size, in pixels. |
| 651 | * |
| 652 | * This should really only be used for things like server-side filtering of available |
| 653 | * applications. Most applications don't need the level of stability guaranteed by this and |
| 654 | * should instead query either the size of the display they're currently running on or the |
| 655 | * size of the default display. |
| 656 | * @hide |
| 657 | */ |
| 658 | @SystemApi |
Dianne Hackborn | 337e01a | 2018-02-27 17:16:37 -0800 | [diff] [blame] | 659 | @TestApi |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 660 | public Point getStableDisplaySize() { |
| 661 | return mGlobal.getStableDisplaySize(); |
| 662 | } |
| 663 | |
| 664 | /** |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 665 | * Fetch {@link BrightnessChangeEvent}s. |
| 666 | * @hide until we make it a system api. |
| 667 | */ |
Kenny Guy | 0ff4489 | 2018-01-10 14:06:42 +0000 | [diff] [blame] | 668 | @SystemApi |
| 669 | @TestApi |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 670 | @RequiresPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE) |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 671 | public List<BrightnessChangeEvent> getBrightnessEvents() { |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 672 | return mGlobal.getBrightnessEvents(mContext.getOpPackageName()); |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /** |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 676 | * Fetch {@link AmbientBrightnessDayStats}s. |
| 677 | * |
| 678 | * @hide until we make it a system api |
| 679 | */ |
Peeyush Agarwal | 90eabcc | 2018-03-01 12:07:59 +0000 | [diff] [blame] | 680 | @SystemApi |
| 681 | @TestApi |
Peeyush Agarwal | cc155dd | 2018-01-10 11:51:33 +0000 | [diff] [blame] | 682 | @RequiresPermission(Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS) |
| 683 | public List<AmbientBrightnessDayStats> getAmbientBrightnessStats() { |
| 684 | return mGlobal.getAmbientBrightnessStats(); |
| 685 | } |
| 686 | |
| 687 | /** |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 688 | * Sets the global display brightness configuration. |
| 689 | * |
| 690 | * @hide |
| 691 | */ |
Kenny Guy | 0ff4489 | 2018-01-10 14:06:42 +0000 | [diff] [blame] | 692 | @SystemApi |
| 693 | @TestApi |
| 694 | @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 695 | public void setBrightnessConfiguration(BrightnessConfiguration c) { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 696 | setBrightnessConfigurationForUser(c, mContext.getUserId(), mContext.getPackageName()); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
| 700 | * Sets the global display brightness configuration for a specific user. |
| 701 | * |
| 702 | * Note this requires the INTERACT_ACROSS_USERS permission if setting the configuration for a |
| 703 | * user other than the one you're currently running as. |
| 704 | * |
| 705 | * @hide |
| 706 | */ |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 707 | public void setBrightnessConfigurationForUser(BrightnessConfiguration c, int userId, |
| 708 | String packageName) { |
| 709 | mGlobal.setBrightnessConfigurationForUser(c, userId, packageName); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /** |
Kenny Guy | 6d1009f | 2018-03-14 14:28:23 +0000 | [diff] [blame] | 713 | * Gets the global display brightness configuration or the default curve if one hasn't been set. |
| 714 | * |
| 715 | * @hide |
| 716 | */ |
| 717 | @SystemApi |
| 718 | @TestApi |
| 719 | @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) |
| 720 | public BrightnessConfiguration getBrightnessConfiguration() { |
| 721 | return getBrightnessConfigurationForUser(mContext.getUserId()); |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Gets the global display brightness configuration or the default curve if one hasn't been set |
| 726 | * for a specific user. |
| 727 | * |
| 728 | * Note this requires the INTERACT_ACROSS_USERS permission if getting the configuration for a |
| 729 | * user other than the one you're currently running as. |
| 730 | * |
| 731 | * @hide |
| 732 | */ |
| 733 | public BrightnessConfiguration getBrightnessConfigurationForUser(int userId) { |
| 734 | return mGlobal.getBrightnessConfigurationForUser(userId); |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * Gets the default global display brightness configuration or null one hasn't |
| 739 | * been configured. |
| 740 | * |
| 741 | * @hide |
| 742 | */ |
| 743 | @SystemApi |
| 744 | @TestApi |
| 745 | @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) |
| 746 | @Nullable |
| 747 | public BrightnessConfiguration getDefaultBrightnessConfiguration() { |
| 748 | return mGlobal.getDefaultBrightnessConfiguration(); |
| 749 | } |
| 750 | |
| 751 | /** |
Michael Wright | d846023 | 2018-01-16 18:04:59 +0000 | [diff] [blame] | 752 | * Temporarily sets the brightness of the display. |
| 753 | * <p> |
| 754 | * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS} permission. |
| 755 | * </p> |
| 756 | * |
| 757 | * @param brightness The brightness value from 0 to 255. |
| 758 | * |
| 759 | * @hide Requires signature permission. |
| 760 | */ |
| 761 | public void setTemporaryBrightness(int brightness) { |
| 762 | mGlobal.setTemporaryBrightness(brightness); |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * Temporarily sets the auto brightness adjustment factor. |
| 767 | * <p> |
| 768 | * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS} permission. |
| 769 | * </p> |
| 770 | * |
| 771 | * @param adjustment The adjustment factor from -1.0 to 1.0. |
| 772 | * |
| 773 | * @hide Requires signature permission. |
| 774 | */ |
| 775 | public void setTemporaryAutoBrightnessAdjustment(float adjustment) { |
| 776 | mGlobal.setTemporaryAutoBrightnessAdjustment(adjustment); |
| 777 | } |
| 778 | |
| 779 | /** |
Dan Gittik | 122df86 | 2018-03-28 16:59:22 +0100 | [diff] [blame] | 780 | * Returns the minimum brightness curve, which guarantess that any brightness curve that dips |
| 781 | * below it is rejected by the system. |
| 782 | * This prevent auto-brightness from setting the screen so dark as to prevent the user from |
| 783 | * resetting or disabling it, and maps lux to the absolute minimum nits that are still readable |
| 784 | * in that ambient brightness. |
| 785 | * |
| 786 | * @return The minimum brightness curve (as lux values and their corresponding nits values). |
| 787 | * |
| 788 | * @hide |
| 789 | */ |
| 790 | @SystemApi |
| 791 | public Pair<float[], float[]> getMinimumBrightnessCurve() { |
| 792 | return mGlobal.getMinimumBrightnessCurve(); |
| 793 | } |
| 794 | |
| 795 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 796 | * Listens for changes in available display devices. |
| 797 | */ |
| 798 | public interface DisplayListener { |
| 799 | /** |
| 800 | * Called whenever a logical display has been added to the system. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 801 | * Use {@link DisplayManager#getDisplay} to get more information about |
| 802 | * the display. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 803 | * |
| 804 | * @param displayId The id of the logical display that was added. |
| 805 | */ |
| 806 | void onDisplayAdded(int displayId); |
| 807 | |
| 808 | /** |
| 809 | * Called whenever a logical display has been removed from the system. |
| 810 | * |
| 811 | * @param displayId The id of the logical display that was removed. |
| 812 | */ |
| 813 | void onDisplayRemoved(int displayId); |
| 814 | |
| 815 | /** |
Siarhei Vishniakou | 759b88f | 2018-08-13 09:05:19 -0700 | [diff] [blame] | 816 | * Called whenever the properties of a logical {@link android.view.Display}, |
| 817 | * such as size and density, have changed. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 818 | * |
| 819 | * @param displayId The id of the logical display that changed. |
| 820 | */ |
| 821 | void onDisplayChanged(int displayId); |
| 822 | } |
Long Ling | dde62480 | 2019-08-08 16:05:19 -0700 | [diff] [blame] | 823 | |
| 824 | /** |
| 825 | * Interface for accessing keys belonging to {@link |
| 826 | * android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER}. |
| 827 | * @hide |
| 828 | */ |
| 829 | public interface DeviceConfig { |
| 830 | |
| 831 | /** |
Long Ling | 7393663 | 2019-08-20 15:01:14 -0700 | [diff] [blame] | 832 | * Key for refresh rate in the zone defined by thresholds. |
| 833 | * |
| 834 | * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER |
| 835 | * @see android.R.integer#config_defaultZoneBehavior |
| 836 | */ |
| 837 | String KEY_REFRESH_RATE_IN_ZONE = "refresh_rate_in_zone"; |
| 838 | |
| 839 | /** |
| 840 | * Key for accessing the display brightness thresholds for the configured refresh rate zone. |
| 841 | * The value will be a pair of comma separated integers representing the minimum and maximum |
| 842 | * thresholds of the zone, respectively, in display backlight units (i.e. [0, 255]). |
Long Ling | dde62480 | 2019-08-08 16:05:19 -0700 | [diff] [blame] | 843 | * |
| 844 | * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER |
| 845 | * @see android.R.array#config_brightnessThresholdsOfPeakRefreshRate |
| 846 | * @hide |
| 847 | */ |
Long Ling | 7393663 | 2019-08-20 15:01:14 -0700 | [diff] [blame] | 848 | String KEY_PEAK_REFRESH_RATE_DISPLAY_BRIGHTNESS_THRESHOLDS = |
Long Ling | dde62480 | 2019-08-08 16:05:19 -0700 | [diff] [blame] | 849 | "peak_refresh_rate_brightness_thresholds"; |
| 850 | |
| 851 | /** |
Long Ling | 7393663 | 2019-08-20 15:01:14 -0700 | [diff] [blame] | 852 | * Key for accessing the ambient brightness thresholds for the configured refresh rate zone. |
| 853 | * The value will be a pair of comma separated integers representing the minimum and maximum |
| 854 | * thresholds of the zone, respectively, in lux. |
Long Ling | dde62480 | 2019-08-08 16:05:19 -0700 | [diff] [blame] | 855 | * |
| 856 | * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER |
Long Ling | 7393663 | 2019-08-20 15:01:14 -0700 | [diff] [blame] | 857 | * @see android.R.array#config_ambientThresholdsOfPeakRefreshRate |
Long Ling | dde62480 | 2019-08-08 16:05:19 -0700 | [diff] [blame] | 858 | * @hide |
| 859 | */ |
Long Ling | 7393663 | 2019-08-20 15:01:14 -0700 | [diff] [blame] | 860 | String KEY_PEAK_REFRESH_RATE_AMBIENT_BRIGHTNESS_THRESHOLDS = |
| 861 | "peak_refresh_rate_ambient_thresholds"; |
Long Ling | dde62480 | 2019-08-08 16:05:19 -0700 | [diff] [blame] | 862 | |
| 863 | /** |
| 864 | * Key for default peak refresh rate |
| 865 | * |
| 866 | * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER |
| 867 | * @see android.R.integer#config_defaultPeakRefreshRate |
| 868 | * @hide |
| 869 | */ |
| 870 | String KEY_PEAK_REFRESH_RATE_DEFAULT = "peak_refresh_rate_default"; |
Long Ling | 1961cf1 | 2019-08-13 16:07:14 -0700 | [diff] [blame] | 871 | |
| 872 | /** |
| 873 | * Key for controlling which packages are explicitly blocked from running at refresh rates |
| 874 | * higher than 60hz. An app may be added to this list if they exhibit performance issues at |
| 875 | * higher refresh rates. |
| 876 | * |
| 877 | * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER |
| 878 | * @see android.R.array#config_highRefreshRateBlacklist |
| 879 | * @hide |
| 880 | */ |
| 881 | String KEY_HIGH_REFRESH_RATE_BLACKLIST = "high_refresh_rate_blacklist"; |
Long Ling | dde62480 | 2019-08-08 16:05:19 -0700 | [diff] [blame] | 882 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 883 | } |