blob: af2c2a8506d31498de038c316540250ef11656ad [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;
aimitakeshid074e302010-07-29 10:12:27 +090033class DrmConstraints;
Takeshi Aimidc9186562010-11-16 13:56:11 +090034class DrmMetadata;
aimitakeshid074e302010-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:
Takeshi Aimidc549d62010-09-20 23:40:41 +090056 int addUniqueId(int uniqueId);
57
58 void removeUniqueId(int uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090059
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090060 void addClient(int uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090061
Takeshi Aimic7b3ccc2010-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();
aimitakeshid074e302010-07-29 10:12:27 +090069
70 status_t setDrmServiceListener(
71 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
72
aimitakeshid074e302010-07-29 10:12:27 +090073 status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
74
75 DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
76
Takeshi Aimidc9186562010-11-16 13:56:11 +090077 DrmMetadata* getMetadata(int uniqueId, const String8* path);
78
aimitakeshid074e302010-07-29 10:12:27 +090079 bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
80
81 DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
82
83 DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
84
Takeshi Aimidc549d62010-09-20 23:40:41 +090085 status_t saveRights(int uniqueId, const DrmRights& drmRights,
aimitakeshid074e302010-07-29 10:12:27 +090086 const String8& rightsPath, const String8& contentPath);
87
88 String8 getOriginalMimeType(int uniqueId, const String8& path);
89
90 int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
91
92 int checkRightsStatus(int uniqueId, const String8& path, int action);
93
Takeshi Aimidc549d62010-09-20 23:40:41 +090094 status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
aimitakeshid074e302010-07-29 10:12:27 +090095
Takeshi Aimidc549d62010-09-20 23:40:41 +090096 status_t setPlaybackStatus(
Gloria Wang5fc3edb2010-11-19 15:19:36 -080097 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position);
aimitakeshid074e302010-07-29 10:12:27 +090098
99 bool validateAction(
100 int uniqueId, const String8& path, int action, const ActionDescription& description);
101
Takeshi Aimidc549d62010-09-20 23:40:41 +0900102 status_t removeRights(int uniqueId, const String8& path);
aimitakeshid074e302010-07-29 10:12:27 +0900103
Takeshi Aimidc549d62010-09-20 23:40:41 +0900104 status_t removeAllRights(int uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +0900105
106 int openConvertSession(int uniqueId, const String8& mimeType);
107
108 DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
109
110 DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
111
112 status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
113
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800114 DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length);
aimitakeshid074e302010-07-29 10:12:27 +0900115
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +0900116 DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
117
Takeshi Aimidc549d62010-09-20 23:40:41 +0900118 status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
aimitakeshid074e302010-07-29 10:12:27 +0900119
Takeshi Aimidc549d62010-09-20 23:40:41 +0900120 status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshid074e302010-07-29 10:12:27 +0900121 int decryptUnitId, const DrmBuffer* headerInfo);
122
Takeshi Aimidc549d62010-09-20 23:40:41 +0900123 status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
124 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
aimitakeshid074e302010-07-29 10:12:27 +0900125
Takeshi Aimidc549d62010-09-20 23:40:41 +0900126 status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900127
128 ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800129 void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshid074e302010-07-29 10:12:27 +0900130
131 void onInfo(const DrmInfoEvent& event);
132
133private:
134 String8 getSupportedPlugInId(int uniqueId, const String8& path, const String8& mimeType);
135
136 String8 getSupportedPlugInId(const String8& mimeType);
137
138 String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path);
139
aimitakeshid074e302010-07-29 10:12:27 +0900140 bool canHandle(int uniqueId, const String8& path);
141
aimitakeshid074e302010-07-29 10:12:27 +0900142private:
Gloria Wang5c96c652011-03-15 10:52:28 -0700143 Vector<int> mUniqueIdVector;
aimitakeshid074e302010-07-29 10:12:27 +0900144 static const String8 EMPTY_STRING;
145
146 int mDecryptSessionId;
147 int mConvertId;
148 Mutex mLock;
Gloria Wang192b5912011-03-11 14:07:21 -0800149 Mutex mListenerLock;
aimitakeshid074e302010-07-29 10:12:27 +0900150 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