blob: 1c6be46768d7a81a11349ca2763f99b0b5ca37b6 [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_IMPL_H__
18#define __DRM_MANAGER_CLIENT_IMPL_H__
19
20#include <binder/IMemory.h>
21#include <utils/threads.h>
22#include <drm/DrmManagerClient.h>
23
24#include "IDrmManagerService.h"
25
26namespace android {
27
28class DrmInfoEvent;
29/**
30 * This is implementation class for DrmManagerClient class.
31 *
32 * Only the JNI layer creates an instance of this class to delegate
33 * functionality to Native later.
34 *
35 */
36class DrmManagerClientImpl : public BnDrmServiceListener {
37private:
Takeshi Aimie943f842010-10-08 23:05:49 +090038 DrmManagerClientImpl() { }
aimitakeshi27ed8ad2010-07-29 10:12:27 +090039
40public:
41 static DrmManagerClientImpl* create(int* pUniqueId);
42
43 static void remove(int uniqueId);
44
Takeshi Aimie943f842010-10-08 23:05:49 +090045 virtual ~DrmManagerClientImpl() { }
aimitakeshi27ed8ad2010-07-29 10:12:27 +090046
47public:
48 /**
Takeshi Aimie943f842010-10-08 23:05:49 +090049 * Adds the client respective to given unique id.
aimitakeshi27ed8ad2010-07-29 10:12:27 +090050 *
51 * @param[in] uniqueId Unique identifier for a session
aimitakeshi27ed8ad2010-07-29 10:12:27 +090052 */
Takeshi Aimie943f842010-10-08 23:05:49 +090053 void addClient(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090054
55 /**
Takeshi Aimie943f842010-10-08 23:05:49 +090056 * Removes the client respective to given unique id.
aimitakeshi27ed8ad2010-07-29 10:12:27 +090057 *
58 * @param[in] uniqueId Unique identifier for a session
aimitakeshi27ed8ad2010-07-29 10:12:27 +090059 */
Takeshi Aimie943f842010-10-08 23:05:49 +090060 void removeClient(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090061
62 /**
63 * Register a callback to be invoked when the caller required to
64 * receive necessary information
65 *
66 * @param[in] uniqueId Unique identifier for a session
67 * @param[in] infoListener Listener
68 * @return status_t
69 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
70 */
71 status_t setOnInfoListener(
72 int uniqueId, const sp<DrmManagerClient::OnInfoListener>& infoListener);
73
74 /**
75 * Get constraint information associated with input content
76 *
77 * @param[in] uniqueId Unique identifier for a session
78 * @param[in] path Path of the protected content
79 * @param[in] action Actions defined such as,
80 * Action::DEFAULT, Action::PLAY, etc
81 * @return DrmConstraints
82 * key-value pairs of constraint are embedded in it
83 * @note
84 * In case of error, return NULL
85 */
86 DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
87
88 /**
89 * Check whether the given mimetype or path can be handled
90 *
91 * @param[in] uniqueId Unique identifier for a session
92 * @param[in] path Path of the content needs to be handled
93 * @param[in] mimetype Mimetype of the content needs to be handled
94 * @return
95 * True if DrmManager can handle given path or mime type.
96 */
97 bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
98
99 /**
100 * Executes given drm information based on its type
101 *
102 * @param[in] uniqueId Unique identifier for a session
103 * @param[in] drmInfo Information needs to be processed
104 * @return DrmInfoStatus
105 * instance as a result of processing given input
106 */
107 DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
108
109 /**
110 * Retrieves necessary information for registration, unregistration or rights
111 * acquisition information.
112 *
113 * @param[in] uniqueId Unique identifier for a session
114 * @param[in] drmInfoRequest Request information to retrieve drmInfo
115 * @return DrmInfo
116 * instance as a result of processing given input
117 */
118 DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
119
120 /**
121 * Save DRM rights to specified rights path
122 * and make association with content path
123 *
124 * @param[in] uniqueId Unique identifier for a session
125 * @param[in] drmRights DrmRights to be saved
126 * @param[in] rightsPath File path where rights to be saved
127 * @param[in] contentPath File path where content was saved
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900128 * @return status_t
129 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900130 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900131 status_t saveRights(int uniqueId, const DrmRights& drmRights,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900132 const String8& rightsPath, const String8& contentPath);
133
134 /**
135 * Retrieves the mime type embedded inside the original content
136 *
137 * @param[in] uniqueId Unique identifier for a session
138 * @param[in] path the path of the protected content
139 * @return String8
140 * Returns mime-type of the original content, such as "video/mpeg"
141 */
142 String8 getOriginalMimeType(int uniqueId, const String8& path);
143
144 /**
145 * Retrieves the type of the protected object (content, rights, etc..)
146 * using specified path or mimetype. At least one parameter should be non null
147 * to retrieve DRM object type
148 *
149 * @param[in] uniqueId Unique identifier for a session
150 * @param[in] path Path of the content or null.
151 * @param[in] mimeType Mime type of the content or null.
152 * @return type of the DRM content,
153 * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
154 */
155 int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
156
157 /**
158 * Check whether the given content has valid rights or not
159 *
160 * @param[in] uniqueId Unique identifier for a session
161 * @param[in] path Path of the protected content
162 * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc)
163 * @return the status of the rights for the protected content,
164 * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
165 */
166 int checkRightsStatus(int uniqueId, const String8& path, int action);
167
168 /**
169 * Consumes the rights for a content.
170 * If the reserve parameter is true the rights is reserved until the same
171 * application calls this api again with the reserve parameter set to false.
172 *
173 * @param[in] uniqueId Unique identifier for a session
174 * @param[in] decryptHandle Handle for the decryption session
175 * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
176 * @param[in] reserve True if the rights should be reserved.
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900177 * @return status_t
178 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900179 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900180 status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900181
182 /**
183 * Informs the DRM engine about the playback actions performed on the DRM files.
184 *
185 * @param[in] uniqueId Unique identifier for a session
186 * @param[in] decryptHandle Handle for the decryption session
187 * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
188 * @param[in] position Position in the file (in milliseconds) where the start occurs.
189 * Only valid together with Playback::START.
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900190 * @return status_t
191 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900192 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900193 status_t setPlaybackStatus(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900194 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
195
196 /**
197 * Validates whether an action on the DRM content is allowed or not.
198 *
199 * @param[in] uniqueId Unique identifier for a session
200 * @param[in] path Path of the protected content
201 * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc)
202 * @param[in] description Detailed description of the action
203 * @return true if the action is allowed.
204 */
205 bool validateAction(
206 int uniqueId, const String8& path, int action, const ActionDescription& description);
207
208 /**
209 * Removes the rights associated with the given protected content
210 *
211 * @param[in] uniqueId Unique identifier for a session
212 * @param[in] path Path of the protected content
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900213 * @return status_t
214 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900215 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900216 status_t removeRights(int uniqueId, const String8& path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900217
218 /**
219 * Removes all the rights information of each plug-in associated with
220 * DRM framework. Will be used in master reset
221 *
222 * @param[in] uniqueId Unique identifier for a session
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900223 * @return status_t
224 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900225 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900226 status_t removeAllRights(int uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900227
228 /**
229 * This API is for Forward Lock based DRM scheme.
230 * Each time the application tries to download a new DRM file
231 * which needs to be converted, then the application has to
232 * begin with calling this API.
233 *
234 * @param[in] uniqueId Unique identifier for a session
235 * @param[in] mimeType Description/MIME type of the input data packet
236 * @return Return handle for the convert session
237 */
238 int openConvertSession(int uniqueId, const String8& mimeType);
239
240 /**
241 * Accepts and converts the input data which is part of DRM file.
242 * The resultant converted data and the status is returned in the DrmConvertedInfo
243 * object. This method will be called each time there are new block
244 * of data received by the application.
245 *
246 * @param[in] uniqueId Unique identifier for a session
247 * @param[in] convertId Handle for the convert session
248 * @param[in] inputData Input Data which need to be converted
249 * @return Return object contains the status of the data conversion,
250 * the output converted data and offset. In this case the
251 * application will ignore the offset information.
252 */
253 DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
254
255 /**
256 * Informs the Drm Agent when there is no more data which need to be converted
257 * or when an error occurs. Upon successful conversion of the complete data,
258 * the agent will inform that where the header and body signature
259 * should be added. This signature appending is needed to integrity
260 * protect the converted file.
261 *
262 * @param[in] uniqueId Unique identifier for a session
263 * @param[in] convertId Handle for the convert session
264 * @return Return object contains the status of the data conversion,
265 * the header and body signature data. It also informs
266 * the application on which offset these signature data
267 * should be appended.
268 */
269 DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
270
271 /**
272 * Retrieves all DrmSupportInfo instance that native DRM framework can handle.
273 * This interface is meant to be used by JNI layer
274 *
275 * @param[in] uniqueId Unique identifier for a session
276 * @param[out] length Number of elements in drmSupportInfoArray
277 * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo
278 * that native DRM framework can handle
279 * @return status_t
280 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
281 */
282 status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
283
284 /**
285 * Open the decrypt session to decrypt the given protected content
286 *
287 * @param[in] uniqueId Unique identifier for a session
288 * @param[in] fd File descriptor of the protected content to be decrypted
289 * @param[in] offset Start position of the content
290 * @param[in] length The length of the protected content
291 * @return
292 * Handle for the decryption session
293 */
294 DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
295
296 /**
Takeshi Aimie943f842010-10-08 23:05:49 +0900297 * Open the decrypt session to decrypt the given protected content
298 *
299 * @param[in] uniqueId Unique identifier for a session
300 * @param[in] uri Path of the protected content to be decrypted
301 * @return
302 * Handle for the decryption session
303 */
304 DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
305
306 /**
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900307 * Close the decrypt session for the given handle
308 *
309 * @param[in] uniqueId Unique identifier for a session
310 * @param[in] decryptHandle Handle for the decryption session
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900311 * @return status_t
312 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900313 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900314 status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900315
316 /**
317 * Initialize decryption for the given unit of the protected content
318 *
319 * @param[in] uniqueId Unique identifier for a session
320 * @param[in] decryptHandle Handle for the decryption session
321 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
322 * @param[in] headerInfo Information for initializing decryption of this decrypUnit
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 initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900327 int decryptUnitId, const DrmBuffer* headerInfo);
328
329 /**
330 * Decrypt the protected content buffers for the given unit
331 * This method will be called any number of times, based on number of
332 * encrypted streams received from application.
333 *
334 * @param[in] uniqueId Unique identifier for a session
335 * @param[in] decryptHandle Handle for the decryption session
336 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
337 * @param[in] encBuffer Encrypted data block
338 * @param[out] decBuffer Decrypted data block
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900339 * @param[in] IV Optional buffer
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900340 * @return status_t
341 * Returns the error code for this API
342 * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
343 * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
344 * DRM_ERROR_DECRYPT for failure.
345 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900346 status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
347 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900348
349 /**
350 * Finalize decryption for the given unit of the protected content
351 *
352 * @param[in] uniqueId Unique identifier for a session
353 * @param[in] decryptHandle Handle for the decryption session
354 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900355 * @return status_t
356 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900357 */
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900358 status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900359
360 /**
361 * Reads the specified number of bytes from an open DRM file.
362 *
363 * @param[in] uniqueId Unique identifier for a session
364 * @param[in] decryptHandle Handle for the decryption session
365 * @param[out] buffer Reference to the buffer that should receive the read data.
366 * @param[in] numBytes Number of bytes to read.
367 * @param[in] offset Offset with which to update the file position.
368 *
369 * @return Number of bytes read. Returns -1 for Failure.
370 */
371 ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
372 void* buffer, ssize_t numBytes, off_t offset);
373
374 /**
375 * Notify the event to the registered listener
376 *
377 * @param[in] event The event to be notified
378 * @return status_t
379 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
380 */
381 status_t notify(const DrmInfoEvent& event);
382
383private:
384 /**
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900385 * Install new DRM Engine Plug-in at the runtime
386 *
387 * @param[in] uniqueId Unique identifier for a session
388 * @param[in] drmEngine Shared Object(so) File in which DRM Engine defined
389 * @return status_t
390 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
391 */
392 status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
393
394private:
395 Mutex mLock;
396 sp<DrmManagerClient::OnInfoListener> mOnInfoListener;
397
398private:
399 static Mutex mMutex;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900400 static sp<IDrmManagerService> mDrmManagerService;
401 static const sp<IDrmManagerService>& getDrmManagerService();
402 static const String8 EMPTY_STRING;
403};
404
405};
406
407#endif /* __DRM_MANAGER_CLIENT_IMPL_H__ */
408