IDrmEngine.h revision 3473846f64f5b28e1cbeb70ef5867073fc93159e
1/* 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 __IDRM_ENGINE_H__ 18#define __IDRM_ENGINE_H__ 19 20#include <drm/drm_framework_common.h> 21 22namespace android { 23 24class DrmContentIds; 25class DrmConstraints; 26class DrmMetadata; 27class DrmRights; 28class DrmInfo; 29class DrmInfoStatus; 30class DrmConvertedStatus; 31class DrmInfoRequest; 32class DrmSupportInfo; 33class DrmInfoEvent; 34 35/** 36 * This class is an interface for plug-in user 37 * 38 * Responsibility of this class is provide generic interface to DRM Engine Manager. 39 * Each interface need to be as abstract as possible. 40 */ 41class IDrmEngine { 42public: 43 virtual ~IDrmEngine() { 44 } 45 46public: 47 class OnInfoListener { 48 49 public: 50 virtual void onInfo(const DrmInfoEvent& event) = 0; 51 52 virtual ~OnInfoListener() { } 53 }; 54 55public: 56 57 ////////////////////////////////// 58 // Implementation of IDrmEngine // 59 ////////////////////////////////// 60 61 /** 62 * Initialize plug-in 63 * 64 * @param[in] uniqueId Unique identifier for a session 65 * @return status_t 66 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 67 */ 68 virtual status_t initialize(int uniqueId) = 0; 69 70 /** 71 * Register a callback to be invoked when the caller required to 72 * receive necessary information 73 * 74 * @param[in] uniqueId Unique identifier for a session 75 * @param[in] infoListener Listener 76 * @return status_t 77 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 78 */ 79 virtual status_t setOnInfoListener( 80 int uniqueId, const IDrmEngine::OnInfoListener* infoListener) = 0; 81 82 /** 83 * Terminate the plug-in 84 * and release resource bound to plug-in 85 * e.g.) release native resource 86 * 87 * @param[in] uniqueId Unique identifier for a session 88 * @return status_t 89 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 90 */ 91 virtual status_t terminate(int uniqueId) = 0; 92 93 /** 94 * Get constraint information associated with input content 95 * 96 * @param[in] uniqueId Unique identifier for a session 97 * @param[in] path Path of the protected content 98 * @param[in] action Actions defined such as, 99 * Action::DEFAULT, Action::PLAY, etc 100 * @return DrmConstraints 101 * key-value pairs of constraint are embedded in it 102 * @note 103 * In case of error, return NULL 104 */ 105 virtual DrmConstraints* getConstraints( 106 int uniqueId, const String8* path, int action) = 0; 107 108 /** 109 * Get metadata information associated with input content 110 * 111 * @param[in] uniqueId Unique identifier for a session 112 * @param[in] path Path of the protected content 113 * @return DrmMetadata 114 * key-value pairs of metadata 115 * @note 116 * In case of error, return NULL 117 */ 118 virtual DrmMetadata* getMetadata(int uniqueId, const String8* path) = 0; 119 120 /** 121 * Get whether the given content can be handled by this plugin or not 122 * 123 * @param[in] uniqueId Unique identifier for a session 124 * @param[in] path Path the protected object 125 * @return bool 126 * true if this plugin can handle , false in case of not able to handle 127 */ 128 virtual bool canHandle(int uniqueId, const String8& path) = 0; 129 130 /** 131 * Executes given drm information based on its type 132 * 133 * @param[in] uniqueId Unique identifier for a session 134 * @param[in] drmInfo Information needs to be processed 135 * @return DrmInfoStatus 136 * instance as a result of processing given input 137 */ 138 virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0; 139 140 /** 141 * Retrieves necessary information for registration, unregistration or rights 142 * acquisition information. 143 * 144 * @param[in] uniqueId Unique identifier for a session 145 * @param[in] drmInfoRequest Request information to retrieve drmInfo 146 * @return DrmInfo 147 * instance as a result of processing given input 148 */ 149 virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) = 0; 150 151 /** 152 * Save DRM rights to specified rights path 153 * and make association with content path 154 * 155 * @param[in] uniqueId Unique identifier for a session 156 * @param[in] drmRights DrmRights to be saved 157 * @param[in] rightsPath File path where rights to be saved 158 * @param[in] contentPath File path where content was saved 159 * @return status_t 160 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 161 */ 162 virtual status_t saveRights(int uniqueId, const DrmRights& drmRights, 163 const String8& rightsPath, const String8& contentPath) = 0; 164 165 /** 166 * Retrieves the mime type embedded inside the original content 167 * 168 * @param[in] uniqueId Unique identifier for a session 169 * @param[in] path Path of the protected content 170 * @return String8 171 * Returns mime-type of the original content, such as "video/mpeg" 172 */ 173 virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0; 174 175 /** 176 * Retrieves the type of the protected object (content, rights, etc..) 177 * using specified path or mimetype. At least one parameter should be non null 178 * to retrieve DRM object type 179 * 180 * @param[in] uniqueId Unique identifier for a session 181 * @param[in] path Path of the content or null. 182 * @param[in] mimeType Mime type of the content or null. 183 * @return type of the DRM content, 184 * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT 185 */ 186 virtual int getDrmObjectType( 187 int uniqueId, const String8& path, const String8& mimeType) = 0; 188 189 /** 190 * Check whether the given content has valid rights or not 191 * 192 * @param[in] uniqueId Unique identifier for a session 193 * @param[in] path Path of the protected content 194 * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc) 195 * @return the status of the rights for the protected content, 196 * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. 197 */ 198 virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0; 199 200 /** 201 * Consumes the rights for a content. 202 * If the reserve parameter is true the rights is reserved until the same 203 * application calls this api again with the reserve parameter set to false. 204 * 205 * @param[in] uniqueId Unique identifier for a session 206 * @param[in] decryptHandle Handle for the decryption session 207 * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) 208 * @param[in] reserve True if the rights should be reserved. 209 * @return status_t 210 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 211 */ 212 virtual status_t consumeRights( 213 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0; 214 215 /** 216 * Informs the DRM Engine about the playback actions performed on the DRM files. 217 * 218 * @param[in] uniqueId Unique identifier for a session 219 * @param[in] decryptHandle Handle for the decryption session 220 * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) 221 * @param[in] position Position in the file (in milliseconds) where the start occurs. 222 * Only valid together with Playback::START. 223 * @return status_t 224 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 225 */ 226 virtual status_t setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, 227 int playbackStatus, int position) = 0; 228 229 /** 230 * Validates whether an action on the DRM content is allowed or not. 231 * 232 * @param[in] uniqueId Unique identifier for a session 233 * @param[in] path Path of the protected content 234 * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc) 235 * @param[in] description Detailed description of the action 236 * @return true if the action is allowed. 237 */ 238 virtual bool validateAction(int uniqueId, const String8& path, 239 int action, const ActionDescription& description) = 0; 240 241 /** 242 * Removes the rights associated with the given protected content 243 * 244 * @param[in] uniqueId Unique identifier for a session 245 * @param[in] path Path of the protected content 246 * @return status_t 247 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 248 */ 249 virtual status_t removeRights(int uniqueId, const String8& path) = 0; 250 251 /** 252 * Removes all the rights information of each plug-in associated with 253 * DRM framework. Will be used in master reset 254 * 255 * @param[in] uniqueId Unique identifier for a session 256 * @return status_t 257 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 258 */ 259 virtual status_t removeAllRights(int uniqueId) = 0; 260 261 /** 262 * This API is for Forward Lock based DRM scheme. 263 * Each time the application tries to download a new DRM file 264 * which needs to be converted, then the application has to 265 * begin with calling this API. 266 * 267 * @param[in] uniqueId Unique identifier for a session 268 * @param[in] convertId Handle for the convert session 269 * @return status_t 270 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 271 */ 272 virtual status_t openConvertSession(int uniqueId, int convertId) = 0; 273 274 /** 275 * Accepts and converts the input data which is part of DRM file. 276 * The resultant converted data and the status is returned in the DrmConvertedInfo 277 * object. This method will be called each time there are new block 278 * of data received by the application. 279 * 280 * @param[in] uniqueId Unique identifier for a session 281 * @param[in] convertId Handle for the convert session 282 * @param[in] inputData Input Data which need to be converted 283 * @return Return object contains the status of the data conversion, 284 * the output converted data and offset. In this case the 285 * application will ignore the offset information. 286 */ 287 virtual DrmConvertedStatus* convertData( 288 int uniqueId, int convertId, const DrmBuffer* inputData) = 0; 289 290 /** 291 * Informs the Drm Agent when there is no more data which need to be converted 292 * or when an error occurs. Upon successful conversion of the complete data, 293 * the agent will inform that where the header and body signature 294 * should be added. This signature appending is needed to integrity 295 * protect the converted file. 296 * 297 * @param[in] uniqueId Unique identifier for a session 298 * @param[in] convertId Handle for the convert session 299 * @return Return object contains the status of the data conversion, 300 * the header and body signature data. It also informs 301 * the application on which offset these signature data 302 * should be appended. 303 */ 304 virtual DrmConvertedStatus* closeConvertSession( int uniqueId, int convertId) = 0; 305 306 /** 307 * Returns the information about the Drm Engine capabilities which includes 308 * supported MimeTypes and file suffixes. 309 * 310 * @param[in] uniqueId Unique identifier for a session 311 * @return DrmSupportInfo 312 * instance which holds the capabilities of a plug-in 313 */ 314 virtual DrmSupportInfo* getSupportInfo(int uniqueId) = 0; 315 316 /** 317 * Open the decrypt session to decrypt the given protected content 318 * 319 * @param[in] uniqueId Unique identifier for a session 320 * @param[in] decryptHandle Handle for the current decryption session 321 * @param[in] fd File descriptor of the protected content to be decrypted 322 * @param[in] offset Start position of the content 323 * @param[in] length The length of the protected content 324 * @return 325 * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success 326 */ 327 virtual status_t openDecryptSession( 328 int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0; 329 330 /** 331 * Open the decrypt session to decrypt the given protected content 332 * 333 * @param[in] uniqueId Unique identifier for a session 334 * @param[in] decryptHandle Handle for the current decryption session 335 * @param[in] uri Path of the protected content to be decrypted 336 * @return 337 * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success 338 */ 339 virtual status_t openDecryptSession( 340 int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0; 341 342 /** 343 * Close the decrypt session for the given handle 344 * 345 * @param[in] uniqueId Unique identifier for a session 346 * @param[in] decryptHandle Handle for the decryption session 347 * @return status_t 348 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 349 */ 350 virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; 351 352 /** 353 * Initialize decryption for the given unit of the protected content 354 * 355 * @param[in] uniqueId Unique identifier for a session 356 * @param[in] decryptHandle Handle for the decryption session 357 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID 358 * @param[in] headerInfo Information for initializing decryption of this decrypUnit 359 * @return status_t 360 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 361 */ 362 virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, 363 int decryptUnitId, const DrmBuffer* headerInfo) = 0; 364 365 /** 366 * Decrypt the protected content buffers for the given unit 367 * This method will be called any number of times, based on number of 368 * encrypted streams received from application. 369 * 370 * @param[in] uniqueId Unique identifier for a session 371 * @param[in] decryptHandle Handle for the decryption session 372 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID 373 * @param[in] encBuffer Encrypted data block 374 * @param[out] decBuffer Decrypted data block 375 * @param[in] IV Optional buffer 376 * @return status_t 377 * Returns the error code for this API 378 * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED 379 * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, 380 * DRM_ERROR_DECRYPT for failure. 381 */ 382 virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, 383 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) = 0; 384 385 /** 386 * Finalize decryption for the given unit of the protected content 387 * 388 * @param[in] uniqueId Unique identifier for a session 389 * @param[in] decryptHandle Handle for the decryption session 390 * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID 391 * @return status_t 392 * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 393 */ 394 virtual status_t finalizeDecryptUnit( 395 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; 396 397 /** 398 * Reads the specified number of bytes from an open DRM file. 399 * 400 * @param[in] uniqueId Unique identifier for a session 401 * @param[in] decryptHandle Handle for the decryption session 402 * @param[out] buffer Reference to the buffer that should receive the read data. 403 * @param[in] numBytes Number of bytes to read. 404 * @param[in] offset Offset with which to update the file position. 405 * 406 * @return Number of bytes read. Returns -1 for Failure. 407 */ 408 virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, 409 void* buffer, ssize_t numBytes, off_t offset) = 0; 410}; 411 412}; 413 414#endif /* __IDRM_ENGINE_H__ */ 415 416