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 DialingHandlePolicy(const CallDetailInfo & info)31int32_t CallStatusPolicy::DialingHandlePolicy(const CallDetailInfo &info) 32 { 33 std::string number(info.phoneNum); 34 if (IsCallExist(number)) { 35 TELEPHONY_LOGW("this call has created yet!"); 36 return CALL_ERR_CALL_ALREADY_EXISTS; 37 } 38 return TELEPHONY_SUCCESS; 39 } 40 FilterResultsDispose(sptr<CallBase> call)41int32_t CallStatusPolicy::FilterResultsDispose(sptr<CallBase> call) 42 { 43 int32_t ret = TELEPHONY_ERR_FAIL; 44 if (call == nullptr) { 45 TELEPHONY_LOGE("Call is NULL"); 46 return CALL_ERR_CALL_OBJECT_IS_NULL; 47 } 48 if (HasRingingMaximum() || HasDialingMaximum()) { 49 TELEPHONY_LOGI("the number of Ringing or Dialing call is bigger than Maximum, start to hung up"); 50 ret = call->HangUpCall(); 51 if (ret != TELEPHONY_SUCCESS) { 52 TELEPHONY_LOGE("HangUpCall failed!"); 53 return ret; 54 } 55 // Print the log and record the information to the database 56 return TELEPHONY_SUCCESS; 57 } 58 int32_t state; 59 DelayedSingleton<CallControlManager>::GetInstance()->GetVoIPCallState(state); 60 if (state == (int32_t)CallStateToApp::CALL_STATE_RINGING) { 61 ret = call->RejectCall(); 62 if (ret != TELEPHONY_SUCCESS) { 63 TELEPHONY_LOGI("Reject call failed!"); 64 return ret; 65 } 66 return TELEPHONY_SUCCESS; 67 } 68 ret = call->IncomingCallBase(); 69 TELEPHONY_LOGI("IncomingCallBase ret : %{public}d", ret); 70 DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call); 71 // Print the log and record the information to the database 72 // Call notification module 73 return TELEPHONY_SUCCESS; 74 } 75 } // namespace Telephony 76 } // namespace OHOS