Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f95354cf authored by Naomi Musgrave's avatar Naomi Musgrave Committed by Android (Google) Code Review
Browse files

Merge "[MediaProjection] Introduce resize callback."

parents d17713e3 8b3ab2e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25464,6 +25464,7 @@ package android.media.projection {
  public abstract static class MediaProjection.Callback {
    ctor public MediaProjection.Callback();
    method public void onCapturedContentResize(int, int);
    method public void onStop();
  }
+12 −0
Original line number Diff line number Diff line
@@ -169,6 +169,12 @@
      "group": "WM_ERROR",
      "at": "com\/android\/server\/wm\/WindowManagerService.java"
    },
    "-1944652783": {
      "message": "Unable to tell MediaProjectionManagerService to stop the active projection: %s",
      "level": "ERROR",
      "group": "WM_DEBUG_CONTENT_RECORDING",
      "at": "com\/android\/server\/wm\/ContentRecorder.java"
    },
    "-1941440781": {
      "message": "Creating Pending Move-to-back: %s",
      "level": "VERBOSE",
@@ -715,6 +721,12 @@
      "group": "WM_DEBUG_ADD_REMOVE",
      "at": "com\/android\/server\/wm\/WindowManagerService.java"
    },
    "-1423223548": {
      "message": "Unable to tell MediaProjectionManagerService about resizing the active projection: %s",
      "level": "ERROR",
      "group": "WM_DEBUG_CONTENT_RECORDING",
      "at": "com\/android\/server\/wm\/ContentRecorder.java"
    },
    "-1421296808": {
      "message": "Moving to RESUMED: %s (in existing)",
      "level": "VERBOSE",
+1 −0
Original line number Diff line number Diff line
@@ -19,4 +19,5 @@ package android.media.projection;
/** {@hide} */
oneway interface IMediaProjectionCallback {
    void onStop();
    void onCapturedContentResize(int width, int height);
}
+20 −0
Original line number Diff line number Diff line
@@ -27,12 +27,32 @@ import android.view.ContentRecordingSession;
interface IMediaProjectionManager {
    @UnsupportedAppUsage
    boolean hasProjectionPermission(int uid, String packageName);

    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    IMediaProjection createProjection(int uid, String packageName, int type,
            boolean permanentGrant);

    boolean isValidMediaProjection(IMediaProjection projection);

    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    MediaProjectionInfo getActiveProjectionInfo();

    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void stopActiveProjection();

    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void notifyActiveProjectionCapturedContentResized(int width, int height);

    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void addCallback(IMediaProjectionWatcherCallback callback);

    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void removeCallback(IMediaProjectionWatcherCallback callback);

    /**
+52 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ public final class MediaProjection {
    /**
     * Callbacks for the projection session.
     */
    public static abstract class Callback {
    public abstract static class Callback {
        /**
         * Called when the MediaProjection session is no longer valid.
         * <p>
@@ -243,6 +243,46 @@ public final class MediaProjection {
         * </p>
         */
        public void onStop() { }

        /**
         * Indicates the width and height of the captured region in pixels. Called immediately after
         * capture begins to provide the app with accurate sizing for the stream. Also called
         * when the region captured in this MediaProjection session is resized.
         * <p>
         * The given width and height, in pixels, corresponds to the same width and height that
         * would be returned from {@link android.view.WindowMetrics#getBounds()}
         * </p>
         * <p>
         * Without the application resizing the {@link VirtualDisplay} (returned from
         * {@code MediaProjection#createVirtualDisplay}) and output {@link Surface} (provided
         * to {@code MediaProjection#createVirtualDisplay}), the captured stream will have
         * letterboxing (black bars) around the recorded content to make up for the
         * difference in aspect ratio.
         * </p>
         * <p>
         * The application can prevent the letterboxing by overriding this method, and
         * updating the size of both the {@link VirtualDisplay} and output {@link Surface}:
         * </p>
         *
         * <pre>
         * &#x40;Override
         * public String onCapturedContentResize(int width, int height) {
         *     // VirtualDisplay instance from MediaProjection#createVirtualDisplay
         *     virtualDisplay.resize(width, height, dpi);
         *
         *     // Create a new Surface with the updated size (depending on the application's use
         *     // case, this may be through different APIs - see Surface documentation for
         *     // options).
         *     int texName; // the OpenGL texture object name
         *     SurfaceTexture surfaceTexture = new SurfaceTexture(texName);
         *     surfaceTexture.setDefaultBufferSize(width, height);
         *     Surface surface = new Surface(surfaceTexture);
         *
         *     // Ensure the VirtualDisplay has the updated Surface to send the capture to.
         *     virtualDisplay.setSurface(surface);
         * }</pre>
         */
        public void onCapturedContentResize(int width, int height) { }
    }

    private final class MediaProjectionCallback extends IMediaProjectionCallback.Stub {
@@ -252,6 +292,13 @@ public final class MediaProjection {
                cbr.onStop();
            }
        }

        @Override
        public void onCapturedContentResize(int width, int height) {
            for (CallbackRecord cbr : mCallbacks.values()) {
                cbr.onCapturedContentResize(width, height);
            }
        }
    }

    private final static class CallbackRecord {
@@ -271,5 +318,9 @@ public final class MediaProjection {
                }
            });
        }

        public void onCapturedContentResize(int width, int height) {
            mHandler.post(() -> mCallback.onCapturedContentResize(width, height));
        }
    }
}
Loading