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 | |
| 17 | #ifndef CRYPTO_H_ |
| 18 | |
| 19 | #define CRYPTO_H_ |
| 20 | |
| 21 | #include <media/ICrypto.h> |
| 22 | #include <utils/threads.h> |
Jeff Tinker | bafb682 | 2013-03-22 15:26:39 -0700 | [diff] [blame] | 23 | #include <utils/KeyedVector.h> |
| 24 | |
| 25 | #include "SharedLibrary.h" |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 29 | struct CryptoFactory; |
| 30 | struct CryptoPlugin; |
| 31 | |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 32 | struct Crypto : public BnCrypto { |
| 33 | Crypto(); |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 34 | virtual ~Crypto(); |
| 35 | |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 36 | virtual status_t initCheck() const; |
| 37 | |
Jeff Tinker | bafb682 | 2013-03-22 15:26:39 -0700 | [diff] [blame] | 38 | virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]); |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 39 | |
| 40 | virtual status_t createPlugin( |
| 41 | const uint8_t uuid[16], const void *data, size_t size); |
| 42 | |
| 43 | virtual status_t destroyPlugin(); |
| 44 | |
| 45 | virtual bool requiresSecureDecoderComponent( |
| 46 | const char *mime) const; |
| 47 | |
Jeff Tinker | 2514d08 | 2014-11-03 13:29:35 -0800 | [diff] [blame] | 48 | virtual void notifyResolution(uint32_t width, uint32_t height); |
| 49 | |
Jeff Tinker | 1849570 | 2015-04-10 04:10:59 -0700 | [diff] [blame] | 50 | virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId); |
| 51 | |
Edwin Wong | fa2b8f2 | 2012-07-10 20:01:13 -0700 | [diff] [blame] | 52 | virtual ssize_t decrypt( |
Jeff Tinker | 9ac86b3 | 2016-01-23 17:27:58 -0800 | [diff] [blame] | 53 | DestinationType dstType, |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 54 | const uint8_t key[16], |
| 55 | const uint8_t iv[16], |
| 56 | CryptoPlugin::Mode mode, |
Jeff Tinker | 18cb1ec | 2015-12-18 11:55:22 -0800 | [diff] [blame] | 57 | const CryptoPlugin::Pattern &pattern, |
Jeff Tinker | c481b50 | 2015-04-06 18:21:05 -0700 | [diff] [blame] | 58 | const sp<IMemory> &sharedBuffer, size_t offset, |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 59 | const CryptoPlugin::SubSample *subSamples, size_t numSubSamples, |
Andreas Huber | 5b8987e | 2012-04-19 12:52:20 -0700 | [diff] [blame] | 60 | void *dstPtr, |
| 61 | AString *errorDetailMsg); |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 62 | |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 63 | private: |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 64 | mutable Mutex mLock; |
| 65 | |
| 66 | status_t mInitCheck; |
Jeff Tinker | bafb682 | 2013-03-22 15:26:39 -0700 | [diff] [blame] | 67 | sp<SharedLibrary> mLibrary; |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 68 | CryptoFactory *mFactory; |
| 69 | CryptoPlugin *mPlugin; |
| 70 | |
Jeff Tinker | bafb682 | 2013-03-22 15:26:39 -0700 | [diff] [blame] | 71 | static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap; |
| 72 | static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap; |
| 73 | static Mutex mMapLock; |
| 74 | |
| 75 | void findFactoryForScheme(const uint8_t uuid[16]); |
| 76 | bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]); |
| 77 | void closeFactory(); |
Andreas Huber | 1bd139a | 2012-04-03 14:19:20 -0700 | [diff] [blame] | 78 | |
Andreas Huber | ed3e3e0 | 2012-03-26 11:13:27 -0700 | [diff] [blame] | 79 | DISALLOW_EVIL_CONSTRUCTORS(Crypto); |
| 80 | }; |
| 81 | |
| 82 | } // namespace android |
| 83 | |
| 84 | #endif // CRYPTO_H_ |