• 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 <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 init success");
42 }
43 
GetCallerIndex(std::shared_ptr<DataShare::DataShareResultSet> resultSet,std::string compNum)44 ErrCode TelExtensionWrapper::GetCallerIndex(
45     std::shared_ptr<DataShare::DataShareResultSet> resultSet, std::string compNum)
46 {
47     if (getCallerIndex_ == nullptr) {
48         ANS_LOGE("GetCallerIndex wrapper symbol failed");
49         return -1;
50     }
51     return getCallerIndex_(resultSet, compNum);
52 }
53 
CloseTelExtentionWrapper()54 void TelExtensionWrapper::CloseTelExtentionWrapper()
55 {
56     if (telephonyCustHandle_ != nullptr) {
57         dlclose(telephonyCustHandle_);
58         telephonyCustHandle_ = nullptr;
59     }
60 }
61 } // namespace OHOS::Notification