• 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";
23 DistributedLiveviewAllScenariosExtensionWrapper::DistributedLiveviewAllScenariosExtensionWrapper() = default;
24 DistributedLiveviewAllScenariosExtensionWrapper::~DistributedLiveviewAllScenariosExtensionWrapper() = default;
25 
InitExtentionWrapper()26 void DistributedLiveviewAllScenariosExtensionWrapper::InitExtentionWrapper()
27 {
28     ExtensionHandle_ = dlopen(DISTRIBUTED_EXTENTION_LIVEVIEW_ALL_SCENARIOS_PATH.c_str(), RTLD_NOW);
29     if (ExtensionHandle_ == nullptr) {
30         ANS_LOGE("distributed liveview all scenarios extension wrapper dlopen failed, error: %{public}s", dlerror());
31         return;
32     }
33 
34     updateLiveviewEncodeContent_ = (UPDATE_LIVEVIEW_ENCODE_CONTENT)dlsym(ExtensionHandle_,
35         "UpdateLiveviewEncodeContent");
36     if (updateLiveviewEncodeContent_ == nullptr) {
37         ANS_LOGE("distributed liveview all scenarios extension wrapper dlsym updateLiveviewEncodeContent_ failed, "
38             "error: %{public}s", dlerror());
39         return;
40     }
41 
42     updateLiveviewDecodeContent_ = (UPDATE_LIVEVIEW_DECODE_CONTENT)dlsym(ExtensionHandle_,
43         "UpdateLiveviewDecodeContent");
44     if (updateLiveviewDecodeContent_ == nullptr) {
45         ANS_LOGE("distributed liveview all scenarios extension wrapper dlsym updateLiveviewDecodeContent_ failed, "
46             "error: %{public}s", dlerror());
47         return;
48     }
49 
50     triggerHandler_ = (TRIGGER_PUSH_WANT_AGENT)dlsym(ExtensionHandle_, "TriggerPushWantAgent");
51     if (triggerHandler_ == nullptr) {
52         ANS_LOGE("distributed liveview all trigger failed, error: %{public}s", dlerror());
53         return;
54     }
55     ANS_LOGI("distributed liveview all scenarios extension wrapper init success");
56 }
57 
CloseExtentionWrapper()58 void DistributedLiveviewAllScenariosExtensionWrapper::CloseExtentionWrapper()
59 {
60     if (ExtensionHandle_ != nullptr) {
61         dlclose(ExtensionHandle_);
62         ExtensionHandle_ = nullptr;
63     }
64 }
65 
UpdateLiveviewEncodeContent(const sptr<NotificationRequest> & request,std::vector<uint8_t> & buffer)66 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewEncodeContent(
67     const sptr<NotificationRequest> &request, std::vector<uint8_t> &buffer)
68 {
69     if (updateLiveviewEncodeContent_ == nullptr) {
70         ANS_LOGE("distributed UpdateLiveviewEncodeContent wrapper symbol failed");
71         return 0;
72     }
73     return updateLiveviewEncodeContent_(request, buffer);
74 }
75 
UpdateLiveviewDecodeContent(const sptr<NotificationRequest> & request,std::vector<uint8_t> & buffer)76 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewDecodeContent(
77     const sptr<NotificationRequest> &request, std::vector<uint8_t> &buffer)
78 {
79     if (updateLiveviewDecodeContent_ == nullptr) {
80         ANS_LOGE("distributed UpdateLiveviewDecodeContent wrapper symbol failed");
81         return 0;
82     }
83     return updateLiveviewDecodeContent_(request, buffer);
84 }
85 
TriggerPushWantAgent(const sptr<NotificationRequest> & request,int32_t actionType,const AAFwk::WantParams extraInfo)86 ErrCode DistributedLiveviewAllScenariosExtensionWrapper::TriggerPushWantAgent(
87     const sptr<NotificationRequest> &request, int32_t actionType, const AAFwk::WantParams extraInfo)
88 {
89     if (triggerHandler_ == nullptr) {
90         ANS_LOGE("distributed TriggerPushWantAgent wrapper symbol failed");
91         return 0;
92     }
93     return triggerHandler_(request, actionType, extraInfo);
94 }
95 }
96