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