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; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 27 | import android.content.Context; |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 28 | import android.graphics.Point; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 29 | import android.media.projection.MediaProjection; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 30 | import android.os.Handler; |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 31 | import android.os.UserHandle; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 32 | import android.util.SparseArray; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 33 | import android.view.Display; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 34 | import android.view.Surface; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 35 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 36 | import java.util.ArrayList; |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 37 | import java.util.List; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 38 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 39 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 40 | * Manages the properties of attached displays. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 41 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 42 | @SystemService(Context.DISPLAY_SERVICE) |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 43 | public final class DisplayManager { |
| 44 | private static final String TAG = "DisplayManager"; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 45 | private static final boolean DEBUG = false; |
| 46 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 47 | private final Context mContext; |
| 48 | private final DisplayManagerGlobal mGlobal; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 49 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 50 | private final Object mLock = new Object(); |
| 51 | private final SparseArray<Display> mDisplays = new SparseArray<Display>(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 52 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 53 | private final ArrayList<Display> mTempDisplays = new ArrayList<Display>(); |
| 54 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 55 | /** |
| 56 | * Broadcast receiver that indicates when the Wifi display status changes. |
| 57 | * <p> |
| 58 | * The status is provided as a {@link WifiDisplayStatus} object in the |
| 59 | * {@link #EXTRA_WIFI_DISPLAY_STATUS} extra. |
| 60 | * </p><p> |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 61 | * 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] | 62 | * </p> |
| 63 | * @hide |
| 64 | */ |
| 65 | public static final String ACTION_WIFI_DISPLAY_STATUS_CHANGED = |
| 66 | "android.hardware.display.action.WIFI_DISPLAY_STATUS_CHANGED"; |
| 67 | |
| 68 | /** |
| 69 | * Contains a {@link WifiDisplayStatus} object. |
| 70 | * @hide |
| 71 | */ |
| 72 | public static final String EXTRA_WIFI_DISPLAY_STATUS = |
| 73 | "android.hardware.display.extra.WIFI_DISPLAY_STATUS"; |
| 74 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Display category: Presentation displays. |
| 77 | * <p> |
| 78 | * 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] | 79 | * use as presentation displays such as HDMI or Wireless displays. Applications |
| 80 | * may automatically project their content to presentation displays to provide |
| 81 | * richer second screen experiences. |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 82 | * </p> |
| 83 | * |
Jeff Brown | 511cd35 | 2013-08-23 17:43:37 -0700 | [diff] [blame] | 84 | * @see android.app.Presentation |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 85 | * @see Display#FLAG_PRESENTATION |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 86 | * @see #getDisplays(String) |
| 87 | */ |
| 88 | public static final String DISPLAY_CATEGORY_PRESENTATION = |
| 89 | "android.hardware.display.category.PRESENTATION"; |
| 90 | |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Virtual display flag: Create a public display. |
| 93 | * |
| 94 | * <h3>Public virtual displays</h3> |
| 95 | * <p> |
| 96 | * When this flag is set, the virtual display is public. |
| 97 | * </p><p> |
| 98 | * A public virtual display behaves just like most any other display that is connected |
| 99 | * to the system such as an HDMI or Wireless display. Applications can open |
| 100 | * windows on the display and the system may mirror the contents of other displays |
| 101 | * onto it. |
| 102 | * </p><p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 103 | * Creating a public virtual display that isn't restricted to own-content only implicitly |
| 104 | * creates an auto-mirroring display. See {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} for |
| 105 | * restrictions on who is allowed to create an auto-mirroring display. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 106 | * </p> |
| 107 | * |
| 108 | * <h3>Private virtual displays</h3> |
| 109 | * <p> |
| 110 | * When this flag is not set, the virtual display is private as defined by the |
| 111 | * {@link Display#FLAG_PRIVATE} display flag. |
| 112 | * </p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 113 | * |
| 114 | * <p> |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 115 | * A private virtual display belongs to the application that created it. Only the a owner of a |
| 116 | * private virtual display and the apps that are already on that display are allowed to place |
| 117 | * windows upon it. The private virtual display also does not participate in display mirroring: |
| 118 | * it will neither receive mirrored content from another display nor allow its own content to be |
| 119 | * mirrored elsewhere. More precisely, the only processes that are allowed to enumerate or |
| 120 | * interact with the private display are those that have the same UID as the application that |
| 121 | * originally created the private virtual display or as the activities that are already on that |
| 122 | * display. |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 123 | * </p> |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 124 | * |
| 125 | * @see #createVirtualDisplay |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 126 | * @see #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 127 | * @see #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 128 | */ |
| 129 | public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1 << 0; |
| 130 | |
| 131 | /** |
| 132 | * Virtual display flag: Create a presentation display. |
| 133 | * |
| 134 | * <h3>Presentation virtual displays</h3> |
| 135 | * <p> |
| 136 | * When this flag is set, the virtual display is registered as a presentation |
| 137 | * display in the {@link #DISPLAY_CATEGORY_PRESENTATION presentation display category}. |
| 138 | * Applications may automatically project their content to presentation displays |
| 139 | * to provide richer second screen experiences. |
| 140 | * </p> |
| 141 | * |
| 142 | * <h3>Non-presentation virtual displays</h3> |
| 143 | * <p> |
| 144 | * When this flag is not set, the virtual display is not registered as a presentation |
| 145 | * display. Applications can still project their content on the display but they |
| 146 | * will typically not do so automatically. This option is appropriate for |
| 147 | * more special-purpose displays. |
| 148 | * </p> |
| 149 | * |
Jeff Brown | 511cd35 | 2013-08-23 17:43:37 -0700 | [diff] [blame] | 150 | * @see android.app.Presentation |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 151 | * @see #createVirtualDisplay |
| 152 | * @see #DISPLAY_CATEGORY_PRESENTATION |
| 153 | * @see Display#FLAG_PRESENTATION |
| 154 | */ |
| 155 | public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 1 << 1; |
| 156 | |
| 157 | /** |
| 158 | * Virtual display flag: Create a secure display. |
| 159 | * |
| 160 | * <h3>Secure virtual displays</h3> |
| 161 | * <p> |
| 162 | * When this flag is set, the virtual display is considered secure as defined |
| 163 | * by the {@link Display#FLAG_SECURE} display flag. The caller promises to take |
| 164 | * reasonable measures, such as over-the-air encryption, to prevent the contents |
| 165 | * of the display from being intercepted or recorded on a persistent medium. |
| 166 | * </p><p> |
| 167 | * Creating a secure virtual display requires the |
| 168 | * {@link android.Manifest.permission#CAPTURE_SECURE_VIDEO_OUTPUT} permission. |
| 169 | * This permission is reserved for use by system components and is not available to |
| 170 | * third-party applications. |
| 171 | * </p> |
| 172 | * |
| 173 | * <h3>Non-secure virtual displays</h3> |
| 174 | * <p> |
| 175 | * When this flag is not set, the virtual display is considered unsecure. |
| 176 | * The content of secure windows will be blanked if shown on this display. |
| 177 | * </p> |
| 178 | * |
Jeff Brown | 511cd35 | 2013-08-23 17:43:37 -0700 | [diff] [blame] | 179 | * @see Display#FLAG_SECURE |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 180 | * @see #createVirtualDisplay |
| 181 | */ |
| 182 | public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 1 << 2; |
| 183 | |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 184 | /** |
| 185 | * Virtual display flag: Only show this display's own content; do not mirror |
| 186 | * the content of another display. |
| 187 | * |
| 188 | * <p> |
| 189 | * This flag is used in conjunction with {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}. |
| 190 | * Ordinarily public virtual displays will automatically mirror the content of the |
| 191 | * default display if they have no windows of their own. When this flag is |
| 192 | * specified, the virtual display will only ever show its own content and |
| 193 | * will be blanked instead if it has no windows. |
| 194 | * </p> |
| 195 | * |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 196 | * <p> |
| 197 | * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. If both |
| 198 | * flags are specified then the own-content only behavior will be applied. |
| 199 | * </p> |
| 200 | * |
| 201 | * <p> |
| 202 | * This behavior of this flag is implied whenever neither {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC} |
| 203 | * nor {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} have been set. This flag is only required to |
| 204 | * override the default behavior when creating a public display. |
| 205 | * </p> |
| 206 | * |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 207 | * @see #createVirtualDisplay |
| 208 | */ |
| 209 | public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 1 << 3; |
| 210 | |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 211 | |
| 212 | /** |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 213 | * Virtual display flag: Allows content to be mirrored on private displays when no content is |
| 214 | * being shown. |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 215 | * |
Michael Wright | 9469cdd | 2014-07-29 13:03:56 -0700 | [diff] [blame] | 216 | * <p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 217 | * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}. |
| 218 | * 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] | 219 | * </p> |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 220 | * |
Michael Wright | 9469cdd | 2014-07-29 13:03:56 -0700 | [diff] [blame] | 221 | * <p> |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 222 | * The behavior of this flag is implied whenever {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC} is set |
| 223 | * and {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY} has not been set. This flag is only |
| 224 | * required to override the default behavior when creating a private display. |
| 225 | * </p> |
| 226 | * |
| 227 | * <p> |
| 228 | * Creating an auto-mirroing virtual display requires the |
| 229 | * {@link android.Manifest.permission#CAPTURE_VIDEO_OUTPUT} |
| 230 | * or {@link android.Manifest.permission#CAPTURE_SECURE_VIDEO_OUTPUT} permission. |
| 231 | * These permissions are reserved for use by system components and are not available to |
| 232 | * third-party applications. |
| 233 | * |
| 234 | * Alternatively, an appropriate {@link MediaProjection} may be used to create an |
| 235 | * auto-mirroring virtual display. |
Michael Wright | 9469cdd | 2014-07-29 13:03:56 -0700 | [diff] [blame] | 236 | * </p> |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 237 | * |
| 238 | * @see #createVirtualDisplay |
| 239 | */ |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 240 | public static final int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 1 << 4; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 241 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 242 | /** |
| 243 | * Virtual display flag: Allows content to be displayed on private virtual displays when |
| 244 | * keyguard is shown but is insecure. |
| 245 | * |
| 246 | * <p> |
Andrii Kulian | 732a90a | 2017-08-17 17:21:20 -0700 | [diff] [blame] | 247 | * This might be used in a case when the content of a virtual display is captured and sent to an |
| 248 | * external hardware display that is not visible to the system directly. This flag will allow |
| 249 | * the continued display of content while other displays will be covered by a keyguard which |
| 250 | * doesn't require providing credentials to unlock. This means that there is either no password |
| 251 | * or other authentication method set, or the device is in a trusted state - |
| 252 | * {@link android.service.trust.TrustAgentService} has available and active trust agent. |
| 253 | * </p><p> |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 254 | * This flag can only be applied to private displays as defined by the |
| 255 | * {@link Display#FLAG_PRIVATE} display flag. It is mutually exclusive with |
| 256 | * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}. If both flags are specified then this flag's behavior |
| 257 | * will not be applied. |
| 258 | * </p> |
| 259 | * |
| 260 | * @see #createVirtualDisplay |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 261 | * @see KeyguardManager#isDeviceSecure() |
| 262 | * @see KeyguardManager#isDeviceLocked() |
Andrii Kulian | 22512e8 | 2017-04-13 11:34:43 -0700 | [diff] [blame] | 263 | * @hide |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 264 | */ |
Andrii Kulian | 732a90a | 2017-08-17 17:21:20 -0700 | [diff] [blame] | 265 | // 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] | 266 | 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] | 267 | |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 268 | /** |
| 269 | * Virtual display flag: Specifies that the virtual display can be associated with a |
| 270 | * touchpad device that matches its uniqueId. |
| 271 | * |
| 272 | * @see #createVirtualDisplay |
| 273 | * @hide |
| 274 | */ |
| 275 | public static final int VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH = 1 << 6; |
| 276 | |
Alex Sakhartchouk | 879d24f | 2017-06-20 22:01:19 -0400 | [diff] [blame] | 277 | /** |
| 278 | * Virtual display flag: Indicates that the orientation of this display device is coupled to |
| 279 | * the rotation of its associated logical display. |
| 280 | * |
| 281 | * @see #createVirtualDisplay |
| 282 | * @hide |
| 283 | */ |
| 284 | public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 1 << 7; |
| 285 | |
rongliu | 1e90fc3 | 2017-10-04 17:30:30 -0700 | [diff] [blame] | 286 | /** |
| 287 | * Virtual display flag: Indicates that the contents will be destroyed once |
| 288 | * the display is removed. |
| 289 | * |
rongliu | 3e9f972 | 2017-10-06 11:01:02 -0700 | [diff] [blame] | 290 | * Public virtual displays without this flag will move their content to main display |
| 291 | * stack once they're removed. Private vistual displays will always destroy their |
| 292 | * content on removal even without this flag. |
| 293 | * |
rongliu | 1e90fc3 | 2017-10-04 17:30:30 -0700 | [diff] [blame] | 294 | * @see #createVirtualDisplay |
| 295 | * @hide |
| 296 | */ |
| 297 | public static final int VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL = 1 << 8; |
| 298 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 299 | /** @hide */ |
| 300 | public DisplayManager(Context context) { |
| 301 | mContext = context; |
| 302 | mGlobal = DisplayManagerGlobal.getInstance(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 306 | * Gets information about a logical display. |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 307 | * |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 308 | * The display metrics may be adjusted to provide compatibility |
| 309 | * for legacy applications. |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 310 | * |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 311 | * @param displayId The logical display id. |
| 312 | * @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] | 313 | */ |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 314 | public Display getDisplay(int displayId) { |
| 315 | synchronized (mLock) { |
| 316 | return getOrCreateDisplayLocked(displayId, false /*assumeValid*/); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Gets all currently valid logical displays. |
| 322 | * |
| 323 | * @return An array containing all displays. |
| 324 | */ |
| 325 | public Display[] getDisplays() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 326 | return getDisplays(null); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Gets all currently valid logical displays of the specified category. |
| 331 | * <p> |
| 332 | * When there are multiple displays in a category the returned displays are sorted |
| 333 | * of preference. For example, if the requested category is |
| 334 | * {@link #DISPLAY_CATEGORY_PRESENTATION} and there are multiple presentation displays |
| 335 | * then the displays are sorted so that the first display in the returned array |
| 336 | * is the most preferred presentation display. The application may simply |
| 337 | * use the first display or allow the user to choose. |
| 338 | * </p> |
| 339 | * |
| 340 | * @param category The requested display category or null to return all displays. |
| 341 | * @return An array containing all displays sorted by order of preference. |
| 342 | * |
| 343 | * @see #DISPLAY_CATEGORY_PRESENTATION |
| 344 | */ |
| 345 | public Display[] getDisplays(String category) { |
| 346 | final int[] displayIds = mGlobal.getDisplayIds(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 347 | synchronized (mLock) { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 348 | try { |
| 349 | if (category == null) { |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 350 | addAllDisplaysLocked(mTempDisplays, displayIds); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 351 | } else if (category.equals(DISPLAY_CATEGORY_PRESENTATION)) { |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 352 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_WIFI); |
| 353 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_HDMI); |
| 354 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_OVERLAY); |
| 355 | addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_VIRTUAL); |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 356 | } |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 357 | return mTempDisplays.toArray(new Display[mTempDisplays.size()]); |
| 358 | } finally { |
| 359 | mTempDisplays.clear(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 360 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 361 | } |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 364 | private void addAllDisplaysLocked(ArrayList<Display> displays, int[] displayIds) { |
| 365 | for (int i = 0; i < displayIds.length; i++) { |
| 366 | Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/); |
| 367 | if (display != null) { |
| 368 | displays.add(display); |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | private void addPresentationDisplaysLocked( |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 374 | ArrayList<Display> displays, int[] displayIds, int matchType) { |
| 375 | for (int i = 0; i < displayIds.length; i++) { |
| 376 | Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/); |
| 377 | if (display != null |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 378 | && (display.getFlags() & Display.FLAG_PRESENTATION) != 0 |
| 379 | && display.getType() == matchType) { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 380 | displays.add(display); |
| 381 | } |
| 382 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 385 | private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) { |
| 386 | Display display = mDisplays.get(displayId); |
| 387 | if (display == null) { |
Bryce Lee | c406152 | 2017-05-09 10:40:23 -0700 | [diff] [blame] | 388 | // TODO: We cannot currently provide any override configurations for metrics on displays |
| 389 | // other than the display the context is associated with. |
| 390 | final Context context = mContext.getDisplay().getDisplayId() == displayId |
| 391 | ? mContext : mContext.getApplicationContext(); |
| 392 | |
| 393 | display = mGlobal.getCompatibleDisplay(displayId, context.getResources()); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 394 | if (display != null) { |
| 395 | mDisplays.put(displayId, display); |
| 396 | } |
| 397 | } else if (!assumeValid && !display.isValid()) { |
| 398 | display = null; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 399 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 400 | return display; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 401 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 402 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 403 | /** |
| 404 | * Registers an display listener to receive notifications about when |
| 405 | * displays are added, removed or changed. |
| 406 | * |
| 407 | * @param listener The listener to register. |
| 408 | * @param handler The handler on which the listener should be invoked, or null |
| 409 | * if the listener should be invoked on the calling thread's looper. |
| 410 | * |
| 411 | * @see #unregisterDisplayListener |
| 412 | */ |
| 413 | public void registerDisplayListener(DisplayListener listener, Handler handler) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 414 | mGlobal.registerDisplayListener(listener, handler); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /** |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 418 | * Unregisters a display listener. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 419 | * |
| 420 | * @param listener The listener to unregister. |
| 421 | * |
| 422 | * @see #registerDisplayListener |
| 423 | */ |
| 424 | public void unregisterDisplayListener(DisplayListener listener) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 425 | mGlobal.unregisterDisplayListener(listener); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 429 | * Starts scanning for available Wifi displays. |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 430 | * 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] | 431 | * <p> |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 432 | * Calls to this method nest and must be matched by an equal number of calls to |
| 433 | * {@link #stopWifiDisplayScan()}. |
| 434 | * </p><p> |
| 435 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
| 436 | * </p> |
| 437 | * |
| 438 | * @hide |
| 439 | */ |
| 440 | public void startWifiDisplayScan() { |
| 441 | mGlobal.startWifiDisplayScan(); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Stops scanning for available Wifi displays. |
| 446 | * <p> |
Jeff Brown | af57418 | 2013-11-14 18:16:08 -0800 | [diff] [blame] | 447 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
| 448 | * </p> |
| 449 | * |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 450 | * @hide |
| 451 | */ |
Jeff Brown | ce468a3 | 2013-11-21 16:42:03 -0800 | [diff] [blame] | 452 | public void stopWifiDisplayScan() { |
| 453 | mGlobal.stopWifiDisplayScan(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Connects to a Wifi display. |
| 458 | * 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] | 459 | * <p> |
| 460 | * Automatically remembers the display after a successful connection, if not |
| 461 | * already remembered. |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 462 | * </p><p> |
Jeff Brown | af57418 | 2013-11-14 18:16:08 -0800 | [diff] [blame] | 463 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 464 | * </p> |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 465 | * |
| 466 | * @param deviceAddress The MAC address of the device to which we should connect. |
| 467 | * @hide |
| 468 | */ |
| 469 | public void connectWifiDisplay(String deviceAddress) { |
| 470 | mGlobal.connectWifiDisplay(deviceAddress); |
| 471 | } |
| 472 | |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 473 | /** @hide */ |
| 474 | public void pauseWifiDisplay() { |
| 475 | mGlobal.pauseWifiDisplay(); |
| 476 | } |
| 477 | |
| 478 | /** @hide */ |
| 479 | public void resumeWifiDisplay() { |
| 480 | mGlobal.resumeWifiDisplay(); |
| 481 | } |
| 482 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 483 | /** |
| 484 | * Disconnects from the current Wifi display. |
| 485 | * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast. |
| 486 | * @hide |
| 487 | */ |
| 488 | public void disconnectWifiDisplay() { |
| 489 | mGlobal.disconnectWifiDisplay(); |
| 490 | } |
| 491 | |
| 492 | /** |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 493 | * Renames a Wifi display. |
| 494 | * <p> |
| 495 | * The display must already be remembered for this call to succeed. In other words, |
| 496 | * we must already have successfully connected to the display at least once and then |
| 497 | * not forgotten it. |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 498 | * </p><p> |
| 499 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 500 | * </p> |
| 501 | * |
| 502 | * @param deviceAddress The MAC address of the device to rename. |
| 503 | * @param alias The alias name by which to remember the device, or null |
| 504 | * or empty if no alias should be used. |
| 505 | * @hide |
| 506 | */ |
| 507 | public void renameWifiDisplay(String deviceAddress, String alias) { |
| 508 | mGlobal.renameWifiDisplay(deviceAddress, alias); |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Forgets a previously remembered Wifi display. |
| 513 | * <p> |
| 514 | * Automatically disconnects from the display if currently connected to it. |
Jeff Brown | bc33545 | 2012-09-26 18:34:47 -0700 | [diff] [blame] | 515 | * </p><p> |
| 516 | * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}. |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 517 | * </p> |
| 518 | * |
| 519 | * @param deviceAddress The MAC address of the device to forget. |
| 520 | * @hide |
| 521 | */ |
| 522 | public void forgetWifiDisplay(String deviceAddress) { |
| 523 | mGlobal.forgetWifiDisplay(deviceAddress); |
| 524 | } |
| 525 | |
| 526 | /** |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 527 | * Gets the current Wifi display status. |
| 528 | * Watch for changes in the status by registering a broadcast receiver for |
| 529 | * {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED}. |
| 530 | * |
| 531 | * @return The current Wifi display status. |
| 532 | * @hide |
| 533 | */ |
| 534 | public WifiDisplayStatus getWifiDisplayStatus() { |
| 535 | return mGlobal.getWifiDisplayStatus(); |
| 536 | } |
| 537 | |
| 538 | /** |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 539 | * Creates a virtual display. |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 540 | * |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 541 | * @see #createVirtualDisplay(String, int, int, int, Surface, int, |
| 542 | * VirtualDisplay.Callback, Handler) |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 543 | */ |
| 544 | public VirtualDisplay createVirtualDisplay(@NonNull String name, |
| 545 | int width, int height, int densityDpi, @Nullable Surface surface, int flags) { |
| 546 | return createVirtualDisplay(name, width, height, densityDpi, surface, flags, null, null); |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Creates a virtual display. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 551 | * <p> |
| 552 | * 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] | 553 | * by the application. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 554 | * </p><p> |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 555 | * The virtual display should be {@link VirtualDisplay#release released} |
| 556 | * when no longer needed. Because a virtual display renders to a surface |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 557 | * provided by the application, it will be released automatically when the |
| 558 | * process terminates and all remaining windows on it will be forcibly removed. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 559 | * </p><p> |
| 560 | * The behavior of the virtual display depends on the flags that are provided |
| 561 | * to this method. By default, virtual displays are created to be private, |
| 562 | * non-presentation and unsecure. Permissions may be required to use certain flags. |
Jeff Brown | 92207df | 2014-04-16 13:16:07 -0700 | [diff] [blame] | 563 | * </p><p> |
| 564 | * As of {@link android.os.Build.VERSION_CODES#KITKAT_WATCH}, the surface may |
| 565 | * be attached or detached dynamically using {@link VirtualDisplay#setSurface}. |
| 566 | * Previously, the surface had to be non-null when {@link #createVirtualDisplay} |
| 567 | * was called and could not be changed for the lifetime of the display. |
| 568 | * </p><p> |
| 569 | * Detaching the surface that backs a virtual display has a similar effect to |
| 570 | * turning off the screen. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 571 | * </p> |
| 572 | * |
| 573 | * @param name The name of the virtual display, must be non-empty. |
| 574 | * @param width The width of the virtual display in pixels, must be greater than 0. |
| 575 | * @param height The height of the virtual display in pixels, must be greater than 0. |
| 576 | * @param densityDpi The density of the virtual display in dpi, must be greater than 0. |
| 577 | * @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] | 578 | * be rendered, or null if there is none initially. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 579 | * @param flags A combination of virtual display flags: |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 580 | * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION}, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 581 | * {@link #VIRTUAL_DISPLAY_FLAG_SECURE}, {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}, |
Michael Wright | 6720be4 | 2014-07-29 19:14:16 -0700 | [diff] [blame] | 582 | * or {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 583 | * @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] | 584 | * @param handler The handler on which the listener should be invoked, or null |
| 585 | * if the listener should be invoked on the calling thread's looper. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 586 | * @return The newly created virtual display, or null if the application could |
| 587 | * not create the virtual display. |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 588 | * |
| 589 | * @throws SecurityException if the caller does not have permission to create |
| 590 | * a virtual display with the specified flags. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 591 | */ |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 592 | public VirtualDisplay createVirtualDisplay(@NonNull String name, |
| 593 | int width, int height, int densityDpi, @Nullable Surface surface, int flags, |
Michael Wright | 75ee9fc | 2014-09-01 19:55:22 -0700 | [diff] [blame] | 594 | @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) { |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 595 | return createVirtualDisplay(null /* projection */, name, width, height, densityDpi, surface, |
| 596 | flags, callback, handler, null /* uniqueId */); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /** @hide */ |
| 600 | public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection, |
| 601 | @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface, |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 602 | int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler, |
| 603 | @Nullable String uniqueId) { |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 604 | return mGlobal.createVirtualDisplay(mContext, projection, |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 605 | name, width, height, densityDpi, surface, flags, callback, handler, uniqueId); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /** |
Michael Wright | eedcbf1 | 2017-08-16 23:14:54 +0100 | [diff] [blame] | 609 | * Gets the stable device display size, in pixels. |
| 610 | * |
| 611 | * This should really only be used for things like server-side filtering of available |
| 612 | * applications. Most applications don't need the level of stability guaranteed by this and |
| 613 | * should instead query either the size of the display they're currently running on or the |
| 614 | * size of the default display. |
| 615 | * @hide |
| 616 | */ |
| 617 | @SystemApi |
| 618 | public Point getStableDisplaySize() { |
| 619 | return mGlobal.getStableDisplaySize(); |
| 620 | } |
| 621 | |
| 622 | /** |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 623 | * Fetch {@link BrightnessChangeEvent}s. |
| 624 | * @hide until we make it a system api. |
| 625 | */ |
Kenny Guy | 0ff4489 | 2018-01-10 14:06:42 +0000 | [diff] [blame] | 626 | @SystemApi |
| 627 | @TestApi |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 628 | @RequiresPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE) |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 629 | public List<BrightnessChangeEvent> getBrightnessEvents() { |
Kenny Guy | 29aa30e | 2017-11-30 13:43:46 +0000 | [diff] [blame] | 630 | return mGlobal.getBrightnessEvents(mContext.getOpPackageName()); |
Kenny Guy | 22bd044 | 2017-10-26 00:15:54 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /** |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 634 | * Sets the global display brightness configuration. |
| 635 | * |
| 636 | * @hide |
| 637 | */ |
Kenny Guy | 0ff4489 | 2018-01-10 14:06:42 +0000 | [diff] [blame] | 638 | @SystemApi |
| 639 | @TestApi |
| 640 | @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 641 | public void setBrightnessConfiguration(BrightnessConfiguration c) { |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 642 | setBrightnessConfigurationForUser(c, UserHandle.myUserId(), mContext.getPackageName()); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Sets the global display brightness configuration for a specific user. |
| 647 | * |
| 648 | * Note this requires the INTERACT_ACROSS_USERS permission if setting the configuration for a |
| 649 | * user other than the one you're currently running as. |
| 650 | * |
| 651 | * @hide |
| 652 | */ |
Kenny Guy | 05ce809 | 2018-01-17 13:44:20 +0000 | [diff] [blame] | 653 | public void setBrightnessConfigurationForUser(BrightnessConfiguration c, int userId, |
| 654 | String packageName) { |
| 655 | mGlobal.setBrightnessConfigurationForUser(c, userId, packageName); |
Michael Wright | eef0e13 | 2017-11-21 17:57:52 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 659 | * Listens for changes in available display devices. |
| 660 | */ |
| 661 | public interface DisplayListener { |
| 662 | /** |
| 663 | * Called whenever a logical display has been added to the system. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 664 | * Use {@link DisplayManager#getDisplay} to get more information about |
| 665 | * the display. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 666 | * |
| 667 | * @param displayId The id of the logical display that was added. |
| 668 | */ |
| 669 | void onDisplayAdded(int displayId); |
| 670 | |
| 671 | /** |
| 672 | * Called whenever a logical display has been removed from the system. |
| 673 | * |
| 674 | * @param displayId The id of the logical display that was removed. |
| 675 | */ |
| 676 | void onDisplayRemoved(int displayId); |
| 677 | |
| 678 | /** |
| 679 | * Called whenever the properties of a logical display have changed. |
| 680 | * |
| 681 | * @param displayId The id of the logical display that changed. |
| 682 | */ |
| 683 | void onDisplayChanged(int displayId); |
| 684 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 685 | } |