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 "cs_call.h"
17 
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20 
21 namespace OHOS {
22 namespace Telephony {
CSCall(DialParaInfo & info)23 CSCall::CSCall(DialParaInfo &info) : CarrierCall(info) {}
24 
CSCall(DialParaInfo & info,AppExecFwk::PacMap & extras)25 CSCall::CSCall(DialParaInfo &info, AppExecFwk::PacMap &extras) : CarrierCall(info, extras) {}
26 
~CSCall()27 CSCall::~CSCall() {}
28 
DialingProcess()29 int32_t CSCall::DialingProcess()
30 {
31     return CarrierDialingProcess();
32 }
33 
AnswerCall(int32_t videoState)34 int32_t CSCall::AnswerCall(int32_t videoState)
35 {
36     return CarrierAnswerCall(videoState);
37 }
38 
RejectCall()39 int32_t CSCall::RejectCall()
40 {
41     return CarrierRejectCall();
42 }
43 
HangUpCall()44 int32_t CSCall::HangUpCall()
45 {
46     return CarrierHangUpCall();
47 }
48 
HoldCall()49 int32_t CSCall::HoldCall()
50 {
51     return CarrierHoldCall();
52 }
53 
UnHoldCall()54 int32_t CSCall::UnHoldCall()
55 {
56     return CarrierUnHoldCall();
57 }
58 
SwitchCall()59 int32_t CSCall::SwitchCall()
60 {
61     return CarrierSwitchCall();
62 }
63 
GetCallAttributeInfo(CallAttributeInfo & info)64 void CSCall::GetCallAttributeInfo(CallAttributeInfo &info)
65 {
66     GetCallAttributeCarrierInfo(info);
67 }
68 
SetMute(int32_t mute,int32_t slotId)69 int32_t CSCall::SetMute(int32_t mute, int32_t slotId)
70 {
71     return CarrierSetMute(mute, slotId);
72 }
73 
CombineConference()74 int32_t CSCall::CombineConference()
75 {
76     int32_t ret = DelayedSingleton<CsConference>::GetInstance()->SetMainCall(GetCallID());
77     if (ret != TELEPHONY_SUCCESS) {
78         return ret;
79     }
80     ConferenceState currentState = DelayedSingleton<CsConference>::GetInstance()->GetConferenceState();
81     if (currentState == ConferenceState::CONFERENCE_STATE_CREATING) {
82         TELEPHONY_LOGE("skip combine, a process of combine already exsists");
83         return TELEPHONY_SUCCESS;
84     }
85     DelayedSingleton<CsConference>::GetInstance()->SetConferenceState(ConferenceState::CONFERENCE_STATE_CREATING);
86     return CarrierCombineConference();
87 }
88 
HandleCombineConferenceFailEvent()89 void CSCall::HandleCombineConferenceFailEvent()
90 {
91     std::set<std::int32_t> subCallIdList = DelayedSingleton<CsConference>::GetInstance()->GetSubCallIdList();
92     if (subCallIdList.empty()) {
93         DelayedSingleton<CsConference>::GetInstance()->SetMainCall(ERR_ID);
94     } else {
95         DelayedSingleton<CsConference>::GetInstance()->SetMainCall(*subCallIdList.begin());
96     }
97     ConferenceState oldState = DelayedSingleton<CsConference>::GetInstance()->GetOldConferenceState();
98     DelayedSingleton<CsConference>::GetInstance()->SetConferenceState(oldState);
99 }
100 
SeparateConference()101 int32_t CSCall::SeparateConference()
102 {
103     return CarrierSeparateConference();
104 }
105 
KickOutFromConference()106 int32_t CSCall::KickOutFromConference()
107 {
108     return CarrierKickOutFromConference();
109 }
110 
CanCombineConference()111 int32_t CSCall::CanCombineConference()
112 {
113     int32_t ret = IsSupportConferenceable();
114     if (ret != TELEPHONY_SUCCESS) {
115         TELEPHONY_LOGE("call unsupported conference, error%{public}d", ret);
116         return ret;
117     }
118     return DelayedSingleton<CsConference>::GetInstance()->CanCombineConference();
119 }
120 
CanSeparateConference()121 int32_t CSCall::CanSeparateConference()
122 {
123     return DelayedSingleton<CsConference>::GetInstance()->CanSeparateConference();
124 }
125 
CanKickOutFromConference()126 int32_t CSCall::CanKickOutFromConference()
127 {
128     return DelayedSingleton<CsConference>::GetInstance()->CanKickOutFromConference();
129 }
130 
LaunchConference()131 int32_t CSCall::LaunchConference()
132 {
133     int32_t ret = DelayedSingleton<CsConference>::GetInstance()->JoinToConference(GetCallID());
134     if (ret == TELEPHONY_SUCCESS) {
135         SetTelConferenceState(TelConferenceState::TEL_CONFERENCE_ACTIVE);
136     }
137     return ret;
138 }
139 
ExitConference()140 int32_t CSCall::ExitConference()
141 {
142     int32_t ret = DelayedSingleton<CsConference>::GetInstance()->LeaveFromConference(GetCallID());
143     if (ret == TELEPHONY_SUCCESS) {
144         SetTelConferenceState(TelConferenceState::TEL_CONFERENCE_IDLE);
145     }
146     return ret;
147 }
148 
HoldConference()149 int32_t CSCall::HoldConference()
150 {
151     int32_t ret = DelayedSingleton<CsConference>::GetInstance()->HoldConference(GetCallID());
152     if (ret == TELEPHONY_SUCCESS) {
153         SetTelConferenceState(TelConferenceState::TEL_CONFERENCE_HOLDING);
154     }
155     return ret;
156 }
157 
GetMainCallId(int32_t & mainCallId)158 int32_t CSCall::GetMainCallId(int32_t &mainCallId)
159 {
160     mainCallId = DelayedSingleton<CsConference>::GetInstance()->GetMainCall();
161     return TELEPHONY_SUCCESS;
162 }
163 
GetSubCallIdList(std::vector<std::u16string> & callIdList)164 int32_t CSCall::GetSubCallIdList(std::vector<std::u16string> &callIdList)
165 {
166     return DelayedSingleton<CsConference>::GetInstance()->GetSubCallIdList(GetCallID(), callIdList);
167 }
168 
GetCallIdListForConference(std::vector<std::u16string> & callIdList)169 int32_t CSCall::GetCallIdListForConference(std::vector<std::u16string> &callIdList)
170 {
171     return DelayedSingleton<CsConference>::GetInstance()->GetCallIdListForConference(GetCallID(), callIdList);
172 }
173 
IsSupportConferenceable()174 int32_t CSCall::IsSupportConferenceable()
175 {
176     // get from configure file
177 #ifdef ABILIT_CONFIG_SUPPORT
178     bool carrierSupport = GetCarrierConfig(CS_SUPPORT_CONFERENCE);
179     if (!carrierSupport) {
180         return TELEPHONY_CONFERENCE_CARRIER_NOT_SUPPORT;
181     }
182 #endif
183     return CarrierCall::IsSupportConferenceable();
184 }
185 } // namespace Telephony
186 } // namespace OHOS
187