• 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, std::string &detectDetails);
39     void SetParseResult(bool &isBlock, NumberMarkInfo &info, int32_t &blockReason, std::string &detectDetails);
40     std::string GetDetectPhoneNum();
41     void NotifyAll();
42     bool WaitForDetectResult();
43     void ParseDetectResult(const std::string &jsonData, bool &isBlock, NumberMarkInfo &info,
44         int32_t &blockReason, std::string &detectDetails);
45     void ParseNeedNotifyResult(const std::string &jsonData);
46 
47 private:
48     bool ConnectSpamCallAbility(const AAFwk::Want &want, const std::string &phoneNumber, const int32_t &slotId);
49     void DisconnectSpamCallAbility();
50     bool JsonGetNumberValue(cJSON *json, const std::string key, int32_t &out);
51     bool JsonGetStringValue(cJSON *json, const std::string key, std::string &out);
52     bool JsonGetBoolValue(cJSON *json, const std::string key);
53     void ParseMarkResults(NumberMarkInfo &info, cJSON *root, std::string &detectDetails, bool isBlock);
54     int32_t errCode_ = -1;
55     std::string result_ = "";
56     std::string phoneNumber_ = "";
57     NumberMarkInfo info_;
58     bool isBlock_ = false;
59     int32_t blockReason_ = 0;
60     std::string detectDetails_ = "";
61     std::unique_ptr<TimeWaitHelper> timeWaitHelper_ {nullptr};
62     ffrt::mutex mutex_;
63 };
64 } // namespace Telephony
65 } // namespace OHOS
66 #endif // TELEPHONY_SPAM_CALL_ADAPTER_MANAGER_H