1 /* 2 * Copyright (C) 2017 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 MOCK_CAS_PLUGIN_H_ 18 #define MOCK_CAS_PLUGIN_H_ 19 20 #include <media/cas/CasAPI.h> 21 #include <media/cas/DescramblerAPI.h> 22 #include <utils/Mutex.h> 23 24 extern "C" { 25 android::CasFactory *createCasFactory(); 26 android::DescramblerFactory *createDescramblerFactory(); 27 } 28 29 namespace android { 30 31 class MockCasFactory : public CasFactory { 32 public: MockCasFactory()33 MockCasFactory() {} ~MockCasFactory()34 virtual ~MockCasFactory() {} 35 36 virtual bool isSystemIdSupported( 37 int32_t CA_system_id) const override; 38 virtual status_t queryPlugins( 39 std::vector<CasPluginDescriptor> *descriptors) const override; 40 virtual status_t createPlugin( 41 int32_t CA_system_id, 42 void *appData, 43 CasPluginCallback callback, 44 CasPlugin **plugin) override; 45 virtual status_t createPlugin( 46 int32_t CA_system_id, 47 void *appData, 48 CasPluginCallbackExt callback, 49 CasPlugin **plugin) override; 50 }; 51 52 class MockDescramblerFactory : public DescramblerFactory { 53 public: MockDescramblerFactory()54 MockDescramblerFactory() {} ~MockDescramblerFactory()55 virtual ~MockDescramblerFactory() {} 56 57 virtual bool isSystemIdSupported( 58 int32_t CA_system_id) const override; 59 virtual status_t createPlugin( 60 int32_t CA_system_id, DescramblerPlugin **plugin) override; 61 }; 62 63 class MockCasPlugin : public CasPlugin { 64 public: 65 MockCasPlugin(); 66 virtual ~MockCasPlugin(); 67 68 virtual status_t setPrivateData( 69 const CasData &data) override; 70 71 virtual status_t openSession(CasSessionId *sessionId) override; 72 73 virtual status_t closeSession( 74 const CasSessionId &sessionId) override; 75 76 virtual status_t setSessionPrivateData( 77 const CasSessionId &sessionId, 78 const CasData &data) override; 79 80 virtual status_t processEcm( 81 const CasSessionId &sessionId, const CasEcm &ecm) override; 82 83 virtual status_t processEmm(const CasEmm &emm) override; 84 85 virtual status_t sendEvent( 86 int32_t event, int32_t arg, const CasData &eventData) override; 87 88 virtual status_t sendSessionEvent( 89 const CasSessionId &sessionId, 90 int32_t event, int32_t arg, const CasData &eventData) override; 91 92 virtual status_t provision(const String8 &str) override; 93 94 virtual status_t refreshEntitlements( 95 int32_t refreshType, const CasData &refreshData) override; 96 97 private: 98 99 Mutex mLock; 100 }; 101 102 class MockDescramblerPlugin : public DescramblerPlugin { 103 public: MockDescramblerPlugin()104 MockDescramblerPlugin() {} ~MockDescramblerPlugin()105 virtual ~MockDescramblerPlugin() {}; 106 107 virtual bool requiresSecureDecoderComponent( 108 const char *mime) const override; 109 110 virtual status_t setMediaCasSession( 111 const CasSessionId &sessionId) override; 112 113 virtual ssize_t descramble( 114 bool secure, 115 ScramblingControl scramblingControl, 116 size_t numSubSamples, 117 const SubSample *subSamples, 118 const void *srcPtr, 119 int32_t srcOffset, 120 void *dstPtr, 121 int32_t dstOffset, 122 AString *errorDetailMsg) override; 123 124 private: 125 String8 subSamplesToString( 126 SubSample const *subSamples, 127 size_t numSubSamples) const; 128 String8 arrayToString(uint8_t const *array, size_t len) const; 129 }; 130 } // namespace android 131 132 #endif // MOCK_CAS_PLUGIN_H_ 133