IDrmEngine.h revision 9d2f386dd2885eaffa11fd494ae258bb09fe6397
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/*
2d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch * Copyright (C) 2010 The Android Open Source Project
3d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch *
4d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch * Licensed under the Apache License, Version 2.0 (the "License");
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * you may not use this file except in compliance with the License.
6d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch * You may obtain a copy of the License at
7d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch *
8d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch *      http://www.apache.org/licenses/LICENSE-2.0
946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) *
1046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) * Unless required by applicable law or agreed to in writing, software
11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS,
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * See the License for the specific language governing permissions and
14d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch * limitations under the License.
15d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch */
16d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
17d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#ifndef __IDRM_ENGINE_H__
18d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#define __IDRM_ENGINE_H__
1946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include <drm/drm_framework_common.h>
2146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace android {
2346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class DrmConstraints;
25d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass DrmMetadata;
26d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass DrmRights;
27d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass DrmInfo;
28d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass DrmInfoStatus;
29d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass DrmConvertedStatus;
30d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass DrmInfoRequest;
3146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class DrmSupportInfo;
3246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class DrmInfoEvent;
3346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)/**
3546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) * This class is an interface for plug-in user
36d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch *
37d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch * Responsibility of this class is provide generic interface to DRM Engine Manager.
38d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch * Each interface need to be as abstract as possible.
3946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) */
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass IDrmEngine {
4146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)public:
4246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    virtual ~IDrmEngine() {
4346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    }
4446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)public:
4646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    class OnInfoListener {
4746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    public:
4946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        virtual void onInfo(const DrmInfoEvent& event) = 0;
5046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
5146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        virtual ~OnInfoListener() { }
5246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    };
53d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
54d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochpublic:
5546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
5646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    //////////////////////////////////
5746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    // Implementation of IDrmEngine //
5846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    //////////////////////////////////
5946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
6046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    /**
6146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * Initialize plug-in
6246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     *
63d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch     * @param[in] uniqueId Unique identifier for a session
64d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch     * @return status_t
6546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
6646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     */
6746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    virtual status_t initialize(int uniqueId) = 0;
6846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
6946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    /**
7046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * Register a callback to be invoked when the caller required to
7146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * receive necessary information
72f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)     *
7346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * @param[in] uniqueId Unique identifier for a session
7446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * @param[in] infoListener Listener
7546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * @return status_t
7646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
7746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     */
7846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    virtual status_t setOnInfoListener(
7946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)            int uniqueId, const IDrmEngine::OnInfoListener* infoListener) = 0;
8046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
8146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    /**
82d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch     * Terminate the plug-in
83d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch     * and release resource bound to plug-in
84d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch     * 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 metadata information associated with input content
109     *
110     * @param[in] uniqueId Unique identifier for a session
111     * @param[in] path Path of the protected content
112     * @return DrmMetadata
113     *         key-value pairs of metadata
114     * @note
115     *      In case of error, return NULL
116     */
117    virtual DrmMetadata* getMetadata(int uniqueId, const String8* path) = 0;
118
119    /**
120     * Get whether the given content can be handled by this plugin or not
121     *
122     * @param[in] uniqueId Unique identifier for a session
123     * @param[in] path Path the protected object
124     * @return bool
125     *     true if this plugin can handle , false in case of not able to handle
126     */
127    virtual bool canHandle(int uniqueId, const String8& path) = 0;
128
129    /**
130     * Executes given drm information based on its type
131     *
132     * @param[in] uniqueId Unique identifier for a session
133     * @param[in] drmInfo Information needs to be processed
134     * @return DrmInfoStatus
135     *     instance as a result of processing given input
136     */
137    virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0;
138
139    /**
140     * Retrieves necessary information for registration, unregistration or rights
141     * acquisition information.
142     *
143     * @param[in] uniqueId Unique identifier for a session
144     * @param[in] drmInfoRequest Request information to retrieve drmInfo
145     * @return DrmInfo
146     *     instance as a result of processing given input
147     */
148    virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) = 0;
149
150    /**
151     * Save DRM rights to specified rights path
152     * and make association with content path
153     *
154     * @param[in] uniqueId Unique identifier for a session
155     * @param[in] drmRights DrmRights to be saved
156     * @param[in] rightsPath File path where rights to be saved
157     * @param[in] contentPath File path where content was saved
158     * @return status_t
159     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
160     */
161    virtual status_t saveRights(int uniqueId, const DrmRights& drmRights,
162            const String8& rightsPath, const String8& contentPath) = 0;
163
164    /**
165     * Retrieves the mime type embedded inside the original content
166     *
167     * @param[in] uniqueId Unique identifier for a session
168     * @param[in] path Path of the protected content
169     * @return String8
170     *     Returns mime-type of the original content, such as "video/mpeg"
171     */
172    virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0;
173
174    /**
175     * Retrieves the type of the protected object (content, rights, etc..)
176     * using specified path or mimetype. At least one parameter should be non null
177     * to retrieve DRM object type
178     *
179     * @param[in] uniqueId Unique identifier for a session
180     * @param[in] path Path of the content or null.
181     * @param[in] mimeType Mime type of the content or null.
182     * @return type of the DRM content,
183     *     such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
184     */
185    virtual int getDrmObjectType(
186            int uniqueId, const String8& path, const String8& mimeType) = 0;
187
188    /**
189     * Check whether the given content has valid rights or not
190     *
191     * @param[in] uniqueId Unique identifier for a session
192     * @param[in] path Path of the protected content
193     * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc)
194     * @return the status of the rights for the protected content,
195     *     such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
196     */
197    virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0;
198
199    /**
200     * Consumes the rights for a content.
201     * If the reserve parameter is true the rights is reserved until the same
202     * application calls this api again with the reserve parameter set to false.
203     *
204     * @param[in] uniqueId Unique identifier for a session
205     * @param[in] decryptHandle Handle for the decryption session
206     * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
207     * @param[in] reserve True if the rights should be reserved.
208     * @return status_t
209     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
210     */
211    virtual status_t consumeRights(
212            int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0;
213
214    /**
215     * Informs the DRM Engine about the playback actions performed on the DRM files.
216     *
217     * @param[in] uniqueId Unique identifier for a session
218     * @param[in] decryptHandle Handle for the decryption session
219     * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
220     * @param[in] position Position in the file (in milliseconds) where the start occurs.
221     *     Only valid together with Playback::START.
222     * @return status_t
223     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
224     */
225    virtual status_t setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
226            int playbackStatus, int64_t position) = 0;
227
228    /**
229     * Validates whether an action on the DRM content is allowed or not.
230     *
231     * @param[in] uniqueId Unique identifier for a session
232     * @param[in] path Path of the protected content
233     * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc)
234     * @param[in] description Detailed description of the action
235     * @return true if the action is allowed.
236     */
237    virtual bool validateAction(int uniqueId, const String8& path,
238            int action, const ActionDescription& description) = 0;
239
240    /**
241     * Removes the rights associated with the given protected content
242     *
243     * @param[in] uniqueId Unique identifier for a session
244     * @param[in] path Path of the protected content
245     * @return status_t
246     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
247     */
248    virtual status_t removeRights(int uniqueId, const String8& path) = 0;
249
250    /**
251     * Removes all the rights information of each plug-in associated with
252     * DRM framework. Will be used in master reset
253     *
254     * @param[in] uniqueId Unique identifier for a session
255     * @return status_t
256     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
257     */
258    virtual status_t removeAllRights(int uniqueId) = 0;
259
260    /**
261     * This API is for Forward Lock based DRM scheme.
262     * Each time the application tries to download a new DRM file
263     * which needs to be converted, then the application has to
264     * begin with calling this API.
265     *
266     * @param[in] uniqueId Unique identifier for a session
267     * @param[in] convertId Handle for the convert session
268     * @return status_t
269     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
270     */
271    virtual status_t openConvertSession(int uniqueId, int convertId) = 0;
272
273    /**
274     * Accepts and converts the input data which is part of DRM file.
275     * The resultant converted data and the status is returned in the DrmConvertedInfo
276     * object. This method will be called each time there are new block
277     * of data received by the application.
278     *
279     * @param[in] uniqueId Unique identifier for a session
280     * @param[in] convertId Handle for the convert session
281     * @param[in] inputData Input Data which need to be converted
282     * @return Return object contains the status of the data conversion,
283     *     the output converted data and offset. In this case the
284     *     application will ignore the offset information.
285     */
286    virtual DrmConvertedStatus* convertData(
287            int uniqueId, int convertId, const DrmBuffer* inputData) = 0;
288
289    /**
290     * Informs the Drm Agent when there is no more data which need to be converted
291     * or when an error occurs. Upon successful conversion of the complete data,
292     * the agent will inform that where the header and body signature
293     * should be added. This signature appending is needed to integrity
294     * protect the converted file.
295     *
296     * @param[in] uniqueId Unique identifier for a session
297     * @param[in] convertId Handle for the convert session
298     * @return Return object contains the status of the data conversion,
299     *     the header and body signature data. It also informs
300     *     the application on which offset these signature data
301     *     should be appended.
302     */
303    virtual DrmConvertedStatus* closeConvertSession( int uniqueId, int convertId) = 0;
304
305    /**
306     * Returns the information about the Drm Engine capabilities which includes
307     * supported MimeTypes and file suffixes.
308     *
309     * @param[in] uniqueId Unique identifier for a session
310     * @return DrmSupportInfo
311     *     instance which holds the capabilities of a plug-in
312     */
313    virtual DrmSupportInfo* getSupportInfo(int uniqueId) = 0;
314
315    /**
316     * Open the decrypt session to decrypt the given protected content
317     *
318     * @param[in] uniqueId Unique identifier for a session
319     * @param[in] decryptHandle Handle for the current decryption session
320     * @param[in] fd File descriptor of the protected content to be decrypted
321     * @param[in] offset Start position of the content
322     * @param[in] length The length of the protected content
323     * @param[in] mime Mime type of the protected content if it is
324     *     not NULL or empty
325     * @return
326     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
327     */
328    virtual status_t openDecryptSession(
329        int uniqueId, DecryptHandle* decryptHandle,
330        int fd, off64_t offset, off64_t length, const char* mime) = 0;
331
332    /**
333     * Open the decrypt session to decrypt the given protected content
334     *
335     * @param[in] uniqueId Unique identifier for a session
336     * @param[in] decryptHandle Handle for the current decryption session
337     * @param[in] uri Path of the protected content to be decrypted
338     * @param[in] mime Mime type of the protected content if it is
339     *     not NULL or empty
340     * @return
341     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
342     */
343    virtual status_t openDecryptSession(
344        int uniqueId, DecryptHandle* decryptHandle,
345        const char* uri, const char* mime) = 0;
346
347    /**
348     * Close the decrypt session for the given handle
349     *
350     * @param[in] uniqueId Unique identifier for a session
351     * @param[in] decryptHandle Handle for the decryption session
352     * @return status_t
353     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
354     */
355    virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
356
357    /**
358     * Initialize decryption for the given unit of the protected content
359     *
360     * @param[in] uniqueId Unique identifier for a session
361     * @param[in] decryptHandle Handle for the decryption session
362     * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
363     * @param[in] headerInfo Information for initializing decryption of this decrypUnit
364     * @return status_t
365     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
366     */
367    virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
368            int decryptUnitId, const DrmBuffer* headerInfo) = 0;
369
370    /**
371     * Decrypt the protected content buffers for the given unit
372     * This method will be called any number of times, based on number of
373     * encrypted streams received from application.
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     * @param[in] encBuffer Encrypted data block
379     * @param[out] decBuffer Decrypted data block
380     * @param[in] IV Optional buffer
381     * @return status_t
382     *     Returns the error code for this API
383     *     DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
384     *     DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
385     *     DRM_ERROR_DECRYPT for failure.
386     */
387    virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
388            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) = 0;
389
390    /**
391     * Finalize decryption for the given unit of the protected content
392     *
393     * @param[in] uniqueId Unique identifier for a session
394     * @param[in] decryptHandle Handle for the decryption session
395     * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
396     * @return status_t
397     *     Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
398     */
399    virtual status_t finalizeDecryptUnit(
400            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0;
401
402    /**
403     * Reads the specified number of bytes from an open DRM file.
404     *
405     * @param[in] uniqueId Unique identifier for a session
406     * @param[in] decryptHandle Handle for the decryption session
407     * @param[out] buffer Reference to the buffer that should receive the read data.
408     * @param[in] numBytes Number of bytes to read.
409     * @param[in] offset Offset with which to update the file position.
410     *
411     * @return Number of bytes read. Returns -1 for Failure.
412     */
413    virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
414            void* buffer, ssize_t numBytes, off64_t offset) = 0;
415};
416
417};
418
419#endif /* __IDRM_ENGINE_H__ */
420
421