1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/ics/drm/DrmManagerClient.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,377 @@ 1.4 +/* 1.5 + * Copyright (C) 2010 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef __DRM_MANAGER_CLIENT_H__ 1.21 +#define __DRM_MANAGER_CLIENT_H__ 1.22 + 1.23 +#include <utils/threads.h> 1.24 +#include <binder/IInterface.h> 1.25 +#include "drm_framework_common.h" 1.26 + 1.27 +namespace android { 1.28 + 1.29 +class DrmInfo; 1.30 +class DrmRights; 1.31 +class DrmMetadata; 1.32 +class DrmInfoEvent; 1.33 +class DrmInfoStatus; 1.34 +class DrmInfoRequest; 1.35 +class DrmSupportInfo; 1.36 +class DrmConstraints; 1.37 +class DrmConvertedStatus; 1.38 +class DrmManagerClientImpl; 1.39 + 1.40 +/** 1.41 + * The Native application will instantiate this class and access DRM Framework 1.42 + * services through this class. 1.43 + * 1.44 + */ 1.45 +class DrmManagerClient { 1.46 +public: 1.47 + DrmManagerClient(); 1.48 + 1.49 + virtual ~DrmManagerClient(); 1.50 + 1.51 +public: 1.52 + class OnInfoListener: virtual public RefBase { 1.53 + 1.54 + public: 1.55 + virtual ~OnInfoListener() {} 1.56 + 1.57 + public: 1.58 + virtual void onInfo(const DrmInfoEvent& event) = 0; 1.59 + }; 1.60 + 1.61 +/** 1.62 + * APIs which will be used by native modules (e.g. StageFright) 1.63 + * 1.64 + */ 1.65 +public: 1.66 + /** 1.67 + * Open the decrypt session to decrypt the given protected content 1.68 + * 1.69 + * @param[in] fd File descriptor of the protected content to be decrypted 1.70 + * @param[in] offset Start position of the content 1.71 + * @param[in] length The length of the protected content 1.72 + * @return 1.73 + * Handle for the decryption session 1.74 + */ 1.75 + sp<DecryptHandle> openDecryptSession(int fd, off64_t offset, off64_t length); 1.76 + 1.77 + /** 1.78 + * Open the decrypt session to decrypt the given protected content 1.79 + * 1.80 + * @param[in] uri Path of the protected content to be decrypted 1.81 + * @return 1.82 + * Handle for the decryption session 1.83 + */ 1.84 + sp<DecryptHandle> openDecryptSession(const char* uri); 1.85 + 1.86 + /** 1.87 + * Close the decrypt session for the given handle 1.88 + * 1.89 + * @param[in] decryptHandle Handle for the decryption session 1.90 + * @return status_t 1.91 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.92 + */ 1.93 + status_t closeDecryptSession(sp<DecryptHandle> &decryptHandle); 1.94 + 1.95 + /** 1.96 + * Consumes the rights for a content. 1.97 + * If the reserve parameter is true the rights is reserved until the same 1.98 + * application calls this api again with the reserve parameter set to false. 1.99 + * 1.100 + * @param[in] decryptHandle Handle for the decryption session 1.101 + * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) 1.102 + * @param[in] reserve True if the rights should be reserved. 1.103 + * @return status_t 1.104 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure. 1.105 + * In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned. 1.106 + */ 1.107 + status_t consumeRights(sp<DecryptHandle> &decryptHandle, int action, bool reserve); 1.108 + 1.109 + /** 1.110 + * Informs the DRM engine about the playback actions performed on the DRM files. 1.111 + * 1.112 + * @param[in] decryptHandle Handle for the decryption session 1.113 + * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) 1.114 + * @param[in] position Position in the file (in milliseconds) where the start occurs. 1.115 + * Only valid together with Playback::START. 1.116 + * @return status_t 1.117 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.118 + */ 1.119 + status_t setPlaybackStatus( 1.120 + sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position); 1.121 + 1.122 + /** 1.123 + * Initialize decryption for the given unit of the protected content 1.124 + * 1.125 + * @param[in] decryptHandle Handle for the decryption session 1.126 + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID 1.127 + * @param[in] headerInfo Information for initializing decryption of this decrypUnit 1.128 + * @return status_t 1.129 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.130 + */ 1.131 + status_t initializeDecryptUnit( 1.132 + sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); 1.133 + 1.134 + /** 1.135 + * Decrypt the protected content buffers for the given unit 1.136 + * This method will be called any number of times, based on number of 1.137 + * encrypted streams received from application. 1.138 + * 1.139 + * @param[in] decryptHandle Handle for the decryption session 1.140 + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID 1.141 + * @param[in] encBuffer Encrypted data block 1.142 + * @param[out] decBuffer Decrypted data block 1.143 + * @param[in] IV Optional buffer 1.144 + * @return status_t 1.145 + * Returns the error code for this API 1.146 + * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED 1.147 + * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, 1.148 + * DRM_ERROR_DECRYPT for failure. 1.149 + */ 1.150 + status_t decrypt( 1.151 + sp<DecryptHandle> &decryptHandle, int decryptUnitId, 1.152 + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL); 1.153 + 1.154 + /** 1.155 + * Finalize decryption for the given unit of the protected content 1.156 + * 1.157 + * @param[in] decryptHandle Handle for the decryption session 1.158 + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID 1.159 + * @return status_t 1.160 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.161 + */ 1.162 + status_t finalizeDecryptUnit( 1.163 + sp<DecryptHandle> &decryptHandle, int decryptUnitId); 1.164 + 1.165 + /** 1.166 + * Reads the specified number of bytes from an open DRM file. 1.167 + * 1.168 + * @param[in] decryptHandle Handle for the decryption session 1.169 + * @param[out] buffer Reference to the buffer that should receive the read data. 1.170 + * @param[in] numBytes Number of bytes to read. 1.171 + * @param[in] offset Offset with which to update the file position. 1.172 + * 1.173 + * @return Number of bytes read. Returns -1 for Failure. 1.174 + */ 1.175 + ssize_t pread(sp<DecryptHandle> &decryptHandle, 1.176 + void* buffer, ssize_t numBytes, off64_t offset); 1.177 + 1.178 + /** 1.179 + * Validates whether an action on the DRM content is allowed or not. 1.180 + * 1.181 + * @param[in] path Path of the protected content 1.182 + * @param[in] action Action to validate. (Action::DEFAULT, Action::PLAY, etc) 1.183 + * @param[in] description Detailed description of the action 1.184 + * @return true if the action is allowed. 1.185 + */ 1.186 + bool validateAction(const String8& path, int action, const ActionDescription& description); 1.187 + 1.188 +/** 1.189 + * APIs which are just the underlying implementation for the Java API 1.190 + * 1.191 + */ 1.192 +public: 1.193 + /** 1.194 + * Register a callback to be invoked when the caller required to 1.195 + * receive necessary information 1.196 + * 1.197 + * @param[in] infoListener Listener 1.198 + * @return status_t 1.199 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.200 + */ 1.201 + status_t setOnInfoListener(const sp<DrmManagerClient::OnInfoListener>& infoListener); 1.202 + 1.203 + /** 1.204 + * Get constraint information associated with input content 1.205 + * 1.206 + * @param[in] path Path of the protected content 1.207 + * @param[in] action Actions defined such as, 1.208 + * Action::DEFAULT, Action::PLAY, etc 1.209 + * @return DrmConstraints 1.210 + * key-value pairs of constraint are embedded in it 1.211 + * @note 1.212 + * In case of error, return NULL 1.213 + */ 1.214 + DrmConstraints* getConstraints(const String8* path, const int action); 1.215 + 1.216 + /** 1.217 + * Get metadata information associated with input content 1.218 + * 1.219 + * @param[in] path Path of the protected content 1.220 + * @return DrmMetadata 1.221 + * key-value pairs of metadata 1.222 + * @note 1.223 + * In case of error, return NULL 1.224 + */ 1.225 + DrmMetadata* getMetadata(const String8* path); 1.226 + 1.227 + /** 1.228 + * Check whether the given mimetype or path can be handled 1.229 + * 1.230 + * @param[in] path Path of the content needs to be handled 1.231 + * @param[in] mimetype Mimetype of the content needs to be handled 1.232 + * @return 1.233 + * True if DrmManager can handle given path or mime type. 1.234 + */ 1.235 + bool canHandle(const String8& path, const String8& mimeType); 1.236 + 1.237 + /** 1.238 + * Executes given drm information based on its type 1.239 + * 1.240 + * @param[in] drmInfo Information needs to be processed 1.241 + * @return DrmInfoStatus 1.242 + * instance as a result of processing given input 1.243 + */ 1.244 + DrmInfoStatus* processDrmInfo(const DrmInfo* drmInfo); 1.245 + 1.246 + /** 1.247 + * Retrieves necessary information for registration, unregistration or rights 1.248 + * acquisition information. 1.249 + * 1.250 + * @param[in] drmInfoRequest Request information to retrieve drmInfo 1.251 + * @return DrmInfo 1.252 + * instance as a result of processing given input 1.253 + */ 1.254 + DrmInfo* acquireDrmInfo(const DrmInfoRequest* drmInfoRequest); 1.255 + 1.256 + /** 1.257 + * Save DRM rights to specified rights path 1.258 + * and make association with content path 1.259 + * 1.260 + * @param[in] drmRights DrmRights to be saved 1.261 + * @param[in] rightsPath File path where rights to be saved 1.262 + * @param[in] contentPath File path where content was saved 1.263 + * @return status_t 1.264 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.265 + */ 1.266 + status_t saveRights( 1.267 + const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); 1.268 + 1.269 + /** 1.270 + * Retrieves the mime type embedded inside the original content 1.271 + * 1.272 + * @param[in] path the path of the protected content 1.273 + * @return String8 1.274 + * Returns mime-type of the original content, such as "video/mpeg" 1.275 + */ 1.276 + String8 getOriginalMimeType(const String8& path); 1.277 + 1.278 + /** 1.279 + * Retrieves the type of the protected object (content, rights, etc..) 1.280 + * by using specified path or mimetype. At least one parameter should be non null 1.281 + * to retrieve DRM object type 1.282 + * 1.283 + * @param[in] path Path of the content or null. 1.284 + * @param[in] mimeType Mime type of the content or null. 1.285 + * @return type of the DRM content, 1.286 + * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT 1.287 + */ 1.288 + int getDrmObjectType(const String8& path, const String8& mimeType); 1.289 + 1.290 + /** 1.291 + * Check whether the given content has valid rights or not 1.292 + * 1.293 + * @param[in] path Path of the protected content 1.294 + * @param[in] action Action to perform 1.295 + * @return the status of the rights for the protected content, 1.296 + * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. 1.297 + */ 1.298 + int checkRightsStatus(const String8& path, int action); 1.299 + 1.300 + /** 1.301 + * Removes the rights associated with the given protected content 1.302 + * 1.303 + * @param[in] path Path of the protected content 1.304 + * @return status_t 1.305 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.306 + */ 1.307 + status_t removeRights(const String8& path); 1.308 + 1.309 + /** 1.310 + * Removes all the rights information of each plug-in associated with 1.311 + * DRM framework. Will be used in master reset 1.312 + * 1.313 + * @return status_t 1.314 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.315 + */ 1.316 + status_t removeAllRights(); 1.317 + 1.318 + /** 1.319 + * This API is for Forward Lock DRM. 1.320 + * Each time the application tries to download a new DRM file 1.321 + * which needs to be converted, then the application has to 1.322 + * begin with calling this API. 1.323 + * 1.324 + * @param[in] convertId Handle for the convert session 1.325 + * @param[in] mimeType Description/MIME type of the input data packet 1.326 + * @return Return handle for the convert session 1.327 + */ 1.328 + int openConvertSession(const String8& mimeType); 1.329 + 1.330 + /** 1.331 + * Passes the input data which need to be converted. The resultant 1.332 + * converted data and the status is returned in the DrmConvertedInfo 1.333 + * object. This method will be called each time there are new block 1.334 + * of data received by the application. 1.335 + * 1.336 + * @param[in] convertId Handle for the convert session 1.337 + * @param[in] inputData Input Data which need to be converted 1.338 + * @return Return object contains the status of the data conversion, 1.339 + * the output converted data and offset. In this case the 1.340 + * application will ignore the offset information. 1.341 + */ 1.342 + DrmConvertedStatus* convertData(int convertId, const DrmBuffer* inputData); 1.343 + 1.344 + /** 1.345 + * When there is no more data which need to be converted or when an 1.346 + * error occurs that time the application has to inform the Drm agent 1.347 + * via this API. Upon successful conversion of the complete data, 1.348 + * the agent will inform that where the header and body signature 1.349 + * should be added. This signature appending is needed to integrity 1.350 + * protect the converted file. 1.351 + * 1.352 + * @param[in] convertId Handle for the convert session 1.353 + * @return Return object contains the status of the data conversion, 1.354 + * the header and body signature data. It also informs 1.355 + * the application on which offset these signature data 1.356 + * should be appended. 1.357 + */ 1.358 + DrmConvertedStatus* closeConvertSession(int convertId); 1.359 + 1.360 + /** 1.361 + * Retrieves all DrmSupportInfo instance that native DRM framework can handle. 1.362 + * This interface is meant to be used by JNI layer 1.363 + * 1.364 + * @param[out] length Number of elements in drmSupportInfoArray 1.365 + * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo 1.366 + * that native DRM framework can handle 1.367 + * @return status_t 1.368 + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure 1.369 + */ 1.370 + status_t getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray); 1.371 + 1.372 +private: 1.373 + int mUniqueId; 1.374 + sp<DrmManagerClientImpl> mDrmManagerClientImpl; 1.375 +}; 1.376 + 1.377 +}; 1.378 + 1.379 +#endif /* __DRM_MANAGER_CLIENT_H__ */ 1.380 +