• 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_client.h"
17 
18 #include <memory>
19 
20 #include "system_ability_definition.h"
21 
22 #include "telephony_errors.h"
23 
24 #include "bluetooth_call_proxy.h"
25 #include "call_manager_proxy.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 static std::shared_ptr<CallManagerProxy> g_callManagerProxyPtr = nullptr;
30 static sptr<IBluetoothCall> g_bluetoothCallProxyPtr = nullptr;
31 
BluetoothCallClient()32 BluetoothCallClient::BluetoothCallClient() {}
33 
~BluetoothCallClient()34 BluetoothCallClient::~BluetoothCallClient() {}
35 
Init()36 void BluetoothCallClient::Init()
37 {
38     if (g_callManagerProxyPtr == nullptr) {
39         g_callManagerProxyPtr = DelayedSingleton<CallManagerProxy>::GetInstance();
40         if (g_callManagerProxyPtr == nullptr) {
41             TELEPHONY_LOGE("g_callManagerProxyPtr is nullptr");
42             return;
43         }
44         g_callManagerProxyPtr->Init(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
45         sptr<IRemoteObject> iRemoteObjectPtr = g_callManagerProxyPtr->GetProxyObjectPtr(PROXY_BLUETOOTH_CALL);
46         if (iRemoteObjectPtr == nullptr) {
47             TELEPHONY_LOGE("GetProxyObjectPtr failed!");
48             return;
49         }
50         g_bluetoothCallProxyPtr = iface_cast<IBluetoothCall>(iRemoteObjectPtr);
51         if (g_bluetoothCallProxyPtr == nullptr) {
52             TELEPHONY_LOGE("iface_cast<ICallManagerService> failed!");
53             return;
54         }
55         TELEPHONY_LOGI("BluetoothCallClient init success!");
56     }
57 }
58 
UnInit()59 void BluetoothCallClient::UnInit()
60 {
61     if (g_callManagerProxyPtr != nullptr) {
62         g_callManagerProxyPtr->UnInit();
63     } else {
64         TELEPHONY_LOGE("init first please!");
65     }
66 }
67 
RegisterCallBack(std::unique_ptr<CallManagerCallback> callback)68 int32_t BluetoothCallClient::RegisterCallBack(std::unique_ptr<CallManagerCallback> callback)
69 {
70     if (g_callManagerProxyPtr != nullptr) {
71         return g_callManagerProxyPtr->RegisterCallBack(std::move(callback));
72     } else {
73         TELEPHONY_LOGE("init first please!");
74         return TELEPHONY_ERR_UNINIT;
75     }
76 }
77 
UnRegisterCallBack()78 int32_t BluetoothCallClient::UnRegisterCallBack()
79 {
80     if (g_callManagerProxyPtr != nullptr) {
81         return g_callManagerProxyPtr->UnRegisterCallBack();
82     } else {
83         TELEPHONY_LOGE("init first please!");
84         return TELEPHONY_ERR_UNINIT;
85     }
86 }
87 
DialCall(std::u16string number,AppExecFwk::PacMap & extras)88 int32_t BluetoothCallClient::DialCall(std::u16string number, AppExecFwk::PacMap &extras)
89 {
90     if (g_callManagerProxyPtr != nullptr) {
91         return g_callManagerProxyPtr->DialCall(number, extras);
92     } else {
93         TELEPHONY_LOGE("init first please!");
94         return TELEPHONY_ERR_UNINIT;
95     }
96 }
97 
AnswerCall()98 int32_t BluetoothCallClient::AnswerCall()
99 {
100     if (g_bluetoothCallProxyPtr != nullptr) {
101         return g_bluetoothCallProxyPtr->AnswerCall();
102     } else {
103         TELEPHONY_LOGE("init first please!");
104         return TELEPHONY_ERR_UNINIT;
105     }
106 }
107 
RejectCall()108 int32_t BluetoothCallClient::RejectCall()
109 {
110     if (g_bluetoothCallProxyPtr != nullptr) {
111         return g_bluetoothCallProxyPtr->RejectCall();
112     } else {
113         TELEPHONY_LOGE("init first please!");
114         return TELEPHONY_ERR_UNINIT;
115     }
116 }
117 
HangUpCall()118 int32_t BluetoothCallClient::HangUpCall()
119 {
120     if (g_bluetoothCallProxyPtr != nullptr) {
121         return g_bluetoothCallProxyPtr->HangUpCall();
122     } else {
123         TELEPHONY_LOGE("init first please!");
124         return TELEPHONY_ERR_UNINIT;
125     }
126 }
127 
GetCallState()128 int32_t BluetoothCallClient::GetCallState()
129 {
130     if (g_bluetoothCallProxyPtr != nullptr) {
131         return g_bluetoothCallProxyPtr->GetCallState();
132     } else {
133         TELEPHONY_LOGE("init first please!");
134         return TELEPHONY_ERR_UNINIT;
135     }
136 }
137 
HoldCall()138 int32_t BluetoothCallClient::HoldCall()
139 {
140     if (g_bluetoothCallProxyPtr != nullptr) {
141         return g_bluetoothCallProxyPtr->HoldCall();
142     } else {
143         TELEPHONY_LOGE("init first please!");
144         return TELEPHONY_ERR_UNINIT;
145     }
146 }
147 
UnHoldCall()148 int32_t BluetoothCallClient::UnHoldCall()
149 {
150     if (g_bluetoothCallProxyPtr != nullptr) {
151         return g_bluetoothCallProxyPtr->UnHoldCall();
152     } else {
153         TELEPHONY_LOGE("init first please!");
154         return TELEPHONY_ERR_UNINIT;
155     }
156 }
157 
SwitchCall()158 int32_t BluetoothCallClient::SwitchCall()
159 {
160     if (g_bluetoothCallProxyPtr != nullptr) {
161         return g_bluetoothCallProxyPtr->SwitchCall();
162     } else {
163         TELEPHONY_LOGE("init first please!");
164         return TELEPHONY_ERR_UNINIT;
165     }
166 }
167 
CombineConference()168 int32_t BluetoothCallClient::CombineConference()
169 {
170     if (g_bluetoothCallProxyPtr != nullptr) {
171         return g_bluetoothCallProxyPtr->CombineConference();
172     } else {
173         TELEPHONY_LOGE("init first please!");
174         return TELEPHONY_ERR_UNINIT;
175     }
176 }
177 
SeparateConference()178 int32_t BluetoothCallClient::SeparateConference()
179 {
180     if (g_bluetoothCallProxyPtr != nullptr) {
181         return g_bluetoothCallProxyPtr->SeparateConference();
182     } else {
183         TELEPHONY_LOGE("init first please!");
184         return TELEPHONY_ERR_UNINIT;
185     }
186 }
187 
StartDtmf(char str)188 int32_t BluetoothCallClient::StartDtmf(char str)
189 {
190     if (g_bluetoothCallProxyPtr != nullptr) {
191         return g_bluetoothCallProxyPtr->StartDtmf(str);
192     } else {
193         TELEPHONY_LOGE("init first please!");
194         return TELEPHONY_ERR_UNINIT;
195     }
196 }
197 
StopDtmf()198 int32_t BluetoothCallClient::StopDtmf()
199 {
200     if (g_bluetoothCallProxyPtr != nullptr) {
201         return g_bluetoothCallProxyPtr->StopDtmf();
202     } else {
203         TELEPHONY_LOGE("init first please!");
204         return TELEPHONY_ERR_UNINIT;
205     }
206 }
207 
IsRinging()208 bool BluetoothCallClient::IsRinging()
209 {
210     if (g_callManagerProxyPtr != nullptr) {
211         return g_callManagerProxyPtr->IsRinging();
212     } else {
213         TELEPHONY_LOGE("init first please!");
214         return TELEPHONY_ERR_UNINIT;
215     }
216 }
217 
HasCall()218 bool BluetoothCallClient::HasCall()
219 {
220     if (g_callManagerProxyPtr != nullptr) {
221         return g_callManagerProxyPtr->HasCall();
222     } else {
223         TELEPHONY_LOGE("init first please!");
224         return TELEPHONY_ERR_UNINIT;
225     }
226 }
227 
IsNewCallAllowed()228 bool BluetoothCallClient::IsNewCallAllowed()
229 {
230     if (g_callManagerProxyPtr != nullptr) {
231         return g_callManagerProxyPtr->IsNewCallAllowed();
232     } else {
233         TELEPHONY_LOGE("init first please!");
234         return TELEPHONY_ERR_UNINIT;
235     }
236 }
237 
IsInEmergencyCall()238 bool BluetoothCallClient::IsInEmergencyCall()
239 {
240     if (g_callManagerProxyPtr != nullptr) {
241         return g_callManagerProxyPtr->IsInEmergencyCall();
242     } else {
243         TELEPHONY_LOGE("init first please!");
244         return TELEPHONY_ERR_UNINIT;
245     }
246 }
247 
SetMuted(bool isMute)248 int32_t BluetoothCallClient::SetMuted(bool isMute)
249 {
250     if (g_callManagerProxyPtr != nullptr) {
251         return g_callManagerProxyPtr->SetMuted(isMute);
252     } else {
253         TELEPHONY_LOGE("init first please!");
254         return TELEPHONY_ERR_UNINIT;
255     }
256 }
257 
MuteRinger()258 int32_t BluetoothCallClient::MuteRinger()
259 {
260     if (g_callManagerProxyPtr != nullptr) {
261         return g_callManagerProxyPtr->MuteRinger();
262     } else {
263         TELEPHONY_LOGE("init first please!");
264         return TELEPHONY_ERR_UNINIT;
265     }
266 }
267 
SetAudioDevice(AudioDevice deviceType)268 int32_t BluetoothCallClient::SetAudioDevice(AudioDevice deviceType)
269 {
270     if (g_callManagerProxyPtr != nullptr) {
271         return g_callManagerProxyPtr->SetAudioDevice(deviceType);
272     } else {
273         TELEPHONY_LOGE("init first please!");
274         return TELEPHONY_ERR_UNINIT;
275     }
276 }
277 
GetCurrentCallList(int32_t slotId)278 std::vector<CallAttributeInfo> BluetoothCallClient::GetCurrentCallList(int32_t slotId)
279 {
280     std::vector<CallAttributeInfo> callVec;
281     callVec.clear();
282     if (g_bluetoothCallProxyPtr != nullptr) {
283         return g_bluetoothCallProxyPtr->GetCurrentCallList(slotId);
284     } else {
285         TELEPHONY_LOGE("init first please!");
286         return callVec;
287     }
288 }
289 } // namespace Telephony
290 } // namespace OHOS