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