• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 setStatusCallback(
69             CasPluginStatusCallback callback) override;
70 
71     virtual status_t setPrivateData(
72             const CasData &data) override;
73 
74     virtual status_t openSession(CasSessionId *sessionId) override;
75 
76     virtual status_t openSession(uint32_t intent, uint32_t mode,
77                                      CasSessionId *sessionId) override;
78 
79     virtual status_t closeSession(
80             const CasSessionId &sessionId) override;
81 
82     virtual status_t setSessionPrivateData(
83             const CasSessionId &sessionId,
84             const CasData &data) override;
85 
86     virtual status_t processEcm(
87             const CasSessionId &sessionId, const CasEcm &ecm) override;
88 
89     virtual status_t processEmm(const CasEmm &emm) override;
90 
91     virtual status_t sendEvent(
92             int32_t event, int32_t arg, const CasData &eventData) override;
93 
94     virtual status_t sendSessionEvent(
95             const CasSessionId &sessionId,
96             int32_t event, int32_t arg, const CasData &eventData) override;
97 
98      virtual status_t provision(const String8 &str) override;
99 
100     virtual status_t refreshEntitlements(
101             int32_t refreshType, const CasData &refreshData) override;
102 
103 private:
104 
105     Mutex mLock;
106 };
107 
108 class MockDescramblerPlugin : public DescramblerPlugin {
109 public:
MockDescramblerPlugin()110     MockDescramblerPlugin() {}
~MockDescramblerPlugin()111     virtual ~MockDescramblerPlugin() {};
112 
113     virtual bool requiresSecureDecoderComponent(
114             const char *mime) const override;
115 
116     virtual status_t setMediaCasSession(
117             const CasSessionId &sessionId) override;
118 
119     virtual ssize_t descramble(
120             bool secure,
121             ScramblingControl scramblingControl,
122             size_t numSubSamples,
123             const SubSample *subSamples,
124             const void *srcPtr,
125             int32_t srcOffset,
126             void *dstPtr,
127             int32_t dstOffset,
128             AString *errorDetailMsg) override;
129 
130 private:
131     String8 subSamplesToString(
132             SubSample const *subSamples,
133             size_t numSubSamples) const;
134     String8 arrayToString(uint8_t const *array, size_t len) const;
135 };
136 } // namespace android
137 
138 #endif // MOCK_CAS_PLUGIN_H_
139