DrmManager.h revision 27ed8ad2db653f6ac07dcf8bcc05e2409c8bb024
1/*
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:
56
57    status_t loadPlugIns(int uniqueId);
58
59    status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
60
61    status_t setDrmServiceListener(
62            int uniqueId, const sp<IDrmServiceListener>& drmServiceListener);
63
64    status_t unloadPlugIns(int uniqueId);
65
66    status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
67
68    DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
69
70    bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
71
72    DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
73
74    DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
75
76    void saveRights(int uniqueId, const DrmRights& drmRights,
77            const String8& rightsPath, const String8& contentPath);
78
79    String8 getOriginalMimeType(int uniqueId, const String8& path);
80
81    int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
82
83    int checkRightsStatus(int uniqueId, const String8& path, int action);
84
85    void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
86
87    void setPlaybackStatus(
88            int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
89
90    bool validateAction(
91            int uniqueId, const String8& path, int action, const ActionDescription& description);
92
93    void removeRights(int uniqueId, const String8& path);
94
95    void removeAllRights(int uniqueId);
96
97    int openConvertSession(int uniqueId, const String8& mimeType);
98
99    DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
100
101    DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
102
103    status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
104
105    DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
106
107    void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
108
109    void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
110            int decryptUnitId, const DrmBuffer* headerInfo);
111
112    status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
113            int decryptUnitId, const DrmBuffer* encBuffer,DrmBuffer** decBuffer);
114
115    void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
116
117    ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
118            void* buffer, ssize_t numBytes, off_t offset);
119
120    void onInfo(const DrmInfoEvent& event);
121
122private:
123    String8 getSupportedPlugInId(int uniqueId, const String8& path, const String8& mimeType);
124
125    String8 getSupportedPlugInId(const String8& mimeType);
126
127    String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path);
128
129    void populate(int uniqueId);
130
131    bool canHandle(int uniqueId, const String8& path);
132
133    void initializePlugIns(int uniqueId);
134
135private:
136    static const String8 EMPTY_STRING;
137
138    int mDecryptSessionId;
139    int mConvertId;
140    Mutex mLock;
141    Mutex mDecryptLock;
142    Mutex mConvertLock;
143    TPlugInManager<IDrmEngine> mPlugInManager;
144    KeyedVector< DrmSupportInfo, String8 > mSupportInfoToPlugInIdMap;
145    KeyedVector< int, IDrmEngine*> mConvertSessionMap;
146    KeyedVector< int, sp<IDrmServiceListener> > mServiceListeners;
147    KeyedVector< int, IDrmEngine*> mDecryptSessionMap;
148};
149
150};
151
152#endif /* __DRM_MANAGER_H__ */
153
154