• 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 "bluetooth_call_policy.h"
17 
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20 
21 namespace OHOS {
22 namespace Telephony {
BluetoothCallPolicy()23 BluetoothCallPolicy::BluetoothCallPolicy() {}
24 
~BluetoothCallPolicy()25 BluetoothCallPolicy::~BluetoothCallPolicy() {}
26 
AnswerCallPolicy(int32_t & callId)27 int32_t BluetoothCallPolicy::AnswerCallPolicy(int32_t &callId)
28 {
29     if (IsCallExist(TelCallState::CALL_STATUS_INCOMING, callId)) {
30         TELEPHONY_LOGI("incoming call is exist, callId:%{public}d", callId);
31         return TELEPHONY_SUCCESS;
32     }
33     if (IsCallExist(TelCallState::CALL_STATUS_WAITING, callId)) {
34         TELEPHONY_LOGI("waiting call is exist, callId:%{public}d", callId);
35         return TELEPHONY_SUCCESS;
36     }
37     TELEPHONY_LOGW("AnswerCallPolicy failed");
38     return CALL_ERR_ILLEGAL_CALL_OPERATION;
39 }
40 
RejectCallPolicy(int32_t & callId)41 int32_t BluetoothCallPolicy::RejectCallPolicy(int32_t &callId)
42 {
43     if (IsCallExist(TelCallState::CALL_STATUS_INCOMING, callId)) {
44         TELEPHONY_LOGI("incoming call is exist, callId:%{public}d", callId);
45         return TELEPHONY_SUCCESS;
46     }
47     if (IsCallExist(TelCallState::CALL_STATUS_WAITING, callId)) {
48         TELEPHONY_LOGI("waiting call is exist, callId:%{public}d", callId);
49         return TELEPHONY_SUCCESS;
50     }
51     TELEPHONY_LOGW("RejectCallPolicy failed");
52     return CALL_ERR_ILLEGAL_CALL_OPERATION;
53 }
54 
HoldCallPolicy(int32_t & callId)55 int32_t BluetoothCallPolicy::HoldCallPolicy(int32_t &callId)
56 {
57     if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId)) {
58         TELEPHONY_LOGI("active call is exist, callId:%{public}d", callId);
59         return TELEPHONY_SUCCESS;
60     }
61     TELEPHONY_LOGW("HoldCallPolicy failed");
62     return CALL_ERR_ILLEGAL_CALL_OPERATION;
63 }
64 
UnHoldCallPolicy(int32_t & callId)65 int32_t BluetoothCallPolicy::UnHoldCallPolicy(int32_t &callId)
66 {
67     if (IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
68         TELEPHONY_LOGI("holding call is exist, callId:%{public}d", callId);
69         return TELEPHONY_SUCCESS;
70     }
71     TELEPHONY_LOGW("HoldCallPolicy failed");
72     return CALL_ERR_ILLEGAL_CALL_OPERATION;
73 }
74 
HangUpPolicy(int32_t & callId)75 int32_t BluetoothCallPolicy::HangUpPolicy(int32_t &callId)
76 {
77     if (IsCallExist(TelCallState::CALL_STATUS_INCOMING, callId)) {
78         TELEPHONY_LOGI("incoming call is exist, callId:%{public}d", callId);
79         return TELEPHONY_SUCCESS;
80     }
81     if (IsCallExist(TelCallState::CALL_STATUS_WAITING, callId)) {
82         TELEPHONY_LOGI("waiting call is exist, callId:%{public}d", callId);
83         return TELEPHONY_SUCCESS;
84     }
85     if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId)) {
86         TELEPHONY_LOGI("active call is exist, callId:%{public}d", callId);
87         return TELEPHONY_SUCCESS;
88     }
89     if (IsCallExist(TelCallState::CALL_STATUS_ALERTING, callId)) {
90         TELEPHONY_LOGI("alerting call is exist, callId:%{public}d", callId);
91         return TELEPHONY_SUCCESS;
92     }
93     if (IsCallExist(TelCallState::CALL_STATUS_DIALING, callId)) {
94         TELEPHONY_LOGI("dialing call is exist, callId:%{public}d", callId);
95         return TELEPHONY_SUCCESS;
96     }
97     if (IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
98         TELEPHONY_LOGI("holding call is exist, callId:%{public}d", callId);
99         return TELEPHONY_SUCCESS;
100     }
101     TELEPHONY_LOGW("HangUpPolicy failed");
102     return CALL_ERR_ILLEGAL_CALL_OPERATION;
103 }
104 
SwitchCallPolicy(int32_t & callId)105 int32_t BluetoothCallPolicy::SwitchCallPolicy(int32_t &callId)
106 {
107     if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE) &&
108         IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
109         TELEPHONY_LOGI("active call and holding call are exist, callId:%{public}d", callId);
110         return TELEPHONY_SUCCESS;
111     }
112     TELEPHONY_LOGW("SwitchCallPolicy failed");
113     return CALL_ERR_ILLEGAL_CALL_OPERATION;
114 }
115 
StartDtmfPolicy(int32_t & callId)116 int32_t BluetoothCallPolicy::StartDtmfPolicy(int32_t &callId)
117 {
118     if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId)) {
119         TELEPHONY_LOGI("active call is exist, callId:%{public}d", callId);
120         return TELEPHONY_SUCCESS;
121     }
122     if (IsCallExist(TelCallState::CALL_STATUS_ALERTING, callId)) {
123         TELEPHONY_LOGI("alerting call is exist, callId:%{public}d", callId);
124         return TELEPHONY_SUCCESS;
125     }
126     if (IsCallExist(TelCallState::CALL_STATUS_DIALING, callId)) {
127         TELEPHONY_LOGI("dialing call is exist, callId:%{public}d", callId);
128         return TELEPHONY_SUCCESS;
129     }
130     if (IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
131         TELEPHONY_LOGI("holding call is exist, callId:%{public}d", callId);
132         return TELEPHONY_SUCCESS;
133     }
134     TELEPHONY_LOGW("StartDtmfPolicy failed");
135     return CALL_ERR_ILLEGAL_CALL_OPERATION;
136 }
137 
CombineConferencePolicy(int32_t & callId)138 int32_t BluetoothCallPolicy::CombineConferencePolicy(int32_t &callId)
139 {
140     if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId) &&
141         IsCallExist(TelCallState::CALL_STATUS_HOLDING)) {
142         TELEPHONY_LOGI("active call and holding call are exist, callId:%{public}d", callId);
143         return TELEPHONY_SUCCESS;
144     }
145     TELEPHONY_LOGW("CombineConferencePolicy failed");
146     return CALL_ERR_ILLEGAL_CALL_OPERATION;
147 }
148 
SeparateConferencePolicy(int32_t & callId)149 int32_t BluetoothCallPolicy::SeparateConferencePolicy(int32_t &callId)
150 {
151     if (IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_ACTIVE, callId) ||
152         IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_HOLDING, callId)) {
153         TELEPHONY_LOGI("conference call is exist, callId:%{public}d", callId);
154         return TELEPHONY_SUCCESS;
155     }
156     TELEPHONY_LOGW("SeparateConferencePolicy failed");
157     return CALL_ERR_ILLEGAL_CALL_OPERATION;
158 }
159 
KickOutFromConferencePolicy(int32_t & callId)160 int32_t BluetoothCallPolicy::KickOutFromConferencePolicy(int32_t &callId)
161 {
162     if (IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_ACTIVE, callId) ||
163         IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_HOLDING, callId)) {
164         TELEPHONY_LOGI("conference call is exist, callId:%{public}d", callId);
165         return TELEPHONY_SUCCESS;
166     }
167     TELEPHONY_LOGW("KickOutFromConferencePolicy failed");
168     return CALL_ERR_ILLEGAL_CALL_OPERATION;
169 }
170 } // namespace Telephony
171 } // namespace OHOS
172