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,int cause)22 void BluetoothHfpAgObserverProxy::OnConnectionStateChanged(const BluetoothRawAddress &device, int state, int cause)
23 {
24 MessageParcel data;
25 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
26 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged WriteInterfaceToken error");
27 return;
28 }
29 if (!data.WriteParcelable(&device)) {
30 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged write device error");
31 return;
32 }
33 if (!data.WriteInt32(state)) {
34 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged write state error");
35 return;
36 }
37 if (!data.WriteInt32(cause)) {
38 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged write cause error");
39 return;
40 }
41 MessageParcel reply;
42 MessageOption option {
43 MessageOption::TF_ASYNC
44 };
45 int error = Remote()->SendRequest(
46 BluetoothHfpAgObserverInterfaceCode::BT_HFP_AG_OBSERVER_CONNECTION_STATE_CHANGED, data, reply, option);
47 if (error != NO_ERROR) {
48 HILOGE("BluetoothHfpAgObserverProxy::OnConnectionStateChanged done fail, error: %{public}d", error);
49 return;
50 }
51 }
52
OnScoStateChanged(const BluetoothRawAddress & device,int state,int reason)53 void BluetoothHfpAgObserverProxy::OnScoStateChanged(const BluetoothRawAddress &device, int state, int reason)
54 {
55 MessageParcel data;
56 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
57 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged WriteInterfaceToken error");
58 return;
59 }
60 if (!data.WriteParcelable(&device)) {
61 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged WriteParcelable error");
62 return;
63 }
64 if (!data.WriteInt32(state)) {
65 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged WriteInt32 error");
66 return;
67 }
68 if (!data.WriteInt32(reason)) {
69 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged WriteInt32 error");
70 return;
71 }
72 MessageParcel reply;
73 MessageOption option {
74 MessageOption::TF_ASYNC
75 };
76 int error = Remote()->SendRequest(
77 BluetoothHfpAgObserverInterfaceCode::BT_HFP_AG_OBSERVER_SCO_STATE_CHANGED, data, reply, option);
78 if (error != NO_ERROR) {
79 HILOGE("BluetoothHfpAgObserverProxy::OnScoStateChanged done fail, error: %{public}d", error);
80 return;
81 }
82 }
83
OnActiveDeviceChanged(const BluetoothRawAddress & device)84 void BluetoothHfpAgObserverProxy::OnActiveDeviceChanged(const BluetoothRawAddress &device)
85 {
86 MessageParcel data;
87 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
88 HILOGE("BluetoothHfpAgObserverProxy::OnActiveDeviceChanged WriteInterfaceToken error");
89 return;
90 }
91 if (!data.WriteParcelable(&device)) {
92 HILOGE("BluetoothHfpAgObserverProxy::OnActiveDeviceChanged WriteParcelable error");
93 return;
94 }
95 MessageParcel reply;
96 MessageOption option {
97 MessageOption::TF_ASYNC
98 };
99 int error = Remote()->SendRequest(
100 BluetoothHfpAgObserverInterfaceCode::BT_HFP_AG_OBSERVER_ACTIVE_DEVICE_CHANGED, data, reply, option);
101 if (error != NO_ERROR) {
102 HILOGE("BluetoothHfpAgObserverProxy::OnActiveDeviceChanged done fail, error: %{public}d", error);
103 return;
104 }
105 }
106
OnHfEnhancedDriverSafetyChanged(const BluetoothRawAddress & device,int indValue)107 void BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged(const BluetoothRawAddress &device, int indValue)
108 {
109 MessageParcel data;
110 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
111 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged WriteInterfaceToken error");
112 return;
113 }
114 if (!data.WriteParcelable(&device)) {
115 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged WriteParcelable error");
116 return;
117 }
118 if (!data.WriteInt32(indValue)) {
119 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged WriteInt32 error");
120 return;
121 }
122 MessageParcel reply;
123 MessageOption option {
124 MessageOption::TF_ASYNC
125 };
126 int error = Remote()->SendRequest(
127 BluetoothHfpAgObserverInterfaceCode::BT_HFP_AG_OBSERVER_HF_ENHANCED_DRIVER_SAFETY_CHANGED, data, reply, option);
128 if (error != NO_ERROR) {
129 HILOGE("BluetoothHfpAgObserverProxy::OnHfEnhancedDriverSafetyChanged done fail, error: %{public}d", error);
130 return;
131 }
132 }
133
OnHfpStackChanged(const BluetoothRawAddress & device,int action)134 void BluetoothHfpAgObserverProxy::OnHfpStackChanged(const BluetoothRawAddress &device, int action)
135 {
136 MessageParcel data;
137 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
138 HILOGE("BluetoothHfpAgObserverProxy::OnHfpStackChanged WriteInterfaceToken error");
139 return;
140 }
141 if (!data.WriteParcelable(&device)) {
142 HILOGE("BluetoothHfpAgObserverProxy::OnHfpStackChanged WriteParcelable error");
143 return;
144 }
145 if (!data.WriteInt32(action)) {
146 HILOGE("BluetoothHfpAgObserverProxy::OnHfpStackChanged WriteInt32 error");
147 return;
148 }
149 MessageParcel reply;
150 MessageOption option {
151 MessageOption::TF_ASYNC
152 };
153 int error = Remote()->SendRequest(
154 BluetoothHfpAgObserverInterfaceCode::BT_HFP_AG_OBSERVER_HFP_STACK_CHANGED, data, reply, option);
155 if (error != NO_ERROR) {
156 HILOGE("BluetoothHfpAgObserverProxy::OnHfpStackChanged done fail, error: %{public}d", error);
157 return;
158 }
159 }
160
OnVirtualDeviceChanged(int32_t action,std::string address)161 void BluetoothHfpAgObserverProxy::OnVirtualDeviceChanged(int32_t action, std::string address)
162 {
163 MessageParcel data;
164 if (!data.WriteInterfaceToken(BluetoothHfpAgObserverProxy::GetDescriptor())) {
165 HILOGE("BluetoothHfpAgObserverProxy::OnVirtualDeviceChanged WriteInterfaceToken error");
166 return;
167 }
168 if (!data.WriteInt32(action)) {
169 HILOGE("BluetoothHfpAgObserverProxy::OnVirtualDeviceChanged WriteInt32 error");
170 return;
171 }
172 if (!data.WriteString(address)) {
173 HILOGE("BluetoothHfpAgObserverProxy::OnVirtualDeviceChanged WriteString error");
174 return;
175 }
176 MessageParcel reply;
177 MessageOption option {
178 MessageOption::TF_ASYNC
179 };
180 int error = Remote()->SendRequest(
181 BluetoothHfpAgObserverInterfaceCode::BT_HFP_AG_OBSERVER_VIRTUALDEVICE_CHANGED, data, reply, option);
182 if (error != NO_ERROR) {
183 HILOGE("BluetoothHfpAgObserverProxy::OnVirtualDeviceChanged done fail, error: %{public}d", error);
184 return;
185 }
186 }
187 } // namespace Bluetooth
188 } // namespace OHOS
189