IDrmEngine.h revision e943f84129326ab885cc7a69dcfa17f766b72b89
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     * @return status_t
147     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
148     */
149    virtual status_t saveRights(int uniqueId, const DrmRights& drmRights,
150            const String8& rightsPath, const String8& contentPath) = 0;
151
152    /**
153     * Retrieves the mime type embedded inside the original content
154     *
155     * @param[in] uniqueId Unique identifier for a session
156     * @param[in] path Path of the protected content
157     * @return String8
158     *     Returns mime-type of the original content, such as "video/mpeg"
159     */
160    virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0;
161
162    /**
163     * Retrieves the type of the protected object (content, rights, etc..)
164     * using specified path or mimetype. At least one parameter should be non null
165     * to retrieve DRM object type
166     *
167     * @param[in] uniqueId Unique identifier for a session
168     * @param[in] path Path of the content or null.
169     * @param[in] mimeType Mime type of the content or null.
170     * @return type of the DRM content,
171     *     such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
172     */
173    virtual int getDrmObjectType(
174            int uniqueId, const String8& path, const String8& mimeType) = 0;
175
176    /**
177     * Check whether the given content has valid rights or not
178     *
179     * @param[in] uniqueId Unique identifier for a session
180     * @param[in] path Path of the protected content
181     * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc)
182     * @return the status of the rights for the protected content,
183     *     such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
184     */
185    virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0;
186
187    /**
188     * Consumes the rights for a content.
189     * If the reserve parameter is true the rights is reserved until the same
190     * application calls this api again with the reserve parameter set to false.
191     *
192     * @param[in] uniqueId Unique identifier for a session
193     * @param[in] decryptHandle Handle for the decryption session
194     * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
195     * @param[in] reserve True if the rights should be reserved.
196     * @return status_t
197     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
198     */
199    virtual status_t consumeRights(
200            int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0;
201
202    /**
203     * Informs the DRM Engine about the playback actions performed on the DRM files.
204     *
205     * @param[in] uniqueId Unique identifier for a session
206     * @param[in] decryptHandle Handle for the decryption session
207     * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
208     * @param[in] position Position in the file (in milliseconds) where the start occurs.
209     *     Only valid together with Playback::START.
210     * @return status_t
211     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
212     */
213    virtual status_t setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
214            int playbackStatus, int position) = 0;
215
216    /**
217     * Validates whether an action on the DRM content is allowed or not.
218     *
219     * @param[in] uniqueId Unique identifier for a session
220     * @param[in] path Path of the protected content
221     * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc)
222     * @param[in] description Detailed description of the action
223     * @return true if the action is allowed.
224     */
225    virtual bool validateAction(int uniqueId, const String8& path,
226            int action, const ActionDescription& description) = 0;
227
228    /**
229     * Removes the rights associated with the given protected content
230     *
231     * @param[in] uniqueId Unique identifier for a session
232     * @param[in] path Path of the protected content
233     * @return status_t
234     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
235     */
236    virtual status_t removeRights(int uniqueId, const String8& path) = 0;
237
238    /**
239     * Removes all the rights information of each plug-in associated with
240     * DRM framework. Will be used in master reset
241     *
242     * @param[in] uniqueId Unique identifier for a session
243     * @return status_t
244     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
245     */
246    virtual status_t removeAllRights(int uniqueId) = 0;
247
248    /**
249     * This API is for Forward Lock based DRM scheme.
250     * Each time the application tries to download a new DRM file
251     * which needs to be converted, then the application has to
252     * begin with calling this API.
253     *
254     * @param[in] uniqueId Unique identifier for a session
255     * @param[in] convertId Handle for the convert session
256     * @return status_t
257     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
258     */
259    virtual status_t openConvertSession(int uniqueId, int convertId) = 0;
260
261    /**
262     * Accepts and converts the input data which is part of DRM file.
263     * The resultant converted data and the status is returned in the DrmConvertedInfo
264     * object. This method will be called each time there are new block
265     * of data received by the application.
266     *
267     * @param[in] uniqueId Unique identifier for a session
268     * @param[in] convertId Handle for the convert session
269     * @param[in] inputData Input Data which need to be converted
270     * @return Return object contains the status of the data conversion,
271     *     the output converted data and offset. In this case the
272     *     application will ignore the offset information.
273     */
274    virtual DrmConvertedStatus* convertData(
275            int uniqueId, int convertId, const DrmBuffer* inputData) = 0;
276
277    /**
278     * Informs the Drm Agent when there is no more data which need to be converted
279     * or when an error occurs. Upon successful conversion of the complete data,
280     * the agent will inform that where the header and body signature
281     * should be added. This signature appending is needed to integrity
282     * protect the converted file.
283     *
284     * @param[in] uniqueId Unique identifier for a session
285     * @param[in] convertId Handle for the convert session
286     * @return Return object contains the status of the data conversion,
287     *     the header and body signature data. It also informs
288     *     the application on which offset these signature data
289     *     should be appended.
290     */
291    virtual DrmConvertedStatus* closeConvertSession( int uniqueId, int convertId) = 0;
292
293    /**
294     * Returns the information about the Drm Engine capabilities which includes
295     * supported MimeTypes and file suffixes.
296     *
297     * @param[in] uniqueId Unique identifier for a session
298     * @return DrmSupportInfo
299     *     instance which holds the capabilities of a plug-in
300     */
301    virtual DrmSupportInfo* getSupportInfo(int uniqueId) = 0;
302
303    /**
304     * Open the decrypt session to decrypt the given protected content
305     *
306     * @param[in] uniqueId Unique identifier for a session
307     * @param[in] decryptHandle Handle for the current decryption session
308     * @param[in] fd File descriptor of the protected content to be decrypted
309     * @param[in] offset Start position of the content
310     * @param[in] length The length of the protected content
311     * @return
312     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
313     */
314    virtual status_t openDecryptSession(
315        int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0;
316
317    /**
318     * Open the decrypt session to decrypt the given protected content
319     *
320     * @param[in] uniqueId Unique identifier for a session
321     * @param[in] decryptHandle Handle for the current decryption session
322     * @param[in] uri Path of the protected content to be decrypted
323     * @return
324     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
325     */
326    virtual status_t openDecryptSession(
327        int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0;
328
329    /**
330     * Close the decrypt session for the given handle
331     *
332     * @param[in] uniqueId Unique identifier for a session
333     * @param[in] decryptHandle Handle for the decryption session
334     * @return status_t
335     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
336     */
337    virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
338
339    /**
340     * Initialize decryption for the given unit of the protected content
341     *
342     * @param[in] uniqueId Unique identifier for a session
343     * @param[in] decryptHandle Handle for the decryption session
344     * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
345     * @param[in] headerInfo Information for initializing decryption of this decrypUnit
346     * @return status_t
347     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
348     */
349    virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
350            int decryptUnitId, const DrmBuffer* headerInfo) = 0;
351
352    /**
353     * Decrypt the protected content buffers for the given unit
354     * This method will be called any number of times, based on number of
355     * encrypted streams received from application.
356     *
357     * @param[in] uniqueId Unique identifier for a session
358     * @param[in] decryptHandle Handle for the decryption session
359     * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
360     * @param[in] encBuffer Encrypted data block
361     * @param[out] decBuffer Decrypted data block
362     * @param[in] IV Optional buffer
363     * @return status_t
364     *     Returns the error code for this API
365     *     DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
366     *     DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
367     *     DRM_ERROR_DECRYPT for failure.
368     */
369    virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
370            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) = 0;
371
372    /**
373     * Finalize decryption for the given unit of the protected content
374     *
375     * @param[in] uniqueId Unique identifier for a session
376     * @param[in] decryptHandle Handle for the decryption session
377     * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
378     * @return status_t
379     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
380     */
381    virtual status_t finalizeDecryptUnit(
382            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0;
383
384    /**
385     * Reads the specified number of bytes from an open DRM file.
386     *
387     * @param[in] uniqueId Unique identifier for a session
388     * @param[in] decryptHandle Handle for the decryption session
389     * @param[out] buffer Reference to the buffer that should receive the read data.
390     * @param[in] numBytes Number of bytes to read.
391     * @param[in] offset Offset with which to update the file position.
392     *
393     * @return Number of bytes read. Returns -1 for Failure.
394     */
395    virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
396            void* buffer, ssize_t numBytes, off_t offset) = 0;
397};
398
399};
400
401#endif /* __IDRM_ENGINE_H__ */
402
403