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 16 #include "call_status_policy.h" 17 18 #include <securec.h> 19 20 #include "call_manager_errors.h" 21 #include "telephony_log_wrapper.h" 22 23 #include "call_control_manager.h" 24 25 namespace OHOS { 26 namespace Telephony { CallStatusPolicy()27CallStatusPolicy::CallStatusPolicy() {} 28 ~CallStatusPolicy()29CallStatusPolicy::~CallStatusPolicy() {} 30 IncomingHandlePolicy(const CallDetailInfo & info)31int32_t CallStatusPolicy::IncomingHandlePolicy(const CallDetailInfo &info) 32 { 33 std::string numberStr(info.phoneNum); 34 if (numberStr.empty()) { 35 TELEPHONY_LOGE("phone number is NULL!"); 36 return CALL_ERR_PHONE_NUMBER_EMPTY; 37 } 38 return TELEPHONY_SUCCESS; 39 } 40 DialingHandlePolicy(const CallDetailInfo & info)41int32_t CallStatusPolicy::DialingHandlePolicy(const CallDetailInfo &info) 42 { 43 std::string number(info.phoneNum); 44 if (IsCallExist(number)) { 45 TELEPHONY_LOGW("this call has created yet!"); 46 return CALL_ERR_CALL_ALREADY_EXISTS; 47 } 48 return TELEPHONY_SUCCESS; 49 } 50 FilterResultsDispose(sptr<CallBase> call)51int32_t CallStatusPolicy::FilterResultsDispose(sptr<CallBase> call) 52 { 53 int32_t ret = TELEPHONY_ERR_FAIL; 54 if (call == nullptr) { 55 TELEPHONY_LOGE("Call is NULL"); 56 return CALL_ERR_CALL_OBJECT_IS_NULL; 57 } 58 if (HasRingingMaximum() || HasDialingMaximum()) { 59 TELEPHONY_LOGI("the number of Ringing or Dialing call is bigger than Maximum, start to hung up"); 60 ret = call->HangUpCall(); 61 if (ret != TELEPHONY_SUCCESS) { 62 TELEPHONY_LOGE("HangUpCall failed!"); 63 return ret; 64 } 65 // Print the log and record the information to the database 66 return TELEPHONY_SUCCESS; 67 } 68 int32_t state; 69 DelayedSingleton<CallControlManager>::GetInstance()->GetVoIPCallState(state); 70 if (state == (int32_t)CallStateToApp::CALL_STATE_RINGING) { 71 ret = call->RejectCall(); 72 if (ret != TELEPHONY_SUCCESS) { 73 TELEPHONY_LOGI("Reject call failed!"); 74 return ret; 75 } 76 return TELEPHONY_SUCCESS; 77 } 78 ret = call->IncomingCallBase(); 79 TELEPHONY_LOGI("IncomingCallBase ret : %{public}d", ret); 80 DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call); 81 // Print the log and record the information to the database 82 // Call notification module 83 return TELEPHONY_SUCCESS; 84 } 85 } // namespace Telephony 86 } // namespace OHOS