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