blob: d5f3c50660a72b073e22230f5045a4d8c5d399c6 [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#ifndef CRYPTO_H_
18
19#define CRYPTO_H_
20
21#include <media/ICrypto.h>
22#include <utils/threads.h>
Jeff Tinkerbafb6822013-03-22 15:26:39 -070023#include <utils/KeyedVector.h>
24
25#include "SharedLibrary.h"
Andreas Hubered3e3e02012-03-26 11:13:27 -070026
27namespace android {
28
Andreas Huber1bd139a2012-04-03 14:19:20 -070029struct CryptoFactory;
30struct CryptoPlugin;
31
Andreas Hubered3e3e02012-03-26 11:13:27 -070032struct Crypto : public BnCrypto {
33 Crypto();
Andreas Hubered3e3e02012-03-26 11:13:27 -070034 virtual ~Crypto();
35
Andreas Huber1bd139a2012-04-03 14:19:20 -070036 virtual status_t initCheck() const;
37
Jeff Tinkerbafb6822013-03-22 15:26:39 -070038 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
Andreas Huber1bd139a2012-04-03 14:19:20 -070039
40 virtual status_t createPlugin(
41 const uint8_t uuid[16], const void *data, size_t size);
42
43 virtual status_t destroyPlugin();
44
45 virtual bool requiresSecureDecoderComponent(
46 const char *mime) const;
47
Jeff Tinker2514d082014-11-03 13:29:35 -080048 virtual void notifyResolution(uint32_t width, uint32_t height);
49
Edwin Wongfa2b8f22012-07-10 20:01:13 -070050 virtual ssize_t decrypt(
Andreas Huber1bd139a2012-04-03 14:19:20 -070051 bool secure,
52 const uint8_t key[16],
53 const uint8_t iv[16],
54 CryptoPlugin::Mode mode,
Jeff Tinkerc481b502015-04-06 18:21:05 -070055 const sp<IMemory> &sharedBuffer, size_t offset,
Andreas Huber1bd139a2012-04-03 14:19:20 -070056 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
Andreas Huber5b8987e2012-04-19 12:52:20 -070057 void *dstPtr,
58 AString *errorDetailMsg);
Andreas Huber1bd139a2012-04-03 14:19:20 -070059
Andreas Hubered3e3e02012-03-26 11:13:27 -070060private:
Andreas Huber1bd139a2012-04-03 14:19:20 -070061 mutable Mutex mLock;
62
63 status_t mInitCheck;
Jeff Tinkerbafb6822013-03-22 15:26:39 -070064 sp<SharedLibrary> mLibrary;
Andreas Huber1bd139a2012-04-03 14:19:20 -070065 CryptoFactory *mFactory;
66 CryptoPlugin *mPlugin;
67
Jeff Tinkerbafb6822013-03-22 15:26:39 -070068 static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap;
69 static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap;
70 static Mutex mMapLock;
71
72 void findFactoryForScheme(const uint8_t uuid[16]);
73 bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]);
74 void closeFactory();
Andreas Huber1bd139a2012-04-03 14:19:20 -070075
Andreas Hubered3e3e02012-03-26 11:13:27 -070076 DISALLOW_EVIL_CONSTRUCTORS(Crypto);
77};
78
79} // namespace android
80
81#endif // CRYPTO_H_