blob: 1ace957a76da11734b1f1ab2ae18a32f7e5b5d17 [file] [log] [blame]
Jeff Tinkera53d6552017-01-20 00:31:46 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef CRYPTO_HAL_H_
18
19#define CRYPTO_HAL_H_
20
21#include <android/hardware/drm/1.0/ICryptoFactory.h>
22#include <android/hardware/drm/1.0/ICryptoPlugin.h>
23#include <media/ICrypto.h>
24#include <utils/KeyedVector.h>
25#include <utils/threads.h>
26
27#include "SharedLibrary.h"
28
29namespace android {
30
31struct CryptoHal : public BnCrypto {
32 CryptoHal();
33 virtual ~CryptoHal();
34
35 virtual status_t initCheck() const;
36
37 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
38
39 virtual status_t createPlugin(
40 const uint8_t uuid[16], const void *data, size_t size);
41
42 virtual status_t destroyPlugin();
43
44 virtual bool requiresSecureDecoderComponent(
45 const char *mime) const;
46
47 virtual void notifyResolution(uint32_t width, uint32_t height);
48
49 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId);
50
51 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
52 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
53 const sp<IMemory> &source, size_t offset,
54 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
55 const ICrypto::DestinationBuffer &destination,
56 AString *errorDetailMsg);
57
58private:
59 mutable Mutex mLock;
60
61 sp<SharedLibrary> mLibrary;
62 sp<::android::hardware::drm::V1_0::ICryptoFactory> mFactory;
63 sp<::android::hardware::drm::V1_0::ICryptoPlugin> mPlugin;
64
65 /**
66 * mInitCheck is:
67 * NO_INIT if a plugin hasn't been created yet
68 * ERROR_UNSUPPORTED if a plugin can't be created for the uuid
69 * OK after a plugin has been created and mPlugin is valid
70 */
71 status_t mInitCheck;
72
73 void *mHeapBase;
74
75 sp<::android::hardware::drm::V1_0::ICryptoFactory>
76 makeCryptoFactory();
77 sp<::android::hardware::drm::V1_0::ICryptoPlugin>
78 makeCryptoPlugin(const uint8_t uuid[16], const void *initData,
79 size_t size);
80
81 status_t setHeapBase(const sp<IMemory> &sharedBuffer);
82
83 DISALLOW_EVIL_CONSTRUCTORS(CryptoHal);
84};
85
86} // namespace android
87
88#endif // CRYPTO_HAL_H_