blob: 52527dcf4fdef1de2865962cdbf0dcf8f00de512 [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
Takeshi Aimidc549d62010-09-20 23:40:41 +090017//#define LOG_NDEBUG 0
aimitakeshid074e302010-07-29 10:12:27 +090018#define LOG_TAG "DrmManager(Native)"
19#include "utils/Log.h"
20
21#include <utils/String8.h>
22#include <drm/DrmInfo.h>
23#include <drm/DrmInfoEvent.h>
24#include <drm/DrmRights.h>
25#include <drm/DrmConstraints.h>
26#include <drm/DrmInfoStatus.h>
27#include <drm/DrmInfoRequest.h>
28#include <drm/DrmSupportInfo.h>
29#include <drm/DrmConvertedStatus.h>
30#include <IDrmEngine.h>
31
32#include "DrmManager.h"
33#include "ReadWriteUtils.h"
34
35#define DECRYPT_FILE_ERROR -1
36
37using namespace android;
38
Takeshi Aimidc549d62010-09-20 23:40:41 +090039Vector<int> DrmManager::mUniqueIdVector;
aimitakeshid074e302010-07-29 10:12:27 +090040const String8 DrmManager::EMPTY_STRING("");
41
42DrmManager::DrmManager() :
43 mDecryptSessionId(0),
44 mConvertId(0) {
45
46}
47
48DrmManager::~DrmManager() {
49
50}
51
Takeshi Aimidc549d62010-09-20 23:40:41 +090052int DrmManager::addUniqueId(int uniqueId) {
53 if (0 == uniqueId) {
54 int temp = 0;
55 bool foundUniqueId = false;
56 srand(time(NULL));
57
58 while (!foundUniqueId) {
59 const int size = mUniqueIdVector.size();
60 temp = rand() % 100;
61
62 int index = 0;
63 for (; index < size; ++index) {
64 if (mUniqueIdVector.itemAt(index) == temp) {
65 foundUniqueId = false;
66 break;
67 }
68 }
69 if (index == size) {
70 foundUniqueId = true;
71 }
72 }
73 uniqueId = temp;
74 }
75 mUniqueIdVector.push(uniqueId);
76 return uniqueId;
77}
78
79void DrmManager::removeUniqueId(int uniqueId) {
80 for (unsigned int i = 0; i < mUniqueIdVector.size(); i++) {
81 if (uniqueId == mUniqueIdVector.itemAt(i)) {
82 mUniqueIdVector.removeAt(i);
83 break;
84 }
85 }
86}
87
aimitakeshid074e302010-07-29 10:12:27 +090088status_t DrmManager::loadPlugIns(int uniqueId) {
89 String8 pluginDirPath("/system/lib/drm/plugins/native");
90 return loadPlugIns(uniqueId, pluginDirPath);
91}
92
93status_t DrmManager::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
94 if (mSupportInfoToPlugInIdMap.isEmpty()) {
95 mPlugInManager.loadPlugIns(plugInDirPath);
96
97 initializePlugIns(uniqueId);
98
99 populate(uniqueId);
100 } else {
101 initializePlugIns(uniqueId);
102 }
103
104 return DRM_NO_ERROR;
105}
106
107status_t DrmManager::setDrmServiceListener(
108 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
109 Mutex::Autolock _l(mLock);
110 mServiceListeners.add(uniqueId, drmServiceListener);
111 return DRM_NO_ERROR;
112}
113
114status_t DrmManager::unloadPlugIns(int uniqueId) {
115 Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
116
117 for (unsigned int index = 0; index < plugInIdList.size(); index++) {
118 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
119 rDrmEngine.terminate(uniqueId);
120 }
121
Takeshi Aimidc549d62010-09-20 23:40:41 +0900122 if (0 >= mUniqueIdVector.size()) {
123 mConvertSessionMap.clear();
124 mDecryptSessionMap.clear();
125 mSupportInfoToPlugInIdMap.clear();
126 mPlugInManager.unloadPlugIns();
127 }
aimitakeshid074e302010-07-29 10:12:27 +0900128 return DRM_NO_ERROR;
129}
130
131DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) {
132 const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path);
133 if (EMPTY_STRING != plugInId) {
134 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
135 return rDrmEngine.getConstraints(uniqueId, path, action);
136 }
137 return NULL;
138}
139
140status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) {
141 mPlugInManager.loadPlugIn(absolutePath);
142
143 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(absolutePath);
144 rDrmEngine.initialize(uniqueId);
145 rDrmEngine.setOnInfoListener(uniqueId, this);
146
147 DrmSupportInfo* info = rDrmEngine.getSupportInfo(uniqueId);
148 mSupportInfoToPlugInIdMap.add(*info, absolutePath);
149
150 return DRM_NO_ERROR;
151}
152
153bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
154 const String8 plugInId = getSupportedPlugInId(mimeType);
155 bool result = (EMPTY_STRING != plugInId) ? true : false;
156
157 if (NULL != path) {
158 if (result) {
159 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
160 result = rDrmEngine.canHandle(uniqueId, path);
161 } else {
162 result = canHandle(uniqueId, path);
163 }
164 }
165 return result;
166}
167
168DrmInfoStatus* DrmManager::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
169 const String8 plugInId = getSupportedPlugInId(drmInfo->getMimeType());
170 if (EMPTY_STRING != plugInId) {
171 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
172 return rDrmEngine.processDrmInfo(uniqueId, drmInfo);
173 }
174 return NULL;
175}
176
177bool DrmManager::canHandle(int uniqueId, const String8& path) {
178 bool result = false;
179 Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
180
181 for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
182 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInPathList[i]);
183 result = rDrmEngine.canHandle(uniqueId, path);
184
185 if (result) {
186 break;
187 }
188 }
189 return result;
190}
191
192DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
193 const String8 plugInId = getSupportedPlugInId(drmInfoRequest->getMimeType());
194 if (EMPTY_STRING != plugInId) {
195 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
196 return rDrmEngine.acquireDrmInfo(uniqueId, drmInfoRequest);
197 }
198 return NULL;
199}
200
Takeshi Aimidc549d62010-09-20 23:40:41 +0900201status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights,
aimitakeshid074e302010-07-29 10:12:27 +0900202 const String8& rightsPath, const String8& contentPath) {
203 const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType());
Takeshi Aimidc549d62010-09-20 23:40:41 +0900204 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900205 if (EMPTY_STRING != plugInId) {
206 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900207 result = rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath);
aimitakeshid074e302010-07-29 10:12:27 +0900208 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900209 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900210}
211
212String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) {
213 const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
214 if (EMPTY_STRING != plugInId) {
215 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
216 return rDrmEngine.getOriginalMimeType(uniqueId, path);
217 }
218 return EMPTY_STRING;
219}
220
221int DrmManager::getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) {
222 const String8 plugInId = getSupportedPlugInId(uniqueId, path, mimeType);
223 if (EMPTY_STRING != plugInId) {
224 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
225 return rDrmEngine.getDrmObjectType(uniqueId, path, mimeType);
226 }
227 return DrmObjectType::UNKNOWN;
228}
229
230int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) {
231 const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
232 if (EMPTY_STRING != plugInId) {
233 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
234 return rDrmEngine.checkRightsStatus(uniqueId, path, action);
235 }
236 return RightsStatus::RIGHTS_INVALID;
237}
238
Takeshi Aimidc549d62010-09-20 23:40:41 +0900239status_t DrmManager::consumeRights(
aimitakeshid074e302010-07-29 10:12:27 +0900240 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
Takeshi Aimidc549d62010-09-20 23:40:41 +0900241 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900242 if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
243 IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900244 result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshid074e302010-07-29 10:12:27 +0900245 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900246 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900247}
248
Takeshi Aimidc549d62010-09-20 23:40:41 +0900249status_t DrmManager::setPlaybackStatus(
aimitakeshid074e302010-07-29 10:12:27 +0900250 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
Takeshi Aimidc549d62010-09-20 23:40:41 +0900251 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900252 if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
253 IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900254 result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshid074e302010-07-29 10:12:27 +0900255 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900256 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900257}
258
259bool DrmManager::validateAction(
260 int uniqueId, const String8& path, int action, const ActionDescription& description) {
261 const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
262 if (EMPTY_STRING != plugInId) {
263 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
264 return rDrmEngine.validateAction(uniqueId, path, action, description);
265 }
266 return false;
267}
268
Takeshi Aimidc549d62010-09-20 23:40:41 +0900269status_t DrmManager::removeRights(int uniqueId, const String8& path) {
aimitakeshid074e302010-07-29 10:12:27 +0900270 const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900271 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900272 if (EMPTY_STRING != plugInId) {
273 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900274 result = rDrmEngine.removeRights(uniqueId, path);
aimitakeshid074e302010-07-29 10:12:27 +0900275 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900276 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900277}
278
Takeshi Aimidc549d62010-09-20 23:40:41 +0900279status_t DrmManager::removeAllRights(int uniqueId) {
aimitakeshid074e302010-07-29 10:12:27 +0900280 Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
Takeshi Aimidc549d62010-09-20 23:40:41 +0900281 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900282 for (unsigned int index = 0; index < plugInIdList.size(); index++) {
283 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
Takeshi Aimidc549d62010-09-20 23:40:41 +0900284 result = rDrmEngine.removeAllRights(uniqueId);
285 if (DRM_NO_ERROR != result) {
286 break;
287 }
aimitakeshid074e302010-07-29 10:12:27 +0900288 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900289 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900290}
291
292int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) {
293 int convertId = -1;
294
295 const String8 plugInId = getSupportedPlugInId(mimeType);
296 if (EMPTY_STRING != plugInId) {
297 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
298
Takeshi Aimidc549d62010-09-20 23:40:41 +0900299 if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) {
300 Mutex::Autolock _l(mConvertLock);
301 ++mConvertId;
302 convertId = mConvertId;
303 mConvertSessionMap.add(convertId, &rDrmEngine);
304 }
aimitakeshid074e302010-07-29 10:12:27 +0900305 }
306 return convertId;
307}
308
309DrmConvertedStatus* DrmManager::convertData(
310 int uniqueId, int convertId, const DrmBuffer* inputData) {
311 DrmConvertedStatus *drmConvertedStatus = NULL;
312
313 if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) {
314 IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId);
315 drmConvertedStatus = drmEngine->convertData(uniqueId, convertId, inputData);
316 }
317 return drmConvertedStatus;
318}
319
320DrmConvertedStatus* DrmManager::closeConvertSession(int uniqueId, int convertId) {
321 DrmConvertedStatus *drmConvertedStatus = NULL;
322
323 if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) {
324 IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId);
325 drmConvertedStatus = drmEngine->closeConvertSession(uniqueId, convertId);
326 mConvertSessionMap.removeItem(convertId);
327 }
328 return drmConvertedStatus;
329}
330
331status_t DrmManager::getAllSupportInfo(
332 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
333 Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
334 int size = plugInPathList.size();
335 int validPlugins = 0;
336
337 if (0 < size) {
338 Vector<DrmSupportInfo> drmSupportInfoList;
339
340 for (int i = 0; i < size; ++i) {
341 String8 plugInPath = plugInPathList[i];
342 DrmSupportInfo* drmSupportInfo
343 = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId);
344 if (NULL != drmSupportInfo) {
345 drmSupportInfoList.add(*drmSupportInfo);
346 delete drmSupportInfo; drmSupportInfo = NULL;
347 }
348 }
349
350 validPlugins = drmSupportInfoList.size();
351 if (0 < validPlugins) {
352 *drmSupportInfoArray = new DrmSupportInfo[validPlugins];
353 for (int i = 0; i < validPlugins; ++i) {
354 (*drmSupportInfoArray)[i] = drmSupportInfoList[i];
355 }
356 }
357 }
358 *length = validPlugins;
359 return DRM_NO_ERROR;
360}
361
362DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) {
aimitakeshid074e302010-07-29 10:12:27 +0900363 status_t result = DRM_ERROR_CANNOT_HANDLE;
364 Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
365
366 DecryptHandle* handle = new DecryptHandle();
367 if (NULL != handle) {
368 Mutex::Autolock _l(mDecryptLock);
369 handle->decryptId = mDecryptSessionId + 1;
370
371 for (unsigned int index = 0; index < plugInIdList.size(); index++) {
372 String8 plugInId = plugInIdList.itemAt(index);
373 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
374 result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length);
375
aimitakeshid074e302010-07-29 10:12:27 +0900376 if (DRM_NO_ERROR == result) {
377 ++mDecryptSessionId;
378 mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
aimitakeshid074e302010-07-29 10:12:27 +0900379 break;
380 }
381 }
382 }
383
Takeshi Aimidc549d62010-09-20 23:40:41 +0900384 if (DRM_NO_ERROR != result) {
aimitakeshid074e302010-07-29 10:12:27 +0900385 delete handle; handle = NULL;
386 LOGE("DrmManager::openDecryptSession: no capable plug-in found");
387 }
388
389 return handle;
390}
391
Takeshi Aimidc549d62010-09-20 23:40:41 +0900392status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
393 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900394 if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
395 IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900396 result = drmEngine->closeDecryptSession(uniqueId, decryptHandle);
397 if (DRM_NO_ERROR == result) {
398 mDecryptSessionMap.removeItem(decryptHandle->decryptId);
399 }
aimitakeshid074e302010-07-29 10:12:27 +0900400 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900401 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900402}
403
Takeshi Aimidc549d62010-09-20 23:40:41 +0900404status_t DrmManager::initializeDecryptUnit(
aimitakeshid074e302010-07-29 10:12:27 +0900405 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
Takeshi Aimidc549d62010-09-20 23:40:41 +0900406 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900407 if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
408 IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900409 result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo);
aimitakeshid074e302010-07-29 10:12:27 +0900410 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900411 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900412}
413
Takeshi Aimidc549d62010-09-20 23:40:41 +0900414status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
415 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
416 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900417 if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
418 IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900419 result = drmEngine->decrypt(
420 uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshid074e302010-07-29 10:12:27 +0900421 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900422 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900423}
424
Takeshi Aimidc549d62010-09-20 23:40:41 +0900425status_t DrmManager::finalizeDecryptUnit(
aimitakeshid074e302010-07-29 10:12:27 +0900426 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
Takeshi Aimidc549d62010-09-20 23:40:41 +0900427 status_t result = DRM_ERROR_UNKNOWN;
aimitakeshid074e302010-07-29 10:12:27 +0900428 if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
429 IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
Takeshi Aimidc549d62010-09-20 23:40:41 +0900430 result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900431 }
Takeshi Aimidc549d62010-09-20 23:40:41 +0900432 return result;
aimitakeshid074e302010-07-29 10:12:27 +0900433}
434
435ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle,
436 void* buffer, ssize_t numBytes, off_t offset) {
437 ssize_t result = DECRYPT_FILE_ERROR;
438
439 if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
440 IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
441 result = drmEngine->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
442 }
443 return result;
444}
445
446void DrmManager::initializePlugIns(int uniqueId) {
447 Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
448
449 for (unsigned int index = 0; index < plugInIdList.size(); index++) {
450 IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
451 rDrmEngine.initialize(uniqueId);
452 rDrmEngine.setOnInfoListener(uniqueId, this);
453 }
454}
455
456void DrmManager::populate(int uniqueId) {
457 Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
458
459 for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
460 String8 plugInPath = plugInPathList[i];
461 DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId);
462 if (NULL != info) {
463 mSupportInfoToPlugInIdMap.add(*info, plugInPath);
464 }
465 }
466}
467
468String8 DrmManager::getSupportedPlugInId(
469 int uniqueId, const String8& path, const String8& mimeType) {
470 String8 plugInId("");
471
472 if (EMPTY_STRING != mimeType) {
473 plugInId = getSupportedPlugInId(mimeType);
474 } else {
475 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
476 }
477 return plugInId;
478}
479
480String8 DrmManager::getSupportedPlugInId(const String8& mimeType) {
481 String8 plugInId("");
482
483 if (EMPTY_STRING != mimeType) {
484 for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) {
485 const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index);
486
487 if (drmSupportInfo.isSupportedMimeType(mimeType)) {
488 plugInId = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo);
489 break;
490 }
491 }
492 }
493 return plugInId;
494}
495
496String8 DrmManager::getSupportedPlugInIdFromPath(int uniqueId, const String8& path) {
497 String8 plugInId("");
498 const String8 fileSuffix = path.getPathExtension();
499
500 for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) {
501 const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index);
502
503 if (drmSupportInfo.isSupportedFileSuffix(fileSuffix)) {
504 String8 key = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo);
505 IDrmEngine& drmEngine = mPlugInManager.getPlugIn(key);
506
507 if (drmEngine.canHandle(uniqueId, path)) {
508 plugInId = key;
509 break;
510 }
511 }
512 }
513 return plugInId;
514}
515
516void DrmManager::onInfo(const DrmInfoEvent& event) {
517 Mutex::Autolock _l(mLock);
518 for (unsigned int index = 0; index < mServiceListeners.size(); index++) {
519 int uniqueId = mServiceListeners.keyAt(index);
520
521 if (uniqueId == event.getUniqueId()) {
522 sp<IDrmServiceListener> serviceListener = mServiceListeners.valueFor(uniqueId);
523 serviceListener->notify(event);
524 }
525 }
526}
527