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