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

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

fix MediaDrm.isCryptoSchemeSupported(uuid)

1. Don't expect plugins to support an empty mimeType in isContentTypeSupported
2. Move the cts test mock drm plugin to the cts tree so it is always used

b/10528466

Change-Id: I6023f6165b1e9d294986f7e5cd0896e056e376f1
parent 8271f1a2
Loading
Loading
Loading
Loading
+0 −38
Original line number Diff line number Diff line
#
# Copyright (C) 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
    MockDrmCryptoPlugin.cpp

LOCAL_MODULE := libmockdrmcryptoplugin

LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/mediadrm

LOCAL_SHARED_LIBRARIES := \
    libutils liblog

LOCAL_C_INCLUDES += \
    $(TOP)/frameworks/av/include \
    $(TOP)/frameworks/native/include/media

# Set the following flag to enable the decryption passthru flow
#LOCAL_CFLAGS += -DENABLE_PASSTHRU_DECRYPTION

LOCAL_MODULE_TAGS := optional

include $(BUILD_SHARED_LIBRARY)
+0 −705

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −156
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <utils/Mutex.h>

#include "drm/DrmAPI.h"
#include "hardware/CryptoAPI.h"

extern "C" {
      android::DrmFactory *createDrmFactory();
      android::CryptoFactory *createCryptoFactory();
}

namespace android {

    class MockDrmFactory : public DrmFactory {
    public:
        MockDrmFactory() {}
        virtual ~MockDrmFactory() {}

        bool isCryptoSchemeSupported(const uint8_t uuid[16]);
        bool isContentTypeSupported(const String8 &mimeType);
        status_t createDrmPlugin(const uint8_t uuid[16], DrmPlugin **plugin);
    };

    class MockCryptoFactory : public CryptoFactory {
    public:
        MockCryptoFactory() {}
        virtual ~MockCryptoFactory() {}

        bool isCryptoSchemeSupported(const uint8_t uuid[16]) const;
        status_t createPlugin(
            const uint8_t uuid[16], const void *data, size_t size,
            CryptoPlugin **plugin);
    };



    class MockDrmPlugin : public DrmPlugin {
    public:
        MockDrmPlugin() {}
        virtual ~MockDrmPlugin() {}

        // from DrmPlugin
        status_t openSession(Vector<uint8_t> &sessionId);
        status_t closeSession(Vector<uint8_t> const &sessionId);

        status_t getKeyRequest(Vector<uint8_t> const &sessionId,
                               Vector<uint8_t> const &initData,
                               String8 const &mimeType, KeyType keyType,
                               KeyedVector<String8, String8> const &optionalParameters,
                               Vector<uint8_t> &request, String8 &defaultUrl);

        status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
                                    Vector<uint8_t> const &response,
                                    Vector<uint8_t> &keySetId);

        status_t removeKeys(Vector<uint8_t> const &keySetId);

        status_t restoreKeys(Vector<uint8_t> const &sessionId,
                             Vector<uint8_t> const &keySetId);

        status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
                                KeyedVector<String8, String8> &infoMap) const;

        status_t getProvisionRequest(Vector<uint8_t> &request,
                                             String8 &defaultUrl);

        status_t provideProvisionResponse(Vector<uint8_t> const &response);

        status_t getSecureStops(List<Vector<uint8_t> > &secureStops);
        status_t releaseSecureStops(Vector<uint8_t> const &ssRelease);

        status_t getPropertyString(String8 const &name, String8 &value ) const;
        status_t getPropertyByteArray(String8 const &name,
                                              Vector<uint8_t> &value ) const;

        status_t setPropertyString(String8 const &name,
                                   String8 const &value );
        status_t setPropertyByteArray(String8 const &name,
                                      Vector<uint8_t> const &value );

        status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
                                    String8 const &algorithm);

        status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
                                 String8 const &algorithm);

        status_t encrypt(Vector<uint8_t> const &sessionId,
                         Vector<uint8_t> const &keyId,
                         Vector<uint8_t> const &input,
                         Vector<uint8_t> const &iv,
                         Vector<uint8_t> &output);

        status_t decrypt(Vector<uint8_t> const &sessionId,
                         Vector<uint8_t> const &keyId,
                         Vector<uint8_t> const &input,
                         Vector<uint8_t> const &iv,
                         Vector<uint8_t> &output);

        status_t sign(Vector<uint8_t> const &sessionId,
                      Vector<uint8_t> const &keyId,
                      Vector<uint8_t> const &message,
                      Vector<uint8_t> &signature);

        status_t verify(Vector<uint8_t> const &sessionId,
                        Vector<uint8_t> const &keyId,
                        Vector<uint8_t> const &message,
                        Vector<uint8_t> const &signature,
                        bool &match);

    private:
        String8 vectorToString(Vector<uint8_t> const &vector) const;
        String8 arrayToString(uint8_t const *array, size_t len) const;
        String8 stringMapToString(KeyedVector<String8, String8> map) const;

        SortedVector<Vector<uint8_t> > mSessions;
        SortedVector<Vector<uint8_t> > mKeySets;

        static const ssize_t kNotFound = -1;
        ssize_t findSession(Vector<uint8_t> const &sessionId) const;
        ssize_t findKeySet(Vector<uint8_t> const &keySetId) const;

        Mutex mLock;
        KeyedVector<String8, String8> mStringProperties;
        KeyedVector<String8, Vector<uint8_t> > mByteArrayProperties;
    };


    class MockCryptoPlugin : public CryptoPlugin {

        bool requiresSecureDecoderComponent(const char *mime) const;

        ssize_t decrypt(bool secure,
            const uint8_t key[16], const uint8_t iv[16],
            Mode mode, const void *srcPtr,
            const SubSample *subSamples, size_t numSubSamples,
            void *dstPtr, AString *errorDetailMsg);
    private:
        String8 subSamplesToString(CryptoPlugin::SubSample const *subSamples, size_t numSubSamples) const;
        String8 arrayToString(uint8_t const *array, size_t len) const;
    };
};
+5 −1
Original line number Diff line number Diff line
@@ -222,9 +222,13 @@ bool Drm::isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeTyp
        }
    }

    if (mimeType != "") {
        return mFactory->isContentTypeSupported(mimeType);
    }

    return true;
}

status_t Drm::createPlugin(const uint8_t uuid[16]) {
    Mutex::Autolock autoLock(mLock);