• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()27 CallStatusPolicy::CallStatusPolicy() {}
28 
~CallStatusPolicy()29 CallStatusPolicy::~CallStatusPolicy() {}
30 
IncomingHandlePolicy(const CallDetailInfo & info)31 int32_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 
39     if (IsCallExist(numberStr)) {
40         TELEPHONY_LOGE("the call already exists!");
41         return CALL_ERR_CALL_ALREADY_EXISTS;
42     }
43     return TELEPHONY_SUCCESS;
44 }
45 
DialingHandlePolicy(const CallDetailInfo & info)46 int32_t CallStatusPolicy::DialingHandlePolicy(const CallDetailInfo &info)
47 {
48     std::string number(info.phoneNum);
49     if (IsCallExist(number)) {
50         TELEPHONY_LOGW("this call has created yet!");
51         return CALL_ERR_CALL_ALREADY_EXISTS;
52     }
53     return TELEPHONY_SUCCESS;
54 }
55 
FilterResultsDispose(sptr<CallBase> call)56 int32_t CallStatusPolicy::FilterResultsDispose(sptr<CallBase> call)
57 {
58     int32_t ret = TELEPHONY_ERR_FAIL;
59     if (call == nullptr) {
60         TELEPHONY_LOGE("Call is NULL");
61         return CALL_ERR_CALL_OBJECT_IS_NULL;
62     }
63     if (HasRingingMaximum() || HasDialingMaximum()) {
64         TELEPHONY_LOGI("the number of Ringing or Dialing call is bigger than Maximum, start to hung up");
65         ret = call->HangUpCall();
66         if (ret != TELEPHONY_SUCCESS) {
67             TELEPHONY_LOGE("HangUpCall failed!");
68             return ret;
69         }
70         // Print the log and record the information to the database
71         return TELEPHONY_SUCCESS;
72     }
73     ret = call->IncomingCallBase();
74     TELEPHONY_LOGI("IncomingCallBase ret : %{public}d", ret);
75     DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call);
76     // Print the log and record the information to the database
77     // Call notification module
78     return TELEPHONY_SUCCESS;
79 }
80 } // namespace Telephony
81 } // namespace OHOS