diff options
| author | 2024-09-18 08:34:59 +0000 | |
|---|---|---|
| committer | 2024-09-18 08:34:59 +0000 | |
| commit | 2e533348eb87d5a45a946c0015e8aa77989a3c37 (patch) | |
| tree | 743f795bfa186b573230fe726d5118764bfe3b5b | |
| parent | 670f987aedf3cbc5cb4c0a074dcfda2ef5b321a0 (diff) | |
Update MediaProjection documentation for onStop callback
Explicitly call out that locking the screen can lead to the MediaProjection session finishing and calling onStop()
Bug: 365778818
Change-Id: I60b4677f519db830518abdad403bee2577c39a5c
Test: n/a
Flag: DOCS_ONLY
| -rw-r--r-- | media/java/android/media/projection/MediaProjection.java | 44 | ||||
| -rw-r--r-- | media/java/android/media/projection/MediaProjectionManager.java | 15 |
2 files changed, 30 insertions, 29 deletions
diff --git a/media/java/android/media/projection/MediaProjection.java b/media/java/android/media/projection/MediaProjection.java index 3cc0ad27bd9a..31f89960836b 100644 --- a/media/java/android/media/projection/MediaProjection.java +++ b/media/java/android/media/projection/MediaProjection.java @@ -90,24 +90,24 @@ public final class MediaProjection { mDisplayManager = displayManager; } - /** - * Register a listener to receive notifications about when the {@link MediaProjection} or captured - * content changes state. - * - * <p>The callback must be registered before invoking {@link #createVirtualDisplay(String, int, - * int, int, int, Surface, VirtualDisplay.Callback, Handler)} to ensure that any notifications on - * the callback are not missed. The client must implement {@link Callback#onStop()} and clean up - * any resources it is holding, e.g. the {@link VirtualDisplay} and {@link Surface}. This should - * also update any application UI indicating the MediaProjection status as MediaProjection has - * stopped. - * - * @param callback The callback to call. - * @param handler The handler on which the callback should be invoked, or null if the callback - * should be invoked on the calling thread's looper. - * @throws NullPointerException If the given callback is null. - * @see #unregisterCallback - */ - public void registerCallback(@NonNull Callback callback, @Nullable Handler handler) { + /** + * Register a listener to receive notifications about when the {@link MediaProjection} or + * captured content changes state. + * + * <p>The callback must be registered before invoking {@link #createVirtualDisplay(String, int, + * int, int, int, Surface, VirtualDisplay.Callback, Handler)} to ensure that any notifications + * on the callback are not missed. The client must implement {@link Callback#onStop()} to + * properly handle MediaProjection clean up any resources it is holding, e.g. the {@link + * VirtualDisplay} and {@link Surface}. This should also update any application UI indicating + * the MediaProjection status as MediaProjection has stopped. + * + * @param callback The callback to call. + * @param handler The handler on which the callback should be invoked, or null if the callback + * should be invoked on the calling thread's looper. + * @throws NullPointerException If the given callback is null. + * @see #unregisterCallback + */ + public void registerCallback(@NonNull Callback callback, @Nullable Handler handler) { try { final Callback c = Objects.requireNonNull(callback); if (handler == null) { @@ -313,7 +313,7 @@ public final class MediaProjection { */ public abstract static class Callback { /** - * Called when the MediaProjection session is no longer valid. + * Called when the MediaProjection session has been stopped and is no longer valid. * * <p>Once a MediaProjection has been stopped, it's up to the application to release any * resources it may be holding (e.g. releasing the {@link VirtualDisplay} and {@link @@ -321,9 +321,9 @@ public final class MediaProjection { * it should be updated to indicate that MediaProjection is no longer active. * * <p>MediaProjection stopping can be a result of the system stopping the ongoing - * MediaProjection due to various reasons, such as another MediaProjection session starting. - * MediaProjection may also stop due to the user explicitly stopping ongoing MediaProjection - * via any available system-level UI. + * MediaProjection due to various reasons, such as another MediaProjection session starting, + * a user stopping the session via UI affordances in system-level UI, or the screen being + * locked. * * <p>After this callback any call to {@link MediaProjection#createVirtualDisplay} will * fail, even if no such {@link VirtualDisplay} was ever created for this MediaProjection diff --git a/media/java/android/media/projection/MediaProjectionManager.java b/media/java/android/media/projection/MediaProjectionManager.java index 03fd2c67fe46..dc55e41fb74c 100644 --- a/media/java/android/media/projection/MediaProjectionManager.java +++ b/media/java/android/media/projection/MediaProjectionManager.java @@ -60,13 +60,14 @@ import java.util.Map; * <li>Register a {@link MediaProjection.Callback} by calling {@link * MediaProjection#registerCallback(MediaProjection.Callback, Handler)}. This is required to * receive notifications about when the {@link MediaProjection} or captured content changes - * state. When receiving an `onStop()` callback, the client must clean up any resources it is - * holding, e.g. the {@link VirtualDisplay} and {@link Surface}. The MediaProjection may - * further no longer create any new {@link VirtualDisplay}s via {@link - * MediaProjection#createVirtualDisplay(String, int, int, int, int, Surface, - * VirtualDisplay.Callback, Handler)}. Note that the `onStop()` callback can be a result of - * the system stopping MediaProjection due to various reasons or the user stopping the - * MediaProjection via UI affordances in system-level UI. + * state. When receiving an `onStop()` callback the {@link MediaProjection} session has been + * finished and the client must clean up any resources it is holding, e.g. the {@link + * VirtualDisplay} and {@link Surface}. The MediaProjection may further no longer create any + * new {@link VirtualDisplay}s via {@link MediaProjection#createVirtualDisplay(String, int, + * int, int, int, Surface, VirtualDisplay.Callback, Handler)}. Note that the `onStop()` + * callback can be a result of the system stopping MediaProjection due to various reasons. + * This includes the user stopping the MediaProjection via UI affordances in system-level UI, + * the screen being locked, or another {@link MediaProjection} session starting. * <li>Start the screen capture session for media projection by calling {@link * MediaProjection#createVirtualDisplay(String, int, int, int, int, Surface, * android.hardware.display.VirtualDisplay.Callback, Handler)}. |