blob: a38aa9b2b60324fd0d0ede2a264bbe3c688c5477 [file] [log] [blame]
aimitakeshi27ed8ad2010-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 Aimie943f842010-10-08 23:05:49 +090020#include <utils/threads.h>
aimitakeshi27ed8ad2010-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 Aimi34738462010-11-16 13:56:11 +090028class DrmMetadata;
aimitakeshi27ed8ad2010-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 Aimic618b5a2010-11-30 16:27:42 +090052 virtual ~OnInfoListener() {}
53
54 public:
aimitakeshi27ed8ad2010-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
James Dong9d2f3862012-01-10 08:24:37 -080069 * @param[in] mime Mime type of the protected content if it is not NULL or empty
aimitakeshi27ed8ad2010-07-29 10:12:27 +090070 * @return
71 * Handle for the decryption session
72 */
James Dong9d2f3862012-01-10 08:24:37 -080073 sp<DecryptHandle> openDecryptSession(int fd, off64_t offset, off64_t length, const char* mime);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090074
75 /**
Takeshi Aimie943f842010-10-08 23:05:49 +090076 * Open the decrypt session to decrypt the given protected content
77 *
78 * @param[in] uri Path of the protected content to be decrypted
James Dong9d2f3862012-01-10 08:24:37 -080079 * @param[in] mime Mime type of the protected content if it is not NULL or empty
Takeshi Aimie943f842010-10-08 23:05:49 +090080 * @return
81 * Handle for the decryption session
82 */
James Dong9d2f3862012-01-10 08:24:37 -080083 sp<DecryptHandle> openDecryptSession(const char* uri, const char* mime);
Takeshi Aimie943f842010-10-08 23:05:49 +090084
85 /**
Kei Takahashicba7b322012-01-18 17:10:19 +090086 * Open the decrypt session to decrypt the given protected content
87 *
88 * @param[in] buf Data to initiate decrypt session
89 * @param[in] mimeType Mime type of the protected content
90 * @return
91 * Handle for the decryption session
92 */
93 sp<DecryptHandle> openDecryptSession(const DrmBuffer& buf, const String8& mimeType);
94
95 /**
aimitakeshi27ed8ad2010-07-29 10:12:27 +090096 * Close the decrypt session for the given handle
97 *
98 * @param[in] decryptHandle Handle for the decryption session
Takeshi Aimi2272ee22010-09-20 23:40:41 +090099 * @return status_t
100 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900101 */
Gloria Wangb5ce3612011-02-24 16:40:57 -0800102 status_t closeDecryptSession(sp<DecryptHandle> &decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900103
104 /**
105 * Consumes the rights for a content.
106 * If the reserve parameter is true the rights is reserved until the same
107 * application calls this api again with the reserve parameter set to false.
108 *
109 * @param[in] decryptHandle Handle for the decryption session
110 * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
111 * @param[in] reserve True if the rights should be reserved.
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900112 * @return status_t
113 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure.
114 * In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned.
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900115 */
Gloria Wangb5ce3612011-02-24 16:40:57 -0800116 status_t consumeRights(sp<DecryptHandle> &decryptHandle, int action, bool reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900117
118 /**
119 * Informs the DRM engine about the playback actions performed on the DRM files.
120 *
121 * @param[in] decryptHandle Handle for the decryption session
122 * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
123 * @param[in] position Position in the file (in milliseconds) where the start occurs.
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900124 * Only valid together with Playback::START.
125 * @return status_t
126 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900127 */
Gloria Wangb5ce3612011-02-24 16:40:57 -0800128 status_t setPlaybackStatus(
129 sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900130
131 /**
132 * Initialize decryption for the given unit of the protected content
133 *
134 * @param[in] decryptHandle Handle for the decryption session
135 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
136 * @param[in] headerInfo Information for initializing decryption of this decrypUnit
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900137 * @return status_t
138 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900139 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900140 status_t initializeDecryptUnit(
Gloria Wangb5ce3612011-02-24 16:40:57 -0800141 sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900142
143 /**
144 * Decrypt the protected content buffers for the given unit
145 * This method will be called any number of times, based on number of
146 * encrypted streams received from application.
147 *
148 * @param[in] decryptHandle Handle for the decryption session
149 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
150 * @param[in] encBuffer Encrypted data block
151 * @param[out] decBuffer Decrypted data block
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900152 * @param[in] IV Optional buffer
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900153 * @return status_t
154 * Returns the error code for this API
155 * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
156 * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
157 * DRM_ERROR_DECRYPT for failure.
158 */
159 status_t decrypt(
Gloria Wangb5ce3612011-02-24 16:40:57 -0800160 sp<DecryptHandle> &decryptHandle, int decryptUnitId,
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900161 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900162
163 /**
164 * Finalize decryption for the given unit of the protected content
165 *
166 * @param[in] decryptHandle Handle for the decryption session
167 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900168 * @return status_t
169 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900170 */
Gloria Wangb5ce3612011-02-24 16:40:57 -0800171 status_t finalizeDecryptUnit(
172 sp<DecryptHandle> &decryptHandle, int decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900173
174 /**
175 * Reads the specified number of bytes from an open DRM file.
176 *
177 * @param[in] decryptHandle Handle for the decryption session
178 * @param[out] buffer Reference to the buffer that should receive the read data.
179 * @param[in] numBytes Number of bytes to read.
180 * @param[in] offset Offset with which to update the file position.
181 *
182 * @return Number of bytes read. Returns -1 for Failure.
183 */
Gloria Wangb5ce3612011-02-24 16:40:57 -0800184 ssize_t pread(sp<DecryptHandle> &decryptHandle,
185 void* buffer, ssize_t numBytes, off64_t offset);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900186
187 /**
188 * Validates whether an action on the DRM content is allowed or not.
189 *
190 * @param[in] path Path of the protected content
191 * @param[in] action Action to validate. (Action::DEFAULT, Action::PLAY, etc)
192 * @param[in] description Detailed description of the action
193 * @return true if the action is allowed.
194 */
195 bool validateAction(const String8& path, int action, const ActionDescription& description);
196
197/**
198 * APIs which are just the underlying implementation for the Java API
199 *
200 */
201public:
202 /**
203 * Register a callback to be invoked when the caller required to
204 * receive necessary information
205 *
206 * @param[in] infoListener Listener
207 * @return status_t
208 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
209 */
210 status_t setOnInfoListener(const sp<DrmManagerClient::OnInfoListener>& infoListener);
211
212 /**
213 * Get constraint information associated with input content
214 *
215 * @param[in] path Path of the protected content
216 * @param[in] action Actions defined such as,
217 * Action::DEFAULT, Action::PLAY, etc
218 * @return DrmConstraints
219 * key-value pairs of constraint are embedded in it
220 * @note
221 * In case of error, return NULL
222 */
223 DrmConstraints* getConstraints(const String8* path, const int action);
224
225 /**
Takeshi Aimi34738462010-11-16 13:56:11 +0900226 * Get metadata information associated with input content
227 *
228 * @param[in] path Path of the protected content
229 * @return DrmMetadata
230 * key-value pairs of metadata
231 * @note
232 * In case of error, return NULL
233 */
234 DrmMetadata* getMetadata(const String8* path);
235
236 /**
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900237 * Check whether the given mimetype or path can be handled
238 *
239 * @param[in] path Path of the content needs to be handled
240 * @param[in] mimetype Mimetype of the content needs to be handled
241 * @return
242 * True if DrmManager can handle given path or mime type.
243 */
244 bool canHandle(const String8& path, const String8& mimeType);
245
246 /**
247 * Executes given drm information based on its type
248 *
249 * @param[in] drmInfo Information needs to be processed
250 * @return DrmInfoStatus
251 * instance as a result of processing given input
252 */
253 DrmInfoStatus* processDrmInfo(const DrmInfo* drmInfo);
254
255 /**
256 * Retrieves necessary information for registration, unregistration or rights
257 * acquisition information.
258 *
259 * @param[in] drmInfoRequest Request information to retrieve drmInfo
260 * @return DrmInfo
261 * instance as a result of processing given input
262 */
263 DrmInfo* acquireDrmInfo(const DrmInfoRequest* drmInfoRequest);
264
265 /**
266 * Save DRM rights to specified rights path
267 * and make association with content path
268 *
269 * @param[in] drmRights DrmRights to be saved
270 * @param[in] rightsPath File path where rights to be saved
271 * @param[in] contentPath File path where content was saved
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900272 * @return status_t
273 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900274 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900275 status_t saveRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900276 const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath);
277
278 /**
279 * Retrieves the mime type embedded inside the original content
280 *
281 * @param[in] path the path of the protected content
James Dongbf5b3b22012-07-30 17:57:39 -0700282 * @param[in] fd the file descriptor of the protected content
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900283 * @return String8
284 * Returns mime-type of the original content, such as "video/mpeg"
285 */
James Dongbf5b3b22012-07-30 17:57:39 -0700286 String8 getOriginalMimeType(const String8& path, int fd);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900287
288 /**
289 * Retrieves the type of the protected object (content, rights, etc..)
290 * by using specified path or mimetype. At least one parameter should be non null
291 * to retrieve DRM object type
292 *
293 * @param[in] path Path of the content or null.
294 * @param[in] mimeType Mime type of the content or null.
295 * @return type of the DRM content,
296 * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
297 */
298 int getDrmObjectType(const String8& path, const String8& mimeType);
299
300 /**
301 * Check whether the given content has valid rights or not
302 *
303 * @param[in] path Path of the protected content
304 * @param[in] action Action to perform
305 * @return the status of the rights for the protected content,
306 * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
307 */
308 int checkRightsStatus(const String8& path, int action);
309
310 /**
311 * Removes the rights associated with the given protected content
312 *
313 * @param[in] path Path of the protected content
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900314 * @return status_t
315 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900316 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900317 status_t removeRights(const String8& path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900318
319 /**
320 * Removes all the rights information of each plug-in associated with
Jeff Tinker6cb49422020-08-13 15:53:28 -0700321 * DRM framework.
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900322 *
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900323 * @return status_t
324 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900325 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900326 status_t removeAllRights();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900327
328 /**
329 * This API is for Forward Lock DRM.
330 * Each time the application tries to download a new DRM file
331 * which needs to be converted, then the application has to
332 * begin with calling this API.
333 *
334 * @param[in] convertId Handle for the convert session
335 * @param[in] mimeType Description/MIME type of the input data packet
336 * @return Return handle for the convert session
337 */
338 int openConvertSession(const String8& mimeType);
339
340 /**
341 * Passes the input data which need to be converted. The resultant
342 * converted data and the status is returned in the DrmConvertedInfo
343 * object. This method will be called each time there are new block
344 * of data received by the application.
345 *
346 * @param[in] convertId Handle for the convert session
347 * @param[in] inputData Input Data which need to be converted
348 * @return Return object contains the status of the data conversion,
349 * the output converted data and offset. In this case the
350 * application will ignore the offset information.
351 */
352 DrmConvertedStatus* convertData(int convertId, const DrmBuffer* inputData);
353
354 /**
355 * When there is no more data which need to be converted or when an
356 * error occurs that time the application has to inform the Drm agent
357 * via this API. Upon successful conversion of the complete data,
358 * the agent will inform that where the header and body signature
359 * should be added. This signature appending is needed to integrity
360 * protect the converted file.
361 *
362 * @param[in] convertId Handle for the convert session
363 * @return Return object contains the status of the data conversion,
364 * the header and body signature data. It also informs
365 * the application on which offset these signature data
366 * should be appended.
367 */
368 DrmConvertedStatus* closeConvertSession(int convertId);
369
370 /**
371 * Retrieves all DrmSupportInfo instance that native DRM framework can handle.
372 * This interface is meant to be used by JNI layer
373 *
374 * @param[out] length Number of elements in drmSupportInfoArray
375 * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo
376 * that native DRM framework can handle
377 * @return status_t
378 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
379 */
380 status_t getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray);
381
382private:
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900383 int mUniqueId;
Gloria Wang25cd5782011-03-24 13:14:02 -0700384 sp<DrmManagerClientImpl> mDrmManagerClientImpl;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900385};
386
387};
388
389#endif /* __DRM_MANAGER_CLIENT_H__ */
390