blob: 26222bca3f6b09519e95f55e410827693cec9127 [file] [log] [blame]
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001/*
2 * Copyright (C) 2010 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 __DRM_MANAGER_H__
18#define __DRM_MANAGER_H__
19
20#include <utils/Errors.h>
21#include <utils/threads.h>
22#include <drm/drm_framework_common.h>
23#include "IDrmEngine.h"
24#include "PlugInManager.h"
25#include "IDrmServiceListener.h"
26
27namespace android {
28
29class IDrmManager;
30class DrmRegistrationInfo;
31class DrmUnregistrationInfo;
32class DrmRightsAcquisitionInfo;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090033class DrmConstraints;
Takeshi Aimi34738462010-11-16 13:56:11 +090034class DrmMetadata;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090035class DrmRights;
36class DrmInfo;
37class DrmInfoStatus;
38class DrmConvertedStatus;
39class DrmInfoRequest;
40class DrmSupportInfo;
41class ActionDescription;
42
43/**
44 * This is implementation class for DRM Manager. This class delegates the
45 * functionality to corresponding DRM Engine.
46 *
47 * The DrmManagerService class creates an instance of this class.
48 *
49 */
50class DrmManager : public IDrmEngine::OnInfoListener {
51public:
52 DrmManager();
53 virtual ~DrmManager();
54
55public:
Gloria Wang8f001512011-07-21 15:10:22 -070056 int addUniqueId(bool isNative);
Takeshi Aimi2272ee22010-09-20 23:40:41 +090057
58 void removeUniqueId(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090059
Takeshi Aimie943f842010-10-08 23:05:49 +090060 void addClient(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090061
Takeshi Aimie943f842010-10-08 23:05:49 +090062 void removeClient(int uniqueId);
63
64 status_t loadPlugIns();
65
66 status_t loadPlugIns(const String8& plugInDirPath);
67
68 status_t unloadPlugIns();
aimitakeshi27ed8ad2010-07-29 10:12:27 +090069
70 status_t setDrmServiceListener(
71 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
72
aimitakeshi27ed8ad2010-07-29 10:12:27 +090073 DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
74
Takeshi Aimi34738462010-11-16 13:56:11 +090075 DrmMetadata* getMetadata(int uniqueId, const String8* path);
76
aimitakeshi27ed8ad2010-07-29 10:12:27 +090077 bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
78
79 DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
80
81 DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
82
Takeshi Aimi2272ee22010-09-20 23:40:41 +090083 status_t saveRights(int uniqueId, const DrmRights& drmRights,
aimitakeshi27ed8ad2010-07-29 10:12:27 +090084 const String8& rightsPath, const String8& contentPath);
85
James Dongbf5b3b22012-07-30 17:57:39 -070086 String8 getOriginalMimeType(int uniqueId, const String8& path, int fd);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090087
88 int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
89
90 int checkRightsStatus(int uniqueId, const String8& path, int action);
91
Jeff Tinker5d49bef2018-10-03 23:01:09 -070092 status_t consumeRights(int uniqueId, sp<DecryptHandle>& decryptHandle, int action,
93 bool reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090094
Takeshi Aimi2272ee22010-09-20 23:40:41 +090095 status_t setPlaybackStatus(
Jeff Tinker5d49bef2018-10-03 23:01:09 -070096 int uniqueId, sp<DecryptHandle>& decryptHandle, int playbackStatus, int64_t position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090097
98 bool validateAction(
99 int uniqueId, const String8& path, int action, const ActionDescription& description);
100
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900101 status_t removeRights(int uniqueId, const String8& path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900102
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900103 status_t removeAllRights(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900104
105 int openConvertSession(int uniqueId, const String8& mimeType);
106
107 DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
108
109 DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
110
111 status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
112
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700113 sp<DecryptHandle> openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800114 int uniqueId, int fd, off64_t offset, off64_t length, const char* mime);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900115
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700116 sp<DecryptHandle> openDecryptSession(int uniqueId, const char* uri, const char* mime);
Takeshi Aimie943f842010-10-08 23:05:49 +0900117
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700118 sp<DecryptHandle> openDecryptSession(int uniqueId, const DrmBuffer& buf,
Kei Takahashicba7b322012-01-18 17:10:19 +0900119 const String8& mimeType);
120
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700121 status_t closeDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900122
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700123 status_t initializeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900124 int decryptUnitId, const DrmBuffer* headerInfo);
125
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700126 status_t decrypt(int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId,
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900127 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900128
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700129 status_t finalizeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle,
130 int decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900131
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700132 ssize_t pread(int uniqueId, sp<DecryptHandle>& decryptHandle,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800133 void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900134
135 void onInfo(const DrmInfoEvent& event);
136
137private:
138 String8 getSupportedPlugInId(int uniqueId, const String8& path, const String8& mimeType);
139
140 String8 getSupportedPlugInId(const String8& mimeType);
141
142 String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path);
143
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900144 bool canHandle(int uniqueId, const String8& path);
145
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900146private:
Henrik B Andersson13f7fe72012-10-26 15:15:15 +0200147 enum {
148 kMaxNumUniqueIds = 0x1000,
149 };
150
151 bool mUniqueIdArray[kMaxNumUniqueIds];
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900152 static const String8 EMPTY_STRING;
153
154 int mDecryptSessionId;
155 int mConvertId;
156 Mutex mLock;
Gloria Wang0e0a5f92011-03-11 14:07:21 -0800157 Mutex mListenerLock;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900158 Mutex mDecryptLock;
159 Mutex mConvertLock;
160 TPlugInManager<IDrmEngine> mPlugInManager;
161 KeyedVector< DrmSupportInfo, String8 > mSupportInfoToPlugInIdMap;
162 KeyedVector< int, IDrmEngine*> mConvertSessionMap;
163 KeyedVector< int, sp<IDrmServiceListener> > mServiceListeners;
164 KeyedVector< int, IDrmEngine*> mDecryptSessionMap;
165};
166
167};
168
169#endif /* __DRM_MANAGER_H__ */
170