1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_HDI_DRM_V1_0_MEDIAKEYSESSIONPROXY_H
17 #define OHOS_HDI_DRM_V1_0_MEDIAKEYSESSIONPROXY_H
18 
19 #include "v1_0/imedia_key_session.h"
20 #include <iproxy_broker.h>
21 
22 namespace OHOS {
23 namespace HDI {
24 namespace Drm {
25 namespace V1_0 {
26 
27 class MediaKeySessionProxy : public IProxyBroker<OHOS::HDI::Drm::V1_0::IMediaKeySession> {
28 public:
MediaKeySessionProxy(const sptr<IRemoteObject>& remote)29     explicit MediaKeySessionProxy(const sptr<IRemoteObject>& remote) : IProxyBroker<OHOS::HDI::Drm::V1_0::IMediaKeySession>(remote) {}
30 
31     virtual ~MediaKeySessionProxy() = default;
32 
33     inline bool IsProxy() override
34     {
35         return true;
36     }
37 
38     int32_t GenerateMediaKeyRequest(const OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo& mediaKeyRequestInfo,
39          OHOS::HDI::Drm::V1_0::MediaKeyRequest& mediaKeyRequest) override;
40 
41     int32_t ProcessMediaKeyResponse(const std::vector<uint8_t>& mediaKeyResponse,
42          std::vector<uint8_t>& mediaKeyId) override;
43 
44     int32_t CheckMediaKeyStatus(std::map<std::string, std::string>& mediaKeyStatus) override;
45 
46     int32_t ClearMediaKeys() override;
47 
48     int32_t GetOfflineReleaseRequest(const std::vector<uint8_t>& mediaKeyId,
49          std::vector<uint8_t>& releaseRequest) override;
50 
51     int32_t ProcessOfflineReleaseResponse(const std::vector<uint8_t>& mediaKeyId,
52          const std::vector<uint8_t>& response) override;
53 
54     int32_t RestoreOfflineMediaKeys(const std::vector<uint8_t>& mediaKeyId) override;
55 
56     int32_t GetContentProtectionLevel(OHOS::HDI::Drm::V1_0::ContentProtectionLevel& level) override;
57 
58     int32_t RequiresSecureDecoderModule(const std::string& mimeType, bool& required) override;
59 
60     int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySessionCallback>& sessionCallback) override;
61 
62     int32_t GetMediaDecryptModule(sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule>& decryptModule) override;
63 
64     int32_t Destroy() override;
65 
66     int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override;
67 
68     static int32_t GenerateMediaKeyRequest_(const OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo& mediaKeyRequestInfo,
69          OHOS::HDI::Drm::V1_0::MediaKeyRequest& mediaKeyRequest, const sptr<IRemoteObject> remote);
70 
71     static int32_t ProcessMediaKeyResponse_(const std::vector<uint8_t>& mediaKeyResponse,
72          std::vector<uint8_t>& mediaKeyId, const sptr<IRemoteObject> remote);
73 
74     static int32_t CheckMediaKeyStatus_(std::map<std::string, std::string>& mediaKeyStatus,
75          const sptr<IRemoteObject> remote);
76 
77     static int32_t ClearMediaKeys_(const sptr<IRemoteObject> remote);
78 
79     static int32_t GetOfflineReleaseRequest_(const std::vector<uint8_t>& mediaKeyId,
80          std::vector<uint8_t>& releaseRequest, const sptr<IRemoteObject> remote);
81 
82     static int32_t ProcessOfflineReleaseResponse_(const std::vector<uint8_t>& mediaKeyId,
83          const std::vector<uint8_t>& response, const sptr<IRemoteObject> remote);
84 
85     static int32_t RestoreOfflineMediaKeys_(const std::vector<uint8_t>& mediaKeyId, const sptr<IRemoteObject> remote);
86 
87     static int32_t GetContentProtectionLevel_(OHOS::HDI::Drm::V1_0::ContentProtectionLevel& level,
88          const sptr<IRemoteObject> remote);
89 
90     static int32_t RequiresSecureDecoderModule_(const std::string& mimeType, bool& required,
91          const sptr<IRemoteObject> remote);
92 
93     static int32_t SetCallback_(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySessionCallback>& sessionCallback,
94          const sptr<IRemoteObject> remote);
95 
96     static int32_t GetMediaDecryptModule_(sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule>& decryptModule,
97          const sptr<IRemoteObject> remote);
98 
99     static int32_t Destroy_(const sptr<IRemoteObject> remote);
100 
101     static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr<IRemoteObject> remote);
102 
103 private:
104     static inline BrokerDelegator<OHOS::HDI::Drm::V1_0::MediaKeySessionProxy> delegator_;
105 };
106 
107 } // V1_0
108 } // Drm
109 } // HDI
110 } // OHOS
111 
112 #endif // OHOS_HDI_DRM_V1_0_MEDIAKEYSESSIONPROXY_H