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 CAS_IMPL_H_
18#define CAS_IMPL_H_
19
20#include <media/stagefright/foundation/ABase.h>
21#include <android/media/BnCas.h>
22
23namespace android {
24namespace media {
25class ICasListener;
26}
27using namespace media;
28using namespace MediaCas;
29using binder::Status;
30class CasPlugin;
31class SharedLibrary;
32
33class CasImpl : public BnCas {
34public:
35    CasImpl(const sp<ICasListener> &listener);
36    virtual ~CasImpl();
37
38    static void OnEvent(
39            void *appData,
40            int32_t event,
41            int32_t arg,
42            uint8_t *data,
43            size_t size);
44
45    void init(const sp<SharedLibrary>& library, CasPlugin *plugin);
46    void onEvent(
47            int32_t event,
48            int32_t arg,
49            uint8_t *data,
50            size_t size);
51
52    // ICas inherits
53
54    virtual Status setPrivateData(
55            const CasData& pvtData) override;
56
57    virtual Status openSession(CasSessionId* _aidl_return) override;
58
59    virtual Status closeSession(const CasSessionId& sessionId) override;
60
61    virtual Status setSessionPrivateData(
62            const CasSessionId& sessionId,
63            const CasData& pvtData) override;
64
65    virtual Status processEcm(
66            const CasSessionId& sessionId, const ParcelableCasData& ecm) override;
67
68    virtual Status processEmm(const ParcelableCasData& emm) override;
69
70    virtual Status sendEvent(
71            int32_t event, int32_t arg, const ::std::unique_ptr<CasData> &eventData) override;
72
73    virtual Status provision(const String16& provisionString) override;
74
75    virtual Status refreshEntitlements(
76            int32_t refreshType, const ::std::unique_ptr<CasData> &refreshData) override;
77
78    virtual Status release() override;
79
80private:
81    struct PluginHolder;
82    sp<SharedLibrary> mLibrary;
83    sp<PluginHolder> mPluginHolder;
84    sp<ICasListener> mListener;
85
86    DISALLOW_EVIL_CONSTRUCTORS(CasImpl);
87};
88
89} // namespace android
90
91#endif // CAS_IMPL_H_
92