• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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 #include "bluetooth_hfp_hf_proxy.h"
16 #include "bluetooth_errorcode.h"
17 #include "bluetooth_log.h"
18 
19 namespace OHOS {
20 namespace Bluetooth {
ConnectSco(const BluetoothRawAddress & device)21 bool BluetoothHfpHfProxy::ConnectSco(const BluetoothRawAddress &device)
22 {
23     MessageParcel data;
24     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
25         HILOGE("BluetoothHfpHfProxy::ConnectSco WriteInterfaceToken error");
26         return false;
27     }
28     if (!data.WriteParcelable(&device)) {
29         HILOGE("BluetoothHfpHfProxy::ConnectSco WriteParcelable error");
30         return false;
31     }
32     MessageParcel reply;
33     MessageOption option {
34         MessageOption::TF_SYNC
35     };
36     int error = Remote()->SendRequest(
37         BluetoothHfpHfInterfaceCode::BT_HFP_HF_CONNECT_SCO, data, reply, option);
38     if (error != NO_ERROR) {
39         HILOGE("BluetoothHfpHfProxy::ConnectSco done fail, error: %{public}d", error);
40         return false;
41     }
42     return reply.ReadBool();
43 }
44 
DisconnectSco(const BluetoothRawAddress & device)45 bool BluetoothHfpHfProxy::DisconnectSco(const BluetoothRawAddress &device)
46 {
47     MessageParcel data;
48     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
49         HILOGE("BluetoothHfpHfProxy::DisconnectSco WriteInterfaceToken error");
50         return false;
51     }
52     if (!data.WriteParcelable(&device)) {
53         HILOGE("BluetoothHfpHfProxy::DisconnectSco WriteParcelable error");
54         return false;
55     }
56     MessageParcel reply;
57     MessageOption option {
58         MessageOption::TF_SYNC
59     };
60     int error = Remote()->SendRequest(
61         BluetoothHfpHfInterfaceCode::BT_HFP_HF_DISCONNECT_SCO, data, reply, option);
62     if (error != NO_ERROR) {
63         HILOGE("BluetoothHfpHfProxy::DisconnectSco done fail, error: %{public}d", error);
64         return false;
65     }
66     return reply.ReadBool();
67 }
68 
GetDevicesByStates(const std::vector<int> & states,std::vector<BluetoothRawAddress> & devices)69 int BluetoothHfpHfProxy::GetDevicesByStates(const std::vector<int> &states, std::vector<BluetoothRawAddress> &devices)
70 {
71     MessageParcel data;
72     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
73         HILOGE("BluetoothHfpHfProxy::GetDevicesByStates WriteInterfaceToken error");
74         return ERROR;
75     }
76     if (!data.WriteInt32Vector(states)) {
77         HILOGE("BluetoothHfpHfProxy::GetDevicesByStates WriteInt32Vector error");
78         return ERROR;
79     }
80     MessageParcel reply;
81     MessageOption option {
82         MessageOption::TF_SYNC
83     };
84     int error = Remote()->SendRequest(
85         BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_DEVICES_BY_STATES, data, reply, option);
86     if (error != NO_ERROR) {
87         HILOGE("BluetoothHfpHfProxy::GetDevicesByStates done fail, error: %{public}d", error);
88         return ERROR;
89     }
90     uint32_t devNum = reply.ReadUint32();
91     for (uint32_t i = 0; i < devNum; i++) {
92         std::shared_ptr<BluetoothRawAddress> dev(reply.ReadParcelable<BluetoothRawAddress>());
93         if (!dev) {
94             return TRANSACTION_ERR;
95         }
96         devices.push_back(*dev);
97     }
98     return NO_ERROR;
99 }
100 
GetDeviceState(const BluetoothRawAddress & device)101 int BluetoothHfpHfProxy::GetDeviceState(const BluetoothRawAddress &device)
102 {
103     MessageParcel data;
104     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
105         HILOGE("BluetoothHfpHfProxy::GetDeviceState WriteInterfaceToken error");
106         return ERROR;
107     }
108     if (!data.WriteParcelable(&device)) {
109         HILOGE("BluetoothHfpHfProxy::GetDeviceState WriteParcelable error");
110         return ERROR;
111     }
112     MessageParcel reply;
113     MessageOption option {
114         MessageOption::TF_SYNC
115     };
116     int error = Remote()->SendRequest(
117         BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_DEVICE_STATE, data, reply, option);
118     if (error != NO_ERROR) {
119         HILOGE("BluetoothHfpHfProxy::GetDeviceState done fail, error: %{public}d", error);
120         return ERROR;
121     }
122     return reply.ReadInt32();
123 }
124 
GetScoState(const BluetoothRawAddress & device)125 int BluetoothHfpHfProxy::GetScoState(const BluetoothRawAddress &device)
126 {
127     MessageParcel data;
128     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
129         HILOGE("BluetoothHfpHfProxy::GetScoState WriteInterfaceToken error");
130         return ERROR;
131     }
132     if (!data.WriteParcelable(&device)) {
133         HILOGE("BluetoothHfpHfProxy::GetScoState WriteParcelable error");
134         return ERROR;
135     }
136     MessageParcel reply;
137     MessageOption option {
138         MessageOption::TF_SYNC
139     };
140     int error = Remote()->SendRequest(
141         BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_SCO_STATE, data, reply, option);
142     if (error != NO_ERROR) {
143         HILOGE("BluetoothHfpHfProxy::GetScoState done fail, error: %{public}d", error);
144         return ERROR;
145     }
146     return reply.ReadInt32();
147 }
148 
SendDTMFTone(const BluetoothRawAddress & device,uint8_t code)149 bool BluetoothHfpHfProxy::SendDTMFTone(const BluetoothRawAddress &device, uint8_t code)
150 {
151     MessageParcel data;
152     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
153         HILOGE("BluetoothHfpHfProxy::SendDTMFTone WriteInterfaceToken error");
154         return false;
155     }
156     if (!data.WriteParcelable(&device)) {
157         HILOGE("BluetoothHfpHfProxy::SendDTMFTone WriteParcelable error");
158         return false;
159     }
160     if (!data.WriteUint8(code)) {
161         HILOGE("BluetoothHfpHfProxy::SendDTMFTone WriteUint8 error");
162         return false;
163     }
164     MessageParcel reply;
165     MessageOption option {
166         MessageOption::TF_SYNC
167     };
168     int error = Remote()->SendRequest(
169         BluetoothHfpHfInterfaceCode::BT_HFP_HF_SEND_DTMF_TONE, data, reply, option);
170     if (error != NO_ERROR) {
171         HILOGE("BluetoothHfpHfProxy::SendDTMFTone done fail, error: %{public}d", error);
172         return false;
173     }
174     return reply.ReadBool();
175 }
176 
Connect(const BluetoothRawAddress & device)177 int BluetoothHfpHfProxy::Connect(const BluetoothRawAddress &device)
178 {
179     MessageParcel data;
180     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
181         HILOGE("BluetoothHfpHfProxy::Connect WriteInterfaceToken error");
182         return ERROR;
183     }
184     if (!data.WriteParcelable(&device)) {
185         HILOGE("BluetoothHfpHfProxy::Connect WriteParcelable error");
186         return ERROR;
187     }
188     MessageParcel reply;
189     MessageOption option {
190         MessageOption::TF_SYNC
191     };
192     int error = Remote()->SendRequest(
193         BluetoothHfpHfInterfaceCode::BT_HFP_HF_CONNECT, data, reply, option);
194     if (error != NO_ERROR) {
195         HILOGE("BluetoothHfpHfProxy::Connect done fail, error: %{public}d", error);
196         return ERROR;
197     }
198     return reply.ReadInt32();
199 }
200 
Disconnect(const BluetoothRawAddress & device)201 int BluetoothHfpHfProxy::Disconnect(const BluetoothRawAddress &device)
202 {
203     MessageParcel data;
204     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
205         HILOGE("BluetoothHfpHfProxy::Disconnect WriteInterfaceToken error");
206         return ERROR;
207     }
208     if (!data.WriteParcelable(&device)) {
209         HILOGE("BluetoothHfpHfProxy::Disconnect WriteParcelable error");
210         return ERROR;
211     }
212     MessageParcel reply;
213     MessageOption option {
214         MessageOption::TF_SYNC
215     };
216     int error = Remote()->SendRequest(
217         BluetoothHfpHfInterfaceCode::BT_HFP_HF_DISCONNECT, data, reply, option);
218     if (error != NO_ERROR) {
219         HILOGE("BluetoothHfpHfProxy::Disconnect done fail, error: %{public}d", error);
220         return ERROR;
221     }
222     return reply.ReadInt32();
223 }
224 
OpenVoiceRecognition(const BluetoothRawAddress & device)225 bool BluetoothHfpHfProxy::OpenVoiceRecognition(const BluetoothRawAddress &device)
226 {
227     MessageParcel data;
228     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
229         HILOGE("BluetoothHfpHfProxy::OpenVoiceRecognition WriteInterfaceToken error");
230         return false;
231     }
232     if (!data.WriteParcelable(&device)) {
233         HILOGE("BluetoothHfpHfProxy::OpenVoiceRecognition WriteParcelable error");
234         return false;
235     }
236     MessageParcel reply;
237     MessageOption option {
238         MessageOption::TF_SYNC
239     };
240     int error = Remote()->SendRequest(
241         BluetoothHfpHfInterfaceCode::BT_HFP_HF_OPEN_VOICE_RECOGNITION, data, reply, option);
242     if (error != NO_ERROR) {
243         HILOGE("BluetoothHfpHfProxy::OpenVoiceRecognition done fail, error: %{public}d", error);
244         return false;
245     }
246     return reply.ReadBool();
247 }
248 
CloseVoiceRecognition(const BluetoothRawAddress & device)249 bool BluetoothHfpHfProxy::CloseVoiceRecognition(const BluetoothRawAddress &device)
250 {
251     MessageParcel data;
252     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
253         HILOGE("BluetoothHfpHfProxy::CloseVoiceRecognition WriteInterfaceToken error");
254         return false;
255     }
256     if (!data.WriteParcelable(&device)) {
257         HILOGE("BluetoothHfpHfProxy::CloseVoiceRecognition WriteParcelable error");
258         return false;
259     }
260     MessageParcel reply;
261     MessageOption option {
262         MessageOption::TF_SYNC
263     };
264     int error = Remote()->SendRequest(
265         BluetoothHfpHfInterfaceCode::BT_HFP_HF_CLOSE_VOICE_RECOGNITION, data, reply, option);
266     if (error != NO_ERROR) {
267         HILOGE("BluetoothHfpHfProxy::CloseVoiceRecognition done fail, error: %{public}d", error);
268         return false;
269     }
270     return reply.ReadBool();
271 }
272 
GetCurrentCallList(const BluetoothRawAddress & device,std::vector<BluetoothHfpHfCall> & calls)273 int BluetoothHfpHfProxy::GetCurrentCallList(const BluetoothRawAddress &device, std::vector<BluetoothHfpHfCall> &calls)
274 {
275     MessageParcel data;
276     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
277         HILOGE("BluetoothHfpHfProxy::GetCurrentCallList WriteInterfaceToken error");
278         return ERROR;
279     }
280     if (!data.WriteParcelable(&device)) {
281         HILOGE("BluetoothHfpHfProxy::GetCurrentCallList WriteParcelable error");
282         return ERROR;
283     }
284     MessageParcel reply;
285     MessageOption option {
286         MessageOption::TF_SYNC
287     };
288     int error = Remote()->SendRequest(
289         BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_CURRENT_CALL_LIST, data, reply, option);
290     if (error != NO_ERROR) {
291         HILOGE("BluetoothHfpHfProxy::GetCurrentCallList done fail, error: %{public}d", error);
292         return ERROR;
293     }
294     uint32_t callNum = reply.ReadUint32();
295     for (uint32_t i = 0; i < callNum; i++) {
296         std::shared_ptr<BluetoothHfpHfCall> call(reply.ReadParcelable<BluetoothHfpHfCall>());
297         if (!call) {
298             return TRANSACTION_ERR;
299         }
300         calls.push_back(*call);
301     }
302     return NO_ERROR;
303 }
304 
AcceptIncomingCall(const BluetoothRawAddress & device,int flag)305 bool BluetoothHfpHfProxy::AcceptIncomingCall(const BluetoothRawAddress &device, int flag)
306 {
307     MessageParcel data;
308     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
309         HILOGE("BluetoothHfpHfProxy::AcceptIncomingCall WriteInterfaceToken error");
310         return false;
311     }
312     if (!data.WriteParcelable(&device)) {
313         HILOGE("BluetoothHfpHfProxy::AcceptIncomingCall WriteParcelable error");
314         return false;
315     }
316     if (!data.WriteInt32(flag)) {
317         HILOGE("BluetoothHfpHfProxy::AcceptIncomingCall WriteInt32 error");
318         return false;
319     }
320     MessageParcel reply;
321     MessageOption option {
322         MessageOption::TF_SYNC
323     };
324     int error = Remote()->SendRequest(
325         BluetoothHfpHfInterfaceCode::BT_HFP_HF_ACCEPT_INCOMING_CALL, data, reply, option);
326     if (error != NO_ERROR) {
327         HILOGE("BluetoothHfpHfProxy::AcceptIncomingCall done fail, error: %{public}d", error);
328         return false;
329     }
330     return reply.ReadBool();
331 }
332 
HoldActiveCall(const BluetoothRawAddress & device)333 bool BluetoothHfpHfProxy::HoldActiveCall(const BluetoothRawAddress &device)
334 {
335     MessageParcel data;
336     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
337         HILOGE("BluetoothHfpHfProxy::HoldActiveCall WriteInterfaceToken error");
338         return false;
339     }
340     if (!data.WriteParcelable(&device)) {
341         HILOGE("BluetoothHfpHfProxy::HoldActiveCall WriteParcelable error");
342         return false;
343     }
344     MessageParcel reply;
345     MessageOption option {
346         MessageOption::TF_SYNC
347     };
348     int error = Remote()->SendRequest(
349         BluetoothHfpHfInterfaceCode::BT_HFP_HF_HOLD_ACTIVE_CALL, data, reply, option);
350     if (error != NO_ERROR) {
351         HILOGE("BluetoothHfpHfProxy::HoldActiveCall done fail, error: %{public}d", error);
352         return false;
353     }
354     return reply.ReadBool();
355 }
356 
RejectIncomingCall(const BluetoothRawAddress & device)357 bool BluetoothHfpHfProxy::RejectIncomingCall(const BluetoothRawAddress &device)
358 {
359     MessageParcel data;
360     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
361         HILOGE("BluetoothHfpHfProxy::RejectIncomingCall WriteInterfaceToken error");
362         return false;
363     }
364     if (!data.WriteParcelable(&device)) {
365         HILOGE("BluetoothHfpHfProxy::RejectIncomingCall WriteParcelable error");
366         return false;
367     }
368     MessageParcel reply;
369     MessageOption option {
370         MessageOption::TF_SYNC
371     };
372     int error = Remote()->SendRequest(
373         BluetoothHfpHfInterfaceCode::BT_HFP_HF_REJECT_INCOMING_CALL, data, reply, option);
374     if (error != NO_ERROR) {
375         HILOGE("BluetoothHfpHfProxy::RejectIncomingCall done fail, error: %{public}d", error);
376         return false;
377     }
378     return reply.ReadBool();
379 }
380 
HandleIncomingCall(const BluetoothRawAddress & device,int flag)381 bool BluetoothHfpHfProxy::HandleIncomingCall(const BluetoothRawAddress &device, int flag)
382 {
383     MessageParcel data;
384     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
385         HILOGE("BluetoothHfpHfProxy::HandleIncomingCall WriteInterfaceToken error");
386         return false;
387     }
388     if (!data.WriteParcelable(&device)) {
389         HILOGE("BluetoothHfpHfProxy::HandleIncomingCall WriteParcelable error");
390         return false;
391     }
392     if (!data.WriteInt32(flag)) {
393         HILOGE("BluetoothHfpHfProxy::HandleIncomingCall WriteInt32 error");
394         return false;
395     }
396     MessageParcel reply;
397     MessageOption option {
398         MessageOption::TF_SYNC
399     };
400     int error = Remote()->SendRequest(
401         BluetoothHfpHfInterfaceCode::BT_HFP_HF_HANDLE_INCOMING_CALL, data, reply, option);
402     if (error != NO_ERROR) {
403         HILOGE("BluetoothHfpHfProxy::HandleIncomingCall done fail, error: %{public}d", error);
404         return false;
405     }
406     return reply.ReadBool();
407 }
408 
HandleMultiCall(const BluetoothRawAddress & device,int flag,int index)409 bool BluetoothHfpHfProxy::HandleMultiCall(const BluetoothRawAddress &device, int flag, int index)
410 {
411     MessageParcel data;
412     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
413         HILOGE("BluetoothHfpHfProxy::HandleMultiCall WriteInterfaceToken error");
414         return false;
415     }
416     if (!data.WriteParcelable(&device)) {
417         HILOGE("BluetoothHfpHfProxy::HandleMultiCall WriteParcelable error");
418         return false;
419     }
420     if (!data.WriteInt32(flag)) {
421         HILOGE("BluetoothHfpHfProxy::HandleMultiCall WriteInt32 flag error");
422         return false;
423     }
424     if (!data.WriteInt32(index)) {
425         HILOGE("BluetoothHfpHfProxy::HandleMultiCall WriteInt32 index error");
426         return false;
427     }
428     MessageParcel reply;
429     MessageOption option {
430         MessageOption::TF_SYNC
431     };
432     int error = Remote()->SendRequest(
433         BluetoothHfpHfInterfaceCode::BT_HFP_HF_HANDLE_MULLTI_CALL, data, reply, option);
434     if (error != NO_ERROR) {
435         HILOGE("BluetoothHfpHfProxy::HandleMultiCall done fail, error: %{public}d", error);
436         return false;
437     }
438     return reply.ReadBool();
439 }
440 
DialLastNumber(const BluetoothRawAddress & device)441 bool BluetoothHfpHfProxy::DialLastNumber(const BluetoothRawAddress &device)
442 {
443     MessageParcel data;
444     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
445         HILOGE("BluetoothHfpHfProxy::DialLastNumber WriteInterfaceToken error");
446         return false;
447     }
448     if (!data.WriteParcelable(&device)) {
449         HILOGE("BluetoothHfpHfProxy::DialLastNumber WriteParcelable error");
450         return false;
451     }
452     MessageParcel reply;
453     MessageOption option {
454         MessageOption::TF_SYNC
455     };
456     int error = Remote()->SendRequest(
457         BluetoothHfpHfInterfaceCode::BT_HFP_HF_DIAL_LAST_NUMBER, data, reply, option);
458     if (error != NO_ERROR) {
459         HILOGE("BluetoothHfpHfProxy::DialLastNumber done fail, error: %{public}d", error);
460         return false;
461     }
462     return reply.ReadBool();
463 }
464 
DialMemory(const BluetoothRawAddress & device,int index)465 bool BluetoothHfpHfProxy::DialMemory(const BluetoothRawAddress &device, int index)
466 {
467     MessageParcel data;
468     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
469         HILOGE("BluetoothHfpHfProxy::DialMemory WriteInterfaceToken error");
470         return false;
471     }
472     if (!data.WriteParcelable(&device)) {
473         HILOGE("BluetoothHfpHfProxy::DialMemory WriteParcelable error");
474         return false;
475     }
476 
477     if (!data.WriteInt32(index)) {
478         HILOGE("BluetoothHfpHfProxy::DialMemory WriteInt32 error");
479         return false;
480     }
481     MessageParcel reply;
482     MessageOption option {
483         MessageOption::TF_SYNC
484     };
485     int error = Remote()->SendRequest(
486         BluetoothHfpHfInterfaceCode::BT_HFP_HF_DIAL_MEMORY, data, reply, option);
487     if (error != NO_ERROR) {
488         HILOGE("BluetoothHfpHfProxy::DialMemory done fail, error: %{public}d", error);
489         return false;
490     }
491     return reply.ReadBool();
492 }
493 
SendVoiceTag(const BluetoothRawAddress & device,int index)494 bool BluetoothHfpHfProxy::SendVoiceTag(const BluetoothRawAddress &device, int index)
495 {
496     MessageParcel data;
497     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
498         HILOGE("BluetoothHfpHfProxy::SendVoiceTag WriteInterfaceToken error");
499         return false;
500     }
501     if (!data.WriteParcelable(&device)) {
502         HILOGE("BluetoothHfpHfProxy::SendVoiceTag WriteParcelable error");
503         return false;
504     }
505 
506     if (!data.WriteInt32(index)) {
507         HILOGE("BluetoothHfpHfProxy::SendVoiceTag WriteInt32 error");
508         return false;
509     }
510     MessageParcel reply;
511     MessageOption option {
512         MessageOption::TF_SYNC
513     };
514     int error = Remote()->SendRequest(
515         BluetoothHfpHfInterfaceCode::BT_HFP_HF_SEND_VOICE_TAG, data, reply, option);
516     if (error != NO_ERROR) {
517         HILOGE("BluetoothHfpHfProxy::SendVoiceTag done fail, error: %{public}d", error);
518         return false;
519     }
520     return reply.ReadBool();
521 }
522 
SendKeyPressed(const BluetoothRawAddress & device)523 bool BluetoothHfpHfProxy::SendKeyPressed(const BluetoothRawAddress &device)
524 {
525     MessageParcel data;
526     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
527         HILOGE("BluetoothHfpHfProxy::SendKeyPressed WriteInterfaceToken error");
528         return false;
529     }
530     if (!data.WriteParcelable(&device)) {
531         HILOGE("BluetoothHfpHfProxy::SendKeyPressed WriteParcelable error");
532         return false;
533     }
534 
535     MessageParcel reply;
536     MessageOption option {
537         MessageOption::TF_SYNC
538     };
539     int error = Remote()->SendRequest(
540         BluetoothHfpHfInterfaceCode::BT_HFP_HF_SEND_KEY_PRESSED, data, reply, option);
541     if (error != NO_ERROR) {
542         HILOGE("BluetoothHfpHfProxy::SendKeyPressed done fail, error: %{public}d", error);
543         return false;
544     }
545     return reply.ReadBool();
546 }
547 
FinishActiveCall(const BluetoothRawAddress & device,const BluetoothHfpHfCall & call)548 bool BluetoothHfpHfProxy::FinishActiveCall(const BluetoothRawAddress &device, const BluetoothHfpHfCall &call)
549 {
550     MessageParcel data;
551     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
552         HILOGE("BluetoothHfpHfProxy::FinishActiveCall WriteInterfaceToken error");
553         return false;
554     }
555     if (!data.WriteParcelable(&device)) {
556         HILOGE("BluetoothHfpHfProxy::FinishActiveCall WriteParcelable error");
557         return false;
558     }
559     if (!data.WriteParcelable(&call)) {
560         HILOGE("BluetoothHfpHfProxy::FinishActiveCall WriteParcelable error");
561         return false;
562     }
563     MessageParcel reply;
564     MessageOption option {
565         MessageOption::TF_SYNC
566     };
567     int error = Remote()->SendRequest(
568         BluetoothHfpHfInterfaceCode::BT_HFP_HF_FINISH_ATIVE_CALL, data, reply, option);
569     if (error != NO_ERROR) {
570         HILOGE("BluetoothHfpHfProxy::FinishActiveCall done fail, error: %{public}d", error);
571         return false;
572     }
573     return reply.ReadBool();
574 }
575 
StartDial(const BluetoothRawAddress & device,const std::string & number,BluetoothHfpHfCall & call)576 int BluetoothHfpHfProxy::StartDial(
577     const BluetoothRawAddress &device, const std::string &number, BluetoothHfpHfCall &call)
578 {
579     MessageParcel data;
580     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
581         HILOGE("BluetoothHfpHfProxy::StartDial WriteInterfaceToken error");
582         return ERROR;
583     }
584     if (!data.WriteParcelable(&device)) {
585         HILOGE("BluetoothHfpHfProxy::StartDial WriteParcelable error");
586         return ERROR;
587     }
588     if (!data.WriteString(number)) {
589         HILOGE("BluetoothHfpHfProxy::StartDial WriteString error");
590         return ERROR;
591     }
592     if (!data.WriteParcelable(&call)) {
593         HILOGE("BluetoothHfpHfProxy::StartDial WriteParcelable error");
594         return ERROR;
595     }
596     MessageParcel reply;
597     MessageOption option {
598         MessageOption::TF_SYNC
599     };
600     int error = Remote()->SendRequest(
601         BluetoothHfpHfInterfaceCode::BT_HFP_HF_START_DIAL, data, reply, option);
602     if (error != NO_ERROR) {
603         HILOGE("BluetoothHfpHfProxy::StartDial done fail, error: %{public}d", error);
604         return ERROR;
605     }
606     return reply.ReadInt32();
607 }
608 
RegisterObserver(const sptr<IBluetoothHfpHfObserver> & observer)609 void BluetoothHfpHfProxy::RegisterObserver(const sptr<IBluetoothHfpHfObserver> &observer)
610 {
611     MessageParcel data;
612     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
613         HILOGE("BluetoothHfpHfProxy::RegisterObserver WriteInterfaceToken error");
614         return;
615     }
616     if (!data.WriteRemoteObject(observer->AsObject())) {
617         HILOGE("BluetoothHfpHfProxy::RegisterObserver WriteRemoteObject error");
618         return;
619     }
620     MessageParcel reply;
621     MessageOption option {
622         MessageOption::TF_ASYNC
623     };
624     int error = Remote()->SendRequest(
625         BluetoothHfpHfInterfaceCode::BT_HFP_HF_REGISTER_OBSERVER, data, reply, option);
626     if (error != NO_ERROR) {
627         HILOGE("BluetoothHfpHfProxy::RegisterObserver done fail, error: %{public}d", error);
628         return;
629     }
630 }
631 
DeregisterObserver(const sptr<IBluetoothHfpHfObserver> & observer)632 void BluetoothHfpHfProxy::DeregisterObserver(const sptr<IBluetoothHfpHfObserver> &observer)
633 {
634     MessageParcel data;
635     if (!data.WriteInterfaceToken(BluetoothHfpHfProxy::GetDescriptor())) {
636         HILOGE("BluetoothHfpHfProxy::DeregisterObserver WriteInterfaceToken error");
637         return;
638     }
639     if (!data.WriteRemoteObject(observer->AsObject())) {
640         HILOGE("BluetoothHfpHfProxy::DeregisterObserver WriteRemoteObject error");
641         return;
642     }
643     MessageParcel reply;
644     MessageOption option {
645         MessageOption::TF_ASYNC
646     };
647     int error = Remote()->SendRequest(
648         BluetoothHfpHfInterfaceCode::BT_HFP_HF_DEREGISTER_OBSERVER, data, reply, option);
649     if (error != NO_ERROR) {
650         HILOGE("BluetoothHfpHfProxy::DeregisterObserver done fail, error: %{public}d", error);
651         return;
652     }
653 }
654 
655 }  // namespace Bluetooth
656 }  // namespace OHOS
657