blob: 12142bce1ca751195d65cc236da775e85f567e3e [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:
Takeshi Aimif05913a2010-11-30 16:27:42 +090052 virtual ~OnInfoListener() {}
53
54 public:
aimitakeshid074e302010-07-29 10:12:27 +090055 virtual void onInfo(const DrmInfoEvent& event) = 0;
56 };
57
58/**
59 * APIs which will be used by native modules (e.g. StageFright)
60 *
61 */
62public:
63 /**
64 * Open the decrypt session to decrypt the given protected content
65 *
66 * @param[in] fd File descriptor of the protected content to be decrypted
67 * @param[in] offset Start position of the content
68 * @param[in] length The length of the protected content
69 * @return
70 * Handle for the decryption session
71 */
Gloria Wang5fc3edb2010-11-19 15:19:36 -080072 DecryptHandle* openDecryptSession(int fd, off64_t offset, off64_t length);
aimitakeshid074e302010-07-29 10:12:27 +090073
74 /**
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090075 * Open the decrypt session to decrypt the given protected content
76 *
77 * @param[in] uri Path of the protected content to be decrypted
78 * @return
79 * Handle for the decryption session
80 */
81 DecryptHandle* openDecryptSession(const char* uri);
82
83 /**
aimitakeshid074e302010-07-29 10:12:27 +090084 * Close the decrypt session for the given handle
85 *
86 * @param[in] decryptHandle Handle for the decryption session
Takeshi Aimidc549d62010-09-20 23:40:41 +090087 * @return status_t
88 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +090089 */
Takeshi Aimidc549d62010-09-20 23:40:41 +090090 status_t closeDecryptSession(DecryptHandle* decryptHandle);
aimitakeshid074e302010-07-29 10:12:27 +090091
92 /**
93 * Consumes the rights for a content.
94 * If the reserve parameter is true the rights is reserved until the same
95 * application calls this api again with the reserve parameter set to false.
96 *
97 * @param[in] decryptHandle Handle for the decryption session
98 * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
99 * @param[in] reserve True if the rights should be reserved.
Takeshi Aimidc549d62010-09-20 23:40:41 +0900100 * @return status_t
101 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure.
102 * In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned.
aimitakeshid074e302010-07-29 10:12:27 +0900103 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900104 status_t consumeRights(DecryptHandle* decryptHandle, int action, bool reserve);
aimitakeshid074e302010-07-29 10:12:27 +0900105
106 /**
107 * Informs the DRM engine about the playback actions performed on the DRM files.
108 *
109 * @param[in] decryptHandle Handle for the decryption session
110 * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
111 * @param[in] position Position in the file (in milliseconds) where the start occurs.
Takeshi Aimidc549d62010-09-20 23:40:41 +0900112 * Only valid together with Playback::START.
113 * @return status_t
114 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900115 */
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800116 status_t setPlaybackStatus(DecryptHandle* decryptHandle, int playbackStatus, int64_t position);
aimitakeshid074e302010-07-29 10:12:27 +0900117
118 /**
119 * Initialize decryption for the given unit of the protected content
120 *
121 * @param[in] decryptHandle Handle for the decryption session
122 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
123 * @param[in] headerInfo Information for initializing decryption of this decrypUnit
Takeshi Aimidc549d62010-09-20 23:40:41 +0900124 * @return status_t
125 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900126 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900127 status_t initializeDecryptUnit(
aimitakeshid074e302010-07-29 10:12:27 +0900128 DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo);
129
130 /**
131 * Decrypt the protected content buffers for the given unit
132 * This method will be called any number of times, based on number of
133 * encrypted streams received from application.
134 *
135 * @param[in] decryptHandle Handle for the decryption session
136 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
137 * @param[in] encBuffer Encrypted data block
138 * @param[out] decBuffer Decrypted data block
Takeshi Aimidc549d62010-09-20 23:40:41 +0900139 * @param[in] IV Optional buffer
aimitakeshid074e302010-07-29 10:12:27 +0900140 * @return status_t
141 * Returns the error code for this API
142 * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
143 * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
144 * DRM_ERROR_DECRYPT for failure.
145 */
146 status_t decrypt(
147 DecryptHandle* decryptHandle, int decryptUnitId,
Takeshi Aimidc549d62010-09-20 23:40:41 +0900148 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL);
aimitakeshid074e302010-07-29 10:12:27 +0900149
150 /**
151 * Finalize decryption for the given unit of the protected content
152 *
153 * @param[in] decryptHandle Handle for the decryption session
154 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
Takeshi Aimidc549d62010-09-20 23:40:41 +0900155 * @return status_t
156 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900157 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900158 status_t finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900159
160 /**
161 * Reads the specified number of bytes from an open DRM file.
162 *
163 * @param[in] decryptHandle Handle for the decryption session
164 * @param[out] buffer Reference to the buffer that should receive the read data.
165 * @param[in] numBytes Number of bytes to read.
166 * @param[in] offset Offset with which to update the file position.
167 *
168 * @return Number of bytes read. Returns -1 for Failure.
169 */
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800170 ssize_t pread(DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshid074e302010-07-29 10:12:27 +0900171
172 /**
173 * Validates whether an action on the DRM content is allowed or not.
174 *
175 * @param[in] path Path of the protected content
176 * @param[in] action Action to validate. (Action::DEFAULT, Action::PLAY, etc)
177 * @param[in] description Detailed description of the action
178 * @return true if the action is allowed.
179 */
180 bool validateAction(const String8& path, int action, const ActionDescription& description);
181
182/**
183 * APIs which are just the underlying implementation for the Java API
184 *
185 */
186public:
187 /**
188 * Register a callback to be invoked when the caller required to
189 * receive necessary information
190 *
191 * @param[in] infoListener Listener
192 * @return status_t
193 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
194 */
195 status_t setOnInfoListener(const sp<DrmManagerClient::OnInfoListener>& infoListener);
196
197 /**
198 * Get constraint information associated with input content
199 *
200 * @param[in] path Path of the protected content
201 * @param[in] action Actions defined such as,
202 * Action::DEFAULT, Action::PLAY, etc
203 * @return DrmConstraints
204 * key-value pairs of constraint are embedded in it
205 * @note
206 * In case of error, return NULL
207 */
208 DrmConstraints* getConstraints(const String8* path, const int action);
209
210 /**
Takeshi Aimidc9186562010-11-16 13:56:11 +0900211 * Get metadata information associated with input content
212 *
213 * @param[in] path Path of the protected content
214 * @return DrmMetadata
215 * key-value pairs of metadata
216 * @note
217 * In case of error, return NULL
218 */
219 DrmMetadata* getMetadata(const String8* path);
220
221 /**
aimitakeshid074e302010-07-29 10:12:27 +0900222 * Check whether the given mimetype or path can be handled
223 *
224 * @param[in] path Path of the content needs to be handled
225 * @param[in] mimetype Mimetype of the content needs to be handled
226 * @return
227 * True if DrmManager can handle given path or mime type.
228 */
229 bool canHandle(const String8& path, const String8& mimeType);
230
231 /**
232 * Executes given drm information based on its type
233 *
234 * @param[in] drmInfo Information needs to be processed
235 * @return DrmInfoStatus
236 * instance as a result of processing given input
237 */
238 DrmInfoStatus* processDrmInfo(const DrmInfo* drmInfo);
239
240 /**
241 * Retrieves necessary information for registration, unregistration or rights
242 * acquisition information.
243 *
244 * @param[in] drmInfoRequest Request information to retrieve drmInfo
245 * @return DrmInfo
246 * instance as a result of processing given input
247 */
248 DrmInfo* acquireDrmInfo(const DrmInfoRequest* drmInfoRequest);
249
250 /**
251 * Save DRM rights to specified rights path
252 * and make association with content path
253 *
254 * @param[in] drmRights DrmRights to be saved
255 * @param[in] rightsPath File path where rights to be saved
256 * @param[in] contentPath File path where content was saved
Takeshi Aimidc549d62010-09-20 23:40:41 +0900257 * @return status_t
258 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900259 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900260 status_t saveRights(
aimitakeshid074e302010-07-29 10:12:27 +0900261 const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath);
262
263 /**
264 * Retrieves the mime type embedded inside the original content
265 *
266 * @param[in] path the path of the protected content
267 * @return String8
268 * Returns mime-type of the original content, such as "video/mpeg"
269 */
270 String8 getOriginalMimeType(const String8& path);
271
272 /**
273 * Retrieves the type of the protected object (content, rights, etc..)
274 * by using specified path or mimetype. At least one parameter should be non null
275 * to retrieve DRM object type
276 *
277 * @param[in] path Path of the content or null.
278 * @param[in] mimeType Mime type of the content or null.
279 * @return type of the DRM content,
280 * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
281 */
282 int getDrmObjectType(const String8& path, const String8& mimeType);
283
284 /**
285 * Check whether the given content has valid rights or not
286 *
287 * @param[in] path Path of the protected content
288 * @param[in] action Action to perform
289 * @return the status of the rights for the protected content,
290 * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
291 */
292 int checkRightsStatus(const String8& path, int action);
293
294 /**
295 * Removes the rights associated with the given protected content
296 *
297 * @param[in] path Path of the protected content
Takeshi Aimidc549d62010-09-20 23:40:41 +0900298 * @return status_t
299 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900300 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900301 status_t removeRights(const String8& path);
aimitakeshid074e302010-07-29 10:12:27 +0900302
303 /**
304 * Removes all the rights information of each plug-in associated with
305 * DRM framework. Will be used in master reset
306 *
Takeshi Aimidc549d62010-09-20 23:40:41 +0900307 * @return status_t
308 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900309 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900310 status_t removeAllRights();
aimitakeshid074e302010-07-29 10:12:27 +0900311
312 /**
313 * This API is for Forward Lock DRM.
314 * Each time the application tries to download a new DRM file
315 * which needs to be converted, then the application has to
316 * begin with calling this API.
317 *
318 * @param[in] convertId Handle for the convert session
319 * @param[in] mimeType Description/MIME type of the input data packet
320 * @return Return handle for the convert session
321 */
322 int openConvertSession(const String8& mimeType);
323
324 /**
325 * Passes the input data which need to be converted. The resultant
326 * converted data and the status is returned in the DrmConvertedInfo
327 * object. This method will be called each time there are new block
328 * of data received by the application.
329 *
330 * @param[in] convertId Handle for the convert session
331 * @param[in] inputData Input Data which need to be converted
332 * @return Return object contains the status of the data conversion,
333 * the output converted data and offset. In this case the
334 * application will ignore the offset information.
335 */
336 DrmConvertedStatus* convertData(int convertId, const DrmBuffer* inputData);
337
338 /**
339 * When there is no more data which need to be converted or when an
340 * error occurs that time the application has to inform the Drm agent
341 * via this API. Upon successful conversion of the complete data,
342 * the agent will inform that where the header and body signature
343 * should be added. This signature appending is needed to integrity
344 * protect the converted file.
345 *
346 * @param[in] convertId Handle for the convert session
347 * @return Return object contains the status of the data conversion,
348 * the header and body signature data. It also informs
349 * the application on which offset these signature data
350 * should be appended.
351 */
352 DrmConvertedStatus* closeConvertSession(int convertId);
353
354 /**
355 * Retrieves all DrmSupportInfo instance that native DRM framework can handle.
356 * This interface is meant to be used by JNI layer
357 *
358 * @param[out] length Number of elements in drmSupportInfoArray
359 * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo
360 * that native DRM framework can handle
361 * @return status_t
362 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
363 */
364 status_t getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray);
365
366private:
aimitakeshid074e302010-07-29 10:12:27 +0900367 int mUniqueId;
aimitakeshid074e302010-07-29 10:12:27 +0900368 DrmManagerClientImpl* mDrmManagerClientImpl;
369};
370
371};
372
373#endif /* __DRM_MANAGER_CLIENT_H__ */
374