1 /*
2 * Copyright (C) 2024-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 "callback_stub_helper.h"
17 #include "telephony_log_wrapper.h"
18 #include "call_manager_errors.h"
19 #include "spam_call_adapter.h"
20 #include "call_number_utils.h"
21 #include "call_manager_hisysevent.h"
22
23 namespace OHOS {
24 namespace Telephony {
25 constexpr int32_t DECISION_REASON_TRUSTLIST = 2;
CallbackStubHelper(std::shared_ptr<SpamCallAdapter> spamCallAdapter)26 CallbackStubHelper::CallbackStubHelper(std::shared_ptr<SpamCallAdapter> spamCallAdapter)
27 {
28 spamCallAdapter_ = spamCallAdapter;
29 };
~CallbackStubHelper()30 CallbackStubHelper::~CallbackStubHelper()
31 {
32 TELEPHONY_LOGW("~CallbackStubHelper");
33 };
34
OnResult(int32_t & errCode,std::string & result)35 int32_t CallbackStubHelper::OnResult(int32_t &errCode, std::string &result)
36 {
37 TELEPHONY_LOGI("OnResult errCode: %{public}d", errCode);
38 if (spamCallAdapter_ == nullptr) {
39 TELEPHONY_LOGE("spamCallAdapter_ is nullptr");
40 return TELEPHONY_ERR_LOCAL_PTR_NULL;
41 }
42 spamCallAdapter_->SetDetectResult(errCode, result);
43 if (errCode == 0) {
44 NumberMarkInfo numberMarkInfo;
45 bool isBlock = false;
46 int32_t blockReason;
47 std::string detectDetails = "";
48 spamCallAdapter_->ParseDetectResult(result, isBlock, numberMarkInfo, blockReason, detectDetails);
49 if (blockReason == DECISION_REASON_TRUSTLIST) {
50 TELEPHONY_LOGW("trustlist, need query numbermark");
51 DelayedSingleton<CallNumberUtils>::GetInstance()->
52 QueryYellowPageAndMarkInfo(numberMarkInfo, spamCallAdapter_->GetDetectPhoneNum());
53 }
54 spamCallAdapter_->SetParseResult(isBlock, numberMarkInfo, blockReason, detectDetails);
55 CallManagerHisysevent::WriteIncomingNumIdentityBehaviorEvent(
56 static_cast<int32_t>(numberMarkInfo.markType), isBlock, blockReason);
57 }
58 spamCallAdapter_->NotifyAll();
59 return TELEPHONY_SUCCESS;
60 }
61 } // namespace Telephony
62 } // namespace OHOS