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 <dlfcn.h>
17 #include "telephony_ext_wrapper.h"
18 #include "telephony_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Telephony {
22 namespace {
23 const std::string TELEPHONY_EXT_WRAPPER_PATH = "libtelephony_ext_service.z.so";
24 } // namespace
25 
TelephonyExtWrapper()26 TelephonyExtWrapper::TelephonyExtWrapper()
27 {
28     TELEPHONY_LOGD("TelephonyExtWrapper::TelephonyExtWrapper() create");
29 }
~TelephonyExtWrapper()30 TelephonyExtWrapper::~TelephonyExtWrapper()
31 {
32     TELEPHONY_LOGD("TelephonyExtWrapper::~TelephonyExtWrapper() start");
33     if (telephonyExtWrapperHandle_ != nullptr) {
34         dlclose(telephonyExtWrapperHandle_);
35         telephonyExtWrapperHandle_ = nullptr;
36     }
37 }
InitTelephonyExtWrapper()38 void TelephonyExtWrapper::InitTelephonyExtWrapper()
39 {
40     telephonyExtWrapperHandle_ = dlopen(TELEPHONY_EXT_WRAPPER_PATH.c_str(), RTLD_NOW);
41     if (telephonyExtWrapperHandle_ == nullptr) {
42         TELEPHONY_LOGE("libtelephony_ext_service.z.so was not loaded, error: %{public}s", dlerror());
43         return;
44     }
45     isCustEtwsMessage_ = (IS_CUST_ETWS_MSG)dlsym(telephonyExtWrapperHandle_, "IsCustEtwsMessage");
46     getCustEtwsType_ = (GET_CUST_ETWS_TYPE)dlsym(telephonyExtWrapperHandle_, "GetCustEtwsType");
47     if (isCustEtwsMessage_ == nullptr || getCustEtwsType_ == nullptr) {
48         TELEPHONY_LOGE("[ETWS]telephony ext wrapper symbol failed, error: %{public}s", dlerror());
49         return;
50     }
51     TELEPHONY_LOGI("telephony ext wrapper init success");
52 }
53 } // namespace Telephony
54 } // namespace OHOS