• 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 "carrier_call.h"
17 
18 #include <securec.h>
19 
20 #include "call_manager_errors.h"
21 #include "call_manager_hisysevent.h"
22 #include "telephony_log_wrapper.h"
23 
24 #include "call_number_utils.h"
25 
26 namespace OHOS {
27 namespace Telephony {
CarrierCall(DialParaInfo & info)28 CarrierCall::CarrierCall(DialParaInfo &info)
29     : CallBase(info), dialScene_(DialScene::CALL_NORMAL), slotId_(info.accountId), index_(info.index),
30     isEcc_(info.isEcc), cellularCallConnectionPtr_(DelayedSingleton<CellularCallConnection>::GetInstance())
31 {}
32 
CarrierCall(DialParaInfo & info,AppExecFwk::PacMap & extras)33 CarrierCall::CarrierCall(DialParaInfo &info, AppExecFwk::PacMap &extras)
34     : CallBase(info, extras), dialScene_((DialScene)extras.GetIntValue("dialScene")), slotId_(info.accountId),
35     index_(info.index), isEcc_(info.isEcc),
36     cellularCallConnectionPtr_(DelayedSingleton<CellularCallConnection>::GetInstance())
37 {}
38 
~CarrierCall()39 CarrierCall::~CarrierCall() {}
40 
CarrierDialingProcess()41 int32_t CarrierCall::CarrierDialingProcess()
42 {
43     TELEPHONY_LOGI("CarrierDialingProcess start");
44     int32_t ret = DialCallBase();
45     if (ret != TELEPHONY_SUCCESS) {
46         CarrierHangUpCall();
47     }
48     return ret;
49 }
50 
CarrierAnswerCall(int32_t videoState)51 int32_t CarrierCall::CarrierAnswerCall(int32_t videoState)
52 {
53     CellularCallInfo callInfo;
54     int32_t ret = AnswerCallBase();
55     if (ret != TELEPHONY_SUCCESS) {
56         TELEPHONY_LOGE("answer call failed!");
57         CallManagerHisysevent::WriteAnswerCallFaultEvent(
58             slotId_, INVALID_PARAMETER, videoState, ret, "the device is currently not ringing");
59         return CALL_ERR_ANSWER_FAILED;
60     }
61     ret = PackCellularCallInfo(callInfo);
62     if (ret != TELEPHONY_SUCCESS) {
63         TELEPHONY_LOGW("PackCellularCallInfo failed!");
64         CallManagerHisysevent::WriteAnswerCallFaultEvent(
65             slotId_, INVALID_PARAMETER, videoState, ret, "PackCellularCallInfo failed");
66     }
67     if (cellularCallConnectionPtr_ == nullptr) {
68         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
69         return TELEPHONY_ERR_LOCAL_PTR_NULL;
70     }
71     ret = cellularCallConnectionPtr_->Answer(callInfo);
72     if (ret != TELEPHONY_SUCCESS) {
73         TELEPHONY_LOGE("answer call failed!");
74         return CALL_ERR_ANSWER_FAILED;
75     }
76     return TELEPHONY_SUCCESS;
77 }
78 
CarrierRejectCall()79 int32_t CarrierCall::CarrierRejectCall()
80 {
81     CellularCallInfo callInfo;
82     int32_t ret = RejectCallBase();
83     if (ret != TELEPHONY_SUCCESS) {
84         return ret;
85     }
86     ret = PackCellularCallInfo(callInfo);
87     if (ret != TELEPHONY_SUCCESS) {
88         TELEPHONY_LOGW("PackCellularCallInfo failed!");
89         CallManagerHisysevent::WriteHangUpFaultEvent(
90             slotId_, callInfo.callId, ret, "Reject PackCellularCallInfo failed");
91     }
92     TelCallState state = GetTelCallState();
93     if (cellularCallConnectionPtr_ == nullptr) {
94         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
95         return TELEPHONY_ERR_LOCAL_PTR_NULL;
96     }
97     if (state == TelCallState::CALL_STATUS_INCOMING) {
98         ret = cellularCallConnectionPtr_->Reject(callInfo);
99     } else {
100         ret = cellularCallConnectionPtr_->HangUp(callInfo, CallSupplementType::TYPE_DEFAULT);
101     }
102     if (ret != TELEPHONY_SUCCESS) {
103         TELEPHONY_LOGE("Reject failed!");
104         return CALL_ERR_REJECT_FAILED;
105     }
106     return TELEPHONY_SUCCESS;
107 }
108 
CarrierHangUpCall()109 int32_t CarrierCall::CarrierHangUpCall()
110 {
111     int32_t ret = CALL_ERR_HANGUP_FAILED;
112     CellularCallInfo callInfo;
113     ret = PackCellularCallInfo(callInfo);
114     if (ret != TELEPHONY_SUCCESS) {
115         TELEPHONY_LOGW("PackCellularCallInfo failed!");
116         CallManagerHisysevent::WriteHangUpFaultEvent(
117             callInfo.accountId, callInfo.callId, ret, "HangUp PackCellularCallInfo failed");
118     }
119     uint64_t policyFlag = GetPolicyFlag();
120     if (cellularCallConnectionPtr_ == nullptr) {
121         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
122         return TELEPHONY_ERR_LOCAL_PTR_NULL;
123     }
124     if (policyFlag & POLICY_FLAG_HANG_UP_ACTIVE) {
125         ret = cellularCallConnectionPtr_->HangUp(callInfo, CallSupplementType::TYPE_HANG_UP_ACTIVE);
126     } else if (policyFlag & POLICY_FLAG_HANG_UP_HOLD_WAIT) {
127         ret = cellularCallConnectionPtr_->HangUp(callInfo, CallSupplementType::TYPE_HANG_UP_HOLD_WAIT);
128     } else {
129         ret = cellularCallConnectionPtr_->HangUp(callInfo, CallSupplementType::TYPE_DEFAULT);
130     }
131     if (ret != TELEPHONY_SUCCESS) {
132         TELEPHONY_LOGE("End failed!");
133         return CALL_ERR_HANGUP_FAILED;
134     }
135     return TELEPHONY_SUCCESS;
136 }
137 
CarrierHoldCall()138 int32_t CarrierCall::CarrierHoldCall()
139 {
140     CellularCallInfo callInfo;
141     int32_t ret = PackCellularCallInfo(callInfo);
142     if (ret != TELEPHONY_SUCCESS) {
143         TELEPHONY_LOGW("PackCellularCallInfo failed!");
144     }
145     if (cellularCallConnectionPtr_ == nullptr) {
146         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
147         return TELEPHONY_ERR_LOCAL_PTR_NULL;
148     }
149     ret = cellularCallConnectionPtr_->HoldCall(callInfo);
150     if (ret != TELEPHONY_SUCCESS) {
151         TELEPHONY_LOGE("Hold failed!");
152         return CALL_ERR_HOLD_FAILED;
153     }
154     return TELEPHONY_SUCCESS;
155 }
156 
CarrierUnHoldCall()157 int32_t CarrierCall::CarrierUnHoldCall()
158 {
159     CellularCallInfo callInfo;
160     int32_t ret = PackCellularCallInfo(callInfo);
161     if (ret != TELEPHONY_SUCCESS) {
162         TELEPHONY_LOGW("PackCellularCallInfo failed!");
163     }
164     if (cellularCallConnectionPtr_ == nullptr) {
165         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
166         return TELEPHONY_ERR_LOCAL_PTR_NULL;
167     }
168     ret = cellularCallConnectionPtr_->UnHoldCall(callInfo);
169     if (ret != TELEPHONY_SUCCESS) {
170         TELEPHONY_LOGE("UnHold failed!");
171         return CALL_ERR_UNHOLD_FAILED;
172     }
173     return TELEPHONY_SUCCESS;
174 }
175 
CarrierSetMute(int32_t mute,int32_t slotId)176 int32_t CarrierCall::CarrierSetMute(int32_t mute, int32_t slotId)
177 {
178     if (cellularCallConnectionPtr_ == nullptr) {
179         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
180         return TELEPHONY_ERR_LOCAL_PTR_NULL;
181     }
182     int32_t ret = cellularCallConnectionPtr_->SetMute(mute, slotId);
183     if (ret != TELEPHONY_SUCCESS) {
184         TELEPHONY_LOGE("SetMute failed!");
185         return CALL_ERR_UNHOLD_FAILED;
186     }
187     return TELEPHONY_SUCCESS;
188 }
189 
GetCallAttributeCarrierInfo(CallAttributeInfo & info)190 void CarrierCall::GetCallAttributeCarrierInfo(CallAttributeInfo &info)
191 {
192     std::lock_guard<std::mutex> lock(mutex_);
193     info.isEcc = isEcc_;
194     info.accountId = slotId_;
195     info.index = index_;
196     GetCallAttributeBaseInfo(info);
197 }
198 
GetEmergencyState()199 bool CarrierCall::GetEmergencyState()
200 {
201     std::lock_guard<std::mutex> lock(mutex_);
202     return isEcc_;
203 }
204 
CarrierSwitchCall()205 int32_t CarrierCall::CarrierSwitchCall()
206 {
207     CellularCallInfo callInfo;
208     int32_t ret = PackCellularCallInfo(callInfo);
209     if (ret != TELEPHONY_SUCCESS) {
210         TELEPHONY_LOGW("PackCellularCallInfo failed!");
211     }
212     if (cellularCallConnectionPtr_ == nullptr) {
213         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
214         return TELEPHONY_ERR_LOCAL_PTR_NULL;
215     }
216     ret = cellularCallConnectionPtr_->SwitchCall(callInfo);
217     if (ret != TELEPHONY_SUCCESS) {
218         TELEPHONY_LOGE("SwitchCall failed!");
219         return CALL_ERR_UNHOLD_FAILED;
220     }
221     return TELEPHONY_SUCCESS;
222 }
223 
GetSlotId()224 int32_t CarrierCall::GetSlotId()
225 {
226     return slotId_;
227 }
228 
CarrierCombineConference()229 int32_t CarrierCall::CarrierCombineConference()
230 {
231     CellularCallInfo callInfo;
232     int32_t ret = PackCellularCallInfo(callInfo);
233     if (ret != TELEPHONY_SUCCESS) {
234         TELEPHONY_LOGW("PackCellularCallInfo failed!");
235     }
236     if (cellularCallConnectionPtr_ == nullptr) {
237         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
238         return TELEPHONY_ERR_LOCAL_PTR_NULL;
239     }
240     return cellularCallConnectionPtr_->CombineConference(callInfo);
241 }
242 
CarrierSeparateConference()243 int32_t CarrierCall::CarrierSeparateConference()
244 {
245     CellularCallInfo callInfo;
246     int32_t ret = PackCellularCallInfo(callInfo);
247     if (ret != TELEPHONY_SUCCESS) {
248         TELEPHONY_LOGW("PackCellularCallInfo failed!");
249     }
250     if (cellularCallConnectionPtr_ == nullptr) {
251         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
252         return TELEPHONY_ERR_LOCAL_PTR_NULL;
253     }
254     return cellularCallConnectionPtr_->SeparateConference(callInfo);
255 }
256 
CarrierKickOutFromConference()257 int32_t CarrierCall::CarrierKickOutFromConference()
258 {
259     CellularCallInfo callInfo;
260     int32_t ret = PackCellularCallInfo(callInfo);
261     if (ret != TELEPHONY_SUCCESS) {
262         TELEPHONY_LOGW("PackCellularCallInfo failed!");
263     }
264     if (cellularCallConnectionPtr_ == nullptr) {
265         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
266         return TELEPHONY_ERR_LOCAL_PTR_NULL;
267     }
268     return cellularCallConnectionPtr_->KickOutFromConference(callInfo);
269 }
270 
IsSupportConferenceable()271 int32_t CarrierCall::IsSupportConferenceable()
272 {
273     // emergency call not allowed to join conference
274     return GetEmergencyState() != true ? TELEPHONY_SUCCESS : CALL_ERR_EMERGENCY_UNSUPPORT_CONFERENCEABLE;
275 }
276 
PackCellularCallInfo(CellularCallInfo & callInfo)277 int32_t CarrierCall::PackCellularCallInfo(CellularCallInfo &callInfo)
278 {
279     callInfo.callId = callId_;
280     callInfo.callType = callType_;
281     callInfo.videoState = static_cast<int32_t>(videoState_);
282     callInfo.index = index_;
283     callInfo.slotId = slotId_;
284     callInfo.accountId = slotId_;
285     if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
286         TELEPHONY_LOGW("memset_s failed!");
287         return TELEPHONY_ERR_MEMSET_FAIL;
288     }
289     if (accountNumber_.length() > static_cast<size_t>(kMaxNumberLen)) {
290         TELEPHONY_LOGE("Number out of limit!");
291         return CALL_ERR_NUMBER_OUT_OF_RANGE;
292     }
293     if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, accountNumber_.c_str(), accountNumber_.length()) != EOK) {
294         TELEPHONY_LOGW("memcpy_s failed!");
295         return TELEPHONY_ERR_MEMCPY_FAIL;
296     }
297     return TELEPHONY_SUCCESS;
298 }
299 
StartDtmf(char str)300 int32_t CarrierCall::StartDtmf(char str)
301 {
302     CellularCallInfo callInfo;
303     int32_t ret = PackCellularCallInfo(callInfo);
304     if (ret != TELEPHONY_SUCCESS) {
305         TELEPHONY_LOGW("PackCellularCallInfo failed!");
306     }
307     if (cellularCallConnectionPtr_ == nullptr) {
308         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
309         return TELEPHONY_ERR_LOCAL_PTR_NULL;
310     }
311     return cellularCallConnectionPtr_->StartDtmf(str, callInfo);
312 }
313 
StopDtmf()314 int32_t CarrierCall::StopDtmf()
315 {
316     CellularCallInfo callInfo;
317     int32_t ret = PackCellularCallInfo(callInfo);
318     if (ret != TELEPHONY_SUCCESS) {
319         TELEPHONY_LOGW("PackCellularCallInfo failed!");
320     }
321     if (cellularCallConnectionPtr_ == nullptr) {
322         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
323         return TELEPHONY_ERR_LOCAL_PTR_NULL;
324     }
325     return cellularCallConnectionPtr_->StopDtmf(callInfo);
326 }
327 
PostDialProceed(bool proceed)328 int32_t CarrierCall::PostDialProceed(bool proceed)
329 {
330     CellularCallInfo callInfo;
331     int32_t ret = PackCellularCallInfo(callInfo);
332     if (ret != TELEPHONY_SUCCESS) {
333         TELEPHONY_LOGW("PackCellularCallInfo failed!");
334     }
335     if (cellularCallConnectionPtr_ == nullptr) {
336         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
337         return TELEPHONY_ERR_LOCAL_PTR_NULL;
338     }
339     return cellularCallConnectionPtr_->PostDialProceed(callInfo, proceed);
340 }
341 
SetSlotId(int32_t slotId)342 void CarrierCall::SetSlotId(int32_t slotId)
343 {
344     slotId_ = slotId;
345 }
346 
SetCallIndex(int32_t index)347 void CarrierCall::SetCallIndex(int32_t index)
348 {
349     index_ = index;
350 }
351 
GetCallIndex()352 int32_t CarrierCall::GetCallIndex()
353 {
354     return index_;
355 }
356 } // namespace Telephony
357 } // namespace OHOS
358