blob: e6ba3c470ce093a533bb881a27e49867c46709bc [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_CLIENT_H__
18#define __DRM_MANAGER_CLIENT_H__
19
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090020#include <utils/threads.h>
aimitakeshid074e302010-07-29 10:12:27 +090021#include <binder/IInterface.h>
22#include "drm_framework_common.h"
23
24namespace android {
25
26class DrmInfo;
27class DrmRights;
Takeshi Aimidc9186562010-11-16 13:56:11 +090028class DrmMetadata;
aimitakeshid074e302010-07-29 10:12:27 +090029class DrmInfoEvent;
30class DrmInfoStatus;
31class DrmInfoRequest;
32class DrmSupportInfo;
33class DrmConstraints;
34class DrmConvertedStatus;
35class DrmManagerClientImpl;
36
37/**
38 * The Native application will instantiate this class and access DRM Framework
39 * services through this class.
40 *
41 */
42class DrmManagerClient {
43public:
44 DrmManagerClient();
45
46 virtual ~DrmManagerClient();
47
48public:
49 class OnInfoListener: virtual public RefBase {
50
51 public:
52 virtual void onInfo(const DrmInfoEvent& event) = 0;
53 };
54
55/**
56 * APIs which will be used by native modules (e.g. StageFright)
57 *
58 */
59public:
60 /**
61 * Open the decrypt session to decrypt the given protected content
62 *
63 * @param[in] fd File descriptor of the protected content to be decrypted
64 * @param[in] offset Start position of the content
65 * @param[in] length The length of the protected content
66 * @return
67 * Handle for the decryption session
68 */
Gloria Wang5fc3edb2010-11-19 15:19:36 -080069 DecryptHandle* openDecryptSession(int fd, off64_t offset, off64_t length);
aimitakeshid074e302010-07-29 10:12:27 +090070
71 /**
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090072 * Open the decrypt session to decrypt the given protected content
73 *
74 * @param[in] uri Path of the protected content to be decrypted
75 * @return
76 * Handle for the decryption session
77 */
78 DecryptHandle* openDecryptSession(const char* uri);
79
80 /**
aimitakeshid074e302010-07-29 10:12:27 +090081 * Close the decrypt session for the given handle
82 *
83 * @param[in] decryptHandle Handle for the decryption session
Takeshi Aimidc549d62010-09-20 23:40:41 +090084 * @return status_t
85 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +090086 */
Takeshi Aimidc549d62010-09-20 23:40:41 +090087 status_t closeDecryptSession(DecryptHandle* decryptHandle);
aimitakeshid074e302010-07-29 10:12:27 +090088
89 /**
90 * Consumes the rights for a content.
91 * If the reserve parameter is true the rights is reserved until the same
92 * application calls this api again with the reserve parameter set to false.
93 *
94 * @param[in] decryptHandle Handle for the decryption session
95 * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
96 * @param[in] reserve True if the rights should be reserved.
Takeshi Aimidc549d62010-09-20 23:40:41 +090097 * @return status_t
98 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure.
99 * In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned.
aimitakeshid074e302010-07-29 10:12:27 +0900100 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900101 status_t consumeRights(DecryptHandle* decryptHandle, int action, bool reserve);
aimitakeshid074e302010-07-29 10:12:27 +0900102
103 /**
104 * Informs the DRM engine about the playback actions performed on the DRM files.
105 *
106 * @param[in] decryptHandle Handle for the decryption session
107 * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
108 * @param[in] position Position in the file (in milliseconds) where the start occurs.
Takeshi Aimidc549d62010-09-20 23:40:41 +0900109 * Only valid together with Playback::START.
110 * @return status_t
111 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900112 */
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800113 status_t setPlaybackStatus(DecryptHandle* decryptHandle, int playbackStatus, int64_t position);
aimitakeshid074e302010-07-29 10:12:27 +0900114
115 /**
116 * Initialize decryption for the given unit of the protected content
117 *
118 * @param[in] decryptHandle Handle for the decryption session
119 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
120 * @param[in] headerInfo Information for initializing decryption of this decrypUnit
Takeshi Aimidc549d62010-09-20 23:40:41 +0900121 * @return status_t
122 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900123 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900124 status_t initializeDecryptUnit(
aimitakeshid074e302010-07-29 10:12:27 +0900125 DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo);
126
127 /**
128 * Decrypt the protected content buffers for the given unit
129 * This method will be called any number of times, based on number of
130 * encrypted streams received from application.
131 *
132 * @param[in] decryptHandle Handle for the decryption session
133 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
134 * @param[in] encBuffer Encrypted data block
135 * @param[out] decBuffer Decrypted data block
Takeshi Aimidc549d62010-09-20 23:40:41 +0900136 * @param[in] IV Optional buffer
aimitakeshid074e302010-07-29 10:12:27 +0900137 * @return status_t
138 * Returns the error code for this API
139 * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
140 * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
141 * DRM_ERROR_DECRYPT for failure.
142 */
143 status_t decrypt(
144 DecryptHandle* decryptHandle, int decryptUnitId,
Takeshi Aimidc549d62010-09-20 23:40:41 +0900145 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL);
aimitakeshid074e302010-07-29 10:12:27 +0900146
147 /**
148 * Finalize decryption for the given unit of the protected content
149 *
150 * @param[in] decryptHandle Handle for the decryption session
151 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
Takeshi Aimidc549d62010-09-20 23:40:41 +0900152 * @return status_t
153 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900154 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900155 status_t finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900156
157 /**
158 * Reads the specified number of bytes from an open DRM file.
159 *
160 * @param[in] decryptHandle Handle for the decryption session
161 * @param[out] buffer Reference to the buffer that should receive the read data.
162 * @param[in] numBytes Number of bytes to read.
163 * @param[in] offset Offset with which to update the file position.
164 *
165 * @return Number of bytes read. Returns -1 for Failure.
166 */
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800167 ssize_t pread(DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshid074e302010-07-29 10:12:27 +0900168
169 /**
170 * Validates whether an action on the DRM content is allowed or not.
171 *
172 * @param[in] path Path of the protected content
173 * @param[in] action Action to validate. (Action::DEFAULT, Action::PLAY, etc)
174 * @param[in] description Detailed description of the action
175 * @return true if the action is allowed.
176 */
177 bool validateAction(const String8& path, int action, const ActionDescription& description);
178
179/**
180 * APIs which are just the underlying implementation for the Java API
181 *
182 */
183public:
184 /**
185 * Register a callback to be invoked when the caller required to
186 * receive necessary information
187 *
188 * @param[in] infoListener Listener
189 * @return status_t
190 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
191 */
192 status_t setOnInfoListener(const sp<DrmManagerClient::OnInfoListener>& infoListener);
193
194 /**
195 * Get constraint information associated with input content
196 *
197 * @param[in] path Path of the protected content
198 * @param[in] action Actions defined such as,
199 * Action::DEFAULT, Action::PLAY, etc
200 * @return DrmConstraints
201 * key-value pairs of constraint are embedded in it
202 * @note
203 * In case of error, return NULL
204 */
205 DrmConstraints* getConstraints(const String8* path, const int action);
206
207 /**
Takeshi Aimidc9186562010-11-16 13:56:11 +0900208 * Get metadata information associated with input content
209 *
210 * @param[in] path Path of the protected content
211 * @return DrmMetadata
212 * key-value pairs of metadata
213 * @note
214 * In case of error, return NULL
215 */
216 DrmMetadata* getMetadata(const String8* path);
217
218 /**
aimitakeshid074e302010-07-29 10:12:27 +0900219 * Check whether the given mimetype or path can be handled
220 *
221 * @param[in] path Path of the content needs to be handled
222 * @param[in] mimetype Mimetype of the content needs to be handled
223 * @return
224 * True if DrmManager can handle given path or mime type.
225 */
226 bool canHandle(const String8& path, const String8& mimeType);
227
228 /**
229 * Executes given drm information based on its type
230 *
231 * @param[in] drmInfo Information needs to be processed
232 * @return DrmInfoStatus
233 * instance as a result of processing given input
234 */
235 DrmInfoStatus* processDrmInfo(const DrmInfo* drmInfo);
236
237 /**
238 * Retrieves necessary information for registration, unregistration or rights
239 * acquisition information.
240 *
241 * @param[in] drmInfoRequest Request information to retrieve drmInfo
242 * @return DrmInfo
243 * instance as a result of processing given input
244 */
245 DrmInfo* acquireDrmInfo(const DrmInfoRequest* drmInfoRequest);
246
247 /**
248 * Save DRM rights to specified rights path
249 * and make association with content path
250 *
251 * @param[in] drmRights DrmRights to be saved
252 * @param[in] rightsPath File path where rights to be saved
253 * @param[in] contentPath File path where content was saved
Takeshi Aimidc549d62010-09-20 23:40:41 +0900254 * @return status_t
255 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900256 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900257 status_t saveRights(
aimitakeshid074e302010-07-29 10:12:27 +0900258 const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath);
259
260 /**
261 * Retrieves the mime type embedded inside the original content
262 *
263 * @param[in] path the path of the protected content
264 * @return String8
265 * Returns mime-type of the original content, such as "video/mpeg"
266 */
267 String8 getOriginalMimeType(const String8& path);
268
269 /**
270 * Retrieves the type of the protected object (content, rights, etc..)
271 * by using specified path or mimetype. At least one parameter should be non null
272 * to retrieve DRM object type
273 *
274 * @param[in] path Path of the content or null.
275 * @param[in] mimeType Mime type of the content or null.
276 * @return type of the DRM content,
277 * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
278 */
279 int getDrmObjectType(const String8& path, const String8& mimeType);
280
281 /**
282 * Check whether the given content has valid rights or not
283 *
284 * @param[in] path Path of the protected content
285 * @param[in] action Action to perform
286 * @return the status of the rights for the protected content,
287 * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
288 */
289 int checkRightsStatus(const String8& path, int action);
290
291 /**
292 * Removes the rights associated with the given protected content
293 *
294 * @param[in] path Path of the protected content
Takeshi Aimidc549d62010-09-20 23:40:41 +0900295 * @return status_t
296 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900297 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900298 status_t removeRights(const String8& path);
aimitakeshid074e302010-07-29 10:12:27 +0900299
300 /**
301 * Removes all the rights information of each plug-in associated with
302 * DRM framework. Will be used in master reset
303 *
Takeshi Aimidc549d62010-09-20 23:40:41 +0900304 * @return status_t
305 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900306 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900307 status_t removeAllRights();
aimitakeshid074e302010-07-29 10:12:27 +0900308
309 /**
310 * This API is for Forward Lock DRM.
311 * Each time the application tries to download a new DRM file
312 * which needs to be converted, then the application has to
313 * begin with calling this API.
314 *
315 * @param[in] convertId Handle for the convert session
316 * @param[in] mimeType Description/MIME type of the input data packet
317 * @return Return handle for the convert session
318 */
319 int openConvertSession(const String8& mimeType);
320
321 /**
322 * Passes the input data which need to be converted. The resultant
323 * converted data and the status is returned in the DrmConvertedInfo
324 * object. This method will be called each time there are new block
325 * of data received by the application.
326 *
327 * @param[in] convertId Handle for the convert session
328 * @param[in] inputData Input Data which need to be converted
329 * @return Return object contains the status of the data conversion,
330 * the output converted data and offset. In this case the
331 * application will ignore the offset information.
332 */
333 DrmConvertedStatus* convertData(int convertId, const DrmBuffer* inputData);
334
335 /**
336 * When there is no more data which need to be converted or when an
337 * error occurs that time the application has to inform the Drm agent
338 * via this API. Upon successful conversion of the complete data,
339 * the agent will inform that where the header and body signature
340 * should be added. This signature appending is needed to integrity
341 * protect the converted file.
342 *
343 * @param[in] convertId Handle for the convert session
344 * @return Return object contains the status of the data conversion,
345 * the header and body signature data. It also informs
346 * the application on which offset these signature data
347 * should be appended.
348 */
349 DrmConvertedStatus* closeConvertSession(int convertId);
350
351 /**
352 * Retrieves all DrmSupportInfo instance that native DRM framework can handle.
353 * This interface is meant to be used by JNI layer
354 *
355 * @param[out] length Number of elements in drmSupportInfoArray
356 * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo
357 * that native DRM framework can handle
358 * @return status_t
359 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
360 */
361 status_t getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray);
362
363private:
aimitakeshid074e302010-07-29 10:12:27 +0900364 int mUniqueId;
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +0900365 Mutex mDecryptLock;
aimitakeshid074e302010-07-29 10:12:27 +0900366 DrmManagerClientImpl* mDrmManagerClientImpl;
367};
368
369};
370
371#endif /* __DRM_MANAGER_CLIENT_H__ */
372