• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TELEPHONY_SPAM_CALL_ADAPTER_MANAGER_H
17 #define TELEPHONY_SPAM_CALL_ADAPTER_MANAGER_H
18 
19 #include <string>
20 
21 #include "call_manager_info.h"
22 #include "singleton.h"
23 #include "cJSON.h"
24 #include "time_wait_helper.h"
25 #include "ability_connect_callback_stub.h"
26 #include <memory>
27 #include "ffrt.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 class SpamCallAdapter : public std::enable_shared_from_this<SpamCallAdapter> {
32 public:
33     SpamCallAdapter();
34     ~SpamCallAdapter();
35     bool DetectSpamCall(const std::string &phoneNumber, const int32_t &slotId);
36     void GetDetectResult(int32_t &errCode, std::string &result);
37     void SetDetectResult(int32_t &errCode, std::string &result);
38     void GetParseResult(bool &isBlock, NumberMarkInfo &info, int32_t &blockReason);
39     void SetParseResult(bool &isBlock, NumberMarkInfo &info, int32_t &blockReason);
40     std::string GetDetectPhoneNum();
41     void NotifyAll();
42     bool WaitForDetectResult();
43     void ParseDetectResult(const std::string &jsonData, bool &isBlock, NumberMarkInfo &info, int32_t &blockReason);
44     void ParseNeedNotifyResult(const std::string &jsonData);
45 
46 private:
47     bool ConnectSpamCallAbility(const AAFwk::Want &want, const std::string &phoneNumber, const int32_t &slotId);
48     void DisconnectSpamCallAbility();
49     bool JsonGetNumberValue(cJSON *json, const std::string key, int32_t &out);
50     bool JsonGetStringValue(cJSON *json, const std::string key, std::string &out);
51     bool JsonGetBoolValue(cJSON *json, const std::string key);
52     void ParseMarkResults(NumberMarkInfo &info, cJSON *root, bool isBlock);
53     int32_t errCode_ = -1;
54     std::string result_ = "";
55     std::string phoneNumber_ = "";
56     NumberMarkInfo info_ = {
57         .markType = MarkType::MARK_TYPE_NONE,
58         .markContent = "",
59         .markCount = -1,
60         .markSource = "",
61         .isCloud = false,
62     };
63     bool isBlock_ = false;
64     int32_t blockReason_ = 0;
65     std::unique_ptr<TimeWaitHelper> timeWaitHelper_ {nullptr};
66     ffrt::mutex mutex_;
67 };
68 } // namespace Telephony
69 } // namespace OHOS
70 #endif // TELEPHONY_SPAM_CALL_ADAPTER_MANAGER_H