Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1 | /* |
| 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 Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 20 | #include <aidl/android/hardware/drm/ICryptoPlugin.h> |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame^] | 21 | #include <aidl/android/hardware/drm/IDrmFactory.h> |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 22 | #include <mediadrm/ICrypto.h> |
| 23 | #include <utils/KeyedVector.h> |
| 24 | #include <utils/threads.h> |
| 25 | |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame^] | 26 | using IDrmFactoryAidl = ::aidl::android::hardware::drm::IDrmFactory; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 27 | using ICryptoPluginAidl = ::aidl::android::hardware::drm::ICryptoPlugin; |
| 28 | using ::aidl::android::hardware::drm::Uuid; |
| 29 | |
| 30 | // -------Hidl interface related----------------- |
| 31 | // TODO: replace before removing hidl interface |
| 32 | using ::android::hardware::drm::V1_0::DestinationBuffer; |
| 33 | using ::android::hardware::drm::V1_0::SharedBuffer; |
| 34 | |
| 35 | using ::android::hardware::HidlMemory; |
| 36 | |
| 37 | // -------Hidl interface related end------------- |
| 38 | |
| 39 | class IMemoryHeap; |
| 40 | |
| 41 | namespace android { |
| 42 | |
| 43 | struct 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 Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame^] | 65 | const std::vector<std::shared_ptr<IDrmFactoryAidl>> mFactories; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 66 | 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 Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 79 | std::shared_ptr<ICryptoPluginAidl> makeCryptoPlugin( |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame^] | 80 | const std::shared_ptr<IDrmFactoryAidl>& factory, const Uuid& uuidAidl, |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 81 | const std::vector<uint8_t> initData); |
| 82 | |
| 83 | status_t checkSharedBuffer(const ::SharedBuffer& buffer); |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame^] | 84 | bool isCryptoSchemeSupportedInternal(const uint8_t uuid[16], int* factoryIdx); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 85 | |
| 86 | DISALLOW_EVIL_CONSTRUCTORS(CryptoHalAidl); |
| 87 | }; |
| 88 | |
| 89 | } // namespace android |
| 90 | |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 91 | #endif // CRYPTO_HAL_AIDL_H_ |