blob: b8fe46d08e31a1b9704b42390ddf0b5af2cbd702 [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 Wangae775272011-02-24 16:40:57 -080072 sp<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 */
Gloria Wangae775272011-02-24 16:40:57 -080081 sp<DecryptHandle> openDecryptSession(const char* uri);
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090082
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 */
Gloria Wangae775272011-02-24 16:40:57 -080090 status_t closeDecryptSession(sp<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 */
Gloria Wangae775272011-02-24 16:40:57 -0800104 status_t consumeRights(sp<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 Wangae775272011-02-24 16:40:57 -0800116 status_t setPlaybackStatus(
117 sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position);
aimitakeshid074e302010-07-29 10:12:27 +0900118
119 /**
120 * Initialize decryption for the given unit of the protected content
121 *
122 * @param[in] decryptHandle Handle for the decryption session
123 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
124 * @param[in] headerInfo Information for initializing decryption of this decrypUnit
Takeshi Aimidc549d62010-09-20 23:40:41 +0900125 * @return status_t
126 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900127 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900128 status_t initializeDecryptUnit(
Gloria Wangae775272011-02-24 16:40:57 -0800129 sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo);
aimitakeshid074e302010-07-29 10:12:27 +0900130
131 /**
132 * Decrypt the protected content buffers for the given unit
133 * This method will be called any number of times, based on number of
134 * encrypted streams received from application.
135 *
136 * @param[in] decryptHandle Handle for the decryption session
137 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
138 * @param[in] encBuffer Encrypted data block
139 * @param[out] decBuffer Decrypted data block
Takeshi Aimidc549d62010-09-20 23:40:41 +0900140 * @param[in] IV Optional buffer
aimitakeshid074e302010-07-29 10:12:27 +0900141 * @return status_t
142 * Returns the error code for this API
143 * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
144 * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
145 * DRM_ERROR_DECRYPT for failure.
146 */
147 status_t decrypt(
Gloria Wangae775272011-02-24 16:40:57 -0800148 sp<DecryptHandle> &decryptHandle, int decryptUnitId,
Takeshi Aimidc549d62010-09-20 23:40:41 +0900149 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL);
aimitakeshid074e302010-07-29 10:12:27 +0900150
151 /**
152 * Finalize decryption for the given unit of the protected content
153 *
154 * @param[in] decryptHandle Handle for the decryption session
155 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
Takeshi Aimidc549d62010-09-20 23:40:41 +0900156 * @return status_t
157 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900158 */
Gloria Wangae775272011-02-24 16:40:57 -0800159 status_t finalizeDecryptUnit(
160 sp<DecryptHandle> &decryptHandle, int decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900161
162 /**
163 * Reads the specified number of bytes from an open DRM file.
164 *
165 * @param[in] decryptHandle Handle for the decryption session
166 * @param[out] buffer Reference to the buffer that should receive the read data.
167 * @param[in] numBytes Number of bytes to read.
168 * @param[in] offset Offset with which to update the file position.
169 *
170 * @return Number of bytes read. Returns -1 for Failure.
171 */
Gloria Wangae775272011-02-24 16:40:57 -0800172 ssize_t pread(sp<DecryptHandle> &decryptHandle,
173 void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshid074e302010-07-29 10:12:27 +0900174
175 /**
176 * Validates whether an action on the DRM content is allowed or not.
177 *
178 * @param[in] path Path of the protected content
179 * @param[in] action Action to validate. (Action::DEFAULT, Action::PLAY, etc)
180 * @param[in] description Detailed description of the action
181 * @return true if the action is allowed.
182 */
183 bool validateAction(const String8& path, int action, const ActionDescription& description);
184
185/**
186 * APIs which are just the underlying implementation for the Java API
187 *
188 */
189public:
190 /**
191 * Register a callback to be invoked when the caller required to
192 * receive necessary information
193 *
194 * @param[in] infoListener Listener
195 * @return status_t
196 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
197 */
198 status_t setOnInfoListener(const sp<DrmManagerClient::OnInfoListener>& infoListener);
199
200 /**
201 * Get constraint information associated with input content
202 *
203 * @param[in] path Path of the protected content
204 * @param[in] action Actions defined such as,
205 * Action::DEFAULT, Action::PLAY, etc
206 * @return DrmConstraints
207 * key-value pairs of constraint are embedded in it
208 * @note
209 * In case of error, return NULL
210 */
211 DrmConstraints* getConstraints(const String8* path, const int action);
212
213 /**
Takeshi Aimidc9186562010-11-16 13:56:11 +0900214 * Get metadata information associated with input content
215 *
216 * @param[in] path Path of the protected content
217 * @return DrmMetadata
218 * key-value pairs of metadata
219 * @note
220 * In case of error, return NULL
221 */
222 DrmMetadata* getMetadata(const String8* path);
223
224 /**
aimitakeshid074e302010-07-29 10:12:27 +0900225 * Check whether the given mimetype or path can be handled
226 *
227 * @param[in] path Path of the content needs to be handled
228 * @param[in] mimetype Mimetype of the content needs to be handled
229 * @return
230 * True if DrmManager can handle given path or mime type.
231 */
232 bool canHandle(const String8& path, const String8& mimeType);
233
234 /**
235 * Executes given drm information based on its type
236 *
237 * @param[in] drmInfo Information needs to be processed
238 * @return DrmInfoStatus
239 * instance as a result of processing given input
240 */
241 DrmInfoStatus* processDrmInfo(const DrmInfo* drmInfo);
242
243 /**
244 * Retrieves necessary information for registration, unregistration or rights
245 * acquisition information.
246 *
247 * @param[in] drmInfoRequest Request information to retrieve drmInfo
248 * @return DrmInfo
249 * instance as a result of processing given input
250 */
251 DrmInfo* acquireDrmInfo(const DrmInfoRequest* drmInfoRequest);
252
253 /**
254 * Save DRM rights to specified rights path
255 * and make association with content path
256 *
257 * @param[in] drmRights DrmRights to be saved
258 * @param[in] rightsPath File path where rights to be saved
259 * @param[in] contentPath File path where content was saved
Takeshi Aimidc549d62010-09-20 23:40:41 +0900260 * @return status_t
261 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900262 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900263 status_t saveRights(
aimitakeshid074e302010-07-29 10:12:27 +0900264 const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath);
265
266 /**
267 * Retrieves the mime type embedded inside the original content
268 *
269 * @param[in] path the path of the protected content
270 * @return String8
271 * Returns mime-type of the original content, such as "video/mpeg"
272 */
273 String8 getOriginalMimeType(const String8& path);
274
275 /**
276 * Retrieves the type of the protected object (content, rights, etc..)
277 * by using specified path or mimetype. At least one parameter should be non null
278 * to retrieve DRM object type
279 *
280 * @param[in] path Path of the content or null.
281 * @param[in] mimeType Mime type of the content or null.
282 * @return type of the DRM content,
283 * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
284 */
285 int getDrmObjectType(const String8& path, const String8& mimeType);
286
287 /**
288 * Check whether the given content has valid rights or not
289 *
290 * @param[in] path Path of the protected content
291 * @param[in] action Action to perform
292 * @return the status of the rights for the protected content,
293 * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
294 */
295 int checkRightsStatus(const String8& path, int action);
296
297 /**
298 * Removes the rights associated with the given protected content
299 *
300 * @param[in] path Path of the protected content
Takeshi Aimidc549d62010-09-20 23:40:41 +0900301 * @return status_t
302 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900303 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900304 status_t removeRights(const String8& path);
aimitakeshid074e302010-07-29 10:12:27 +0900305
306 /**
307 * Removes all the rights information of each plug-in associated with
308 * DRM framework. Will be used in master reset
309 *
Takeshi Aimidc549d62010-09-20 23:40:41 +0900310 * @return status_t
311 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshid074e302010-07-29 10:12:27 +0900312 */
Takeshi Aimidc549d62010-09-20 23:40:41 +0900313 status_t removeAllRights();
aimitakeshid074e302010-07-29 10:12:27 +0900314
315 /**
316 * This API is for Forward Lock DRM.
317 * Each time the application tries to download a new DRM file
318 * which needs to be converted, then the application has to
319 * begin with calling this API.
320 *
321 * @param[in] convertId Handle for the convert session
322 * @param[in] mimeType Description/MIME type of the input data packet
323 * @return Return handle for the convert session
324 */
325 int openConvertSession(const String8& mimeType);
326
327 /**
328 * Passes the input data which need to be converted. The resultant
329 * converted data and the status is returned in the DrmConvertedInfo
330 * object. This method will be called each time there are new block
331 * of data received by the application.
332 *
333 * @param[in] convertId Handle for the convert session
334 * @param[in] inputData Input Data which need to be converted
335 * @return Return object contains the status of the data conversion,
336 * the output converted data and offset. In this case the
337 * application will ignore the offset information.
338 */
339 DrmConvertedStatus* convertData(int convertId, const DrmBuffer* inputData);
340
341 /**
342 * When there is no more data which need to be converted or when an
343 * error occurs that time the application has to inform the Drm agent
344 * via this API. Upon successful conversion of the complete data,
345 * the agent will inform that where the header and body signature
346 * should be added. This signature appending is needed to integrity
347 * protect the converted file.
348 *
349 * @param[in] convertId Handle for the convert session
350 * @return Return object contains the status of the data conversion,
351 * the header and body signature data. It also informs
352 * the application on which offset these signature data
353 * should be appended.
354 */
355 DrmConvertedStatus* closeConvertSession(int convertId);
356
357 /**
358 * Retrieves all DrmSupportInfo instance that native DRM framework can handle.
359 * This interface is meant to be used by JNI layer
360 *
361 * @param[out] length Number of elements in drmSupportInfoArray
362 * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo
363 * that native DRM framework can handle
364 * @return status_t
365 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
366 */
367 status_t getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray);
368
369private:
aimitakeshid074e302010-07-29 10:12:27 +0900370 int mUniqueId;
Gloria Wang4c87a752011-03-24 13:14:02 -0700371 sp<DrmManagerClientImpl> mDrmManagerClientImpl;
aimitakeshid074e302010-07-29 10:12:27 +0900372};
373
374};
375
376#endif /* __DRM_MANAGER_CLIENT_H__ */
377