blob: 36673cd66ca2fa7777942107fef4bdaa7d30722b [file] [log] [blame]
Jeff Brownfa25bf52012-07-23 19:26:30 -07001/*
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
17package android.hardware.display;
18
Kenny Guy29aa30e2017-11-30 13:43:46 +000019import android.Manifest;
Michael Wrightc39d47a2014-07-08 18:07:36 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Kenny Guy29aa30e2017-11-30 13:43:46 +000022import android.annotation.RequiresPermission;
Michael Wrighteedcbf12017-08-16 23:14:54 +010023import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060024import android.annotation.SystemService;
Kenny Guy0ff44892018-01-10 14:06:42 +000025import android.annotation.TestApi;
Adrian Roose99bc052017-11-20 17:55:31 +010026import android.app.KeyguardManager;
Jeff Brownfa25bf52012-07-23 19:26:30 -070027import android.content.Context;
Michael Wrighteedcbf12017-08-16 23:14:54 +010028import android.graphics.Point;
Michael Wrightc39d47a2014-07-08 18:07:36 -070029import android.media.projection.MediaProjection;
Jeff Brown98365d72012-08-19 20:30:52 -070030import android.os.Handler;
Michael Wrighteef0e132017-11-21 17:57:52 +000031import android.os.UserHandle;
Jeff Brownbd6e1502012-08-28 03:27:37 -070032import android.util.SparseArray;
Jeff Brown98365d72012-08-19 20:30:52 -070033import android.view.Display;
Jeff Browna506a6e2013-06-04 00:02:38 -070034import android.view.Surface;
Jeff Brown98365d72012-08-19 20:30:52 -070035
Jeff Brown92130f62012-10-24 21:28:33 -070036import java.util.ArrayList;
Kenny Guy22bd0442017-10-26 00:15:54 +010037import java.util.List;
Jeff Brown92130f62012-10-24 21:28:33 -070038
Jeff Brownfa25bf52012-07-23 19:26:30 -070039/**
Jeff Brownbd6e1502012-08-28 03:27:37 -070040 * Manages the properties of attached displays.
Jeff Brownfa25bf52012-07-23 19:26:30 -070041 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060042@SystemService(Context.DISPLAY_SERVICE)
Jeff Brownfa25bf52012-07-23 19:26:30 -070043public final class DisplayManager {
44 private static final String TAG = "DisplayManager";
Jeff Brown98365d72012-08-19 20:30:52 -070045 private static final boolean DEBUG = false;
46
Jeff Brownbd6e1502012-08-28 03:27:37 -070047 private final Context mContext;
48 private final DisplayManagerGlobal mGlobal;
Jeff Brownfa25bf52012-07-23 19:26:30 -070049
Jeff Brownbd6e1502012-08-28 03:27:37 -070050 private final Object mLock = new Object();
51 private final SparseArray<Display> mDisplays = new SparseArray<Display>();
Jeff Brownfa25bf52012-07-23 19:26:30 -070052
Jeff Brown92130f62012-10-24 21:28:33 -070053 private final ArrayList<Display> mTempDisplays = new ArrayList<Display>();
54
Jeff Browne08ae382012-09-07 20:36:36 -070055 /**
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 Brownbc335452012-09-26 18:34:47 -070061 * This broadcast is only sent to registered receivers and can only be sent by the system.
Jeff Browne08ae382012-09-07 20:36:36 -070062 * </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 Brown92130f62012-10-24 21:28:33 -070075 /**
76 * Display category: Presentation displays.
77 * <p>
78 * This category can be used to identify secondary displays that are suitable for
Jeff Brown7d00aff2013-08-02 19:03:49 -070079 * 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 Brown92130f62012-10-24 21:28:33 -070082 * </p>
83 *
Jeff Brown511cd352013-08-23 17:43:37 -070084 * @see android.app.Presentation
Jeff Brown7d00aff2013-08-02 19:03:49 -070085 * @see Display#FLAG_PRESENTATION
Jeff Brown92130f62012-10-24 21:28:33 -070086 * @see #getDisplays(String)
87 */
88 public static final String DISPLAY_CATEGORY_PRESENTATION =
89 "android.hardware.display.category.PRESENTATION";
90
Jeff Brown7d00aff2013-08-02 19:03:49 -070091 /**
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 Wright6720be42014-07-29 19:14:16 -0700103 * 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 Brown7d00aff2013-08-02 19:03:49 -0700106 * </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 Wright6720be42014-07-29 19:14:16 -0700113 *
114 * <p>
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800115 * 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 Wright6720be42014-07-29 19:14:16 -0700123 * </p>
Jeff Brown7d00aff2013-08-02 19:03:49 -0700124 *
125 * @see #createVirtualDisplay
Jeff Brownd14c8c92014-01-07 18:13:09 -0800126 * @see #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
Michael Wright6720be42014-07-29 19:14:16 -0700127 * @see #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
Jeff Brown7d00aff2013-08-02 19:03:49 -0700128 */
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 Brown511cd352013-08-23 17:43:37 -0700150 * @see android.app.Presentation
Jeff Brown7d00aff2013-08-02 19:03:49 -0700151 * @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 Brown511cd352013-08-23 17:43:37 -0700179 * @see Display#FLAG_SECURE
Jeff Brown7d00aff2013-08-02 19:03:49 -0700180 * @see #createVirtualDisplay
181 */
182 public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 1 << 2;
183
Jeff Brownd14c8c92014-01-07 18:13:09 -0800184 /**
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 Wright6720be42014-07-29 19:14:16 -0700196 * <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 Brownd14c8c92014-01-07 18:13:09 -0800207 * @see #createVirtualDisplay
208 */
209 public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 1 << 3;
210
Michael Wrightc39d47a2014-07-08 18:07:36 -0700211
212 /**
Michael Wright6720be42014-07-29 19:14:16 -0700213 * Virtual display flag: Allows content to be mirrored on private displays when no content is
214 * being shown.
Michael Wrightc39d47a2014-07-08 18:07:36 -0700215 *
Michael Wright9469cdd2014-07-29 13:03:56 -0700216 * <p>
Michael Wright6720be42014-07-29 19:14:16 -0700217 * 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 Wright9469cdd2014-07-29 13:03:56 -0700219 * </p>
Michael Wrightc39d47a2014-07-08 18:07:36 -0700220 *
Michael Wright9469cdd2014-07-29 13:03:56 -0700221 * <p>
Michael Wright6720be42014-07-29 19:14:16 -0700222 * 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 Wright9469cdd2014-07-29 13:03:56 -0700236 * </p>
Michael Wrightc39d47a2014-07-08 18:07:36 -0700237 *
238 * @see #createVirtualDisplay
239 */
Michael Wright6720be42014-07-29 19:14:16 -0700240 public static final int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 1 << 4;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700241
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800242 /**
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 Kulian732a90a2017-08-17 17:21:20 -0700247 * 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 Kulianfc8f82b2017-01-26 13:17:27 -0800254 * 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 Roose99bc052017-11-20 17:55:31 +0100261 * @see KeyguardManager#isDeviceSecure()
262 * @see KeyguardManager#isDeviceLocked()
Andrii Kulian22512e82017-04-13 11:34:43 -0700263 * @hide
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800264 */
Andrii Kulian732a90a2017-08-17 17:21:20 -0700265 // TODO: Update name and documentation and un-hide the flag. Don't change the value before that.
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800266 public static final int VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800267
Santos Cordonb0608632017-04-05 10:31:15 -0700268 /**
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 Sakhartchouk879d24f2017-06-20 22:01:19 -0400277 /**
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
rongliu1e90fc32017-10-04 17:30:30 -0700286 /**
287 * Virtual display flag: Indicates that the contents will be destroyed once
288 * the display is removed.
289 *
rongliu3e9f9722017-10-06 11:01:02 -0700290 * 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 *
rongliu1e90fc32017-10-04 17:30:30 -0700294 * @see #createVirtualDisplay
295 * @hide
296 */
297 public static final int VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL = 1 << 8;
298
Jeff Brownbd6e1502012-08-28 03:27:37 -0700299 /** @hide */
300 public DisplayManager(Context context) {
301 mContext = context;
302 mGlobal = DisplayManagerGlobal.getInstance();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700303 }
304
305 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700306 * Gets information about a logical display.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700307 *
Jeff Brownbd6e1502012-08-28 03:27:37 -0700308 * The display metrics may be adjusted to provide compatibility
309 * for legacy applications.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700310 *
Jeff Brownbd6e1502012-08-28 03:27:37 -0700311 * @param displayId The logical display id.
312 * @return The display object, or null if there is no valid display with the given id.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700313 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700314 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 Brown92130f62012-10-24 21:28:33 -0700326 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 Brownbd6e1502012-08-28 03:27:37 -0700347 synchronized (mLock) {
Jeff Brown92130f62012-10-24 21:28:33 -0700348 try {
349 if (category == null) {
Jeff Brown7d00aff2013-08-02 19:03:49 -0700350 addAllDisplaysLocked(mTempDisplays, displayIds);
Jeff Brown92130f62012-10-24 21:28:33 -0700351 } else if (category.equals(DISPLAY_CATEGORY_PRESENTATION)) {
Jeff Brown7d00aff2013-08-02 19:03:49 -0700352 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 Brown848c2dc2012-08-19 20:18:08 -0700356 }
Jeff Brown92130f62012-10-24 21:28:33 -0700357 return mTempDisplays.toArray(new Display[mTempDisplays.size()]);
358 } finally {
359 mTempDisplays.clear();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700360 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700361 }
Jeff Brown92130f62012-10-24 21:28:33 -0700362 }
363
Jeff Brown7d00aff2013-08-02 19:03:49 -0700364 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 Brown92130f62012-10-24 21:28:33 -0700374 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 Brown7d00aff2013-08-02 19:03:49 -0700378 && (display.getFlags() & Display.FLAG_PRESENTATION) != 0
379 && display.getType() == matchType) {
Jeff Brown92130f62012-10-24 21:28:33 -0700380 displays.add(display);
381 }
382 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700383 }
384
Jeff Brownbd6e1502012-08-28 03:27:37 -0700385 private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) {
386 Display display = mDisplays.get(displayId);
387 if (display == null) {
Bryce Leec4061522017-05-09 10:40:23 -0700388 // 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 Brownbd6e1502012-08-28 03:27:37 -0700394 if (display != null) {
395 mDisplays.put(displayId, display);
396 }
397 } else if (!assumeValid && !display.isValid()) {
398 display = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700399 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700400 return display;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700401 }
Jeff Brown98365d72012-08-19 20:30:52 -0700402
Jeff Brown98365d72012-08-19 20:30:52 -0700403 /**
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 Brownbd6e1502012-08-28 03:27:37 -0700414 mGlobal.registerDisplayListener(listener, handler);
Jeff Brown98365d72012-08-19 20:30:52 -0700415 }
416
417 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -0700418 * Unregisters a display listener.
Jeff Brown98365d72012-08-19 20:30:52 -0700419 *
420 * @param listener The listener to unregister.
421 *
422 * @see #registerDisplayListener
423 */
424 public void unregisterDisplayListener(DisplayListener listener) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700425 mGlobal.unregisterDisplayListener(listener);
Jeff Brown98365d72012-08-19 20:30:52 -0700426 }
427
428 /**
Jeff Brownce468a32013-11-21 16:42:03 -0800429 * Starts scanning for available Wifi displays.
Jeff Browne08ae382012-09-07 20:36:36 -0700430 * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
Jeff Brownaf574182013-11-14 18:16:08 -0800431 * <p>
Jeff Brownce468a32013-11-21 16:42:03 -0800432 * 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 Brownaf574182013-11-14 18:16:08 -0800447 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
448 * </p>
449 *
Jeff Browne08ae382012-09-07 20:36:36 -0700450 * @hide
451 */
Jeff Brownce468a32013-11-21 16:42:03 -0800452 public void stopWifiDisplayScan() {
453 mGlobal.stopWifiDisplayScan();
Jeff Browne08ae382012-09-07 20:36:36 -0700454 }
455
456 /**
457 * Connects to a Wifi display.
458 * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
Jeff Brown89d55462012-09-19 11:33:42 -0700459 * <p>
460 * Automatically remembers the display after a successful connection, if not
461 * already remembered.
Jeff Brownbc335452012-09-26 18:34:47 -0700462 * </p><p>
Jeff Brownaf574182013-11-14 18:16:08 -0800463 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
Jeff Brown89d55462012-09-19 11:33:42 -0700464 * </p>
Jeff Browne08ae382012-09-07 20:36:36 -0700465 *
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 Zhang1f3ecaa2013-05-03 15:55:36 -0700473 /** @hide */
474 public void pauseWifiDisplay() {
475 mGlobal.pauseWifiDisplay();
476 }
477
478 /** @hide */
479 public void resumeWifiDisplay() {
480 mGlobal.resumeWifiDisplay();
481 }
482
Jeff Browne08ae382012-09-07 20:36:36 -0700483 /**
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 Brown89d55462012-09-19 11:33:42 -0700493 * 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 Brownbc335452012-09-26 18:34:47 -0700498 * </p><p>
499 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
Jeff Brown89d55462012-09-19 11:33:42 -0700500 * </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 Brownbc335452012-09-26 18:34:47 -0700515 * </p><p>
516 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
Jeff Brown89d55462012-09-19 11:33:42 -0700517 * </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 Browne08ae382012-09-07 20:36:36 -0700527 * 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 Brown7d00aff2013-08-02 19:03:49 -0700539 * Creates a virtual display.
Michael Wrightc39d47a2014-07-08 18:07:36 -0700540 *
Dianne Hackborn8ad2af72015-03-17 17:00:24 -0700541 * @see #createVirtualDisplay(String, int, int, int, Surface, int,
542 * VirtualDisplay.Callback, Handler)
Michael Wrightc39d47a2014-07-08 18:07:36 -0700543 */
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 Browna506a6e2013-06-04 00:02:38 -0700551 * <p>
552 * The content of a virtual display is rendered to a {@link Surface} provided
Jeff Brown7d00aff2013-08-02 19:03:49 -0700553 * by the application.
Jeff Browna506a6e2013-06-04 00:02:38 -0700554 * </p><p>
Jeff Brown7d00aff2013-08-02 19:03:49 -0700555 * The virtual display should be {@link VirtualDisplay#release released}
556 * when no longer needed. Because a virtual display renders to a surface
Jeff Browna506a6e2013-06-04 00:02:38 -0700557 * 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 Brown7d00aff2013-08-02 19:03:49 -0700559 * </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 Brown92207df2014-04-16 13:16:07 -0700563 * </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 Browna506a6e2013-06-04 00:02:38 -0700571 * </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 Brown92207df2014-04-16 13:16:07 -0700578 * be rendered, or null if there is none initially.
Jeff Brown7d00aff2013-08-02 19:03:49 -0700579 * @param flags A combination of virtual display flags:
Jeff Brownd14c8c92014-01-07 18:13:09 -0800580 * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION},
Michael Wrightc39d47a2014-07-08 18:07:36 -0700581 * {@link #VIRTUAL_DISPLAY_FLAG_SECURE}, {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY},
Michael Wright6720be42014-07-29 19:14:16 -0700582 * or {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
Michael Wright75ee9fc2014-09-01 19:55:22 -0700583 * @param callback Callback to call when the state of the {@link VirtualDisplay} changes
Michael Wright5438e4e2014-07-25 14:05:42 -0700584 * @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 Browna506a6e2013-06-04 00:02:38 -0700586 * @return The newly created virtual display, or null if the application could
587 * not create the virtual display.
Jeff Brown7d00aff2013-08-02 19:03:49 -0700588 *
589 * @throws SecurityException if the caller does not have permission to create
590 * a virtual display with the specified flags.
Jeff Browna506a6e2013-06-04 00:02:38 -0700591 */
Michael Wrightc39d47a2014-07-08 18:07:36 -0700592 public VirtualDisplay createVirtualDisplay(@NonNull String name,
593 int width, int height, int densityDpi, @Nullable Surface surface, int flags,
Michael Wright75ee9fc2014-09-01 19:55:22 -0700594 @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) {
Santos Cordonb0608632017-04-05 10:31:15 -0700595 return createVirtualDisplay(null /* projection */, name, width, height, densityDpi, surface,
596 flags, callback, handler, null /* uniqueId */);
Michael Wrightc39d47a2014-07-08 18:07:36 -0700597 }
598
599 /** @hide */
600 public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection,
601 @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface,
Santos Cordonb0608632017-04-05 10:31:15 -0700602 int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler,
603 @Nullable String uniqueId) {
Michael Wrightc39d47a2014-07-08 18:07:36 -0700604 return mGlobal.createVirtualDisplay(mContext, projection,
Santos Cordonb0608632017-04-05 10:31:15 -0700605 name, width, height, densityDpi, surface, flags, callback, handler, uniqueId);
Jeff Browna506a6e2013-06-04 00:02:38 -0700606 }
607
608 /**
Michael Wrighteedcbf12017-08-16 23:14:54 +0100609 * 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 Guy22bd0442017-10-26 00:15:54 +0100623 * Fetch {@link BrightnessChangeEvent}s.
624 * @hide until we make it a system api.
625 */
Kenny Guy0ff44892018-01-10 14:06:42 +0000626 @SystemApi
627 @TestApi
Kenny Guy29aa30e2017-11-30 13:43:46 +0000628 @RequiresPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE)
Kenny Guy22bd0442017-10-26 00:15:54 +0100629 public List<BrightnessChangeEvent> getBrightnessEvents() {
Kenny Guy29aa30e2017-11-30 13:43:46 +0000630 return mGlobal.getBrightnessEvents(mContext.getOpPackageName());
Kenny Guy22bd0442017-10-26 00:15:54 +0100631 }
632
633 /**
Michael Wrighteef0e132017-11-21 17:57:52 +0000634 * Sets the global display brightness configuration.
635 *
636 * @hide
637 */
Kenny Guy0ff44892018-01-10 14:06:42 +0000638 @SystemApi
639 @TestApi
640 @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
Michael Wrighteef0e132017-11-21 17:57:52 +0000641 public void setBrightnessConfiguration(BrightnessConfiguration c) {
Kenny Guy05ce8092018-01-17 13:44:20 +0000642 setBrightnessConfigurationForUser(c, UserHandle.myUserId(), mContext.getPackageName());
Michael Wrighteef0e132017-11-21 17:57:52 +0000643 }
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 Guy05ce8092018-01-17 13:44:20 +0000653 public void setBrightnessConfigurationForUser(BrightnessConfiguration c, int userId,
654 String packageName) {
655 mGlobal.setBrightnessConfigurationForUser(c, userId, packageName);
Michael Wrighteef0e132017-11-21 17:57:52 +0000656 }
657
658 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700659 * 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 Brownbd6e1502012-08-28 03:27:37 -0700664 * Use {@link DisplayManager#getDisplay} to get more information about
665 * the display.
Jeff Brown98365d72012-08-19 20:30:52 -0700666 *
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 Brownfa25bf52012-07-23 19:26:30 -0700685}