• 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_service.h"
17 
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20 
21 #include "bluetooth_call_manager.h"
22 
23 namespace OHOS {
24 namespace Telephony {
BluetoothCallService()25 BluetoothCallService::BluetoothCallService()
26     : callControlManagerPtr_(DelayedSingleton<CallControlManager>::GetInstance()),
27     sendDtmfState_(false), sendDtmfCallId_(ERR_ID)
28 {}
29 
~BluetoothCallService()30 BluetoothCallService::~BluetoothCallService()
31 {}
32 
AnswerCall()33 int32_t BluetoothCallService::AnswerCall()
34 {
35     int32_t callId = ERR_ID;
36     int32_t ret = AnswerCallPolicy(callId);
37     if (ret != TELEPHONY_SUCCESS) {
38         TELEPHONY_LOGE("AnswerCallPolicy failed!");
39         return ret;
40     }
41     sptr<CallBase> call = GetOneCallObject(callId);
42     if (call == nullptr) {
43         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
44         return TELEPHONY_ERR_LOCAL_PTR_NULL;
45     }
46     VideoStateType videoState = call->GetVideoStateType();
47     if (callControlManagerPtr_ != nullptr) {
48         return callControlManagerPtr_->AnswerCall(callId, static_cast<int32_t>(videoState));
49     } else {
50         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
51         return TELEPHONY_ERR_LOCAL_PTR_NULL;
52     }
53 }
54 
RejectCall()55 int32_t BluetoothCallService::RejectCall()
56 {
57     int32_t callId = ERR_ID;
58     bool rejectWithMessage = false;
59     std::u16string textMessage = Str8ToStr16("");
60     int32_t ret = RejectCallPolicy(callId);
61     if (ret != TELEPHONY_SUCCESS) {
62         TELEPHONY_LOGE("RejectCallPolicy failed!");
63         return ret;
64     }
65     if (callControlManagerPtr_ != nullptr) {
66         return callControlManagerPtr_->RejectCall(callId, rejectWithMessage, textMessage);
67     } else {
68         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
69         return TELEPHONY_ERR_LOCAL_PTR_NULL;
70     }
71 }
72 
HangUpCall()73 int32_t BluetoothCallService::HangUpCall()
74 {
75     int32_t callId = ERR_ID;
76     int32_t ret = HangUpPolicy(callId);
77     if (ret != TELEPHONY_SUCCESS) {
78         TELEPHONY_LOGE("HangUpPolicy failed!");
79         return ret;
80     }
81     if (callControlManagerPtr_ != nullptr) {
82         return callControlManagerPtr_->HangUpCall(callId);
83     } else {
84         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
85         return TELEPHONY_ERR_LOCAL_PTR_NULL;
86     }
87 }
88 
GetCallState()89 int32_t BluetoothCallService::GetCallState()
90 {
91     int32_t numActive = GetCallNum(TelCallState::CALL_STATUS_ACTIVE);
92     int32_t numHeld = GetCallNum(TelCallState::CALL_STATUS_HOLDING);
93     int32_t callState = static_cast<int32_t>(TelCallState::CALL_STATUS_IDLE);
94     std::string number = "";
95     if (numHeld > 0) {
96         callState = static_cast<int32_t>(TelCallState::CALL_STATUS_HOLDING);
97         number = GetCallNumber(TelCallState::CALL_STATUS_HOLDING);
98     }
99     if (numActive > 0) {
100         callState = static_cast<int32_t>(TelCallState::CALL_STATUS_ACTIVE);
101         number = GetCallNumber(TelCallState::CALL_STATUS_ACTIVE);
102     }
103     return DelayedSingleton<BluetoothCallManager>::GetInstance()->
104         SendBtCallState(numActive, numHeld, callState, number);
105 }
106 
HoldCall()107 int32_t BluetoothCallService::HoldCall()
108 {
109     int32_t callId = ERR_ID;
110     int32_t ret = HoldCallPolicy(callId);
111     if (ret != TELEPHONY_SUCCESS) {
112         TELEPHONY_LOGE("HoldCallPolicy failed!");
113         return ret;
114     }
115     if (callControlManagerPtr_ != nullptr) {
116         return callControlManagerPtr_->HoldCall(callId);
117     } else {
118         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
119         return TELEPHONY_ERR_LOCAL_PTR_NULL;
120     }
121 }
122 
UnHoldCall()123 int32_t BluetoothCallService::UnHoldCall()
124 {
125     int32_t callId = ERR_ID;
126     int32_t ret = UnHoldCallPolicy(callId);
127     if (ret != TELEPHONY_SUCCESS) {
128         TELEPHONY_LOGE("UnHoldCallPolicy failed!");
129         return ret;
130     }
131     if (callControlManagerPtr_ != nullptr) {
132         return callControlManagerPtr_->UnHoldCall(callId);
133     } else {
134         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
135         return TELEPHONY_ERR_LOCAL_PTR_NULL;
136     }
137 }
138 
SwitchCall()139 int32_t BluetoothCallService::SwitchCall()
140 {
141     int32_t callId = ERR_ID;
142     int32_t ret = SwitchCallPolicy(callId);
143     if (ret != TELEPHONY_SUCCESS) {
144         TELEPHONY_LOGE("SwitchCallPolicy failed!");
145         return ret;
146     }
147     if (callControlManagerPtr_ != nullptr) {
148         return callControlManagerPtr_->SwitchCall(callId);
149     } else {
150         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
151         return TELEPHONY_ERR_LOCAL_PTR_NULL;
152     }
153 }
154 
StartDtmf(char str)155 int32_t BluetoothCallService::StartDtmf(char str)
156 {
157     int32_t callId = ERR_ID;
158     int32_t ret = StartDtmfPolicy(callId);
159     if (ret != TELEPHONY_SUCCESS) {
160         TELEPHONY_LOGE("StartDtmfPolicy failed!");
161         return ret;
162     }
163     if (callControlManagerPtr_ != nullptr) {
164         {
165             std::lock_guard<std::mutex> guard(lock_);
166             sendDtmfState_ = true;
167             sendDtmfCallId_ = callId;
168         }
169         return callControlManagerPtr_->StartDtmf(callId, str);
170     } else {
171         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
172         return TELEPHONY_ERR_LOCAL_PTR_NULL;
173     }
174 }
175 
StopDtmf()176 int32_t BluetoothCallService::StopDtmf()
177 {
178     int32_t callId = ERR_ID;
179     if (callControlManagerPtr_ != nullptr) {
180         {
181             std::lock_guard<std::mutex> guard(lock_);
182             callId = sendDtmfCallId_;
183             sendDtmfState_ = false;
184             sendDtmfCallId_ = ERR_ID;
185         }
186         return callControlManagerPtr_->StopDtmf(callId);
187     } else {
188         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
189         return TELEPHONY_ERR_LOCAL_PTR_NULL;
190     }
191 }
192 
CombineConference()193 int32_t BluetoothCallService::CombineConference()
194 {
195     int32_t callId = ERR_ID;
196     int32_t ret = CombineConferencePolicy(callId);
197     if (ret != TELEPHONY_SUCCESS) {
198         TELEPHONY_LOGE("CombineConferencePolicy failed!");
199         return ret;
200     }
201     if (callControlManagerPtr_ != nullptr) {
202         return callControlManagerPtr_->CombineConference(callId);
203     } else {
204         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
205         return TELEPHONY_ERR_LOCAL_PTR_NULL;
206     }
207 }
208 
SeparateConference()209 int32_t BluetoothCallService::SeparateConference()
210 {
211     int32_t callId = ERR_ID;
212     if (callControlManagerPtr_ != nullptr) {
213         return callControlManagerPtr_->SeparateConference(callId);
214     } else {
215         TELEPHONY_LOGE("callControlManagerPtr_ is nullptr!");
216         return TELEPHONY_ERR_LOCAL_PTR_NULL;
217     }
218 }
219 
GetCurrentCallList(int32_t slotId)220 std::vector<CallAttributeInfo> BluetoothCallService::GetCurrentCallList(int32_t slotId)
221 {
222     return GetCallInfoList(slotId);
223 }
224 } // namespace Telephony
225 } // namespace OHOS
226