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

Commit d571a7ce authored by Jeff Tinker's avatar Jeff Tinker
Browse files

Add securityLevel to MediaDrm isCryptoSchemeSupported API

bug:110701831
test: cts media test cases

Change-Id: Ic85afd3f617b1c8dbe8987b2e23d06787334b1d7
parent cc249beb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24638,6 +24638,7 @@ package android.media {
    method @android.media.MediaDrm.SecurityLevel public int getSecurityLevel(@NonNull byte[]);
    method public static boolean isCryptoSchemeSupported(@NonNull java.util.UUID);
    method public static boolean isCryptoSchemeSupported(@NonNull java.util.UUID, @NonNull String);
    method public static boolean isCryptoSchemeSupported(@NonNull java.util.UUID, @NonNull String, @android.media.MediaDrm.SecurityLevel int);
    method @NonNull public byte[] openSession() throws android.media.NotProvisionedException, android.media.ResourceBusyException;
    method @NonNull public byte[] openSession(@android.media.MediaDrm.SecurityLevel int) throws android.media.NotProvisionedException, android.media.ResourceBusyException;
    method @Nullable public byte[] provideKeyResponse(@NonNull byte[], @NonNull byte[]) throws android.media.DeniedByServerException, android.media.NotProvisionedException;
+22 −3
Original line number Diff line number Diff line
@@ -176,7 +176,8 @@ public final class MediaDrm implements AutoCloseable {
     * @param uuid The UUID of the crypto scheme.
     */
    public static final boolean isCryptoSchemeSupported(@NonNull UUID uuid) {
        return isCryptoSchemeSupportedNative(getByteArrayFromUUID(uuid), null);
        return isCryptoSchemeSupportedNative(getByteArrayFromUUID(uuid), null,
                SECURITY_LEVEL_UNKNOWN);
    }

    /**
@@ -189,7 +190,25 @@ public final class MediaDrm implements AutoCloseable {
     */
    public static final boolean isCryptoSchemeSupported(
            @NonNull UUID uuid, @NonNull String mimeType) {
        return isCryptoSchemeSupportedNative(getByteArrayFromUUID(uuid), mimeType);
        return isCryptoSchemeSupportedNative(getByteArrayFromUUID(uuid),
                mimeType, SECURITY_LEVEL_UNKNOWN);
    }

    /**
     * Query if the given scheme identified by its UUID is supported on
     * this device, and whether the DRM plugin is able to handle the
     * media container format specified by mimeType at the requested
     * security level.
     *
     * @param uuid The UUID of the crypto scheme.
     * @param mimeType The MIME type of the media container, e.g. "video/mp4"
     *   or "video/webm"
     * @param securityLevel the security level requested
     */
    public static final boolean isCryptoSchemeSupported(
            @NonNull UUID uuid, @NonNull String mimeType, @SecurityLevel int securityLevel) {
        return isCryptoSchemeSupportedNative(getByteArrayFromUUID(uuid), mimeType,
                securityLevel);
    }

    private static final byte[] getByteArrayFromUUID(@NonNull UUID uuid) {
@@ -206,7 +225,7 @@ public final class MediaDrm implements AutoCloseable {
    }

    private static final native boolean isCryptoSchemeSupportedNative(
            @NonNull byte[] uuid, @Nullable String mimeType);
            @NonNull byte[] uuid, @Nullable String mimeType, @SecurityLevel int securityLevel);

    private EventHandler createHandler() {
        Looper looper;
+31 −20
Original line number Diff line number Diff line
@@ -542,14 +542,15 @@ void JDrm::disconnect() {


// static
bool JDrm::IsCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) {
bool JDrm::IsCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType,
                                   DrmPlugin::SecurityLevel securityLevel) {
    sp<IDrm> drm = MakeDrm();

    if (drm == NULL) {
        return false;
    }

    return drm->isCryptoSchemeSupported(uuid, mimeType);
    return drm->isCryptoSchemeSupported(uuid, mimeType, securityLevel);
}

status_t JDrm::initCheck() const {
@@ -930,8 +931,30 @@ static void android_media_MediaDrm_native_setup(
    setDrm(env, thiz, drm);
}

DrmPlugin::SecurityLevel jintToSecurityLevel(jint jlevel) {
    DrmPlugin::SecurityLevel level;

    if (jlevel == gSecurityLevels.kSecurityLevelMax) {
        level = DrmPlugin::kSecurityLevelMax;
    }  else if (jlevel == gSecurityLevels.kSecurityLevelSwSecureCrypto) {
        level = DrmPlugin::kSecurityLevelSwSecureCrypto;
    } else if (jlevel == gSecurityLevels.kSecurityLevelSwSecureDecode) {
        level = DrmPlugin::kSecurityLevelSwSecureDecode;
    } else if (jlevel == gSecurityLevels.kSecurityLevelHwSecureCrypto) {
        level = DrmPlugin::kSecurityLevelHwSecureCrypto;
    } else if (jlevel == gSecurityLevels.kSecurityLevelHwSecureDecode) {
        level = DrmPlugin::kSecurityLevelHwSecureDecode;
    } else if (jlevel == gSecurityLevels.kSecurityLevelHwSecureAll) {
        level = DrmPlugin::kSecurityLevelHwSecureAll;
    } else {
        level = DrmPlugin::kSecurityLevelUnknown;
    }
    return level;
}

static jboolean android_media_MediaDrm_isCryptoSchemeSupportedNative(
    JNIEnv *env, jobject /* thiz */, jbyteArray uuidObj, jstring jmimeType) {
        JNIEnv *env, jobject /* thiz */, jbyteArray uuidObj, jstring jmimeType,
        jint jSecurityLevel) {

    if (uuidObj == NULL) {
        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
@@ -952,8 +975,9 @@ static jboolean android_media_MediaDrm_isCryptoSchemeSupportedNative(
    if (jmimeType != NULL) {
        mimeType = JStringToString8(env, jmimeType);
    }
    DrmPlugin::SecurityLevel securityLevel = jintToSecurityLevel(jSecurityLevel);

    return JDrm::IsCryptoSchemeSupported(uuid.array(), mimeType);
    return JDrm::IsCryptoSchemeSupported(uuid.array(), mimeType, securityLevel);
}

static jbyteArray android_media_MediaDrm_openSession(
@@ -965,21 +989,8 @@ static jbyteArray android_media_MediaDrm_openSession(
    }

    Vector<uint8_t> sessionId;
    DrmPlugin::SecurityLevel level;

    if (jlevel == gSecurityLevels.kSecurityLevelMax) {
        level = DrmPlugin::kSecurityLevelMax;
    }  else if (jlevel == gSecurityLevels.kSecurityLevelSwSecureCrypto) {
        level = DrmPlugin::kSecurityLevelSwSecureCrypto;
    } else if (jlevel == gSecurityLevels.kSecurityLevelSwSecureDecode) {
        level = DrmPlugin::kSecurityLevelSwSecureDecode;
    } else if (jlevel == gSecurityLevels.kSecurityLevelHwSecureCrypto) {
        level = DrmPlugin::kSecurityLevelHwSecureCrypto;
    } else if (jlevel == gSecurityLevels.kSecurityLevelHwSecureDecode) {
        level = DrmPlugin::kSecurityLevelHwSecureDecode;
    } else if (jlevel == gSecurityLevels.kSecurityLevelHwSecureAll) {
        level = DrmPlugin::kSecurityLevelHwSecureAll;
    } else {
    DrmPlugin::SecurityLevel level = jintToSecurityLevel(jlevel);
    if (level == DrmPlugin::kSecurityLevelUnknown) {
        jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid security level");
        return NULL;
    }
@@ -1903,7 +1914,7 @@ static const JNINativeMethod gMethods[] = {
    { "native_setup", "(Ljava/lang/Object;[BLjava/lang/String;)V",
      (void *)android_media_MediaDrm_native_setup },

    { "isCryptoSchemeSupportedNative", "([BLjava/lang/String;)Z",
    { "isCryptoSchemeSupportedNative", "([BLjava/lang/String;I)Z",
      (void *)android_media_MediaDrm_isCryptoSchemeSupportedNative },

    { "openSession", "(I)[B",
+3 −1
Original line number Diff line number Diff line
@@ -37,7 +37,9 @@ public:
};

struct JDrm : public BnDrmClient {
    static bool IsCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType);
    static bool IsCryptoSchemeSupported(const uint8_t uuid[16],
                                        const String8 &mimeType,
                                        DrmPlugin::SecurityLevel level);

    JDrm(JNIEnv *env, jobject thiz, const uint8_t uuid[16], const String8 &appPackageName);