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

Commit 3eb07f46 authored by Jeff Tinker's avatar Jeff Tinker Committed by Rahul Frias
Browse files

Add new MediaDrm methods

Methods for querying HDCP, security levels and
number of sessions

bug:64001680
bug:33657579

Test: cts: MediaDrmMockTest, ClearKeySystemTest
gts: GtsMediaTestCases

Change-Id: Ie616f96ab6b74410a3d7548a7f34b20cf0831d0c
parent 633792e2
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -23021,24 +23021,29 @@ package android.media {
    method public android.media.MediaDescription.Builder setTitle(java.lang.CharSequence);
  }
  public final class MediaDrm {
  public final class MediaDrm implements java.lang.AutoCloseable {
    ctor public MediaDrm(java.util.UUID) throws android.media.UnsupportedSchemeException;
    method public void close();
    method public void closeSession(byte[]);
    method protected void finalize();
    method public int getConnectedHdcpLevel();
    method public android.media.MediaDrm.CryptoSession getCryptoSession(byte[], java.lang.String, java.lang.String);
    method public android.media.MediaDrm.KeyRequest getKeyRequest(byte[], byte[], java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>) throws android.media.NotProvisionedException;
    method public int getMaxHdcpLevel();
    method public int getMaxSessionCount();
    method public int getOpenSessionCount();
    method public byte[] getPropertyByteArray(java.lang.String);
    method public java.lang.String getPropertyString(java.lang.String);
    method public android.media.MediaDrm.ProvisionRequest getProvisionRequest();
    method public byte[] getSecureStop(byte[]);
    method public java.util.List<byte[]> getSecureStops();
    method public int getSecurityLevel(byte[]);
    method public static final boolean isCryptoSchemeSupported(java.util.UUID);
    method public static final boolean isCryptoSchemeSupported(java.util.UUID, java.lang.String);
    method public byte[] openSession() throws android.media.NotProvisionedException, android.media.ResourceBusyException;
    method public byte[] provideKeyResponse(byte[], byte[]) throws android.media.DeniedByServerException, android.media.NotProvisionedException;
    method public void provideProvisionResponse(byte[]) throws android.media.DeniedByServerException;
    method public java.util.HashMap<java.lang.String, java.lang.String> queryKeyStatus(byte[]);
    method public final void release();
    method public deprecated void release();
    method public void releaseAllSecureStops();
    method public void releaseSecureStops(byte[]);
    method public void removeKeys(byte[]);
@@ -23048,11 +23053,22 @@ package android.media {
    method public void setOnKeyStatusChangeListener(android.media.MediaDrm.OnKeyStatusChangeListener, android.os.Handler);
    method public void setPropertyByteArray(java.lang.String, byte[]);
    method public void setPropertyString(java.lang.String, java.lang.String);
    method public void setSecurityLevel(byte[], int);
    field public static final deprecated int EVENT_KEY_EXPIRED = 3; // 0x3
    field public static final int EVENT_KEY_REQUIRED = 2; // 0x2
    field public static final deprecated int EVENT_PROVISION_REQUIRED = 1; // 0x1
    field public static final int EVENT_SESSION_RECLAIMED = 5; // 0x5
    field public static final int EVENT_VENDOR_DEFINED = 4; // 0x4
    field public static final int HDCP_LEVEL_UNKNOWN = 0; // 0x0
    field public static final int HDCP_NONE = 1; // 0x1
    field public static final int HDCP_NO_DIGITAL_OUTPUT = 2147483647; // 0x7fffffff
    field public static final int HDCP_V1 = 2; // 0x2
    field public static final int HDCP_V2 = 3; // 0x3
    field public static final int HDCP_V2_1 = 4; // 0x4
    field public static final int HDCP_V2_2 = 5; // 0x5
    field public static final int HW_SECURE_ALL = 5; // 0x5
    field public static final int HW_SECURE_CRYPTO = 3; // 0x3
    field public static final int HW_SECURE_DECODE = 4; // 0x4
    field public static final int KEY_TYPE_OFFLINE = 2; // 0x2
    field public static final int KEY_TYPE_RELEASE = 3; // 0x3
    field public static final int KEY_TYPE_STREAMING = 1; // 0x1
@@ -23061,6 +23077,9 @@ package android.media {
    field public static final java.lang.String PROPERTY_DEVICE_UNIQUE_ID = "deviceUniqueId";
    field public static final java.lang.String PROPERTY_VENDOR = "vendor";
    field public static final java.lang.String PROPERTY_VERSION = "version";
    field public static final int SECURITY_LEVEL_UNKNOWN = 0; // 0x0
    field public static final int SW_SECURE_CRYPTO = 1; // 0x1
    field public static final int SW_SECURE_DECODE = 2; // 0x2
  }
  public final class MediaDrm.CryptoSession {
@@ -23070,6 +23089,9 @@ package android.media {
    method public boolean verify(byte[], byte[], byte[]);
  }
  public static abstract class MediaDrm.HdcpLevel implements java.lang.annotation.Annotation {
  }
  public static final class MediaDrm.KeyRequest {
    method public byte[] getData();
    method public java.lang.String getDefaultUrl();
@@ -23110,6 +23132,9 @@ package android.media {
    method public java.lang.String getDefaultUrl();
  }
  public static abstract class MediaDrm.SecurityLevel implements java.lang.annotation.Annotation {
  }
  public class MediaDrmException extends java.lang.Exception {
    ctor public MediaDrmException(java.lang.String);
  }
+217 −13
Original line number Diff line number Diff line
@@ -16,13 +16,6 @@

package android.media;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -34,6 +27,16 @@ import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.util.Log;
import dalvik.system.CloseGuard;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;


/**
 * MediaDrm can be used to obtain keys for decrypting protected media streams, in
@@ -117,10 +120,13 @@ import android.util.Log;
 * MediaDrm objects on a thread with its own Looper running (main UI
 * thread by default has a Looper running).
 */
public final class MediaDrm {
public final class MediaDrm implements AutoCloseable {

    private static final String TAG = "MediaDrm";

    private final AtomicBoolean mClosed = new AtomicBoolean();
    private final CloseGuard mCloseGuard = CloseGuard.get();

    private static final String PERMISSION = android.Manifest.permission.ACCESS_DRM_CERTIFICATES;

    private EventHandler mEventHandler;
@@ -215,6 +221,8 @@ public final class MediaDrm {
         */
        native_setup(new WeakReference<MediaDrm>(this),
                getByteArrayFromUUID(uuid),  ActivityThread.currentOpPackageName());

        mCloseGuard.open("release");
    }

    /**
@@ -954,6 +962,168 @@ public final class MediaDrm {
     */
    public native void releaseAllSecureStops();

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({HDCP_LEVEL_UNKNOWN, HDCP_NONE, HDCP_V1, HDCP_V2,
                        HDCP_V2_1, HDCP_V2_2, HDCP_NO_DIGITAL_OUTPUT})
    public @interface HdcpLevel {}


    /**
     * The DRM plugin did not report an HDCP level, or an error
     * occurred accessing it
     */
    public static final int HDCP_LEVEL_UNKNOWN = 0;

    /**
     * HDCP is not supported on this device, content is unprotected
     */
    public static final int HDCP_NONE = 1;

    /**
     * HDCP version 1.0
     */
    public static final int HDCP_V1 = 2;

    /**
     * HDCP version 2.0 Type 1.
     */
    public static final int HDCP_V2 = 3;

    /**
     * HDCP version 2.1 Type 1.
     */
    public static final int HDCP_V2_1 = 4;

    /**
     *  HDCP version 2.2 Type 1.
     */
    public static final int HDCP_V2_2 = 5;

    /**
     * No digital output, implicitly secure
     */
    public static final int HDCP_NO_DIGITAL_OUTPUT = Integer.MAX_VALUE;

    /**
     * Return the HDCP level negotiated with downstream receivers the
     * device is connected to. If multiple HDCP-capable displays are
     * simultaneously connected to separate interfaces, this method
     * returns the lowest negotiated level of all interfaces.
     * <p>
     * This method should only be used for informational purposes, not for
     * enforcing compliance with HDCP requirements. Trusted enforcement of
     * HDCP policies must be handled by the DRM system.
     * <p>
     * @return one of {@link #HDCP_LEVEL_UNKNOWN}, {@link #HDCP_NONE},
     * {@link #HDCP_V1}, {@link #HDCP_V2}, {@link #HDCP_V2_1}, {@link #HDCP_V2_2}
     * or {@link #HDCP_NO_DIGITAL_OUTPUT}.
     */
    @HdcpLevel
    public native int getConnectedHdcpLevel();

    /**
     * Return the maximum supported HDCP level. The maximum HDCP level is a
     * constant for a given device, it does not depend on downstream receivers
     * that may be connected. If multiple HDCP-capable interfaces are present,
     * it indicates the highest of the maximum HDCP levels of all interfaces.
     * <p>
     * @return one of {@link #HDCP_LEVEL_UNKNOWN}, {@link #HDCP_NONE},
     * {@link #HDCP_V1}, {@link #HDCP_V2}, {@link #HDCP_V2_1}, {@link #HDCP_V2_2}
     * or {@link #HDCP_NO_DIGITAL_OUTPUT}.
     */
    @HdcpLevel
    public native int getMaxHdcpLevel();

    /**
     * Return the number of MediaDrm sessions that are currently opened
     * simultaneously among all MediaDrm instances for the active DRM scheme.
     * @return the number of open sessions.
     */
    public native int getOpenSessionCount();

    /**
     * Return the maximum number of MediaDrm sessions that may be opened
     * simultaneosly among all MediaDrm instances for the active DRM
     * scheme. The maximum number of sessions is not affected by any
     * sessions that may have already been opened.
     * @return maximum sessions.
     */
    public native int getMaxSessionCount();

    /**
     * Security level indicates the robustness of the device's DRM
     * implementation.
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({SECURITY_LEVEL_UNKNOWN, SW_SECURE_CRYPTO, SW_SECURE_DECODE,
                        HW_SECURE_CRYPTO, HW_SECURE_DECODE, HW_SECURE_ALL})
    public @interface SecurityLevel {}

    /**
     * The DRM plugin did not report a security level, or an error occurred
     * accessing it
     */
    public static final int SECURITY_LEVEL_UNKNOWN = 0;

    /**
     *  Software-based whitebox crypto
     */
    public static final int SW_SECURE_CRYPTO = 1;

    /**
     * Software-based whitebox crypto and an obfuscated decoder
     */
     public static final int SW_SECURE_DECODE = 2;

    /**
     * DRM key management and crypto operations are performed within a
     * hardware backed trusted execution environment
     */
    public static final int HW_SECURE_CRYPTO = 3;

    /**
     * DRM key management, crypto operations and decoding of content
     * are performed within a hardware backed trusted execution environment
     */
     public static final int HW_SECURE_DECODE = 4;

    /**
     * DRM key management, crypto operations, decoding of content and all
     * handling of the media (compressed and uncompressed) is handled within
     * a hardware backed trusted execution environment.
     */
    public static final int HW_SECURE_ALL = 5;

    /**
     * Return the current security level of a session. A session
     * has an initial security level determined by the robustness of
     * the DRM system's implementation on the device. The security
     * level may be adjusted using {@link #setSecurityLevel}.
     * @param sessionId the session to query.
     * <p>
     * @return one of {@link #SECURITY_LEVEL_UNKNOWN},
     * {@link #SW_SECURE_CRYPTO}, {@link #SW_SECURE_DECODE},
     * {@link #HW_SECURE_CRYPTO}, {@link #HW_SECURE_DECODE} or
     * {@link #HW_SECURE_ALL}.
     */
    @SecurityLevel
    public native int getSecurityLevel(@NonNull byte[] sessionId);

    /**
     * Set the security level of a session. This can be useful if specific
     * attributes of a lower security level are needed by an application,
     * such as image manipulation or compositing. Reducing the security
     * level will typically limit decryption to lower content resolutions,
     * depending on the license policy.
     * @param sessionId the session to set the security level on.
     * @param level the new security level, one of
     * {@link #SW_SECURE_CRYPTO}, {@link #SW_SECURE_DECODE},
     * {@link #HW_SECURE_CRYPTO}, {@link #HW_SECURE_DECODE} or
     * {@link #HW_SECURE_ALL}.
     */
    public native void setSecurityLevel(@NonNull byte[] sessionId,
            @SecurityLevel int level);

    /**
     * String property name: identifies the maker of the DRM plugin
     */
@@ -1311,18 +1481,52 @@ public final class MediaDrm {
    }

    @Override
    protected void finalize() {
        native_finalize();
    protected void finalize() throws Throwable {
        try {
            if (mCloseGuard != null) {
                mCloseGuard.warnIfOpen();
            }
            release();
        } finally {
            super.finalize();
        }
    }

    public native final void release();
    /**
     * Releases resources associated with the current session of
     * MediaDrm. It is considered good practice to call this method when
     * the {@link MediaDrm} object is no longer needed in your
     * application. After this method is called, {@link MediaDrm} is no
     * longer usable since it has lost all of its required resource.
     *
     * This method was added in API 28. In API versions 18 through 27, release()
     * should be called instead. There is no need to do anything for API
     * versions prior to 18.
     */
    @Override
    public void close() {
        release();
    }

    /**
     * @deprecated replaced by {@link #close()}.
     */
    @Deprecated
    public void release() {
        mCloseGuard.close();
        if (mClosed.compareAndSet(false, true)) {
            native_release();
        }
    }

    /** @hide */
    public native final void native_release();

    private static native final void native_init();

    private native final void native_setup(Object mediadrm_this, byte[] uuid,
            String appPackageName);

    private native final void native_finalize();

    static {
        System.loadLibrary("media_jni");
        native_init();
+250 −42

File changed.

Preview size limit exceeded, changes collapsed.