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 "liveview_all_scenarios_extension_wrapper.h"
17
18 #include <dlfcn.h>
19 #include <string>
20
21 namespace OHOS::Notification {
22 const std::string EXTENTION_LIVEVIEW_ALL_SCENARIOS_PATH = "libliveview.z.so";
23 LiveviewAllScenariosExtensionWrapper::LiveviewAllScenariosExtensionWrapper() = default;
24 LiveviewAllScenariosExtensionWrapper::~LiveviewAllScenariosExtensionWrapper() = default;
25
InitExtentionWrapper()26 void LiveviewAllScenariosExtensionWrapper::InitExtentionWrapper()
27 {
28 ExtensionHandle_ = dlopen(EXTENTION_LIVEVIEW_ALL_SCENARIOS_PATH.c_str(), RTLD_NOW);
29 if (ExtensionHandle_ == nullptr) {
30 ANS_LOGE("liveview all scenarios extension wrapper dlopen failed, error: %{public}s", dlerror());
31 return;
32 }
33
34 updateLiveviewReminderFlags_ = (UPDATE_LIVEVIEW_REMINDER_FLAGS)dlsym(ExtensionHandle_,
35 "UpdateLiveviewReminderFlags");
36 if (updateLiveviewReminderFlags_ == nullptr) {
37 ANS_LOGE("liveview all scenarios extension wrapper dlsym updateLiveviewReminderFlags_ failed, "
38 "error: %{public}s", dlerror());
39 return;
40 }
41
42 updateLiveviewVoiceContent_ = (UPDATE_LIVEVIEW_VOICE_CONTENT)dlsym(ExtensionHandle_,
43 "UpdateLiveviewVoiceContent");
44 if (updateLiveviewVoiceContent_ == nullptr) {
45 ANS_LOGE("liveview all scenarios extension wrapper dlsym updateLiveviewVoiceContent_ failed, "
46 "error: %{public}s", dlerror());
47 return;
48 }
49
50 ANS_LOGI("liveview all scenarios extension wrapper init success");
51 }
52
CloseExtentionWrapper()53 void LiveviewAllScenariosExtensionWrapper::CloseExtentionWrapper()
54 {
55 if (ExtensionHandle_ != nullptr) {
56 dlclose(ExtensionHandle_);
57 ExtensionHandle_ = nullptr;
58 }
59 }
60
UpdateLiveviewReminderFlags(const sptr<NotificationRequest> & request)61 ErrCode LiveviewAllScenariosExtensionWrapper::UpdateLiveviewReminderFlags(const sptr<NotificationRequest> &request)
62 {
63 if (updateLiveviewReminderFlags_ == nullptr) {
64 ANS_LOGE("UpdateLiveviewReminderFlags wrapper symbol failed");
65 return 0;
66 }
67 return updateLiveviewReminderFlags_(request);
68 }
69
UpdateLiveviewVoiceContent(const sptr<NotificationRequest> & request)70 ErrCode LiveviewAllScenariosExtensionWrapper::UpdateLiveviewVoiceContent(const sptr<NotificationRequest> &request)
71 {
72 if (updateLiveviewVoiceContent_ == nullptr) {
73 ANS_LOGE("UpdateLiveviewVoiceContent wrapper symbol failed");
74 return 0;
75 }
76 return updateLiveviewVoiceContent_(request);
77 }
78 }