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