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 <string>
18
19 #include "advanced_notification_service.h"
20 #include "telephony_extension_wrapper.h"
21 #include "notification_preferences.h"
22
23 namespace OHOS::Notification {
24 const std::string EXTENTION_TELEPHONY_PATH = "libtelephony_cust_api.z.so";
25 TelExtensionWrapper::TelExtensionWrapper() = default;
26 TelExtensionWrapper::~TelExtensionWrapper() = default;
27
InitTelExtentionWrapper()28 void TelExtensionWrapper::InitTelExtentionWrapper()
29 {
30 telephonyCustHandle_ = dlopen(EXTENTION_TELEPHONY_PATH.c_str(), RTLD_NOW);
31 if (telephonyCustHandle_ == nullptr) {
32 ANS_LOGE("telephony extension wrapper symbol failed, error: %{public}s", dlerror());
33 return;
34 }
35
36 getCallerIndex_ = (GET_CALLER_INDEX)dlsym(telephonyCustHandle_, "GetCallerNumIndex");
37 if (getCallerIndex_ == nullptr) {
38 ANS_LOGE("telephony extension wrapper getCallerIndex symbol failed, error: %{public}s", dlerror());
39 return;
40 }
41 ANS_LOGI("telephony extension wrapper telephonyCustHandle_: %{public}p", telephonyCustHandle_);
42 ANS_LOGI("telephony extension wrapper getCallerIndex_: %{public}p", getCallerIndex_);
43 ANS_LOGI("telephony extension wrapper init success");
44 }
45
GetCallerIndex(std::shared_ptr<DataShare::DataShareResultSet> resultSet,std::string compNum)46 ErrCode TelExtensionWrapper::GetCallerIndex(
47 std::shared_ptr<DataShare::DataShareResultSet> resultSet, std::string compNum)
48 {
49 if (getCallerIndex_ == nullptr) {
50 ANS_LOGE("GetCallerIndex wrapper symbol failed");
51 return -1;
52 }
53 return getCallerIndex_(resultSet, compNum);
54 }
55
CloseTelExtentionWrapper()56 void TelExtensionWrapper::CloseTelExtentionWrapper()
57 {
58 if (telephonyCustHandle_ != nullptr) {
59 dlclose(telephonyCustHandle_);
60 telephonyCustHandle_ = nullptr;
61 }
62 }
63 } // namespace OHOS::Notification