blob: fc7f7fbcc6ee770181baf6c5e821d629a746e2b8 [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_AIDL_H_
18#define CRYPTO_HAL_AIDL_H_
19
20#include <aidl/android/hardware/drm/ICryptoFactory.h>
21#include <aidl/android/hardware/drm/ICryptoPlugin.h>
22
23#include <mediadrm/ICrypto.h>
24#include <utils/KeyedVector.h>
25#include <utils/threads.h>
26
27using ICryptoFactoryAidl = ::aidl::android::hardware::drm::ICryptoFactory;
28using ICryptoPluginAidl = ::aidl::android::hardware::drm::ICryptoPlugin;
29using ::aidl::android::hardware::drm::Uuid;
30
31// -------Hidl interface related-----------------
32// TODO: replace before removing hidl interface
33using ::android::hardware::drm::V1_0::DestinationBuffer;
34using ::android::hardware::drm::V1_0::SharedBuffer;
35
36using ::android::hardware::HidlMemory;
37
38// -------Hidl interface related end-------------
39
40class IMemoryHeap;
41
42namespace android {
43
44struct CryptoHalAidl : public ICrypto {
45 CryptoHalAidl();
46 virtual ~CryptoHalAidl();
47 virtual status_t initCheck() const;
48 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
49 virtual status_t createPlugin(const uint8_t uuid[16], const void* data, size_t size);
50 virtual status_t destroyPlugin();
51 virtual bool requiresSecureDecoderComponent(const char* mime) const;
52 virtual void notifyResolution(uint32_t width, uint32_t height);
53 virtual status_t setMediaDrmSession(const Vector<uint8_t>& sessionId);
54 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16], CryptoPlugin::Mode mode,
55 const CryptoPlugin::Pattern& pattern, const ::SharedBuffer& source,
56 size_t offset, const CryptoPlugin::SubSample* subSamples,
57 size_t numSubSamples, const ::DestinationBuffer& destination,
58 AString* errorDetailMsg);
59 virtual int32_t setHeap(const sp<HidlMemory>& heap);
60 virtual void unsetHeap(int32_t seqNum);
61 virtual status_t getLogMessages(Vector<drm::V1_4::LogMessage>& logs) const;
62
63 private:
64 mutable Mutex mLock;
65
66 const std::vector<std::shared_ptr<ICryptoFactoryAidl>> mFactories;
67 std::shared_ptr<ICryptoPluginAidl> mPlugin;
68
69 /**
70 * mInitCheck is:
71 * NO_INIT if a plugin hasn't been created yet
72 * ERROR_UNSUPPORTED if a plugin can't be created for the uuid
73 * OK after a plugin has been created and mPlugin is valid
74 */
75 status_t mInitCheck;
76
77 KeyedVector<int32_t, size_t> mHeapSizes;
78 int32_t mHeapSeqNum;
79
80 std::vector<std::shared_ptr<ICryptoFactoryAidl>> makeCryptoFactories();
81 std::shared_ptr<ICryptoPluginAidl> makeCryptoPlugin(
82 const std::shared_ptr<ICryptoFactoryAidl>& factory, const Uuid& uuidAidl,
83 const std::vector<uint8_t> initData);
84
85 status_t checkSharedBuffer(const ::SharedBuffer& buffer);
86
87 DISALLOW_EVIL_CONSTRUCTORS(CryptoHalAidl);
88};
89
90} // namespace android
91
Kyle Zhanga55209d2022-02-03 01:52:46 +000092#endif // CRYPTO_HAL_AIDL_H_