blob: 2c4df60b35cd971dcdc712e31d941e889fd93746 [file] [log] [blame]
Andreas Hubered3e3e02012-03-26 11:13:27 -07001/*
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
Jeff Tinkera53d6552017-01-20 00:31:46 -080017#include <cutils/native_handle.h>
Andreas Huber1bd139a2012-04-03 14:19:20 -070018#include <media/hardware/CryptoAPI.h>
Jeff Tinkera53d6552017-01-20 00:31:46 -080019#include <media/stagefright/foundation/ABase.h>
Robert Shih9c930d02019-07-16 15:44:13 -070020#include <utils/RefBase.h>
21#include <utils/StrongPointer.h>
Andreas Hubered3e3e02012-03-26 11:13:27 -070022
23#ifndef ANDROID_ICRYPTO_H_
24
25#define ANDROID_ICRYPTO_H_
26
27namespace android {
Robert Shih895fba92019-07-16 16:29:44 -070028namespace hardware {
29class HidlMemory;
30namespace drm {
31namespace V1_0 {
32struct SharedBuffer;
33struct DestinationBuffer;
34} // namespace V1_0
Robert Shih9afca952021-02-12 01:36:06 -080035
36namespace V1_4 {
37struct LogMessage;
38} // namespace V1_4
Robert Shih895fba92019-07-16 16:29:44 -070039} // namespace drm
40} // namespace hardware
41} // namespace android
42
43namespace drm = ::android::hardware::drm;
44using drm::V1_0::SharedBuffer;
45
46namespace android {
Andreas Hubered3e3e02012-03-26 11:13:27 -070047
Andreas Huber5b8987e2012-04-19 12:52:20 -070048struct AString;
49
Robert Shih9c930d02019-07-16 15:44:13 -070050struct ICrypto : public RefBase {
51
52 virtual ~ICrypto() {}
Andreas Hubered3e3e02012-03-26 11:13:27 -070053
Andreas Huber1bd139a2012-04-03 14:19:20 -070054 virtual status_t initCheck() const = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070055
Jeff Tinkerbafb6822013-03-22 15:26:39 -070056 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070057
Andreas Huber1bd139a2012-04-03 14:19:20 -070058 virtual status_t createPlugin(
59 const uint8_t uuid[16], const void *data, size_t size) = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070060
Andreas Huber1bd139a2012-04-03 14:19:20 -070061 virtual status_t destroyPlugin() = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070062
Andreas Huber1bd139a2012-04-03 14:19:20 -070063 virtual bool requiresSecureDecoderComponent(
64 const char *mime) const = 0;
65
Jeff Tinker2514d082014-11-03 13:29:35 -080066 virtual void notifyResolution(uint32_t width, uint32_t height) = 0;
67
Jeff Tinker18495702015-04-10 04:10:59 -070068 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) = 0;
69
Jeff Tinker9ac86b32016-01-23 17:27:58 -080070 enum DestinationType {
Jeff Tinkera53d6552017-01-20 00:31:46 -080071 kDestinationTypeSharedMemory, // non-secure
Jeff Tinker9ac86b32016-01-23 17:27:58 -080072 kDestinationTypeNativeHandle // secure
73 };
74
Robert Shih895fba92019-07-16 16:29:44 -070075 virtual ssize_t decrypt(const uint8_t /*key*/[16], const uint8_t /*iv*/[16],
76 CryptoPlugin::Mode /*mode*/, const CryptoPlugin::Pattern &/*pattern*/,
77 const drm::V1_0::SharedBuffer &/*source*/, size_t /*offset*/,
78 const CryptoPlugin::SubSample * /*subSamples*/, size_t /*numSubSamples*/,
79 const drm::V1_0::DestinationBuffer &/*destination*/, AString * /*errorDetailMsg*/) = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070080
Chong Zhangd07c9272017-03-28 11:02:06 -070081 /**
82 * Declare the heap that the shared memory source buffers passed
Chong Zhang6dcab2b2017-03-28 14:18:27 -070083 * to decrypt will be allocated from. Returns a sequence number
84 * that subsequent decrypt calls can use to refer to the heap,
85 * with -1 indicating failure.
Chong Zhangd07c9272017-03-28 11:02:06 -070086 */
Robert Shih895fba92019-07-16 16:29:44 -070087 virtual int32_t setHeap(const sp<hardware::HidlMemory>& heap) = 0;
Chong Zhang6dcab2b2017-03-28 14:18:27 -070088 virtual void unsetHeap(int32_t seqNum) = 0;
Chong Zhangd07c9272017-03-28 11:02:06 -070089
Robert Shih9afca952021-02-12 01:36:06 -080090 virtual status_t getLogMessages(Vector<drm::V1_4::LogMessage> &logs) const = 0;
91
Robert Shih9c930d02019-07-16 15:44:13 -070092protected:
93 ICrypto() {}
94
Andreas Hubered3e3e02012-03-26 11:13:27 -070095private:
96 DISALLOW_EVIL_CONSTRUCTORS(ICrypto);
97};
98
Andreas Hubered3e3e02012-03-26 11:13:27 -070099} // namespace android
100
101#endif // ANDROID_ICRYPTO_H_