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 #include <binder/IInterface.h> 18 #include <cutils/native_handle.h> 19 #include <media/hardware/CryptoAPI.h> 20 #include <media/stagefright/foundation/ABase.h> 21 22 #ifndef ANDROID_ICRYPTO_H_ 23 24 #define ANDROID_ICRYPTO_H_ 25 26 namespace android { 27 28 struct AString; 29 class IMemory; 30 class IMemoryHeap; 31 32 struct ICrypto : public IInterface { 33 DECLARE_META_INTERFACE(Crypto); 34 35 virtual status_t initCheck() const = 0; 36 37 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) = 0; 38 39 virtual status_t createPlugin( 40 const uint8_t uuid[16], const void *data, size_t size) = 0; 41 42 virtual status_t destroyPlugin() = 0; 43 44 virtual bool requiresSecureDecoderComponent( 45 const char *mime) const = 0; 46 47 virtual void notifyResolution(uint32_t width, uint32_t height) = 0; 48 49 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) = 0; 50 51 struct SourceBuffer { 52 sp<IMemory> mSharedMemory; 53 int32_t mHeapSeqNum; 54 }; 55 56 enum DestinationType { 57 kDestinationTypeSharedMemory, // non-secure 58 kDestinationTypeNativeHandle // secure 59 }; 60 61 struct DestinationBuffer { 62 DestinationType mType; 63 native_handle_t *mHandle; 64 sp<IMemory> mSharedMemory; 65 }; 66 67 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16], 68 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern, 69 const SourceBuffer &source, size_t offset, 70 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples, 71 const DestinationBuffer &destination, AString *errorDetailMsg) = 0; 72 73 /** 74 * Declare the heap that the shared memory source buffers passed 75 * to decrypt will be allocated from. Returns a sequence number 76 * that subsequent decrypt calls can use to refer to the heap, 77 * with -1 indicating failure. 78 */ 79 virtual int32_t setHeap(const sp<IMemoryHeap>& heap) = 0; 80 virtual void unsetHeap(int32_t seqNum) = 0; 81 82 private: 83 DISALLOW_EVIL_CONSTRUCTORS(ICrypto); 84 }; 85 86 struct BnCrypto : public BnInterface<ICrypto> { 87 virtual status_t onTransact( 88 uint32_t code, const Parcel &data, Parcel *reply, 89 uint32_t flags = 0); 90 private: 91 void readVector(const Parcel &data, Vector<uint8_t> &vector) const; 92 void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const; 93 }; 94 95 } // namespace android 96 97 #endif // ANDROID_ICRYPTO_H_ 98