1 /* 2 * Copyright (C) 2025-2025 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 "antifraud_adapter.h" 17 18 #include "anti_fraud_service_client.h" 19 #include "telephony_log_wrapper.h" 20 21 namespace OHOS { 22 namespace Telephony { AntiFraudAdapter()23AntiFraudAdapter::AntiFraudAdapter() 24 {} 25 ~AntiFraudAdapter()26AntiFraudAdapter::~AntiFraudAdapter() 27 {} 28 GetLibAntiFraud()29void* AntiFraudAdapter::GetLibAntiFraud() 30 { 31 if (libAntiFraud_ != nullptr) { 32 return libAntiFraud_; 33 } 34 35 libAntiFraud_ = dlopen("libanti_fraud_service_client.so", RTLD_LAZY); 36 if (libAntiFraud_ == nullptr) { 37 TELEPHONY_LOGE("gLibAntiFraud_ is null"); 38 } 39 40 return libAntiFraud_; 41 } 42 ReleaseAntiFraud()43void AntiFraudAdapter::ReleaseAntiFraud() 44 { 45 TELEPHONY_LOGI("ReleaseAntiFraud"); 46 if (libAntiFraud_ != nullptr) { 47 dlclose(libAntiFraud_); 48 libAntiFraud_ = nullptr; 49 } 50 } 51 CheckAntiFraud(std::string phoneNum)52int32_t AntiFraudAdapter::CheckAntiFraud(std::string phoneNum) 53 { 54 libAntiFraud_ = GetLibAntiFraud(); 55 if (libAntiFraud_ == nullptr) { 56 return -1; 57 } 58 59 PfnAntiFraudVoiceCheck func = 60 reinterpret_cast<PfnAntiFraudVoiceCheck>(dlsym(libAntiFraud_, "AntiFraudVoiceCheck")); 61 if (func == nullptr) { 62 TELEPHONY_LOGE("func is NULL"); 63 return -1; 64 } 65 66 return func(phoneNum); 67 } 68 DetectAntiFraud(const std::shared_ptr<OHOS::AntiFraudService::AntiFraudDetectResListener> & listener)69int32_t AntiFraudAdapter::DetectAntiFraud( 70 const std::shared_ptr<OHOS::AntiFraudService::AntiFraudDetectResListener> &listener) 71 { 72 libAntiFraud_ = GetLibAntiFraud(); 73 if (libAntiFraud_ == nullptr) { 74 return -1; 75 } 76 77 PfnAntiFraudVoiceDetect func = 78 reinterpret_cast<PfnAntiFraudVoiceDetect>(dlsym(libAntiFraud_, "AntiFraudVoiceDetect")); 79 if (func == nullptr) { 80 TELEPHONY_LOGE("func is NULL"); 81 return -1; 82 } 83 84 return func(listener); 85 } 86 StopAntiFraud()87int32_t AntiFraudAdapter::StopAntiFraud() 88 { 89 libAntiFraud_ = GetLibAntiFraud(); 90 if (libAntiFraud_ == nullptr) { 91 return -1; 92 } 93 94 PfnStopAntiFraudVoiceDetect func = 95 reinterpret_cast<PfnStopAntiFraudVoiceDetect>(dlsym(libAntiFraud_, "StopAntiFraudVoiceDetect")); 96 if (func == nullptr) { 97 TELEPHONY_LOGE("func is NULL"); 98 return -1; 99 } 100 101 return func(); 102 } 103 } 104 }