Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 17 | #include <cutils/native_handle.h> |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 18 | #include <media/hardware/CryptoAPI.h> |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 19 | #include <media/stagefright/foundation/ABase.h> |
Robert Shih | 9c930d0 | 2019-07-16 15:44:13 -0700 | [diff] [blame] | 20 | #include <utils/RefBase.h> |
| 21 | #include <utils/StrongPointer.h> |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 22 | |
| 23 | #ifndef ANDROID_ICRYPTO_H_ |
| 24 | |
| 25 | #define ANDROID_ICRYPTO_H_ |
| 26 | |
| 27 | namespace android { |
Robert Shih | 895fba9 | 2019-07-16 16:29:44 -0700 | [diff] [blame] | 28 | namespace hardware { |
| 29 | class HidlMemory; |
| 30 | namespace drm { |
| 31 | namespace V1_0 { |
| 32 | struct SharedBuffer; |
| 33 | struct DestinationBuffer; |
| 34 | } // namespace V1_0 |
Robert Shih | 9afca95 | 2021-02-12 01:36:06 -0800 | [diff] [blame] | 35 | |
| 36 | namespace V1_4 { |
| 37 | struct LogMessage; |
| 38 | } // namespace V1_4 |
Robert Shih | 895fba9 | 2019-07-16 16:29:44 -0700 | [diff] [blame] | 39 | } // namespace drm |
| 40 | } // namespace hardware |
| 41 | } // namespace android |
| 42 | |
| 43 | namespace drm = ::android::hardware::drm; |
| 44 | using drm::V1_0::SharedBuffer; |
| 45 | |
| 46 | namespace android { |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 47 | |
Andreas Huber | 5b8987e | 2012-04-19 12:52:20 -0700 | [diff] [blame] | 48 | struct AString; |
| 49 | |
Robert Shih | 9c930d0 | 2019-07-16 15:44:13 -0700 | [diff] [blame] | 50 | struct ICrypto : public RefBase { |
| 51 | |
| 52 | virtual ~ICrypto() {} |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 53 | |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 54 | virtual status_t initCheck() const = 0; |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 55 | |
Jeff Tinker | bafb682 | 2013-03-22 15:26:39 -0700 | [diff] [blame] | 56 | virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) = 0; |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 57 | |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 58 | virtual status_t createPlugin( |
| 59 | const uint8_t uuid[16], const void *data, size_t size) = 0; |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 60 | |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 61 | virtual status_t destroyPlugin() = 0; |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 62 | |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 63 | virtual bool requiresSecureDecoderComponent( |
| 64 | const char *mime) const = 0; |
| 65 | |
Jeff Tinker | 2514d08 | 2014-11-03 13:29:35 -0800 | [diff] [blame] | 66 | virtual void notifyResolution(uint32_t width, uint32_t height) = 0; |
| 67 | |
Jeff Tinker | 1849570 | 2015-04-10 04:10:59 -0700 | [diff] [blame] | 68 | virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) = 0; |
| 69 | |
Jeff Tinker | 9ac86b3 | 2016-01-23 17:27:58 -0800 | [diff] [blame] | 70 | enum DestinationType { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 71 | kDestinationTypeSharedMemory, // non-secure |
Jeff Tinker | 9ac86b3 | 2016-01-23 17:27:58 -0800 | [diff] [blame] | 72 | kDestinationTypeNativeHandle // secure |
| 73 | }; |
| 74 | |
Robert Shih | 895fba9 | 2019-07-16 16:29:44 -0700 | [diff] [blame] | 75 | virtual ssize_t decrypt(const uint8_t /*key*/[16], const uint8_t /*iv*/[16], |
| 76 | CryptoPlugin::Mode /*mode*/, const CryptoPlugin::Pattern &/*pattern*/, |
| 77 | const drm::V1_0::SharedBuffer &/*source*/, size_t /*offset*/, |
| 78 | const CryptoPlugin::SubSample * /*subSamples*/, size_t /*numSubSamples*/, |
| 79 | const drm::V1_0::DestinationBuffer &/*destination*/, AString * /*errorDetailMsg*/) = 0; |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 80 | |
Chong Zhang | d07c927 | 2017-03-28 11:02:06 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Declare the heap that the shared memory source buffers passed |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 83 | * to decrypt will be allocated from. Returns a sequence number |
| 84 | * that subsequent decrypt calls can use to refer to the heap, |
| 85 | * with -1 indicating failure. |
Chong Zhang | d07c927 | 2017-03-28 11:02:06 -0700 | [diff] [blame] | 86 | */ |
Robert Shih | 895fba9 | 2019-07-16 16:29:44 -0700 | [diff] [blame] | 87 | virtual int32_t setHeap(const sp<hardware::HidlMemory>& heap) = 0; |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 88 | virtual void unsetHeap(int32_t seqNum) = 0; |
Chong Zhang | d07c927 | 2017-03-28 11:02:06 -0700 | [diff] [blame] | 89 | |
Robert Shih | 9afca95 | 2021-02-12 01:36:06 -0800 | [diff] [blame] | 90 | virtual status_t getLogMessages(Vector<drm::V1_4::LogMessage> &logs) const = 0; |
| 91 | |
Robert Shih | 9c930d0 | 2019-07-16 15:44:13 -0700 | [diff] [blame] | 92 | protected: |
| 93 | ICrypto() {} |
| 94 | |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 95 | private: |
| 96 | DISALLOW_EVIL_CONSTRUCTORS(ICrypto); |
| 97 | }; |
| 98 | |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 99 | } // namespace android |
| 100 | |
| 101 | #endif // ANDROID_ICRYPTO_H_ |