blob: 0150d7cbc5bfdf49ae710d7507e22cb63ad8955c [file] [log] [blame]
Kyle Zhang6605add2022-01-13 17:51:23 +00001/*
2 * Copyright (C) 2021 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_HIDL_H_
18#define CRYPTO_HAL_HIDL_H_
19
20#include <android/hardware/drm/1.0/ICryptoFactory.h>
21#include <android/hardware/drm/1.0/ICryptoPlugin.h>
22#include <android/hardware/drm/1.1/ICryptoFactory.h>
23#include <android/hardware/drm/1.2/ICryptoPlugin.h>
24#include <android/hardware/drm/1.4/ICryptoPlugin.h>
25
26#include <mediadrm/ICrypto.h>
27#include <utils/KeyedVector.h>
28#include <utils/threads.h>
29
30namespace drm = ::android::hardware::drm;
31using drm::V1_0::ICryptoFactory;
32using drm::V1_0::ICryptoPlugin;
33using drm::V1_0::SharedBuffer;
34using drm::V1_0::DestinationBuffer;
35
36using ::android::hardware::HidlMemory;
37
38class IMemoryHeap;
39
40namespace android {
41
42struct CryptoHalHidl : public ICrypto {
43 CryptoHalHidl();
44 virtual ~CryptoHalHidl();
45
46 virtual status_t initCheck() const;
47
48 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
49
50 virtual status_t createPlugin(
51 const uint8_t uuid[16], const void *data, size_t size);
52
53 virtual status_t destroyPlugin();
54
55 virtual bool requiresSecureDecoderComponent(
56 const char *mime) const;
57
58 virtual void notifyResolution(uint32_t width, uint32_t height);
59
Sohail Nagaraj5a48d1e2022-12-20 10:44:46 +053060 virtual DrmStatus setMediaDrmSession(const Vector<uint8_t> &sessionId);
Kyle Zhang6605add2022-01-13 17:51:23 +000061
62 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
63 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
64 const ::SharedBuffer &source, size_t offset,
65 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
66 const ::DestinationBuffer &destination,
67 AString *errorDetailMsg);
68
69 virtual int32_t setHeap(const sp<HidlMemory>& heap) {
70 return setHeapBase(heap);
71 }
72 virtual void unsetHeap(int32_t seqNum) { clearHeapBase(seqNum); }
73
74 virtual status_t getLogMessages(Vector<drm::V1_4::LogMessage> &logs) const;
75
76private:
77 mutable Mutex mLock;
78
79 const Vector<sp<ICryptoFactory>> mFactories;
80 sp<ICryptoPlugin> mPlugin;
81 sp<drm::V1_2::ICryptoPlugin> mPluginV1_2;
82
83 /**
84 * mInitCheck is:
85 * NO_INIT if a plugin hasn't been created yet
86 * ERROR_UNSUPPORTED if a plugin can't be created for the uuid
87 * OK after a plugin has been created and mPlugin is valid
88 */
89 status_t mInitCheck;
90
91 KeyedVector<int32_t, size_t> mHeapSizes;
92 int32_t mHeapSeqNum;
93
94 Vector<sp<ICryptoFactory>> makeCryptoFactories();
95 sp<ICryptoPlugin> makeCryptoPlugin(const sp<ICryptoFactory>& factory,
96 const uint8_t uuid[16], const void *initData, size_t size);
97
98 int32_t setHeapBase(const sp<HidlMemory>& heap);
99 void clearHeapBase(int32_t seqNum);
100
101 status_t checkSharedBuffer(const ::SharedBuffer& buffer);
102
103 DISALLOW_EVIL_CONSTRUCTORS(CryptoHalHidl);
104};
105
106} // namespace android
107
108#endif // CRYPTO_HAL_H_