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