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