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, result: %{public}s", errCode, result.c_str());
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              .markType = MarkType::MARK_TYPE_NONE,
46              .markContent = "",
47              .markCount = -1,
48              .markSource = "",
49              .isCloud = false,
50          };
51          bool isBlock = false;
52          int32_t blockReason;
53          spamCallAdapter_->ParseDetectResult(result, isBlock, numberMarkInfo, blockReason);
54          if (blockReason == DECISION_REASON_TRUSTLIST) {
55              TELEPHONY_LOGI("trustlist, need query numbermark");
56              DelayedSingleton<CallNumberUtils>::GetInstance()->
57                  QueryYellowPageAndMarkInfo(numberMarkInfo, spamCallAdapter_->GetDetectPhoneNum());
58          }
59          spamCallAdapter_->SetParseResult(isBlock, numberMarkInfo, blockReason);
60          CallManagerHisysevent::WriteIncomingNumIdentityBehaviorEvent(
61              static_cast<int32_t>(numberMarkInfo.markType), isBlock, blockReason);
62      }
63      spamCallAdapter_->NotifyAll();
64      return TELEPHONY_SUCCESS;
65  }
66  } // namespace Telephony
67  } // namespace OHOS