blob: bc462c2b5050d8ab2f59bc4a8bfc708156e6f6b7 [file] [log] [blame]
aimitakeshid074e302010-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;
33class DrmContentIds;
34class DrmConstraints;
Takeshi Aimidc9186562010-11-16 13:56:11 +090035class DrmMetadata;
aimitakeshid074e302010-07-29 10:12:27 +090036class DrmRights;
37class DrmInfo;
38class DrmInfoStatus;
39class DrmConvertedStatus;
40class DrmInfoRequest;
41class DrmSupportInfo;
42class ActionDescription;
43
44/**
45 * This is implementation class for DRM Manager. This class delegates the
46 * functionality to corresponding DRM Engine.
47 *
48 * The DrmManagerService class creates an instance of this class.
49 *
50 */
51class DrmManager : public IDrmEngine::OnInfoListener {
52public:
53 DrmManager();
54 virtual ~DrmManager();
55
56public:
Takeshi Aimidc549d62010-09-20 23:40:41 +090057 int addUniqueId(int uniqueId);
58
59 void removeUniqueId(int uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090060
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090061 void addClient(int uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090062
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090063 void removeClient(int uniqueId);
64
65 status_t loadPlugIns();
66
67 status_t loadPlugIns(const String8& plugInDirPath);
68
69 status_t unloadPlugIns();
aimitakeshid074e302010-07-29 10:12:27 +090070
71 status_t setDrmServiceListener(
72 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
73
aimitakeshid074e302010-07-29 10:12:27 +090074 status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
75
76 DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
77
Takeshi Aimidc9186562010-11-16 13:56:11 +090078 DrmMetadata* getMetadata(int uniqueId, const String8* path);
79
aimitakeshid074e302010-07-29 10:12:27 +090080 bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
81
82 DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
83
84 DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
85
Takeshi Aimidc549d62010-09-20 23:40:41 +090086 status_t saveRights(int uniqueId, const DrmRights& drmRights,
aimitakeshid074e302010-07-29 10:12:27 +090087 const String8& rightsPath, const String8& contentPath);
88
89 String8 getOriginalMimeType(int uniqueId, const String8& path);
90
91 int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
92
93 int checkRightsStatus(int uniqueId, const String8& path, int action);
94
Takeshi Aimidc549d62010-09-20 23:40:41 +090095 status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
aimitakeshid074e302010-07-29 10:12:27 +090096
Takeshi Aimidc549d62010-09-20 23:40:41 +090097 status_t setPlaybackStatus(
aimitakeshid074e302010-07-29 10:12:27 +090098 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
99
100 bool validateAction(
101 int uniqueId, const String8& path, int action, const ActionDescription& description);
102
Takeshi Aimidc549d62010-09-20 23:40:41 +0900103 status_t removeRights(int uniqueId, const String8& path);
aimitakeshid074e302010-07-29 10:12:27 +0900104
Takeshi Aimidc549d62010-09-20 23:40:41 +0900105 status_t removeAllRights(int uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +0900106
107 int openConvertSession(int uniqueId, const String8& mimeType);
108
109 DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
110
111 DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
112
113 status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
114
115 DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
116
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +0900117 DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
118
Takeshi Aimidc549d62010-09-20 23:40:41 +0900119 status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
aimitakeshid074e302010-07-29 10:12:27 +0900120
Takeshi Aimidc549d62010-09-20 23:40:41 +0900121 status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshid074e302010-07-29 10:12:27 +0900122 int decryptUnitId, const DrmBuffer* headerInfo);
123
Takeshi Aimidc549d62010-09-20 23:40:41 +0900124 status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
125 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
aimitakeshid074e302010-07-29 10:12:27 +0900126
Takeshi Aimidc549d62010-09-20 23:40:41 +0900127 status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900128
129 ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
130 void* buffer, ssize_t numBytes, off_t offset);
131
132 void onInfo(const DrmInfoEvent& event);
133
134private:
135 String8 getSupportedPlugInId(int uniqueId, const String8& path, const String8& mimeType);
136
137 String8 getSupportedPlugInId(const String8& mimeType);
138
139 String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path);
140
aimitakeshid074e302010-07-29 10:12:27 +0900141 bool canHandle(int uniqueId, const String8& path);
142
aimitakeshid074e302010-07-29 10:12:27 +0900143private:
Takeshi Aimidc549d62010-09-20 23:40:41 +0900144 static Vector<int> mUniqueIdVector;
aimitakeshid074e302010-07-29 10:12:27 +0900145 static const String8 EMPTY_STRING;
146
147 int mDecryptSessionId;
148 int mConvertId;
149 Mutex mLock;
150 Mutex mDecryptLock;
151 Mutex mConvertLock;
152 TPlugInManager<IDrmEngine> mPlugInManager;
153 KeyedVector< DrmSupportInfo, String8 > mSupportInfoToPlugInIdMap;
154 KeyedVector< int, IDrmEngine*> mConvertSessionMap;
155 KeyedVector< int, sp<IDrmServiceListener> > mServiceListeners;
156 KeyedVector< int, IDrmEngine*> mDecryptSessionMap;
157};
158
159};
160
161#endif /* __DRM_MANAGER_H__ */
162