• 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 
16 #include "bluetooth_hfp_ag_proxy.h"
17 #include "bluetooth_errorcode.h"
18 #include "bluetooth_log.h"
19 
20 namespace OHOS {
21 namespace Bluetooth {
GetConnectDevices(std::vector<BluetoothRawAddress> & devices)22 int32_t BluetoothHfpAgProxy::GetConnectDevices(std::vector<BluetoothRawAddress> &devices)
23 {
24     MessageParcel data;
25     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
26         HILOGE("BluetoothHfpAgProxy::GetConnectDevices WriteInterfaceToken error");
27         return BT_ERR_IPC_TRANS_FAILED;
28     }
29     MessageParcel reply;
30     MessageOption option {
31         MessageOption::TF_SYNC
32     };
33     int error = Remote()->SendRequest(
34         BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_CONNECT_DEVICES, data, reply, option);
35     if (error != BT_NO_ERROR) {
36         HILOGE("BluetoothHfpAgProxy::GetConnectDevices done fail, error: %{public}d", error);
37         return BT_ERR_IPC_TRANS_FAILED;
38     }
39     uint32_t DevNum = reply.ReadUint32();
40     for (uint32_t i = 0; i < DevNum; i++) {
41         std::shared_ptr<BluetoothRawAddress> dev(reply.ReadParcelable<BluetoothRawAddress>());
42         if (!dev) {
43             return BT_ERR_IPC_TRANS_FAILED;
44         }
45         devices.push_back(*dev);
46     }
47     return BT_NO_ERROR;
48 }
49 
GetDevicesByStates(const std::vector<int> & states,std::vector<BluetoothRawAddress> & devices)50 int BluetoothHfpAgProxy::GetDevicesByStates(const std::vector<int> &states, std::vector<BluetoothRawAddress> &devices)
51 {
52     MessageParcel data;
53     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
54         HILOGE("BluetoothHfpAgProxy::GetDevicesByStates WriteInterfaceToken error");
55         return ERROR;
56     }
57     if (!data.WriteInt32Vector(states)) {
58         HILOGE("BluetoothHfpAgProxy::GetDevicesByStates WriteInt32Vector error");
59         return ERROR;
60     }
61     MessageParcel reply;
62     MessageOption option {
63         MessageOption::TF_SYNC
64     };
65     int error = Remote()->SendRequest(
66         BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_DEVICES_BY_STATES, data, reply, option);
67     if (error != NO_ERROR) {
68         HILOGE("BluetoothHfpAgProxy::GetDevicesByStates done fail, error: %{public}d", error);
69         return ERROR;
70     }
71     uint32_t DevNum = reply.ReadUint32();
72     for (uint32_t i = 0; i < DevNum; i++) {
73         std::shared_ptr<BluetoothRawAddress> dev(reply.ReadParcelable<BluetoothRawAddress>());
74         if (!dev) {
75             return TRANSACTION_ERR;
76         }
77         devices.push_back(*dev);
78     }
79     return NO_ERROR;
80 }
GetDeviceState(const BluetoothRawAddress & device,int32_t & state)81 int32_t BluetoothHfpAgProxy::GetDeviceState(const BluetoothRawAddress &device, int32_t &state)
82 {
83     MessageParcel data;
84     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
85         HILOGE("BluetoothHfpAgProxy::GetDeviceState WriteInterfaceToken error");
86         return BT_ERR_IPC_TRANS_FAILED;
87     }
88     if (!data.WriteParcelable(&device)) {
89         HILOGE("BluetoothHfpAgProxy::GetDeviceState WriteParcelable error");
90         return BT_ERR_IPC_TRANS_FAILED;
91     }
92     MessageParcel reply;
93     MessageOption option {
94         MessageOption::TF_SYNC
95     };
96     int error = Remote()->SendRequest(
97         BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_DEVICE_STATE, data, reply, option);
98     if (error != BT_NO_ERROR) {
99         HILOGE("BluetoothHfpAgProxy::GetDeviceState done fail, error: %{public}d", error);
100         return BT_ERR_IPC_TRANS_FAILED;
101     }
102     // read error code
103     int32_t errCode = reply.ReadInt32();
104     if (errCode != BT_NO_ERROR) {
105         HILOGE("reply errCode: %{public}d", errCode);
106         return errCode;
107     }
108     // read state
109     state = reply.ReadInt32();
110     return BT_NO_ERROR;
111 }
112 
Connect(const BluetoothRawAddress & device)113 int32_t BluetoothHfpAgProxy::Connect(const BluetoothRawAddress &device)
114 {
115     MessageParcel data;
116     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
117         HILOGE("BluetoothHfpAgProxy::Connect WriteInterfaceToken error");
118         return BT_ERR_IPC_TRANS_FAILED;
119     }
120     if (!data.WriteParcelable(&device)) {
121         HILOGE("BluetoothHfpAgProxy::Connect WriteParcelable error");
122         return BT_ERR_IPC_TRANS_FAILED;
123     }
124     MessageParcel reply;
125     MessageOption option {
126         MessageOption::TF_SYNC
127     };
128     int error = Remote()->SendRequest(
129         BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT, data, reply, option);
130     if (error != BT_NO_ERROR) {
131         HILOGE("BluetoothHfpAgProxy::Connect done fail, error: %{public}d", error);
132         return BT_ERR_IPC_TRANS_FAILED;
133     }
134     return reply.ReadInt32();
135 }
136 
Disconnect(const BluetoothRawAddress & device)137 int32_t BluetoothHfpAgProxy::Disconnect(const BluetoothRawAddress &device)
138 {
139     MessageParcel data;
140     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
141         HILOGE("BluetoothHfpAgProxy::Disconnect WriteInterfaceToken error");
142         return BT_ERR_IPC_TRANS_FAILED;
143     }
144     if (!data.WriteParcelable(&device)) {
145         HILOGE("BluetoothHfpAgProxy::Disconnect WriteParcelable error");
146         return BT_ERR_IPC_TRANS_FAILED;
147     }
148     MessageParcel reply;
149     MessageOption option {
150         MessageOption::TF_SYNC
151     };
152     int error = Remote()->SendRequest(
153         BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT, data, reply, option);
154     if (error != BT_NO_ERROR) {
155         HILOGE("BluetoothHfpAgProxy::Disconnect done fail, error: %{public}d", error);
156         return ERROR;
157     }
158     return reply.ReadInt32();
159 }
160 
GetScoState(const BluetoothRawAddress & device)161 int BluetoothHfpAgProxy::GetScoState(const BluetoothRawAddress &device)
162 {
163     MessageParcel data;
164     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
165         HILOGE("BluetoothHfpAgProxy::GetScoState WriteInterfaceToken error");
166         return ERROR;
167     }
168     if (!data.WriteParcelable(&device)) {
169         HILOGE("BluetoothHfpAgProxy::GetScoState WriteParcelable error");
170         return ERROR;
171     }
172     MessageParcel reply;
173     MessageOption option {
174         MessageOption::TF_SYNC
175     };
176     int error = Remote()->SendRequest(
177         BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_SCO_STATE, data, reply, option);
178     if (error != NO_ERROR) {
179         HILOGE("BluetoothHfpAgProxy::GetScoState done fail, error: %{public}d", error);
180         return ERROR;
181     }
182     return reply.ReadInt32();
183 }
184 
ConnectSco()185 bool BluetoothHfpAgProxy::ConnectSco()
186 {
187     MessageParcel data;
188     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
189         HILOGE("BluetoothHfpAgProxy::ConnectSco WriteInterfaceToken error");
190         return false;
191     }
192     MessageParcel reply;
193     MessageOption option {
194         MessageOption::TF_SYNC
195     };
196     int error = Remote()->SendRequest(
197         BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT_SCO, data, reply, option);
198     if (error != NO_ERROR) {
199         HILOGE("BluetoothHfpAgProxy::ConnectSco done fail, error: %{public}d", error);
200         return false;
201     }
202     return reply.ReadBool();
203 }
204 
DisconnectSco()205 bool BluetoothHfpAgProxy::DisconnectSco()
206 {
207     MessageParcel data;
208     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
209         HILOGE("BluetoothHfpAgProxy::DisconnectSco WriteInterfaceToken error");
210         return false;
211     }
212     MessageParcel reply;
213     MessageOption option {
214         MessageOption::TF_SYNC
215     };
216     int error = Remote()->SendRequest(
217         BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT_SCO, data, reply, option);
218     if (error != NO_ERROR) {
219         HILOGE("BluetoothHfpAgProxy::DisconnectSco done fail, error: %{public}d", error);
220         return false;
221     }
222     return reply.ReadBool();
223 }
224 
PhoneStateChanged(int numActive,int numHeld,int callState,const std::string & number,int type,const std::string & name)225 void BluetoothHfpAgProxy::PhoneStateChanged(
226     int numActive, int numHeld, int callState, const std::string &number, int type, const std::string &name)
227 {
228     MessageParcel data;
229     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
230         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged WriteInterfaceToken error");
231         return;
232     }
233     if (!data.WriteInt32(numActive)) {
234         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged WriteInt32 error");
235         return;
236     }
237     if (!data.WriteInt32(numHeld)) {
238         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged WriteInt32 error");
239         return;
240     }
241     if (!data.WriteInt32(callState)) {
242         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged WriteInt32 error");
243         return;
244     }
245     if (!data.WriteString(number)) {
246         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged WriteString error");
247         return;
248     }
249     if (!data.WriteInt32(type)) {
250         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged WriteInt32 error");
251         return;
252     }
253     if (!data.WriteString(name)) {
254         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged WriteString error");
255         return;
256     }
257     MessageParcel reply;
258     MessageOption option {
259         MessageOption::TF_ASYNC
260     };
261     int error = Remote()->SendRequest(
262         BluetoothHfpAgInterfaceCode::BT_HFP_AG_PHONE_STATE_CHANGED, data, reply, option);
263     if (error != NO_ERROR) {
264         HILOGE("BluetoothHfpAgProxy::PhoneStateChanged done fail, error: %{public}d", error);
265         return;
266     }
267 }
268 
ClccResponse(int index,int direction,int status,int mode,bool mpty,const std::string & number,int type)269 void BluetoothHfpAgProxy::ClccResponse(
270     int index, int direction, int status, int mode, bool mpty, const std::string &number, int type)
271 {
272     MessageParcel data;
273     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
274         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteInterfaceToken error");
275         return;
276     }
277     if (!data.WriteInt32(index)) {
278         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteInt32 error");
279         return;
280     }
281     if (!data.WriteInt32(direction)) {
282         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteInt32 error");
283         return;
284     }
285     if (!data.WriteInt32(status)) {
286         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteInt32 error");
287         return;
288     }
289     if (!data.WriteInt32(mode)) {
290         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteInt32 error");
291         return;
292     }
293     if (!data.WriteBool(mpty)) {
294         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteBool error");
295         return;
296     }
297     if (!data.WriteString(number)) {
298         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteString error");
299         return;
300     }
301     if (!data.WriteInt32(type)) {
302         HILOGE("BluetoothHfpAgProxy::ClccResponse WriteInt32 error");
303         return;
304     }
305     MessageParcel reply;
306     MessageOption option {
307         MessageOption::TF_ASYNC
308     };
309     int error = Remote()->SendRequest(
310         BluetoothHfpAgInterfaceCode::BT_HFP_AG_CLCC_RESPONSE, data, reply, option);
311     if (error != NO_ERROR) {
312         HILOGE("BluetoothHfpAgProxy::ClccResponse done fail, error: %{public}d", error);
313         return;
314     }
315 }
316 
OpenVoiceRecognition(const BluetoothRawAddress & device)317 bool BluetoothHfpAgProxy::OpenVoiceRecognition(const BluetoothRawAddress &device)
318 {
319     MessageParcel data;
320     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
321         HILOGE("BluetoothHfpAgProxy::OpenVoiceRecognition WriteInterfaceToken error");
322         return false;
323     }
324     if (!data.WriteParcelable(&device)) {
325         HILOGE("BluetoothHfpAgProxy::OpenVoiceRecognition WriteParcelable error");
326         return false;
327     }
328     MessageParcel reply;
329     MessageOption option {
330         MessageOption::TF_SYNC
331     };
332     int error = Remote()->SendRequest(
333         BluetoothHfpAgInterfaceCode::BT_HFP_AG_OPEN_VOICE_RECOGNITION, data, reply, option);
334     if (error != NO_ERROR) {
335         HILOGE("BluetoothHfpAgProxy::OpenVoiceRecognition done fail, error: %{public}d", error);
336         return false;
337     }
338     return reply.ReadBool();
339 }
340 
CloseVoiceRecognition(const BluetoothRawAddress & device)341 bool BluetoothHfpAgProxy::CloseVoiceRecognition(const BluetoothRawAddress &device)
342 {
343     MessageParcel data;
344     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
345         HILOGE("BluetoothHfpAgProxy::CloseVoiceRecognition WriteInterfaceToken error");
346         return false;
347     }
348     if (!data.WriteParcelable(&device)) {
349         HILOGE("BluetoothHfpAgProxy::CloseVoiceRecognition WriteParcelable error");
350         return false;
351     }
352     MessageParcel reply;
353     MessageOption option {
354         MessageOption::TF_SYNC
355     };
356     int error = Remote()->SendRequest(
357         BluetoothHfpAgInterfaceCode::BT_HFP_AG_CLOSE_VOICE_RECOGNITION, data, reply, option);
358     if (error != NO_ERROR) {
359         HILOGE("BluetoothHfpAgProxy::CloseVoiceRecognition done fail, error: %{public}d", error);
360         return false;
361     }
362     return reply.ReadBool();
363 }
364 
SetActiveDevice(const BluetoothRawAddress & device)365 bool BluetoothHfpAgProxy::SetActiveDevice(const BluetoothRawAddress &device)
366 {
367     MessageParcel data;
368     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
369         HILOGE("BluetoothHfpAgProxy::SetActiveDevice WriteInterfaceToken error");
370         return false;
371     }
372     if (!data.WriteParcelable(&device)) {
373         HILOGE("BluetoothHfpAgProxy::SetActiveDevice WriteParcelable error");
374         return false;
375     }
376     MessageParcel reply;
377     MessageOption option {
378         MessageOption::TF_SYNC
379     };
380     int error = Remote()->SendRequest(
381         BluetoothHfpAgInterfaceCode::BT_HFP_AG_SET_ACTIVE_DEVICE, data, reply, option);
382     if (error != NO_ERROR) {
383         HILOGE("BluetoothHfpAgProxy::SetActiveDevice done fail, error: %{public}d", error);
384         return false;
385     }
386     return reply.ReadBool();
387 }
388 
IntoMock(const BluetoothRawAddress & device,int state)389 bool BluetoothHfpAgProxy::IntoMock(const BluetoothRawAddress &device, int state)
390 {
391         MessageParcel data;
392     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
393         HILOGE("BluetoothHfpAgProxy::IntoMock WriteInterfaceToken error");
394         return false;
395     }
396 
397     if (!data.WriteParcelable(&device)) {
398         HILOGE("BluetoothHfpAgProxy::IntoMock WriteParcelable error");
399         return false;
400     }
401 
402     if (!data.WriteInt32(state)) {
403         HILOGE("BluetoothHfpAgProxy::IntoMock WriteParcelable error");
404         return false;
405     }
406     MessageParcel reply;
407     MessageOption option {
408         MessageOption::TF_SYNC
409     };
410     int error = Remote()->SendRequest(
411         BluetoothHfpAgInterfaceCode::BT_HFP_AG_INTO_MOCK, data, reply, option);
412     if (error != NO_ERROR) {
413         HILOGE("BluetoothHfpAgProxy::IntoMock done fail, error: %{public}d", error);
414         return false;
415     }
416     return reply.ReadBool();
417 }
418 
SendNoCarrier(const BluetoothRawAddress & device)419 bool BluetoothHfpAgProxy::SendNoCarrier(const BluetoothRawAddress &device)
420 {
421         MessageParcel data;
422     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
423         HILOGE("BluetoothHfpAgProxy::SendNoCarrier WriteInterfaceToken error");
424         return false;
425     }
426     if (!data.WriteParcelable(&device)) {
427         HILOGE("BluetoothHfpAgProxy::SendNoCarrier WriteParcelable error");
428         return false;
429     }
430     MessageParcel reply;
431     MessageOption option {
432         MessageOption::TF_SYNC
433     };
434     int error = Remote()->SendRequest(
435         BluetoothHfpAgInterfaceCode::BT_HFP_AG_SEND_NO_CARRIER, data, reply, option);
436     if (error != NO_ERROR) {
437         HILOGE("BluetoothHfpAgProxy::SendNoCarrier done fail, error: %{public}d", error);
438         return false;
439     }
440     return reply.ReadBool();
441 }
442 
GetActiveDevice()443 std::string BluetoothHfpAgProxy::GetActiveDevice()
444 {
445     MessageParcel data;
446     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
447         HILOGE("BluetoothHfpAgProxy::GetActiveDevice WriteInterfaceToken error");
448         return "";
449     }
450     MessageParcel reply;
451     MessageOption option {
452         MessageOption::TF_SYNC
453     };
454     int error = Remote()->SendRequest(
455         BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_ACTIVE_DEVICE, data, reply, option);
456     if (error != NO_ERROR) {
457         HILOGE("BluetoothHfpAgProxy::GetActiveDevice done fail, error: %{public}d", error);
458         return "";
459     }
460     return reply.ReadString();
461 }
462 
SetConnectStrategy(const BluetoothRawAddress & device,int strategy)463 int BluetoothHfpAgProxy::SetConnectStrategy(const BluetoothRawAddress &device, int strategy)
464 {
465     MessageParcel data;
466     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
467         HILOGE("WriteInterfaceToken error");
468         return BT_ERR_IPC_TRANS_FAILED;
469     }
470     if (!data.WriteParcelable(&device)) {
471         HILOGE("write device error");
472         return BT_ERR_IPC_TRANS_FAILED;
473     }
474     if (!data.WriteInt32(strategy)) {
475         HILOGE("write strategy error");
476         return BT_ERR_IPC_TRANS_FAILED;
477     }
478 
479     MessageParcel reply;
480     MessageOption option {
481         MessageOption::TF_SYNC
482     };
483 
484     int error = Remote()->SendRequest(BluetoothHfpAgInterfaceCode::BT_HFP_AG_SET_CONNECT_STRATEGY, data, reply, option);
485     if (error != NO_ERROR) {
486         HILOGE("BluetoothHfpAgProxy::SetConnectStrategy done fail, error: %{public}d", error);
487         return BT_ERR_IPC_TRANS_FAILED;
488     }
489 
490     return reply.ReadInt32();
491 }
492 
GetConnectStrategy(const BluetoothRawAddress & device,int & strategy)493 int BluetoothHfpAgProxy::GetConnectStrategy(const BluetoothRawAddress &device, int &strategy)
494 {
495     MessageParcel data;
496     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
497         HILOGE("WriteInterfaceToken error");
498         return BT_ERR_IPC_TRANS_FAILED;
499     }
500     if (!data.WriteParcelable(&device)) {
501         HILOGE("write device error");
502         return BT_ERR_IPC_TRANS_FAILED;
503     }
504 
505     MessageParcel reply;
506     MessageOption option {
507         MessageOption::TF_SYNC
508     };
509 
510     int error = Remote()->SendRequest(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_CONNECT_STRATEGY, data, reply, option);
511     if (error != NO_ERROR) {
512         HILOGE("BluetoothHfpAgProxy::GetConnectStrategy done fail, error: %{public}d", error);
513         return BT_ERR_IPC_TRANS_FAILED;
514     }
515 
516     int32_t res = reply.ReadInt32();
517     if (res == NO_ERROR) {
518         strategy = reply.ReadInt32();
519     }
520 
521     return res;
522 }
523 
RegisterObserver(const sptr<IBluetoothHfpAgObserver> & observer)524 void BluetoothHfpAgProxy::RegisterObserver(const sptr<IBluetoothHfpAgObserver> &observer)
525 {
526     MessageParcel data;
527     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
528         HILOGE("BluetoothHfpAgProxy::RegisterObserver WriteInterfaceToken error");
529         return;
530     }
531     if (!data.WriteRemoteObject(observer->AsObject())) {
532         HILOGE("BluetoothHfpAgProxy::RegisterObserver WriteRemoteObject error");
533         return;
534     }
535     MessageParcel reply;
536     MessageOption option {
537         MessageOption::TF_ASYNC
538     };
539     int error = Remote()->SendRequest(
540         BluetoothHfpAgInterfaceCode::BT_HFP_AG_REGISTER_OBSERVER, data, reply, option);
541     if (error != NO_ERROR) {
542         HILOGE("BluetoothHfpAgProxy::RegisterObserver done fail, error: %{public}d", error);
543         return;
544     }
545 }
546 
DeregisterObserver(const sptr<IBluetoothHfpAgObserver> & observer)547 void BluetoothHfpAgProxy::DeregisterObserver(const sptr<IBluetoothHfpAgObserver> &observer)
548 {
549     MessageParcel data;
550     if (!data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor())) {
551         HILOGE("BluetoothHfpAgProxy::DeregisterObserver WriteInterfaceToken error");
552         return;
553     }
554     if (!data.WriteRemoteObject(observer->AsObject())) {
555         HILOGE("BluetoothHfpAgProxy::DeregisterObserver WriteRemoteObject error");
556         return;
557     }
558     MessageParcel reply;
559     MessageOption option {
560         MessageOption::TF_ASYNC
561     };
562     int error = Remote()->SendRequest(
563         BluetoothHfpAgInterfaceCode::BT_HFP_AG_DEREGISTER_OBSERVER, data, reply, option);
564     if (error != NO_ERROR) {
565         HILOGE("BluetoothHfpAgProxy::DeregisterObserver done fail, error: %{public}d", error);
566         return;
567     }
568 }
569 }  // namespace Bluetooth
570 }  // namespace OHOS
571