blob: f83c8468fab68c870ce1b7871dd6b42d90a142d6 [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
17#include <binder/IInterface.h>
Jeff Tinkera53d6552017-01-20 00:31:46 -080018#include <cutils/native_handle.h>
Andreas Huber1bd139a2012-04-03 14:19:20 -070019#include <media/hardware/CryptoAPI.h>
Jeff Tinkera53d6552017-01-20 00:31:46 -080020#include <media/stagefright/foundation/ABase.h>
Andreas Hubered3e3e02012-03-26 11:13:27 -070021
22#ifndef ANDROID_ICRYPTO_H_
23
24#define ANDROID_ICRYPTO_H_
25
26namespace android {
27
Andreas Huber5b8987e2012-04-19 12:52:20 -070028struct AString;
Lajos Molnaree4e1b12015-04-17 13:46:19 -070029class IMemory;
Chong Zhangd07c9272017-03-28 11:02:06 -070030class IMemoryHeap;
Andreas Huber5b8987e2012-04-19 12:52:20 -070031
Andreas Hubered3e3e02012-03-26 11:13:27 -070032struct ICrypto : public IInterface {
33 DECLARE_META_INTERFACE(Crypto);
34
Andreas Huber1bd139a2012-04-03 14:19:20 -070035 virtual status_t initCheck() const = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070036
Jeff Tinkerbafb6822013-03-22 15:26:39 -070037 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070038
Andreas Huber1bd139a2012-04-03 14:19:20 -070039 virtual status_t createPlugin(
40 const uint8_t uuid[16], const void *data, size_t size) = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070041
Andreas Huber1bd139a2012-04-03 14:19:20 -070042 virtual status_t destroyPlugin() = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070043
Andreas Huber1bd139a2012-04-03 14:19:20 -070044 virtual bool requiresSecureDecoderComponent(
45 const char *mime) const = 0;
46
Jeff Tinker2514d082014-11-03 13:29:35 -080047 virtual void notifyResolution(uint32_t width, uint32_t height) = 0;
48
Jeff Tinker18495702015-04-10 04:10:59 -070049 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) = 0;
50
Jeff Tinker9ac86b32016-01-23 17:27:58 -080051 enum DestinationType {
Jeff Tinkera53d6552017-01-20 00:31:46 -080052 kDestinationTypeSharedMemory, // non-secure
Jeff Tinker9ac86b32016-01-23 17:27:58 -080053 kDestinationTypeNativeHandle // secure
54 };
55
Jeff Tinkera53d6552017-01-20 00:31:46 -080056 struct DestinationBuffer {
57 DestinationType mType;
58 native_handle_t *mHandle;
59 sp<IMemory> mSharedMemory;
60 };
61
62 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
63 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
64 const sp<IMemory> &source, size_t offset,
Andreas Huber1bd139a2012-04-03 14:19:20 -070065 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
Jeff Tinkera53d6552017-01-20 00:31:46 -080066 const DestinationBuffer &destination, AString *errorDetailMsg) = 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070067
Chong Zhangd07c9272017-03-28 11:02:06 -070068 /**
69 * Declare the heap that the shared memory source buffers passed
70 * to decrypt will be allocated from.
71 */
72 virtual void setHeap(const sp<IMemoryHeap>& heap) = 0;
73 virtual void unsetHeap(const sp<IMemoryHeap>& heap) = 0;
74
Andreas Hubered3e3e02012-03-26 11:13:27 -070075private:
76 DISALLOW_EVIL_CONSTRUCTORS(ICrypto);
77};
78
79struct BnCrypto : public BnInterface<ICrypto> {
80 virtual status_t onTransact(
81 uint32_t code, const Parcel &data, Parcel *reply,
82 uint32_t flags = 0);
Jeff Tinker18495702015-04-10 04:10:59 -070083private:
84 void readVector(const Parcel &data, Vector<uint8_t> &vector) const;
85 void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const;
Andreas Hubered3e3e02012-03-26 11:13:27 -070086};
87
88} // namespace android
89
90#endif // ANDROID_ICRYPTO_H_