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> 23 #include <utils/KeyedVector.h> 24 25 #include "SharedLibrary.h" 26 27 namespace android { 28 29 struct CryptoFactory; 30 struct CryptoPlugin; 31 32 struct Crypto : public BnCrypto { 33 Crypto(); 34 virtual ~Crypto(); 35 36 virtual status_t initCheck() const; 37 38 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]); 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 48 virtual void notifyResolution(uint32_t width, uint32_t height); 49 50 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId); 51 52 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16], 53 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern, 54 const sp<IMemory> &source, size_t offset, 55 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples, 56 const DestinationBuffer &destination, AString *errorDetailMsg); 57 58 virtual void setHeap(const sp<IMemoryHeap>&) {} 59 virtual void unsetHeap(const sp<IMemoryHeap>&) {} 60 61 private: 62 mutable Mutex mLock; 63 64 status_t mInitCheck; 65 sp<SharedLibrary> mLibrary; 66 CryptoFactory *mFactory; 67 CryptoPlugin *mPlugin; 68 69 static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap; 70 static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap; 71 static Mutex mMapLock; 72 73 void findFactoryForScheme(const uint8_t uuid[16]); 74 bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]); 75 void closeFactory(); 76 77 DISALLOW_EVIL_CONSTRUCTORS(Crypto); 78 }; 79 80 } // namespace android 81 82 #endif // CRYPTO_H_ 83