blob: 5fd39e64f2c1c574d4c9a4028f74be02bd127484 [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>
Jeff Tinkere307dc42018-02-11 19:53:54 +000023#include <android/hardware/drm/1.1/ICryptoFactory.h>
Jeff Tinkerb8684f32018-12-12 08:41:31 -080024#include <android/hardware/drm/1.2/ICryptoPlugin.h>
Robert Shih9afca952021-02-12 01:36:06 -080025#include <android/hardware/drm/1.4/ICryptoPlugin.h>
Jeff Tinkerabeb36a2017-02-17 09:42:46 -080026
Jeff Tinker7d2c6e82018-02-16 16:14:59 -080027#include <mediadrm/ICrypto.h>
Jeff Tinkera53d6552017-01-20 00:31:46 -080028#include <utils/KeyedVector.h>
29#include <utils/threads.h>
30
Jeff Tinkere307dc42018-02-11 19:53:54 +000031namespace drm = ::android::hardware::drm;
32using drm::V1_0::ICryptoFactory;
33using drm::V1_0::ICryptoPlugin;
34using drm::V1_0::SharedBuffer;
Robert Shih895fba92019-07-16 16:29:44 -070035using drm::V1_0::DestinationBuffer;
36
37using ::android::hardware::HidlMemory;
Jeff Tinkera53d6552017-01-20 00:31:46 -080038
Jeff Tinker3cb53162017-02-16 12:06:32 -080039class IMemoryHeap;
40
Jeff Tinkera53d6552017-01-20 00:31:46 -080041namespace android {
42
Robert Shih9c930d02019-07-16 15:44:13 -070043struct CryptoHal : public ICrypto {
Jeff Tinkera53d6552017-01-20 00:31:46 -080044 CryptoHal();
45 virtual ~CryptoHal();
46
47 virtual status_t initCheck() const;
48
49 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
50
51 virtual status_t createPlugin(
52 const uint8_t uuid[16], const void *data, size_t size);
53
54 virtual status_t destroyPlugin();
55
56 virtual bool requiresSecureDecoderComponent(
57 const char *mime) const;
58
59 virtual void notifyResolution(uint32_t width, uint32_t height);
60
61 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId);
62
63 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
64 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
Robert Shih895fba92019-07-16 16:29:44 -070065 const ::SharedBuffer &source, size_t offset,
Jeff Tinkera53d6552017-01-20 00:31:46 -080066 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
Robert Shih895fba92019-07-16 16:29:44 -070067 const ::DestinationBuffer &destination,
Jeff Tinkera53d6552017-01-20 00:31:46 -080068 AString *errorDetailMsg);
69
Robert Shih895fba92019-07-16 16:29:44 -070070 virtual int32_t setHeap(const sp<HidlMemory>& heap) {
Chong Zhang6dcab2b2017-03-28 14:18:27 -070071 return setHeapBase(heap);
72 }
73 virtual void unsetHeap(int32_t seqNum) { clearHeapBase(seqNum); }
Chong Zhangd07c9272017-03-28 11:02:06 -070074
Robert Shih9afca952021-02-12 01:36:06 -080075 virtual status_t getLogMessages(Vector<drm::V1_4::LogMessage> &logs) const;
76
Jeff Tinkera53d6552017-01-20 00:31:46 -080077private:
78 mutable Mutex mLock;
79
Jeff Tinkerabeb36a2017-02-17 09:42:46 -080080 const Vector<sp<ICryptoFactory>> mFactories;
81 sp<ICryptoPlugin> mPlugin;
Jeff Tinkerb8684f32018-12-12 08:41:31 -080082 sp<drm::V1_2::ICryptoPlugin> mPluginV1_2;
Jeff Tinkera53d6552017-01-20 00:31:46 -080083
84 /**
85 * mInitCheck is:
86 * NO_INIT if a plugin hasn't been created yet
87 * ERROR_UNSUPPORTED if a plugin can't be created for the uuid
88 * OK after a plugin has been created and mPlugin is valid
89 */
90 status_t mInitCheck;
91
Robert Shih895fba92019-07-16 16:29:44 -070092 KeyedVector<int32_t, size_t> mHeapSizes;
Chong Zhang6dcab2b2017-03-28 14:18:27 -070093 int32_t mHeapSeqNum;
Jeff Tinkera53d6552017-01-20 00:31:46 -080094
Jeff Tinkerabeb36a2017-02-17 09:42:46 -080095 Vector<sp<ICryptoFactory>> makeCryptoFactories();
96 sp<ICryptoPlugin> makeCryptoPlugin(const sp<ICryptoFactory>& factory,
97 const uint8_t uuid[16], const void *initData, size_t size);
Jeff Tinkera53d6552017-01-20 00:31:46 -080098
Robert Shih895fba92019-07-16 16:29:44 -070099 int32_t setHeapBase(const sp<HidlMemory>& heap);
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700100 void clearHeapBase(int32_t seqNum);
Jeff Tinker3cb53162017-02-16 12:06:32 -0800101
Robert Shih895fba92019-07-16 16:29:44 -0700102 status_t checkSharedBuffer(const ::SharedBuffer& buffer);
Jeff Tinkera53d6552017-01-20 00:31:46 -0800103
104 DISALLOW_EVIL_CONSTRUCTORS(CryptoHal);
105};
106
107} // namespace android
108
109#endif // CRYPTO_HAL_H_