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