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

Commit c39d47a8 authored by Michael Wright's avatar Michael Wright
Browse files

Add MediaProjection APIs.

The new MediaProjection infrastructure allows the system to hand out
tokens granting the ability to capture the screen's contents, audio,
etc. at a granular level. It's intended to be used both for screen
casting, via the cast APIs, as well as screen sharing via third party
applications.

The screen sharing case is implemented, but all of audio capturing
is still forthcoming.

Change-Id: I4b24669bed7083e11413c10ed8d6b025f5375316
parent 6ccb5f89
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ LOCAL_SRC_FILES += \
	core/java/android/hardware/ISerialManager.aidl \
	core/java/android/hardware/display/IDisplayManager.aidl \
	core/java/android/hardware/display/IDisplayManagerCallback.aidl \
	core/java/android/hardware/display/IVirtualDisplayCallbacks.aidl \
	core/java/android/hardware/hdmi/IHdmiControlCallback.aidl \
	core/java/android/hardware/hdmi/IHdmiControlService.aidl \
	core/java/android/hardware/hdmi/IHdmiDeviceEventListener.aidl \
@@ -325,6 +326,9 @@ LOCAL_SRC_FILES += \
	media/java/android/media/routing/IMediaRouterDelegate.aidl \
	media/java/android/media/routing/IMediaRouterRoutingCallback.aidl \
	media/java/android/media/routing/IMediaRouterStateCallback.aidl \
	media/java/android/media/projection/IMediaProjection.aidl \
	media/java/android/media/projection/IMediaProjectionCallback.aidl \
	media/java/android/media/projection/IMediaProjectionManager.aidl \
	media/java/android/media/session/IActiveSessionsListener.aidl \
	media/java/android/media/session/ISessionController.aidl \
	media/java/android/media/session/ISessionControllerCallback.aidl \
+32 −0
Original line number Diff line number Diff line
@@ -7191,6 +7191,7 @@ package android.content {
    field public static final java.lang.String LAUNCHER_APPS_SERVICE = "launcherapps";
    field public static final java.lang.String LAYOUT_INFLATER_SERVICE = "layout_inflater";
    field public static final java.lang.String LOCATION_SERVICE = "location";
    field public static final java.lang.String MEDIA_PROJECTION_SERVICE = "media_projection";
    field public static final java.lang.String MEDIA_ROUTER_SERVICE = "media_router";
    field public static final java.lang.String MEDIA_SESSION_SERVICE = "media_session";
    field public static final int MODE_APPEND = 32768; // 0x8000
@@ -13107,6 +13108,7 @@ package android.hardware.display {
  public final class DisplayManager {
    method public android.hardware.display.VirtualDisplay createVirtualDisplay(java.lang.String, int, int, int, android.view.Surface, int);
    method public android.hardware.display.VirtualDisplay createVirtualDisplay(java.lang.String, int, int, int, android.view.Surface, int, android.hardware.display.VirtualDisplay.Callbacks, android.os.Handler);
    method public android.view.Display getDisplay(int);
    method public android.view.Display[] getDisplays();
    method public android.view.Display[] getDisplays(java.lang.String);
@@ -13116,6 +13118,7 @@ package android.hardware.display {
    field public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 8; // 0x8
    field public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 2; // 0x2
    field public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1; // 0x1
    field public static final int VIRTUAL_DISPLAY_FLAG_SCREEN_SHARE = 16; // 0x10
    field public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 4; // 0x4
  }
@@ -13132,6 +13135,13 @@ package android.hardware.display {
    method public void setSurface(android.view.Surface);
  }
  public static abstract class VirtualDisplay.Callbacks {
    ctor public VirtualDisplay.Callbacks();
    method public void onDisplayPaused();
    method public void onDisplayResumed();
    method public void onDisplayStopped();
  }
}
package android.hardware.input {
@@ -16008,6 +16018,28 @@ package android.media.effect {
}
package android.media.projection {
  public final class MediaProjection {
    method public void addCallback(android.media.projection.MediaProjection.Callback, android.os.Handler);
    method public android.media.AudioRecord createAudioRecord(int, int, int, int);
    method public android.hardware.display.VirtualDisplay createVirtualDisplay(java.lang.String, int, int, int, boolean, android.view.Surface, android.hardware.display.VirtualDisplay.Callbacks, android.os.Handler);
    method public void removeCallback(android.media.projection.MediaProjection.Callback);
    method public void stop();
  }
  public static abstract class MediaProjection.Callback {
    ctor public MediaProjection.Callback();
    method public void onStop();
  }
  public final class MediaProjectionManager {
    method public android.media.projection.MediaProjection getMediaProjection(int, android.content.Intent);
    method public android.content.Intent getScreenCaptureIntent();
  }
}
package android.media.routing {
  public final class MediaRouteSelector implements android.os.Parcelable {
+14 −4
Original line number Diff line number Diff line
@@ -192,8 +192,10 @@ public class AppOpsManager {
    public static final int OP_MUTE_MICROPHONE = 44;
    /** @hide */
    public static final int OP_TOAST_WINDOW = 45;
    /** @hide Capture the device's display contents and/or audio */
    public static final int OP_PROJECT_MEDIA = 46;
    /** @hide */
    public static final int _NUM_OP = 46;
    public static final int _NUM_OP = 47;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -263,6 +265,7 @@ public class AppOpsManager {
            OP_GET_USAGE_STATS,
            OP_MUTE_MICROPHONE,
            OP_TOAST_WINDOW,
            OP_PROJECT_MEDIA,
    };

    /**
@@ -316,6 +319,7 @@ public class AppOpsManager {
            null,
            null,
            null,
            null,
    };

    /**
@@ -367,8 +371,9 @@ public class AppOpsManager {
            "MONITOR_LOCATION",
            "MONITOR_HIGH_POWER_LOCATION",
            "GET_USAGE_STATS",
            "OP_MUTE_MICROPHONE",
            "MUTE_MICROPHONE",
            "TOAST_WINDOW",
            "PROJECT_MEDIA",
    };

    /**
@@ -422,6 +427,7 @@ public class AppOpsManager {
            android.Manifest.permission.PACKAGE_USAGE_STATS,
            null, // no permission for muting/unmuting microphone
            null, // no permission for displaying toasts
            null, // no permission for projecting media
    };

    /**
@@ -476,6 +482,7 @@ public class AppOpsManager {
            null, //GET_USAGE_STATS
            UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE
            UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW
            null, //PROJECT_MEDIA
    };

    /**
@@ -529,6 +536,7 @@ public class AppOpsManager {
            false, //GET_USAGE_STATS
            false, //MUTE_MICROPHONE
            true, //TOAST_WINDOW
            false, //PROJECT_MEDIA
    };

    /**
@@ -581,6 +589,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_IGNORED, // OP_GET_USAGE_STATS
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
    };

    /**
@@ -637,6 +646,7 @@ public class AppOpsManager {
            false,
            false,
            false,
            false,
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+7 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.location.ILocationManager;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.MediaRouter;
import android.media.projection.MediaProjectionManager;
import android.media.session.MediaSessionManager;
import android.media.tv.ITvInputManager;
import android.media.tv.TvInputManager;
@@ -752,6 +753,12 @@ class ContextImpl extends Context {
                return new PersistentDataBlockManager(
                        IPersistentDataBlockService.Stub.asInterface(b));
        }});

        registerService(MEDIA_PROJECTION_SERVICE, new ServiceFetcher() {
                public Object createService(ContextImpl ctx) {
                    return new MediaProjectionManager(ctx);
                }
        });
    }

    static ContextImpl getImpl(Context context) {
+9 −0
Original line number Diff line number Diff line
@@ -2858,6 +2858,15 @@ public abstract class Context {
     */
    public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";

    /**
     * Use with {@link #getSystemService} to retrieve a {@link
     * android.media.projection.MediaProjectionManager} instance for managing
     * media projection sessions.
     * @see #getSystemService
     * @see android.media.projection.ProjectionManager
     */
    public static final String MEDIA_PROJECTION_SERVICE = "media_projection";

    /**
     * Determine whether the given permission is allowed for a particular
     * process and user ID running in the system.
Loading