michael@0: /* michael@0: * Copyright (C) 2010 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef __DRM_MANAGER_CLIENT_H__ michael@0: #define __DRM_MANAGER_CLIENT_H__ michael@0: michael@0: #include michael@0: #include michael@0: #include "drm_framework_common.h" michael@0: michael@0: namespace android { michael@0: michael@0: class DrmInfo; michael@0: class DrmRights; michael@0: class DrmMetadata; michael@0: class DrmInfoEvent; michael@0: class DrmInfoStatus; michael@0: class DrmInfoRequest; michael@0: class DrmSupportInfo; michael@0: class DrmConstraints; michael@0: class DrmConvertedStatus; michael@0: class DrmManagerClientImpl; michael@0: michael@0: /** michael@0: * The Native application will instantiate this class and access DRM Framework michael@0: * services through this class. michael@0: * michael@0: */ michael@0: class DrmManagerClient { michael@0: public: michael@0: DrmManagerClient(); michael@0: michael@0: virtual ~DrmManagerClient(); michael@0: michael@0: public: michael@0: class OnInfoListener: virtual public RefBase { michael@0: michael@0: public: michael@0: virtual ~OnInfoListener() {} michael@0: michael@0: public: michael@0: virtual void onInfo(const DrmInfoEvent& event) = 0; michael@0: }; michael@0: michael@0: /** michael@0: * APIs which will be used by native modules (e.g. StageFright) michael@0: * michael@0: */ michael@0: public: michael@0: /** michael@0: * Open the decrypt session to decrypt the given protected content michael@0: * michael@0: * @param[in] fd File descriptor of the protected content to be decrypted michael@0: * @param[in] offset Start position of the content michael@0: * @param[in] length The length of the protected content michael@0: * @return michael@0: * Handle for the decryption session michael@0: */ michael@0: sp openDecryptSession(int fd, off64_t offset, off64_t length); michael@0: michael@0: /** michael@0: * Open the decrypt session to decrypt the given protected content michael@0: * michael@0: * @param[in] uri Path of the protected content to be decrypted michael@0: * @return michael@0: * Handle for the decryption session michael@0: */ michael@0: sp openDecryptSession(const char* uri); michael@0: michael@0: /** michael@0: * Close the decrypt session for the given handle michael@0: * michael@0: * @param[in] decryptHandle Handle for the decryption session michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t closeDecryptSession(sp &decryptHandle); michael@0: michael@0: /** michael@0: * Consumes the rights for a content. michael@0: * If the reserve parameter is true the rights is reserved until the same michael@0: * application calls this api again with the reserve parameter set to false. michael@0: * michael@0: * @param[in] decryptHandle Handle for the decryption session michael@0: * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) michael@0: * @param[in] reserve True if the rights should be reserved. michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure. michael@0: * In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned. michael@0: */ michael@0: status_t consumeRights(sp &decryptHandle, int action, bool reserve); michael@0: michael@0: /** michael@0: * Informs the DRM engine about the playback actions performed on the DRM files. michael@0: * michael@0: * @param[in] decryptHandle Handle for the decryption session michael@0: * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) michael@0: * @param[in] position Position in the file (in milliseconds) where the start occurs. michael@0: * Only valid together with Playback::START. michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t setPlaybackStatus( michael@0: sp &decryptHandle, int playbackStatus, int64_t position); michael@0: michael@0: /** michael@0: * Initialize decryption for the given unit of the protected content michael@0: * michael@0: * @param[in] decryptHandle Handle for the decryption session michael@0: * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID michael@0: * @param[in] headerInfo Information for initializing decryption of this decrypUnit michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t initializeDecryptUnit( michael@0: sp &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); michael@0: michael@0: /** michael@0: * Decrypt the protected content buffers for the given unit michael@0: * This method will be called any number of times, based on number of michael@0: * encrypted streams received from application. michael@0: * michael@0: * @param[in] decryptHandle Handle for the decryption session michael@0: * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID michael@0: * @param[in] encBuffer Encrypted data block michael@0: * @param[out] decBuffer Decrypted data block michael@0: * @param[in] IV Optional buffer michael@0: * @return status_t michael@0: * Returns the error code for this API michael@0: * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED michael@0: * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, michael@0: * DRM_ERROR_DECRYPT for failure. michael@0: */ michael@0: status_t decrypt( michael@0: sp &decryptHandle, int decryptUnitId, michael@0: const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL); michael@0: michael@0: /** michael@0: * Finalize decryption for the given unit of the protected content michael@0: * michael@0: * @param[in] decryptHandle Handle for the decryption session michael@0: * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t finalizeDecryptUnit( michael@0: sp &decryptHandle, int decryptUnitId); michael@0: michael@0: /** michael@0: * Reads the specified number of bytes from an open DRM file. michael@0: * michael@0: * @param[in] decryptHandle Handle for the decryption session michael@0: * @param[out] buffer Reference to the buffer that should receive the read data. michael@0: * @param[in] numBytes Number of bytes to read. michael@0: * @param[in] offset Offset with which to update the file position. michael@0: * michael@0: * @return Number of bytes read. Returns -1 for Failure. michael@0: */ michael@0: ssize_t pread(sp &decryptHandle, michael@0: void* buffer, ssize_t numBytes, off64_t offset); michael@0: michael@0: /** michael@0: * Validates whether an action on the DRM content is allowed or not. michael@0: * michael@0: * @param[in] path Path of the protected content michael@0: * @param[in] action Action to validate. (Action::DEFAULT, Action::PLAY, etc) michael@0: * @param[in] description Detailed description of the action michael@0: * @return true if the action is allowed. michael@0: */ michael@0: bool validateAction(const String8& path, int action, const ActionDescription& description); michael@0: michael@0: /** michael@0: * APIs which are just the underlying implementation for the Java API michael@0: * michael@0: */ michael@0: public: michael@0: /** michael@0: * Register a callback to be invoked when the caller required to michael@0: * receive necessary information michael@0: * michael@0: * @param[in] infoListener Listener michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t setOnInfoListener(const sp& infoListener); michael@0: michael@0: /** michael@0: * Get constraint information associated with input content michael@0: * michael@0: * @param[in] path Path of the protected content michael@0: * @param[in] action Actions defined such as, michael@0: * Action::DEFAULT, Action::PLAY, etc michael@0: * @return DrmConstraints michael@0: * key-value pairs of constraint are embedded in it michael@0: * @note michael@0: * In case of error, return NULL michael@0: */ michael@0: DrmConstraints* getConstraints(const String8* path, const int action); michael@0: michael@0: /** michael@0: * Get metadata information associated with input content michael@0: * michael@0: * @param[in] path Path of the protected content michael@0: * @return DrmMetadata michael@0: * key-value pairs of metadata michael@0: * @note michael@0: * In case of error, return NULL michael@0: */ michael@0: DrmMetadata* getMetadata(const String8* path); michael@0: michael@0: /** michael@0: * Check whether the given mimetype or path can be handled michael@0: * michael@0: * @param[in] path Path of the content needs to be handled michael@0: * @param[in] mimetype Mimetype of the content needs to be handled michael@0: * @return michael@0: * True if DrmManager can handle given path or mime type. michael@0: */ michael@0: bool canHandle(const String8& path, const String8& mimeType); michael@0: michael@0: /** michael@0: * Executes given drm information based on its type michael@0: * michael@0: * @param[in] drmInfo Information needs to be processed michael@0: * @return DrmInfoStatus michael@0: * instance as a result of processing given input michael@0: */ michael@0: DrmInfoStatus* processDrmInfo(const DrmInfo* drmInfo); michael@0: michael@0: /** michael@0: * Retrieves necessary information for registration, unregistration or rights michael@0: * acquisition information. michael@0: * michael@0: * @param[in] drmInfoRequest Request information to retrieve drmInfo michael@0: * @return DrmInfo michael@0: * instance as a result of processing given input michael@0: */ michael@0: DrmInfo* acquireDrmInfo(const DrmInfoRequest* drmInfoRequest); michael@0: michael@0: /** michael@0: * Save DRM rights to specified rights path michael@0: * and make association with content path michael@0: * michael@0: * @param[in] drmRights DrmRights to be saved michael@0: * @param[in] rightsPath File path where rights to be saved michael@0: * @param[in] contentPath File path where content was saved michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t saveRights( michael@0: const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); michael@0: michael@0: /** michael@0: * Retrieves the mime type embedded inside the original content michael@0: * michael@0: * @param[in] path the path of the protected content michael@0: * @return String8 michael@0: * Returns mime-type of the original content, such as "video/mpeg" michael@0: */ michael@0: String8 getOriginalMimeType(const String8& path); michael@0: michael@0: /** michael@0: * Retrieves the type of the protected object (content, rights, etc..) michael@0: * by using specified path or mimetype. At least one parameter should be non null michael@0: * to retrieve DRM object type michael@0: * michael@0: * @param[in] path Path of the content or null. michael@0: * @param[in] mimeType Mime type of the content or null. michael@0: * @return type of the DRM content, michael@0: * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT michael@0: */ michael@0: int getDrmObjectType(const String8& path, const String8& mimeType); michael@0: michael@0: /** michael@0: * Check whether the given content has valid rights or not michael@0: * michael@0: * @param[in] path Path of the protected content michael@0: * @param[in] action Action to perform michael@0: * @return the status of the rights for the protected content, michael@0: * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. michael@0: */ michael@0: int checkRightsStatus(const String8& path, int action); michael@0: michael@0: /** michael@0: * Removes the rights associated with the given protected content michael@0: * michael@0: * @param[in] path Path of the protected content michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t removeRights(const String8& path); michael@0: michael@0: /** michael@0: * Removes all the rights information of each plug-in associated with michael@0: * DRM framework. Will be used in master reset michael@0: * michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t removeAllRights(); michael@0: michael@0: /** michael@0: * This API is for Forward Lock DRM. michael@0: * Each time the application tries to download a new DRM file michael@0: * which needs to be converted, then the application has to michael@0: * begin with calling this API. michael@0: * michael@0: * @param[in] convertId Handle for the convert session michael@0: * @param[in] mimeType Description/MIME type of the input data packet michael@0: * @return Return handle for the convert session michael@0: */ michael@0: int openConvertSession(const String8& mimeType); michael@0: michael@0: /** michael@0: * Passes the input data which need to be converted. The resultant michael@0: * converted data and the status is returned in the DrmConvertedInfo michael@0: * object. This method will be called each time there are new block michael@0: * of data received by the application. michael@0: * michael@0: * @param[in] convertId Handle for the convert session michael@0: * @param[in] inputData Input Data which need to be converted michael@0: * @return Return object contains the status of the data conversion, michael@0: * the output converted data and offset. In this case the michael@0: * application will ignore the offset information. michael@0: */ michael@0: DrmConvertedStatus* convertData(int convertId, const DrmBuffer* inputData); michael@0: michael@0: /** michael@0: * When there is no more data which need to be converted or when an michael@0: * error occurs that time the application has to inform the Drm agent michael@0: * via this API. Upon successful conversion of the complete data, michael@0: * the agent will inform that where the header and body signature michael@0: * should be added. This signature appending is needed to integrity michael@0: * protect the converted file. michael@0: * michael@0: * @param[in] convertId Handle for the convert session michael@0: * @return Return object contains the status of the data conversion, michael@0: * the header and body signature data. It also informs michael@0: * the application on which offset these signature data michael@0: * should be appended. michael@0: */ michael@0: DrmConvertedStatus* closeConvertSession(int convertId); michael@0: michael@0: /** michael@0: * Retrieves all DrmSupportInfo instance that native DRM framework can handle. michael@0: * This interface is meant to be used by JNI layer michael@0: * michael@0: * @param[out] length Number of elements in drmSupportInfoArray michael@0: * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo michael@0: * that native DRM framework can handle michael@0: * @return status_t michael@0: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure michael@0: */ michael@0: status_t getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray); michael@0: michael@0: private: michael@0: int mUniqueId; michael@0: sp mDrmManagerClientImpl; michael@0: }; michael@0: michael@0: }; michael@0: michael@0: #endif /* __DRM_MANAGER_CLIENT_H__ */ michael@0: