• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "distributed_liveview_all_scenarios_extension_wrapper.h"
17 
18 #include <dlfcn.h>
19 #include <string>
20 
21 namespace OHOS::Notification {
22 const std::string DISTRIBUTED_EXTENTION_LIVEVIEW_ALL_SCENARIOS_PATH = "libliveview.z.so";
DistributedLiveviewAllScenariosExtensionWrapper()23 DistributedLiveviewAllScenariosExtensionWrapper::DistributedLiveviewAllScenariosExtensionWrapper()
24 {
25     InitExtentionWrapper();
26 }
27 
~DistributedLiveviewAllScenariosExtensionWrapper()28 DistributedLiveviewAllScenariosExtensionWrapper::~DistributedLiveviewAllScenariosExtensionWrapper()
29 {
30     CloseExtentionWrapper();
31 }
32 
InitExtentionWrapper()33 void DistributedLiveviewAllScenariosExtensionWrapper::InitExtentionWrapper()
34 {
35     ExtensionHandle_ = dlopen(DISTRIBUTED_EXTENTION_LIVEVIEW_ALL_SCENARIOS_PATH.c_str(), RTLD_NOW);
36     if (ExtensionHandle_ == nullptr) {
37         ANS_LOGE("distributed liveview all scenarios extension wrapper dlopen failed, error: %{public}s", dlerror());
38         return;
39     }
40 
41     updateLiveviewEncodeContent_ = (UPDATE_LIVEVIEW_ENCODE_CONTENT)dlsym(ExtensionHandle_,
42         "UpdateLiveviewEncodeTlv");
43     if (updateLiveviewEncodeContent_ == nullptr) {
44         ANS_LOGE("distributed liveview all scenarios extension wrapper dlsym updateLiveviewEncodeContent_ failed, "
45             "error: %{public}s", dlerror());
46         return;
47     }
48 
49     updateLiveviewDecodeContent_ = (UPDATE_LIVEVIEW_DECODE_CONTENT)dlsym(ExtensionHandle_,
50         "UpdateLiveviewDecodeTlv");
51     if (updateLiveviewDecodeContent_ == nullptr) {
52         ANS_LOGE("distributed liveview all scenarios extension wrapper dlsym updateLiveviewDecodeContent_ failed, "
53             "error: %{public}s", dlerror());
54         return;
55     }
56 
57     triggerHandler_ = (TRIGGER_PUSH_WANT_AGENT)dlsym(ExtensionHandle_, "TriggerPushWantAgent");
58     if (triggerHandler_ == nullptr) {
59         ANS_LOGE("distributed liveview all trigger failed, error: %{public}s", dlerror());
60         return;
61     }
62     subscribeHandler_ = (SUBSCRIBE_ALL_CONNECT)dlsym(ExtensionHandle_, "SubscribeAllConnect");
63     if (subscribeHandler_ == nullptr) {
64         ANS_LOGE("distributed subscribe all conncet failed, error: %{public}s", dlerror());
65         return;
66     }
67     unSubscribeHandler_ = (UNSUBSCRIBE_ALL_CONNECT)dlsym(ExtensionHandle_, "UnSubscribeAllConnect");
68     if (unSubscribeHandler_ == nullptr) {
69         ANS_LOGE("distributed unsubscribe all conncet failed, error: %{public}s", dlerror());
70         return;
71     }
72 
73     InitDistributedCollaborateClick();
74     ANS_LOGI("distributed liveview all scenarios extension wrapper init success");
75 }
76 
InitDistributedCollaborateClick()77 void DistributedLiveviewAllScenariosExtensionWrapper::InitDistributedCollaborateClick()
78 {
79     distributedLiveViewOperation_ =
80         (DISTRIBUTED_LIVE_VIEW_OPERATION)dlsym(ExtensionHandle_, "DistributedLiveViewOperation");
81     if (distributedLiveViewOperation_ == nullptr) {
82         ANS_LOGE("distributed liveView operation failed, error: %{public}s", dlerror());
83         return;
84     }
85 
86     restoreCollaborationWindow_ =
87         (RESTORE_COLLABORATION_WINDOW)dlsym(ExtensionHandle_, "RestoreCollaborationWindow");
88     if (restoreCollaborationWindow_ == nullptr) {
89         ANS_LOGE("distributed restore collaboration window failed, error: %{public}s", dlerror());
90         return;
91     }
92 
93     distributedAncoNotificationClick_ =
94         (DISTRIBUTED_ANCO_NOTIFICATION_CLICK)dlsym(ExtensionHandle_, "DistributedAncoNotificationClick");
95     if (distributedAncoNotificationClick_ == nullptr) {
96         ANS_LOGE("distributed anco notification click failed, error: %{public}s", dlerror());
97         return;
98     }
99 
100     updateLiveviewBinFile2PiexlMap_ =
101         (UPDATE_LIVE_VIEW_BIN_FILE_2_PIEXL_MAP)dlsym(ExtensionHandle_, "UpdateLiveviewBinFile2PiexlMap");
102     if (updateLiveviewBinFile2PiexlMap_ == nullptr) {
103         ANS_LOGE("update liveview Bin File 2 PiexlMap failed, error: %{public}s", dlerror());
104         return;
105     }
106 
107     updateLiveviewPiexlMap2BinFile_ =
108         (UPDATE_LIVE_VIEW_PIEXL_MAP_2_BIN_FILE)dlsym(ExtensionHandle_, "UpdateLiveviewPiexlMap2BinFile");
109     if (updateLiveviewPiexlMap2BinFile_ == nullptr) {
110         ANS_LOGE("update liveview PiexlMap 2 Bin File failed, error: %{public}s", dlerror());
111         return;
112     }
113 }
114 
CloseExtentionWrapper()115 void DistributedLiveviewAllScenariosExtensionWrapper::CloseExtentionWrapper()
116 {
117     if (ExtensionHandle_ != nullptr) {
118         dlclose(ExtensionHandle_);
119         subscribeHandler_ = nullptr;
120         unSubscribeHandler_ = nullptr;
121         ExtensionHandle_ = nullptr;
122         triggerHandler_ = nullptr;
123         updateLiveviewEncodeContent_ = nullptr;
124         updateLiveviewDecodeContent_ = nullptr;
125         distributedLiveViewOperation_ = nullptr;
126         restoreCollaborationWindow_ = nullptr;
127         distributedAncoNotificationClick_ = nullptr;
128         updateLiveviewBinFile2PiexlMap_ = nullptr;
129         updateLiveviewPiexlMap2BinFile_ = nullptr;
130     }
131     ANS_LOGI("distributed liveview all scenarios extension wrapper close success");
132 }
133 
UpdateLiveviewEncodeContent(const sptr<NotificationRequest> & request,std::vector<uint8_t> & buffer,const std::string & deviceType)134 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewEncodeContent(
135     const sptr<NotificationRequest> &request, std::vector<uint8_t> &buffer, const std::string& deviceType)
136 {
137     if (updateLiveviewEncodeContent_ == nullptr) {
138         ANS_LOGE("distributed UpdateLiveviewEncodeContent wrapper symbol failed");
139         return 0;
140     }
141     return updateLiveviewEncodeContent_(request, buffer, deviceType);
142 }
143 
UpdateLiveviewDecodeContent(const sptr<NotificationRequest> & request,std::vector<uint8_t> & buffer,const std::string & deviceType)144 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewDecodeContent(
145     const sptr<NotificationRequest> &request, std::vector<uint8_t> &buffer, const std::string& deviceType)
146 {
147     if (updateLiveviewDecodeContent_ == nullptr) {
148         ANS_LOGE("distributed UpdateLiveviewDecodeContent wrapper symbol failed");
149         return 0;
150     }
151     return updateLiveviewDecodeContent_(request, buffer, deviceType);
152 }
153 
TriggerPushWantAgent(const sptr<NotificationRequest> & request,int32_t actionType,const AAFwk::WantParams extraInfo)154 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::TriggerPushWantAgent(
155     const sptr<NotificationRequest> &request, int32_t actionType, const AAFwk::WantParams extraInfo)
156 {
157     if (triggerHandler_ == nullptr) {
158         ANS_LOGE("distributed TriggerPushWantAgent wrapper symbol failed");
159         return 0;
160     }
161     return triggerHandler_(request, actionType, extraInfo);
162 }
163 
SubscribeAllConnect()164 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::SubscribeAllConnect()
165 {
166     if (subscribeHandler_ == nullptr) {
167         ANS_LOGE("Subscribe all connect wrapper symbol failed");
168         return 0;
169     }
170     return subscribeHandler_();
171 }
172 
UnSubscribeAllConnect()173 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UnSubscribeAllConnect()
174 {
175     if (unSubscribeHandler_ == nullptr) {
176         ANS_LOGE("UnSubscribe all connect wrapper symbol failed");
177         return 0;
178     }
179     return unSubscribeHandler_();
180 }
181 
DistributedLiveViewOperation(sptr<NotificationRequest> & request,const int32_t operationType,const int32_t btnIndex)182 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::DistributedLiveViewOperation(
183     sptr<NotificationRequest> &request, const int32_t operationType, const int32_t btnIndex)
184 {
185     if (distributedLiveViewOperation_ == nullptr) {
186         ANS_LOGE("distributed liveView operation wrapper symbol failed");
187         return 0;
188     }
189     return distributedLiveViewOperation_(request, operationType, btnIndex);
190 }
191 
RestoreCollaborationWindow(const std::string & networkId)192 int32_t DistributedLiveviewAllScenariosExtensionWrapper::RestoreCollaborationWindow(const std::string &networkId)
193 {
194     if (restoreCollaborationWindow_ == nullptr) {
195         ANS_LOGE("restore collaboration window wrapper symbol failed");
196         return 0;
197     }
198     return restoreCollaborationWindow_(networkId);
199 }
200 
DistributedAncoNotificationClick(const sptr<NotificationRequest> & request,bool & triggerWantInner)201 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::DistributedAncoNotificationClick(
202     const sptr<NotificationRequest> &request, bool &triggerWantInner)
203 {
204     if (distributedAncoNotificationClick_ == nullptr) {
205         ANS_LOGE("distributed anco notification click wrapper symbol failed");
206         return 0;
207     }
208     return distributedAncoNotificationClick_(request, triggerWantInner);
209 }
210 
UpdateLiveviewBinFile2PiexlMap(std::shared_ptr<Media::PixelMap> & pixelMap,const std::vector<uint8_t> & buffer)211 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewBinFile2PiexlMap(
212     std::shared_ptr<Media::PixelMap> &pixelMap, const std::vector<uint8_t> &buffer)
213 {
214     if (updateLiveviewBinFile2PiexlMap_ == nullptr) {
215         ANS_LOGE("update liveview Bin File 2 PiexlMap wrapper symbol failed");
216         return 0;
217     }
218     return updateLiveviewBinFile2PiexlMap_(pixelMap, buffer);
219 }
220 
UpdateLiveviewPiexlMap2BinFile(const std::shared_ptr<Media::PixelMap> pixelMap,std::vector<uint8_t> & buffer)221 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewPiexlMap2BinFile(
222     const std::shared_ptr<Media::PixelMap> pixelMap, std::vector<uint8_t> &buffer)
223 {
224     if (updateLiveviewPiexlMap2BinFile_ == nullptr) {
225         ANS_LOGE("update liveview PiexlMap 2 Bin File wrapper symbol failed");
226         return 0;
227     }
228     return updateLiveviewPiexlMap2BinFile_(pixelMap, buffer);
229 }
230 }
231