• 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 "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";
LiveviewAllScenariosExtensionWrapper()23 LiveviewAllScenariosExtensionWrapper::LiveviewAllScenariosExtensionWrapper()
24 {
25     InitExtentionWrapper();
26 }
~LiveviewAllScenariosExtensionWrapper()27 LiveviewAllScenariosExtensionWrapper::~LiveviewAllScenariosExtensionWrapper()
28 {
29     CloseExtentionWrapper();
30 }
31 
InitExtentionWrapper()32 void LiveviewAllScenariosExtensionWrapper::InitExtentionWrapper()
33 {
34     ExtensionHandle_ = dlopen(EXTENTION_LIVEVIEW_ALL_SCENARIOS_PATH.c_str(), RTLD_NOW);
35     if (ExtensionHandle_ == nullptr) {
36         ANS_LOGE("liveview all scenarios extension wrapper dlopen failed, error: %{public}s", dlerror());
37         return;
38     }
39 
40     updateLiveviewReminderFlags_ = (UPDATE_LIVEVIEW_REMINDER_FLAGS)dlsym(ExtensionHandle_,
41         "UpdateLiveviewReminderFlags");
42     if (updateLiveviewReminderFlags_ == nullptr) {
43         ANS_LOGE("liveview all scenarios extension wrapper dlsym updateLiveviewReminderFlags_ failed, "
44             "error: %{public}s", dlerror());
45         return;
46     }
47 
48     updateLiveviewVoiceContent_ = (UPDATE_LIVEVIEW_VOICE_CONTENT)dlsym(ExtensionHandle_,
49         "UpdateLiveviewVoiceContent");
50     if (updateLiveviewVoiceContent_ == nullptr) {
51         ANS_LOGE("liveview all scenarios extension wrapper dlsym updateLiveviewVoiceContent_ failed, "
52             "error: %{public}s", dlerror());
53         return;
54     }
55 
56     ANS_LOGI("liveview all scenarios extension wrapper init success");
57 }
58 
CloseExtentionWrapper()59 void LiveviewAllScenariosExtensionWrapper::CloseExtentionWrapper()
60 {
61     if (ExtensionHandle_ != nullptr) {
62         dlclose(ExtensionHandle_);
63         ExtensionHandle_ = nullptr;
64         updateLiveviewReminderFlags_ = nullptr;
65         updateLiveviewVoiceContent_ = nullptr;
66     }
67     ANS_LOGI("liveview all scenarios extension wrapper close success");
68 }
69 
UpdateLiveviewReminderFlags(const sptr<NotificationRequest> & request)70 ErrCode LiveviewAllScenariosExtensionWrapper::UpdateLiveviewReminderFlags(const sptr<NotificationRequest> &request)
71 {
72     if (updateLiveviewReminderFlags_ == nullptr) {
73         ANS_LOGE("UpdateLiveviewReminderFlags wrapper symbol failed");
74         return 0;
75     }
76     return updateLiveviewReminderFlags_(request);
77 }
78 
UpdateLiveviewVoiceContent(const sptr<NotificationRequest> & request)79 ErrCode LiveviewAllScenariosExtensionWrapper::UpdateLiveviewVoiceContent(const sptr<NotificationRequest> &request)
80 {
81     if (updateLiveviewVoiceContent_ == nullptr) {
82         ANS_LOGE("UpdateLiveviewVoiceContent wrapper symbol failed");
83         return 0;
84     }
85     return updateLiveviewVoiceContent_(request);
86 }
87 }