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