1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17 #include "bluetooth_hfp_ag_observer_proxy.h"
18 #include "bluetooth_log.h"
19
20 namespace OHOS {
21 namespace Bluetooth {
OnConnectionStateChanged(const BluetoothRawAddress & device,int state)22 void BluetoothHfpAgObserverProxy::OnConnectionStateChanged(const BluetoothRawAddress &device, int state) {
23 MessageParcel data;
24 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
25 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged WriteInterfaceToken error");
26 return;
27 }
28 if (!data.WriteParcelable(&device)) {
29 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged WriteParcelable error");
30 return;
31 }
32 if (!data.WriteInt32(state)) {
33 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged WriteInt32 error");
34 return;
35 }
36 MessageParcel reply;
37 MessageOption option {
38 MessageOption::TF_ASYNC
39 };
40 int error = Remote()->SendRequest(
41 IBluetoothHfpAgObserver::Code::BT_HFP_AG_OBSERVER_CONNECTION_STATE_CHANGED, data, reply, option);
42 if (error != NO_ERROR) {
43 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged done fail, error: %{public}d", error);
44 return;
45 }
46 }
47
OnScoStateChanged(const BluetoothRawAddress & device,int state)48 void BluetoothHfpAgObserverProxy::OnScoStateChanged(const BluetoothRawAddress &device, int state) {
49 MessageParcel data;
50 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
51 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged WriteInterfaceToken error");
52 return;
53 }
54 if (!data.WriteParcelable(&device)) {
55 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged WriteParcelable error");
56 return;
57 }
58 if (!data.WriteInt32(state)) {
59 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged WriteInt32 error");
60 return;
61 }
62 MessageParcel reply;
63 MessageOption option {
64 MessageOption::TF_ASYNC
65 };
66 int error = Remote()->SendRequest(
67 IBluetoothHfpAgObserver::Code::BT_HFP_AG_OBSERVER_SCO_STATE_CHANGED, data, reply, option);
68 if (error != NO_ERROR) {
69 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged done fail, error: %{public}d", error);
70 return;
71 }
72 }
OnActiveDeviceChanged(const BluetoothRawAddress & device)73 void BluetoothHfpAgObserverProxy::OnActiveDeviceChanged(const BluetoothRawAddress &device) {
74 MessageParcel data;
75 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
76 HILOGE("BluetoothHfpAgObserverProxy::OnActiveDeviceChanged WriteInterfaceToken error");
77 return;
78 }
79 if (!data.WriteParcelable(&device)) {
80 HILOGE("BluetoothHfpAgObserverProxy::OnActiveDeviceChanged WriteParcelable error");
81 return;
82 }
83 MessageParcel reply;
84 MessageOption option {
85 MessageOption::TF_ASYNC
86 };
87 int error = Remote()->SendRequest(
88 IBluetoothHfpAgObserver::Code::BT_HFP_AG_OBSERVER_ACTIVE_DEVICE_CHANGED, data, reply, option);
89 if (error != NO_ERROR) {
90 HILOGE("BluetoothHfpAgObserverProxy::OnActiveDeviceChanged done fail, error: %{public}d", error);
91 return;
92 }
93 }
94
OnHfEnhancedDriverSafetyChanged(const BluetoothRawAddress & device,int indValue)95 void BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged(const BluetoothRawAddress &device, int indValue) {
96 MessageParcel data;
97 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
98 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged WriteInterfaceToken error");
99 return;
100 }
101 if (!data.WriteParcelable(&device)) {
102 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged WriteParcelable error");
103 return;
104 }
105 if (!data.WriteInt32(indValue)) {
106 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged WriteInt32 error");
107 return;
108 }
109 MessageParcel reply;
110 MessageOption option {
111 MessageOption::TF_ASYNC
112 };
113 int error = Remote()->SendRequest(
114 IBluetoothHfpAgObserver::Code::BT_HFP_AG_OBSERVER_HF_ENHANCED_DRIVER_SAFETY_CHANGED, data, reply, option);
115 if (error != NO_ERROR) {
116 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged done fail, error: %{public}d", error);
117 return;
118 }
119 }
120
121 } // namespace Bluetooth
122 } // namespace OHOS
123