blob: dc3e4606eaaf13444e7644b744339e493dde0e32 [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;
33class DrmContentIds;
34class DrmConstraints;
35class 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 Aimi2272ee22010-09-20 23:40:41 +090056 int addUniqueId(int uniqueId);
57
58 void removeUniqueId(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090059
60 status_t loadPlugIns(int uniqueId);
61
62 status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
63
64 status_t setDrmServiceListener(
65 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
66
67 status_t unloadPlugIns(int uniqueId);
68
69 status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
70
71 DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
72
73 bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
74
75 DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
76
77 DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
78
Takeshi Aimi2272ee22010-09-20 23:40:41 +090079 status_t saveRights(int uniqueId, const DrmRights& drmRights,
aimitakeshi27ed8ad2010-07-29 10:12:27 +090080 const String8& rightsPath, const String8& contentPath);
81
82 String8 getOriginalMimeType(int uniqueId, const String8& path);
83
84 int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
85
86 int checkRightsStatus(int uniqueId, const String8& path, int action);
87
Takeshi Aimi2272ee22010-09-20 23:40:41 +090088 status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090089
Takeshi Aimi2272ee22010-09-20 23:40:41 +090090 status_t setPlaybackStatus(
aimitakeshi27ed8ad2010-07-29 10:12:27 +090091 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
92
93 bool validateAction(
94 int uniqueId, const String8& path, int action, const ActionDescription& description);
95
Takeshi Aimi2272ee22010-09-20 23:40:41 +090096 status_t removeRights(int uniqueId, const String8& path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090097
Takeshi Aimi2272ee22010-09-20 23:40:41 +090098 status_t removeAllRights(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090099
100 int openConvertSession(int uniqueId, const String8& mimeType);
101
102 DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
103
104 DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
105
106 status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
107
108 DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
109
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900110 status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900111
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900112 status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900113 int decryptUnitId, const DrmBuffer* headerInfo);
114
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900115 status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
116 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900117
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900118 status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900119
120 ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
121 void* buffer, ssize_t numBytes, off_t offset);
122
123 void onInfo(const DrmInfoEvent& event);
124
125private:
126 String8 getSupportedPlugInId(int uniqueId, const String8& path, const String8& mimeType);
127
128 String8 getSupportedPlugInId(const String8& mimeType);
129
130 String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path);
131
132 void populate(int uniqueId);
133
134 bool canHandle(int uniqueId, const String8& path);
135
136 void initializePlugIns(int uniqueId);
137
138private:
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900139 static Vector<int> mUniqueIdVector;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900140 static const String8 EMPTY_STRING;
141
142 int mDecryptSessionId;
143 int mConvertId;
144 Mutex mLock;
145 Mutex mDecryptLock;
146 Mutex mConvertLock;
147 TPlugInManager<IDrmEngine> mPlugInManager;
148 KeyedVector< DrmSupportInfo, String8 > mSupportInfoToPlugInIdMap;
149 KeyedVector< int, IDrmEngine*> mConvertSessionMap;
150 KeyedVector< int, sp<IDrmServiceListener> > mServiceListeners;
151 KeyedVector< int, IDrmEngine*> mDecryptSessionMap;
152};
153
154};
155
156#endif /* __DRM_MANAGER_H__ */
157