1 /*
2  * Copyright (C) 2021 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 #include "call_incoming_filter_manager.h"
16 
17 #include "securec.h"
18 
19 #include "call_manager_errors.h"
20 #include "telephony_log_wrapper.h"
21 #include "call_manager_inner_type.h"
22 #include "call_control_manager.h"
23 #include "call_data_base_helper.h"
24 #include "cellular_call_connection.h"
25 
26 namespace OHOS {
27 namespace Telephony {
CallIncomingFilterManager()28 CallIncomingFilterManager::CallIncomingFilterManager() : isFirstIncoming(true) {}
29 
~CallIncomingFilterManager()30 CallIncomingFilterManager::~CallIncomingFilterManager() {}
31 
PackCellularCallInfo(CellularCallInfo & callInfo,const CallDetailInfo & info)32 int32_t CallIncomingFilterManager::PackCellularCallInfo(CellularCallInfo &callInfo, const CallDetailInfo &info)
33 {
34     callInfo.callType = info.callType;
35     callInfo.index = info.index;
36     callInfo.slotId = info.accountId;
37     callInfo.accountId = info.accountId;
38     if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
39         TELEPHONY_LOGW("memset_s failed!");
40         return TELEPHONY_ERR_MEMSET_FAIL;
41     }
42     if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, info.phoneNum, kMaxNumberLen) != EOK) {
43         TELEPHONY_LOGW("memcpy_s failed!");
44         return TELEPHONY_ERR_MEMCPY_FAIL;
45     }
46     return TELEPHONY_SUCCESS;
47 }
48 
DoIncomingFilter(const CallDetailInfo & info)49 int32_t CallIncomingFilterManager::DoIncomingFilter(const CallDetailInfo &info)
50 {
51     bool isEcc = false;
52     DelayedSingleton<CellularCallConnection>::GetInstance()->IsEmergencyPhoneNumber(
53         info.phoneNum, info.accountId, isEcc);
54     if (isEcc) {
55         TELEPHONY_LOGI("incoming phoneNumber is ecc.");
56         return TELEPHONY_SUCCESS;
57     }
58     return TELEPHONY_SUCCESS;
59 }
60 } // namespace Telephony
61 } // namespace OHOS