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