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