blob: ef77d6e6815e771b44fbbee67478999f66e68304 [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
Michael Wrightc39d47a2014-07-08 18:07:36 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Michael Wrighteedcbf12017-08-16 23:14:54 +010021import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060022import android.annotation.SystemService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070023import android.content.Context;
Michael Wrighteedcbf12017-08-16 23:14:54 +010024import android.graphics.Point;
Michael Wrightc39d47a2014-07-08 18:07:36 -070025import android.media.projection.MediaProjection;
Jeff Brown98365d72012-08-19 20:30:52 -070026import android.os.Handler;
Jeff Brownbd6e1502012-08-28 03:27:37 -070027import android.util.SparseArray;
Jeff Brown98365d72012-08-19 20:30:52 -070028import android.view.Display;
Jeff Browna506a6e2013-06-04 00:02:38 -070029import android.view.Surface;
Andrii Kulian732a90a2017-08-17 17:21:20 -070030import android.view.WindowManagerPolicy;
Jeff Brown98365d72012-08-19 20:30:52 -070031
Jeff Brown92130f62012-10-24 21:28:33 -070032import java.util.ArrayList;
Kenny Guy22bd0442017-10-26 00:15:54 +010033import java.util.List;
Jeff Brown92130f62012-10-24 21:28:33 -070034
Jeff Brownfa25bf52012-07-23 19:26:30 -070035/**
Jeff Brownbd6e1502012-08-28 03:27:37 -070036 * Manages the properties of attached displays.
Jeff Brownfa25bf52012-07-23 19:26:30 -070037 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060038@SystemService(Context.DISPLAY_SERVICE)
Jeff Brownfa25bf52012-07-23 19:26:30 -070039public final class DisplayManager {
40 private static final String TAG = "DisplayManager";
Jeff Brown98365d72012-08-19 20:30:52 -070041 private static final boolean DEBUG = false;
42
Jeff Brownbd6e1502012-08-28 03:27:37 -070043 private final Context mContext;
44 private final DisplayManagerGlobal mGlobal;
Jeff Brownfa25bf52012-07-23 19:26:30 -070045
Jeff Brownbd6e1502012-08-28 03:27:37 -070046 private final Object mLock = new Object();
47 private final SparseArray<Display> mDisplays = new SparseArray<Display>();
Jeff Brownfa25bf52012-07-23 19:26:30 -070048
Jeff Brown92130f62012-10-24 21:28:33 -070049 private final ArrayList<Display> mTempDisplays = new ArrayList<Display>();
50
Jeff Browne08ae382012-09-07 20:36:36 -070051 /**
52 * Broadcast receiver that indicates when the Wifi display status changes.
53 * <p>
54 * The status is provided as a {@link WifiDisplayStatus} object in the
55 * {@link #EXTRA_WIFI_DISPLAY_STATUS} extra.
56 * </p><p>
Jeff Brownbc335452012-09-26 18:34:47 -070057 * This broadcast is only sent to registered receivers and can only be sent by the system.
Jeff Browne08ae382012-09-07 20:36:36 -070058 * </p>
59 * @hide
60 */
61 public static final String ACTION_WIFI_DISPLAY_STATUS_CHANGED =
62 "android.hardware.display.action.WIFI_DISPLAY_STATUS_CHANGED";
63
64 /**
65 * Contains a {@link WifiDisplayStatus} object.
66 * @hide
67 */
68 public static final String EXTRA_WIFI_DISPLAY_STATUS =
69 "android.hardware.display.extra.WIFI_DISPLAY_STATUS";
70
Jeff Brown92130f62012-10-24 21:28:33 -070071 /**
72 * Display category: Presentation displays.
73 * <p>
74 * This category can be used to identify secondary displays that are suitable for
Jeff Brown7d00aff2013-08-02 19:03:49 -070075 * use as presentation displays such as HDMI or Wireless displays. Applications
76 * may automatically project their content to presentation displays to provide
77 * richer second screen experiences.
Jeff Brown92130f62012-10-24 21:28:33 -070078 * </p>
79 *
Jeff Brown511cd352013-08-23 17:43:37 -070080 * @see android.app.Presentation
Jeff Brown7d00aff2013-08-02 19:03:49 -070081 * @see Display#FLAG_PRESENTATION
Jeff Brown92130f62012-10-24 21:28:33 -070082 * @see #getDisplays(String)
83 */
84 public static final String DISPLAY_CATEGORY_PRESENTATION =
85 "android.hardware.display.category.PRESENTATION";
86
Jeff Brown7d00aff2013-08-02 19:03:49 -070087 /**
88 * Virtual display flag: Create a public display.
89 *
90 * <h3>Public virtual displays</h3>
91 * <p>
92 * When this flag is set, the virtual display is public.
93 * </p><p>
94 * A public virtual display behaves just like most any other display that is connected
95 * to the system such as an HDMI or Wireless display. Applications can open
96 * windows on the display and the system may mirror the contents of other displays
97 * onto it.
98 * </p><p>
Michael Wright6720be42014-07-29 19:14:16 -070099 * Creating a public virtual display that isn't restricted to own-content only implicitly
100 * creates an auto-mirroring display. See {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} for
101 * restrictions on who is allowed to create an auto-mirroring display.
Jeff Brown7d00aff2013-08-02 19:03:49 -0700102 * </p>
103 *
104 * <h3>Private virtual displays</h3>
105 * <p>
106 * When this flag is not set, the virtual display is private as defined by the
107 * {@link Display#FLAG_PRIVATE} display flag.
108 * </p>
Michael Wright6720be42014-07-29 19:14:16 -0700109 *
110 * <p>
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800111 * A private virtual display belongs to the application that created it. Only the a owner of a
112 * private virtual display and the apps that are already on that display are allowed to place
113 * windows upon it. The private virtual display also does not participate in display mirroring:
114 * it will neither receive mirrored content from another display nor allow its own content to be
115 * mirrored elsewhere. More precisely, the only processes that are allowed to enumerate or
116 * interact with the private display are those that have the same UID as the application that
117 * originally created the private virtual display or as the activities that are already on that
118 * display.
Michael Wright6720be42014-07-29 19:14:16 -0700119 * </p>
Jeff Brown7d00aff2013-08-02 19:03:49 -0700120 *
121 * @see #createVirtualDisplay
Jeff Brownd14c8c92014-01-07 18:13:09 -0800122 * @see #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
Michael Wright6720be42014-07-29 19:14:16 -0700123 * @see #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
Jeff Brown7d00aff2013-08-02 19:03:49 -0700124 */
125 public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1 << 0;
126
127 /**
128 * Virtual display flag: Create a presentation display.
129 *
130 * <h3>Presentation virtual displays</h3>
131 * <p>
132 * When this flag is set, the virtual display is registered as a presentation
133 * display in the {@link #DISPLAY_CATEGORY_PRESENTATION presentation display category}.
134 * Applications may automatically project their content to presentation displays
135 * to provide richer second screen experiences.
136 * </p>
137 *
138 * <h3>Non-presentation virtual displays</h3>
139 * <p>
140 * When this flag is not set, the virtual display is not registered as a presentation
141 * display. Applications can still project their content on the display but they
142 * will typically not do so automatically. This option is appropriate for
143 * more special-purpose displays.
144 * </p>
145 *
Jeff Brown511cd352013-08-23 17:43:37 -0700146 * @see android.app.Presentation
Jeff Brown7d00aff2013-08-02 19:03:49 -0700147 * @see #createVirtualDisplay
148 * @see #DISPLAY_CATEGORY_PRESENTATION
149 * @see Display#FLAG_PRESENTATION
150 */
151 public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 1 << 1;
152
153 /**
154 * Virtual display flag: Create a secure display.
155 *
156 * <h3>Secure virtual displays</h3>
157 * <p>
158 * When this flag is set, the virtual display is considered secure as defined
159 * by the {@link Display#FLAG_SECURE} display flag. The caller promises to take
160 * reasonable measures, such as over-the-air encryption, to prevent the contents
161 * of the display from being intercepted or recorded on a persistent medium.
162 * </p><p>
163 * Creating a secure virtual display requires the
164 * {@link android.Manifest.permission#CAPTURE_SECURE_VIDEO_OUTPUT} permission.
165 * This permission is reserved for use by system components and is not available to
166 * third-party applications.
167 * </p>
168 *
169 * <h3>Non-secure virtual displays</h3>
170 * <p>
171 * When this flag is not set, the virtual display is considered unsecure.
172 * The content of secure windows will be blanked if shown on this display.
173 * </p>
174 *
Jeff Brown511cd352013-08-23 17:43:37 -0700175 * @see Display#FLAG_SECURE
Jeff Brown7d00aff2013-08-02 19:03:49 -0700176 * @see #createVirtualDisplay
177 */
178 public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 1 << 2;
179
Jeff Brownd14c8c92014-01-07 18:13:09 -0800180 /**
181 * Virtual display flag: Only show this display's own content; do not mirror
182 * the content of another display.
183 *
184 * <p>
185 * This flag is used in conjunction with {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}.
186 * Ordinarily public virtual displays will automatically mirror the content of the
187 * default display if they have no windows of their own. When this flag is
188 * specified, the virtual display will only ever show its own content and
189 * will be blanked instead if it has no windows.
190 * </p>
191 *
Michael Wright6720be42014-07-29 19:14:16 -0700192 * <p>
193 * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. If both
194 * flags are specified then the own-content only behavior will be applied.
195 * </p>
196 *
197 * <p>
198 * This behavior of this flag is implied whenever neither {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}
199 * nor {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} have been set. This flag is only required to
200 * override the default behavior when creating a public display.
201 * </p>
202 *
Jeff Brownd14c8c92014-01-07 18:13:09 -0800203 * @see #createVirtualDisplay
204 */
205 public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 1 << 3;
206
Michael Wrightc39d47a2014-07-08 18:07:36 -0700207
208 /**
Michael Wright6720be42014-07-29 19:14:16 -0700209 * Virtual display flag: Allows content to be mirrored on private displays when no content is
210 * being shown.
Michael Wrightc39d47a2014-07-08 18:07:36 -0700211 *
Michael Wright9469cdd2014-07-29 13:03:56 -0700212 * <p>
Michael Wright6720be42014-07-29 19:14:16 -0700213 * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}.
214 * If both flags are specified then the own-content only behavior will be applied.
Michael Wright9469cdd2014-07-29 13:03:56 -0700215 * </p>
Michael Wrightc39d47a2014-07-08 18:07:36 -0700216 *
Michael Wright9469cdd2014-07-29 13:03:56 -0700217 * <p>
Michael Wright6720be42014-07-29 19:14:16 -0700218 * The behavior of this flag is implied whenever {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC} is set
219 * and {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY} has not been set. This flag is only
220 * required to override the default behavior when creating a private display.
221 * </p>
222 *
223 * <p>
224 * Creating an auto-mirroing virtual display requires the
225 * {@link android.Manifest.permission#CAPTURE_VIDEO_OUTPUT}
226 * or {@link android.Manifest.permission#CAPTURE_SECURE_VIDEO_OUTPUT} permission.
227 * These permissions are reserved for use by system components and are not available to
228 * third-party applications.
229 *
230 * Alternatively, an appropriate {@link MediaProjection} may be used to create an
231 * auto-mirroring virtual display.
Michael Wright9469cdd2014-07-29 13:03:56 -0700232 * </p>
Michael Wrightc39d47a2014-07-08 18:07:36 -0700233 *
234 * @see #createVirtualDisplay
235 */
Michael Wright6720be42014-07-29 19:14:16 -0700236 public static final int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 1 << 4;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700237
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800238 /**
239 * Virtual display flag: Allows content to be displayed on private virtual displays when
240 * keyguard is shown but is insecure.
241 *
242 * <p>
Andrii Kulian732a90a2017-08-17 17:21:20 -0700243 * This might be used in a case when the content of a virtual display is captured and sent to an
244 * external hardware display that is not visible to the system directly. This flag will allow
245 * the continued display of content while other displays will be covered by a keyguard which
246 * doesn't require providing credentials to unlock. This means that there is either no password
247 * or other authentication method set, or the device is in a trusted state -
248 * {@link android.service.trust.TrustAgentService} has available and active trust agent.
249 * </p><p>
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800250 * This flag can only be applied to private displays as defined by the
251 * {@link Display#FLAG_PRIVATE} display flag. It is mutually exclusive with
252 * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}. If both flags are specified then this flag's behavior
253 * will not be applied.
254 * </p>
255 *
256 * @see #createVirtualDisplay
Andrii Kulian732a90a2017-08-17 17:21:20 -0700257 * @see WindowManagerPolicy#isKeyguardSecure(int)
258 * @see WindowManagerPolicy#isKeyguardTrustedLw()
Andrii Kulian22512e82017-04-13 11:34:43 -0700259 * @hide
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800260 */
Andrii Kulian732a90a2017-08-17 17:21:20 -0700261 // TODO: Update name and documentation and un-hide the flag. Don't change the value before that.
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800262 public static final int VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800263
Santos Cordonb0608632017-04-05 10:31:15 -0700264 /**
265 * Virtual display flag: Specifies that the virtual display can be associated with a
266 * touchpad device that matches its uniqueId.
267 *
268 * @see #createVirtualDisplay
269 * @hide
270 */
271 public static final int VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH = 1 << 6;
272
Alex Sakhartchouk879d24f2017-06-20 22:01:19 -0400273 /**
274 * Virtual display flag: Indicates that the orientation of this display device is coupled to
275 * the rotation of its associated logical display.
276 *
277 * @see #createVirtualDisplay
278 * @hide
279 */
280 public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 1 << 7;
281
rongliu1e90fc32017-10-04 17:30:30 -0700282 /**
283 * Virtual display flag: Indicates that the contents will be destroyed once
284 * the display is removed.
285 *
rongliu3e9f9722017-10-06 11:01:02 -0700286 * Public virtual displays without this flag will move their content to main display
287 * stack once they're removed. Private vistual displays will always destroy their
288 * content on removal even without this flag.
289 *
rongliu1e90fc32017-10-04 17:30:30 -0700290 * @see #createVirtualDisplay
291 * @hide
292 */
293 public static final int VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL = 1 << 8;
294
Jeff Brownbd6e1502012-08-28 03:27:37 -0700295 /** @hide */
296 public DisplayManager(Context context) {
297 mContext = context;
298 mGlobal = DisplayManagerGlobal.getInstance();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700299 }
300
301 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700302 * Gets information about a logical display.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700303 *
Jeff Brownbd6e1502012-08-28 03:27:37 -0700304 * The display metrics may be adjusted to provide compatibility
305 * for legacy applications.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700306 *
Jeff Brownbd6e1502012-08-28 03:27:37 -0700307 * @param displayId The logical display id.
308 * @return The display object, or null if there is no valid display with the given id.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700309 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700310 public Display getDisplay(int displayId) {
311 synchronized (mLock) {
312 return getOrCreateDisplayLocked(displayId, false /*assumeValid*/);
313 }
314 }
315
316 /**
317 * Gets all currently valid logical displays.
318 *
319 * @return An array containing all displays.
320 */
321 public Display[] getDisplays() {
Jeff Brown92130f62012-10-24 21:28:33 -0700322 return getDisplays(null);
323 }
324
325 /**
326 * Gets all currently valid logical displays of the specified category.
327 * <p>
328 * When there are multiple displays in a category the returned displays are sorted
329 * of preference. For example, if the requested category is
330 * {@link #DISPLAY_CATEGORY_PRESENTATION} and there are multiple presentation displays
331 * then the displays are sorted so that the first display in the returned array
332 * is the most preferred presentation display. The application may simply
333 * use the first display or allow the user to choose.
334 * </p>
335 *
336 * @param category The requested display category or null to return all displays.
337 * @return An array containing all displays sorted by order of preference.
338 *
339 * @see #DISPLAY_CATEGORY_PRESENTATION
340 */
341 public Display[] getDisplays(String category) {
342 final int[] displayIds = mGlobal.getDisplayIds();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700343 synchronized (mLock) {
Jeff Brown92130f62012-10-24 21:28:33 -0700344 try {
345 if (category == null) {
Jeff Brown7d00aff2013-08-02 19:03:49 -0700346 addAllDisplaysLocked(mTempDisplays, displayIds);
Jeff Brown92130f62012-10-24 21:28:33 -0700347 } else if (category.equals(DISPLAY_CATEGORY_PRESENTATION)) {
Jeff Brown7d00aff2013-08-02 19:03:49 -0700348 addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_WIFI);
349 addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_HDMI);
350 addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_OVERLAY);
351 addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_VIRTUAL);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700352 }
Jeff Brown92130f62012-10-24 21:28:33 -0700353 return mTempDisplays.toArray(new Display[mTempDisplays.size()]);
354 } finally {
355 mTempDisplays.clear();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700356 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700357 }
Jeff Brown92130f62012-10-24 21:28:33 -0700358 }
359
Jeff Brown7d00aff2013-08-02 19:03:49 -0700360 private void addAllDisplaysLocked(ArrayList<Display> displays, int[] displayIds) {
361 for (int i = 0; i < displayIds.length; i++) {
362 Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/);
363 if (display != null) {
364 displays.add(display);
365 }
366 }
367 }
368
369 private void addPresentationDisplaysLocked(
Jeff Brown92130f62012-10-24 21:28:33 -0700370 ArrayList<Display> displays, int[] displayIds, int matchType) {
371 for (int i = 0; i < displayIds.length; i++) {
372 Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/);
373 if (display != null
Jeff Brown7d00aff2013-08-02 19:03:49 -0700374 && (display.getFlags() & Display.FLAG_PRESENTATION) != 0
375 && display.getType() == matchType) {
Jeff Brown92130f62012-10-24 21:28:33 -0700376 displays.add(display);
377 }
378 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700379 }
380
Jeff Brownbd6e1502012-08-28 03:27:37 -0700381 private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) {
382 Display display = mDisplays.get(displayId);
383 if (display == null) {
Bryce Leec4061522017-05-09 10:40:23 -0700384 // TODO: We cannot currently provide any override configurations for metrics on displays
385 // other than the display the context is associated with.
386 final Context context = mContext.getDisplay().getDisplayId() == displayId
387 ? mContext : mContext.getApplicationContext();
388
389 display = mGlobal.getCompatibleDisplay(displayId, context.getResources());
Jeff Brownbd6e1502012-08-28 03:27:37 -0700390 if (display != null) {
391 mDisplays.put(displayId, display);
392 }
393 } else if (!assumeValid && !display.isValid()) {
394 display = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700395 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700396 return display;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700397 }
Jeff Brown98365d72012-08-19 20:30:52 -0700398
Jeff Brown98365d72012-08-19 20:30:52 -0700399 /**
400 * Registers an display listener to receive notifications about when
401 * displays are added, removed or changed.
402 *
403 * @param listener The listener to register.
404 * @param handler The handler on which the listener should be invoked, or null
405 * if the listener should be invoked on the calling thread's looper.
406 *
407 * @see #unregisterDisplayListener
408 */
409 public void registerDisplayListener(DisplayListener listener, Handler handler) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700410 mGlobal.registerDisplayListener(listener, handler);
Jeff Brown98365d72012-08-19 20:30:52 -0700411 }
412
413 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -0700414 * Unregisters a display listener.
Jeff Brown98365d72012-08-19 20:30:52 -0700415 *
416 * @param listener The listener to unregister.
417 *
418 * @see #registerDisplayListener
419 */
420 public void unregisterDisplayListener(DisplayListener listener) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700421 mGlobal.unregisterDisplayListener(listener);
Jeff Brown98365d72012-08-19 20:30:52 -0700422 }
423
424 /**
Jeff Brownce468a32013-11-21 16:42:03 -0800425 * Starts scanning for available Wifi displays.
Jeff Browne08ae382012-09-07 20:36:36 -0700426 * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
Jeff Brownaf574182013-11-14 18:16:08 -0800427 * <p>
Jeff Brownce468a32013-11-21 16:42:03 -0800428 * Calls to this method nest and must be matched by an equal number of calls to
429 * {@link #stopWifiDisplayScan()}.
430 * </p><p>
431 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
432 * </p>
433 *
434 * @hide
435 */
436 public void startWifiDisplayScan() {
437 mGlobal.startWifiDisplayScan();
438 }
439
440 /**
441 * Stops scanning for available Wifi displays.
442 * <p>
Jeff Brownaf574182013-11-14 18:16:08 -0800443 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
444 * </p>
445 *
Jeff Browne08ae382012-09-07 20:36:36 -0700446 * @hide
447 */
Jeff Brownce468a32013-11-21 16:42:03 -0800448 public void stopWifiDisplayScan() {
449 mGlobal.stopWifiDisplayScan();
Jeff Browne08ae382012-09-07 20:36:36 -0700450 }
451
452 /**
453 * Connects to a Wifi display.
454 * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
Jeff Brown89d55462012-09-19 11:33:42 -0700455 * <p>
456 * Automatically remembers the display after a successful connection, if not
457 * already remembered.
Jeff Brownbc335452012-09-26 18:34:47 -0700458 * </p><p>
Jeff Brownaf574182013-11-14 18:16:08 -0800459 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
Jeff Brown89d55462012-09-19 11:33:42 -0700460 * </p>
Jeff Browne08ae382012-09-07 20:36:36 -0700461 *
462 * @param deviceAddress The MAC address of the device to which we should connect.
463 * @hide
464 */
465 public void connectWifiDisplay(String deviceAddress) {
466 mGlobal.connectWifiDisplay(deviceAddress);
467 }
468
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700469 /** @hide */
470 public void pauseWifiDisplay() {
471 mGlobal.pauseWifiDisplay();
472 }
473
474 /** @hide */
475 public void resumeWifiDisplay() {
476 mGlobal.resumeWifiDisplay();
477 }
478
Jeff Browne08ae382012-09-07 20:36:36 -0700479 /**
480 * Disconnects from the current Wifi display.
481 * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
482 * @hide
483 */
484 public void disconnectWifiDisplay() {
485 mGlobal.disconnectWifiDisplay();
486 }
487
488 /**
Jeff Brown89d55462012-09-19 11:33:42 -0700489 * Renames a Wifi display.
490 * <p>
491 * The display must already be remembered for this call to succeed. In other words,
492 * we must already have successfully connected to the display at least once and then
493 * not forgotten it.
Jeff Brownbc335452012-09-26 18:34:47 -0700494 * </p><p>
495 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
Jeff Brown89d55462012-09-19 11:33:42 -0700496 * </p>
497 *
498 * @param deviceAddress The MAC address of the device to rename.
499 * @param alias The alias name by which to remember the device, or null
500 * or empty if no alias should be used.
501 * @hide
502 */
503 public void renameWifiDisplay(String deviceAddress, String alias) {
504 mGlobal.renameWifiDisplay(deviceAddress, alias);
505 }
506
507 /**
508 * Forgets a previously remembered Wifi display.
509 * <p>
510 * Automatically disconnects from the display if currently connected to it.
Jeff Brownbc335452012-09-26 18:34:47 -0700511 * </p><p>
512 * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
Jeff Brown89d55462012-09-19 11:33:42 -0700513 * </p>
514 *
515 * @param deviceAddress The MAC address of the device to forget.
516 * @hide
517 */
518 public void forgetWifiDisplay(String deviceAddress) {
519 mGlobal.forgetWifiDisplay(deviceAddress);
520 }
521
522 /**
Jeff Browne08ae382012-09-07 20:36:36 -0700523 * Gets the current Wifi display status.
524 * Watch for changes in the status by registering a broadcast receiver for
525 * {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED}.
526 *
527 * @return The current Wifi display status.
528 * @hide
529 */
530 public WifiDisplayStatus getWifiDisplayStatus() {
531 return mGlobal.getWifiDisplayStatus();
532 }
533
534 /**
Jeff Brown7d00aff2013-08-02 19:03:49 -0700535 * Creates a virtual display.
Michael Wrightc39d47a2014-07-08 18:07:36 -0700536 *
Dianne Hackborn8ad2af72015-03-17 17:00:24 -0700537 * @see #createVirtualDisplay(String, int, int, int, Surface, int,
538 * VirtualDisplay.Callback, Handler)
Michael Wrightc39d47a2014-07-08 18:07:36 -0700539 */
540 public VirtualDisplay createVirtualDisplay(@NonNull String name,
541 int width, int height, int densityDpi, @Nullable Surface surface, int flags) {
542 return createVirtualDisplay(name, width, height, densityDpi, surface, flags, null, null);
543 }
544
545 /**
546 * Creates a virtual display.
Jeff Browna506a6e2013-06-04 00:02:38 -0700547 * <p>
548 * The content of a virtual display is rendered to a {@link Surface} provided
Jeff Brown7d00aff2013-08-02 19:03:49 -0700549 * by the application.
Jeff Browna506a6e2013-06-04 00:02:38 -0700550 * </p><p>
Jeff Brown7d00aff2013-08-02 19:03:49 -0700551 * The virtual display should be {@link VirtualDisplay#release released}
552 * when no longer needed. Because a virtual display renders to a surface
Jeff Browna506a6e2013-06-04 00:02:38 -0700553 * provided by the application, it will be released automatically when the
554 * process terminates and all remaining windows on it will be forcibly removed.
Jeff Brown7d00aff2013-08-02 19:03:49 -0700555 * </p><p>
556 * The behavior of the virtual display depends on the flags that are provided
557 * to this method. By default, virtual displays are created to be private,
558 * non-presentation and unsecure. Permissions may be required to use certain flags.
Jeff Brown92207df2014-04-16 13:16:07 -0700559 * </p><p>
560 * As of {@link android.os.Build.VERSION_CODES#KITKAT_WATCH}, the surface may
561 * be attached or detached dynamically using {@link VirtualDisplay#setSurface}.
562 * Previously, the surface had to be non-null when {@link #createVirtualDisplay}
563 * was called and could not be changed for the lifetime of the display.
564 * </p><p>
565 * Detaching the surface that backs a virtual display has a similar effect to
566 * turning off the screen.
Jeff Browna506a6e2013-06-04 00:02:38 -0700567 * </p>
568 *
569 * @param name The name of the virtual display, must be non-empty.
570 * @param width The width of the virtual display in pixels, must be greater than 0.
571 * @param height The height of the virtual display in pixels, must be greater than 0.
572 * @param densityDpi The density of the virtual display in dpi, must be greater than 0.
573 * @param surface The surface to which the content of the virtual display should
Jeff Brown92207df2014-04-16 13:16:07 -0700574 * be rendered, or null if there is none initially.
Jeff Brown7d00aff2013-08-02 19:03:49 -0700575 * @param flags A combination of virtual display flags:
Jeff Brownd14c8c92014-01-07 18:13:09 -0800576 * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION},
Michael Wrightc39d47a2014-07-08 18:07:36 -0700577 * {@link #VIRTUAL_DISPLAY_FLAG_SECURE}, {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY},
Michael Wright6720be42014-07-29 19:14:16 -0700578 * or {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
Michael Wright75ee9fc2014-09-01 19:55:22 -0700579 * @param callback Callback to call when the state of the {@link VirtualDisplay} changes
Michael Wright5438e4e2014-07-25 14:05:42 -0700580 * @param handler The handler on which the listener should be invoked, or null
581 * if the listener should be invoked on the calling thread's looper.
Jeff Browna506a6e2013-06-04 00:02:38 -0700582 * @return The newly created virtual display, or null if the application could
583 * not create the virtual display.
Jeff Brown7d00aff2013-08-02 19:03:49 -0700584 *
585 * @throws SecurityException if the caller does not have permission to create
586 * a virtual display with the specified flags.
Jeff Browna506a6e2013-06-04 00:02:38 -0700587 */
Michael Wrightc39d47a2014-07-08 18:07:36 -0700588 public VirtualDisplay createVirtualDisplay(@NonNull String name,
589 int width, int height, int densityDpi, @Nullable Surface surface, int flags,
Michael Wright75ee9fc2014-09-01 19:55:22 -0700590 @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) {
Santos Cordonb0608632017-04-05 10:31:15 -0700591 return createVirtualDisplay(null /* projection */, name, width, height, densityDpi, surface,
592 flags, callback, handler, null /* uniqueId */);
Michael Wrightc39d47a2014-07-08 18:07:36 -0700593 }
594
595 /** @hide */
596 public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection,
597 @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface,
Santos Cordonb0608632017-04-05 10:31:15 -0700598 int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler,
599 @Nullable String uniqueId) {
Michael Wrightc39d47a2014-07-08 18:07:36 -0700600 return mGlobal.createVirtualDisplay(mContext, projection,
Santos Cordonb0608632017-04-05 10:31:15 -0700601 name, width, height, densityDpi, surface, flags, callback, handler, uniqueId);
Jeff Browna506a6e2013-06-04 00:02:38 -0700602 }
603
604 /**
Michael Wrighteedcbf12017-08-16 23:14:54 +0100605 * Gets the stable device display size, in pixels.
606 *
607 * This should really only be used for things like server-side filtering of available
608 * applications. Most applications don't need the level of stability guaranteed by this and
609 * should instead query either the size of the display they're currently running on or the
610 * size of the default display.
611 * @hide
612 */
613 @SystemApi
614 public Point getStableDisplaySize() {
615 return mGlobal.getStableDisplaySize();
616 }
617
618 /**
Kenny Guy22bd0442017-10-26 00:15:54 +0100619 * Fetch {@link BrightnessChangeEvent}s.
620 * @hide until we make it a system api.
621 */
622 public List<BrightnessChangeEvent> getBrightnessEvents() {
623 return mGlobal.getBrightnessEvents();
624 }
625
626 /**
627 * @hide STOPSHIP - remove when adaptive brightness accepts curves.
628 */
629 public void setBrightness(int brightness) {
630 mGlobal.setBrightness(brightness);
631 }
632
633 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700634 * Listens for changes in available display devices.
635 */
636 public interface DisplayListener {
637 /**
638 * Called whenever a logical display has been added to the system.
Jeff Brownbd6e1502012-08-28 03:27:37 -0700639 * Use {@link DisplayManager#getDisplay} to get more information about
640 * the display.
Jeff Brown98365d72012-08-19 20:30:52 -0700641 *
642 * @param displayId The id of the logical display that was added.
643 */
644 void onDisplayAdded(int displayId);
645
646 /**
647 * Called whenever a logical display has been removed from the system.
648 *
649 * @param displayId The id of the logical display that was removed.
650 */
651 void onDisplayRemoved(int displayId);
652
653 /**
654 * Called whenever the properties of a logical display have changed.
655 *
656 * @param displayId The id of the logical display that changed.
657 */
658 void onDisplayChanged(int displayId);
659 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700660}