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 "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_LOGI("~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 spamCallAdapter_->ParseDetectResult(result, isBlock, numberMarkInfo, blockReason);
48 if (blockReason == DECISION_REASON_TRUSTLIST) {
49 TELEPHONY_LOGI("trustlist, need query numbermark");
50 DelayedSingleton<CallNumberUtils>::GetInstance()->
51 QueryYellowPageAndMarkInfo(numberMarkInfo, spamCallAdapter_->GetDetectPhoneNum());
52 }
53 spamCallAdapter_->SetParseResult(isBlock, numberMarkInfo, blockReason);
54 CallManagerHisysevent::WriteIncomingNumIdentityBehaviorEvent(static_cast<int32_t>(numberMarkInfo.markType));
55 }
56 spamCallAdapter_->NotifyAll();
57 return TELEPHONY_SUCCESS;
58 }
59 } // namespace Telephony
60 } // namespace OHOS