Chong Zhang | 791a1a2 | 2017-01-03 11:36:07 -0800 | [diff] [blame] | 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: |
| 33 | 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 | uint64_t appData, |
| 43 | CasPluginCallback callback, |
| 44 | CasPlugin **plugin) override; |
| 45 | }; |
| 46 | |
| 47 | class MockDescramblerFactory : public DescramblerFactory { |
| 48 | public: |
| 49 | MockDescramblerFactory() {} |
| 50 | virtual ~MockDescramblerFactory() {} |
| 51 | |
| 52 | virtual bool isSystemIdSupported( |
| 53 | int32_t CA_system_id) const override; |
| 54 | virtual status_t createPlugin( |
| 55 | int32_t CA_system_id, DescramblerPlugin **plugin) override; |
| 56 | }; |
| 57 | |
| 58 | class MockCasPlugin : public CasPlugin { |
| 59 | public: |
| 60 | MockCasPlugin(); |
| 61 | virtual ~MockCasPlugin(); |
| 62 | |
| 63 | virtual status_t setPrivateData( |
| 64 | const CasData &data) override; |
| 65 | |
Chong Zhang | a78c1cc | 2017-03-31 17:36:26 -0700 | [diff] [blame] | 66 | virtual status_t openSession(CasSessionId *sessionId) override; |
Chong Zhang | 791a1a2 | 2017-01-03 11:36:07 -0800 | [diff] [blame] | 67 | |
| 68 | virtual status_t closeSession( |
| 69 | const CasSessionId &sessionId) override; |
| 70 | |
| 71 | virtual status_t setSessionPrivateData( |
| 72 | const CasSessionId &sessionId, |
| 73 | const CasData &data) override; |
| 74 | |
| 75 | virtual status_t processEcm( |
| 76 | const CasSessionId &sessionId, const CasEcm &ecm) override; |
| 77 | |
| 78 | virtual status_t processEmm(const CasEmm &emm) override; |
| 79 | |
| 80 | virtual status_t sendEvent( |
| 81 | int32_t event, int32_t arg, const CasData &eventData) override; |
| 82 | |
| 83 | virtual status_t provision(const String8 &str) override; |
| 84 | |
| 85 | virtual status_t refreshEntitlements( |
| 86 | int32_t refreshType, const CasData &refreshData) override; |
| 87 | |
| 88 | private: |
| 89 | |
| 90 | Mutex mLock; |
| 91 | }; |
| 92 | |
| 93 | class MockDescramblerPlugin : public DescramblerPlugin { |
| 94 | public: |
| 95 | MockDescramblerPlugin() {} |
| 96 | virtual ~MockDescramblerPlugin() {}; |
| 97 | |
| 98 | virtual bool requiresSecureDecoderComponent( |
| 99 | const char *mime) const override; |
| 100 | |
| 101 | virtual status_t setMediaCasSession( |
| 102 | const CasSessionId &sessionId) override; |
| 103 | |
| 104 | virtual ssize_t descramble( |
| 105 | bool secure, |
| 106 | ScramblingControl scramblingControl, |
| 107 | size_t numSubSamples, |
| 108 | const SubSample *subSamples, |
| 109 | const void *srcPtr, |
| 110 | int32_t srcOffset, |
| 111 | void *dstPtr, |
| 112 | int32_t dstOffset, |
| 113 | AString *errorDetailMsg) override; |
| 114 | |
| 115 | private: |
| 116 | String8 subSamplesToString( |
| 117 | SubSample const *subSamples, |
| 118 | size_t numSubSamples) const; |
| 119 | String8 arrayToString(uint8_t const *array, size_t len) const; |
| 120 | }; |
| 121 | } // namespace android |
| 122 | |
| 123 | #endif // MOCK_CAS_PLUGIN_H_ |