summaryrefslogtreecommitdiffstats
path: root/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
blob: d46a12733baceb59a7b75fe6aa4fd0f4b970417f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * 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]);
        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
            getLicenseRequest(Vector<uint8_t> const &sessionId,
                              Vector<uint8_t> const &initData,
                              String8 const &mimeType, LicenseType licenseType,
                              KeyedVector<String8, String8> const &optionalParameters,
                              Vector<uint8_t> &request, String8 &defaultUrl);

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

        status_t removeLicense(Vector<uint8_t> const &sessionId);

        status_t
            queryLicenseStatus(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 );

    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;

        static const ssize_t kNotFound = -1;
        ssize_t findSession(Vector<uint8_t> const &sessionId) 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;
    };
};