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