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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "TestPlugin"
19 #include <utils/Log.h>
20 
21 #include <drm/DrmRights.h>
22 #include <drm/DrmConstraints.h>
23 #include <drm/DrmMetadata.h>
24 #include <drm/DrmInfo.h>
25 #include <drm/DrmInfoEvent.h>
26 #include <drm/DrmInfoStatus.h>
27 #include <drm/DrmConvertedStatus.h>
28 #include <drm/DrmInfoRequest.h>
29 #include <drm/DrmSupportInfo.h>
30 #include <TestPlugin.h>
31 
32 using namespace android;
33 
34 
35 // This extern "C" is mandatory to be managed by TPlugInManager
create()36 extern "C" IDrmEngine* create() {
37     return new TestPlugIn();
38 }
39 
40 // This extern "C" is mandatory to be managed by TPlugInManager
destroy(IDrmEngine * pPlugIn)41 extern "C" void destroy(IDrmEngine* pPlugIn) {
42     delete pPlugIn;
43     pPlugIn = NULL;
44 }
45 
TestPlugIn()46 TestPlugIn::TestPlugIn()
47     : DrmEngineBase() {
48 
49 }
50 
~TestPlugIn()51 TestPlugIn::~TestPlugIn() {
52 
53 }
54 
onGetMetadata(int uniqueId,const String8 * path)55 DrmMetadata* TestPlugIn::onGetMetadata(int uniqueId, const String8* path) {
56     return NULL;
57 }
58 
onGetConstraints(int uniqueId,const String8 * path,int action)59 DrmConstraints* TestPlugIn::onGetConstraints(
60         int uniqueId, const String8* path, int action) {
61     return NULL;
62 }
63 
onProcessDrmInfo(int uniqueId,const DrmInfo * drmInfo)64 DrmInfoStatus* TestPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
65     return NULL;
66 }
67 
onSetOnInfoListener(int uniqueId,const IDrmEngine::OnInfoListener * infoListener)68 status_t TestPlugIn::onSetOnInfoListener(
69             int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
70     return DRM_NO_ERROR;
71 }
72 
onInitialize(int uniqueId)73 status_t TestPlugIn::onInitialize(int uniqueId) {
74     return DRM_NO_ERROR;
75 }
76 
onTerminate(int uniqueId)77 status_t TestPlugIn::onTerminate(int uniqueId) {
78     return DRM_NO_ERROR;
79 }
80 
onGetSupportInfo(int uniqueId)81 DrmSupportInfo* TestPlugIn::onGetSupportInfo(int uniqueId) {
82     DrmSupportInfo* drmSupportInfo = new DrmSupportInfo();
83     return drmSupportInfo;
84 }
85 
onSaveRights(int uniqueId,const DrmRights & drmRights,const String8 & rightsPath,const String8 & contentPath)86 status_t TestPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights,
87             const String8& rightsPath, const String8& contentPath) {
88     return DRM_NO_ERROR;
89 }
90 
onAcquireDrmInfo(int uniqueId,const DrmInfoRequest * drmInfoRequest)91 DrmInfo* TestPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
92     return NULL;
93 }
94 
onCanHandle(int uniqueId,const String8 & path)95 bool TestPlugIn::onCanHandle(int uniqueId, const String8& path) {
96     return false;
97 }
98 
onGetOriginalMimeType(int uniqueId,const String8 & path,int fd)99 String8 TestPlugIn::onGetOriginalMimeType(int uniqueId, const String8& path, int fd) {
100     return String8("video/none");
101 }
102 
onGetDrmObjectType(int uniqueId,const String8 & path,const String8 & mimeType)103 int TestPlugIn::onGetDrmObjectType(
104             int uniqueId, const String8& path, const String8& mimeType) {
105     return DrmObjectType::UNKNOWN;
106 }
107 
onCheckRightsStatus(int uniqueId,const String8 & path,int action)108 int TestPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, int action) {
109     int rightsStatus = RightsStatus::RIGHTS_VALID;
110     return rightsStatus;
111 }
112 
onConsumeRights(int uniqueId,sp<DecryptHandle> & decryptHandle,int action,bool reserve)113 status_t TestPlugIn::onConsumeRights(int uniqueId, sp<DecryptHandle>& decryptHandle,
114             int action, bool reserve) {
115     return DRM_NO_ERROR;
116 }
117 
onSetPlaybackStatus(int uniqueId,sp<DecryptHandle> & decryptHandle,int playbackStatus,int64_t position)118 status_t TestPlugIn::onSetPlaybackStatus(int uniqueId, sp<DecryptHandle>& decryptHandle,
119             int playbackStatus, int64_t position) {
120     return DRM_NO_ERROR;
121 }
122 
onValidateAction(int uniqueId,const String8 & path,int action,const ActionDescription & description)123 bool TestPlugIn::onValidateAction(int uniqueId, const String8& path,
124             int action, const ActionDescription& description) {
125     return true;
126 }
127 
onRemoveRights(int uniqueId,const String8 & path)128 status_t TestPlugIn::onRemoveRights(int uniqueId, const String8& path) {
129     return DRM_NO_ERROR;
130 }
131 
onRemoveAllRights(int uniqueId)132 status_t TestPlugIn::onRemoveAllRights(int uniqueId) {
133     return DRM_NO_ERROR;
134 }
135 
onOpenConvertSession(int uniqueId,int convertId)136 status_t TestPlugIn::onOpenConvertSession(int uniqueId, int convertId) {
137     return DRM_NO_ERROR;
138 }
139 
onConvertData(int uniqueId,int convertId,const DrmBuffer * inputData)140 DrmConvertedStatus* TestPlugIn::onConvertData(
141             int uniqueId, int convertId, const DrmBuffer* inputData) {
142     return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0);
143 }
144 
onCloseConvertSession(int uniqueId,int convertId)145 DrmConvertedStatus* TestPlugIn::onCloseConvertSession(int uniqueId, int convertId) {
146     return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0);
147 }
148 
onOpenDecryptSession(int uniqueId,sp<DecryptHandle> & decryptHandle,int fd,off64_t offset,off64_t length)149 status_t TestPlugIn::onOpenDecryptSession(
150             int uniqueId, sp<DecryptHandle>& decryptHandle, int fd, off64_t offset, off64_t length) {
151     return DRM_ERROR_CANNOT_HANDLE;
152 }
153 
onOpenDecryptSession(int uniqueId,sp<DecryptHandle> & decryptHandle,const char * uri)154 status_t TestPlugIn::onOpenDecryptSession(
155             int uniqueId, sp<DecryptHandle>& decryptHandle, const char* uri) {
156     return DRM_ERROR_CANNOT_HANDLE;
157 }
158 
onCloseDecryptSession(int uniqueId,sp<DecryptHandle> & decryptHandle)159 status_t TestPlugIn::onCloseDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle) {
160     return DRM_NO_ERROR;
161 }
162 
onInitializeDecryptUnit(int uniqueId,sp<DecryptHandle> & decryptHandle,int decryptUnitId,const DrmBuffer * headerInfo)163 status_t TestPlugIn::onInitializeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle,
164             int decryptUnitId, const DrmBuffer* headerInfo) {
165     return DRM_NO_ERROR;
166 }
167 
onDecrypt(int uniqueId,sp<DecryptHandle> & decryptHandle,int decryptUnitId,const DrmBuffer * encBuffer,DrmBuffer ** decBuffer,DrmBuffer * IV)168 status_t TestPlugIn::onDecrypt(int uniqueId, sp<DecryptHandle>& decryptHandle,
169             int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
170     return DRM_NO_ERROR;
171 }
172 
onFinalizeDecryptUnit(int uniqueId,sp<DecryptHandle> & decryptHandle,int decryptUnitId)173 status_t TestPlugIn::onFinalizeDecryptUnit(
174             int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId) {
175     return DRM_NO_ERROR;
176 }
177 
onPread(int uniqueId,sp<DecryptHandle> & decryptHandle,void * buffer,ssize_t numBytes,off64_t offset)178 ssize_t TestPlugIn::onPread(int uniqueId, sp<DecryptHandle>& decryptHandle,
179             void* buffer, ssize_t numBytes, off64_t offset) {
180     return 0;
181 }
182 
183