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