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 #include "bluetooth_hfp_hf_observer_proxy.h"
17 #include "bluetooth_log.h"
18
19 namespace OHOS {
20 namespace Bluetooth {
OnConnectionStateChanged(const BluetoothRawAddress & device,int state)21 void BluetoothHfpHfObserverProxy::OnConnectionStateChanged(const BluetoothRawAddress &device, int state) {
22 MessageParcel data;
23 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
24 HILOGE("BluetoothHfpHfObserverProxy::OnConnectionStateChanged WriteInterfaceToken error");
25 return;
26 }
27 if (!data.WriteParcelable(&device)) {
28 HILOGE("BluetoothHfpHfObserverProxy::OnConnectionStateChanged WriteParcelable error");
29 return;
30 }
31 if (!data.WriteInt32(state)) {
32 HILOGE("BluetoothHfpHfObserverProxy::OnConnectionStateChanged WriteInt32 error");
33 return;
34 }
35 MessageParcel reply;
36 MessageOption option {
37 MessageOption::TF_ASYNC
38 };
39 int error = Remote()->SendRequest(
40 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_CONNECTION_STATE_CHANGED, data, reply, option);
41 if (error != NO_ERROR) {
42 HILOGE("BluetoothHfpHfObserverProxy::OnConnectionStateChanged done fail, error: %{public}d", error);
43 return;
44 }
45 }
46
OnScoStateChanged(const BluetoothRawAddress & device,int state)47 void BluetoothHfpHfObserverProxy::OnScoStateChanged(const BluetoothRawAddress &device, int state) {
48 MessageParcel data;
49 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
50 HILOGE("BluetoothHfpHfObserverProxy::OnScoStateChanged WriteInterfaceToken error");
51 return;
52 }
53 if (!data.WriteParcelable(&device)) {
54 HILOGE("BluetoothHfpHfObserverProxy::OnScoStateChanged WriteParcelable error");
55 return;
56 }
57 if (!data.WriteInt32(state)) {
58 HILOGE("BluetoothHfpHfObserverProxy::OnScoStateChanged WriteInt32 error");
59 return;
60 }
61 MessageParcel reply;
62 MessageOption option {
63 MessageOption::TF_ASYNC
64 };
65 int error = Remote()->SendRequest(
66 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_SCO_STATE_CHANGED, data, reply, option);
67 if (error != NO_ERROR) {
68 HILOGE("BluetoothHfpHfObserverProxy::OnScoStateChanged done fail, error: %{public}d", error);
69 return;
70 }
71 }
72
OnCallChanged(const BluetoothRawAddress & device,const BluetoothHfpHfCall & call)73 void BluetoothHfpHfObserverProxy::OnCallChanged(const BluetoothRawAddress &device, const BluetoothHfpHfCall &call) {
74 MessageParcel data;
75 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
76 HILOGE("BluetoothHfpHfObserverProxy::OnCallChanged WriteInterfaceToken error");
77 return;
78 }
79 if (!data.WriteParcelable(&device)) {
80 HILOGE("BluetoothHfpHfObserverProxy::OnCallChanged WriteParcelable error");
81 return;
82 }
83 if (!data.WriteParcelable(&call)) {
84 HILOGE("BluetoothHfpHfObserverProxy::OnCallChanged WriteParcelable error");
85 return;
86 }
87 MessageParcel reply;
88 MessageOption option {
89 MessageOption::TF_ASYNC
90 };
91 int error = Remote()->SendRequest(
92 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_CALL_CHANGED, data, reply, option);
93 if (error != NO_ERROR) {
94 HILOGE("BluetoothHfpHfObserverProxy::OnCallChanged done fail, error: %{public}d", error);
95 return;
96 }
97 }
98
OnSignalStrengthChanged(const BluetoothRawAddress & device,int signal)99 void BluetoothHfpHfObserverProxy::OnSignalStrengthChanged(const BluetoothRawAddress &device, int signal) {
100 MessageParcel data;
101 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
102 HILOGE("BluetoothHfpHfObserverProxy::OnSignalStrengthChanged WriteInterfaceToken error");
103 return;
104 }
105 if (!data.WriteParcelable(&device)) {
106 HILOGE("BluetoothHfpHfObserverProxy::OnSignalStrengthChanged WriteParcelable error");
107 return;
108 }
109 if (!data.WriteInt32(signal)) {
110 HILOGE("BluetoothHfpHfObserverProxy::OnSignalStrengthChanged WriteInt32 error");
111 return;
112 }
113 MessageParcel reply;
114 MessageOption option {
115 MessageOption::TF_ASYNC
116 };
117 int error = Remote()->SendRequest(
118 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_SIGNAL_STRENGTH_CHANGED, data, reply, option);
119 if (error != NO_ERROR) {
120 HILOGE("BluetoothHfpHfObserverProxy::OnSignalStrengthChanged done fail, error: %{public}d", error);
121 return;
122 }
123 }
124
OnRegistrationStatusChanged(const BluetoothRawAddress & device,int status)125 void BluetoothHfpHfObserverProxy::OnRegistrationStatusChanged(const BluetoothRawAddress &device, int status) {
126 MessageParcel data;
127 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
128 HILOGE("BluetoothHfpHfObserverProxy::OnRegistrationStatusChanged WriteInterfaceToken error");
129 return;
130 }
131 if (!data.WriteParcelable(&device)) {
132 HILOGE("BluetoothHfpHfObserverProxy::OnRegistrationStatusChanged WriteParcelable error");
133 return;
134 }
135 if (!data.WriteInt32(status)) {
136 HILOGE("BluetoothHfpHfObserverProxy::OnRegistrationStatusChanged WriteInt32 error");
137 return;
138 }
139 MessageParcel reply;
140 MessageOption option {
141 MessageOption::TF_ASYNC
142 };
143 int error = Remote()->SendRequest(
144 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_REGISTRATION_STATUS_CHANGED, data, reply, option);
145 if (error != NO_ERROR) {
146 HILOGE("BluetoothHfpHfObserverProxy::OnRegistrationStatusChanged done fail, error: %{public}d", error);
147 return;
148 }
149 }
150
OnRoamingStatusChanged(const BluetoothRawAddress & device,int status)151 void BluetoothHfpHfObserverProxy::OnRoamingStatusChanged(const BluetoothRawAddress &device, int status) {
152 MessageParcel data;
153 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
154 HILOGE("BluetoothHfpHfObserverProxy::OnRoamingStatusChanged WriteInterfaceToken error");
155 return;
156 }
157 if (!data.WriteParcelable(&device)) {
158 HILOGE("BluetoothHfpHfObserverProxy::OnRoamingStatusChanged WriteParcelable error");
159 return;
160 }
161 if (!data.WriteInt32(status)) {
162 HILOGE("BluetoothHfpHfObserverProxy::OnRoamingStatusChanged WriteInt32 error");
163 return;
164 }
165 MessageParcel reply;
166 MessageOption option {
167 MessageOption::TF_ASYNC
168 };
169 int error = Remote()->SendRequest(
170 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_ROAMING_STATUS_CHANGED, data, reply, option);
171 if (error != NO_ERROR) {
172 HILOGE("BluetoothHfpHfObserverProxy::OnRoamingStatusChanged done fail, error: %{public}d", error);
173 return;
174 }
175 }
176
OnOperatorSelectionChanged(const BluetoothRawAddress & device,const std::string & name)177 void BluetoothHfpHfObserverProxy::OnOperatorSelectionChanged(const BluetoothRawAddress &device,
178 const std::string &name) {
179 MessageParcel data;
180 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
181 HILOGE("BluetoothHfpHfObserverProxy::OnOperatorSelectionChanged WriteInterfaceToken error");
182 return;
183 }
184 if (!data.WriteParcelable(&device)) {
185 HILOGE("BluetoothHfpHfObserverProxy::OnOperatorSelectionChanged WriteParcelable error");
186 return;
187 }
188 if (!data.WriteString(name)) {
189 HILOGE("BluetoothHfpHfObserverProxy::OnOperatorSelectionChanged WriteString error");
190 return;
191 }
192 MessageParcel reply;
193 MessageOption option {
194 MessageOption::TF_ASYNC
195 };
196 int error = Remote()->SendRequest(
197 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_OPERATOR_SELECTION_CHANGED, data, reply, option);
198 if (error != NO_ERROR) {
199 HILOGE("BluetoothHfpHfObserverProxy::OnOperatorSelectionChanged done fail, error: %{public}d", error);
200 return;
201 }
202 }
203
OnSubscriberNumberChanged(const BluetoothRawAddress & device,const std::string & number)204 void BluetoothHfpHfObserverProxy::OnSubscriberNumberChanged(const BluetoothRawAddress &device,
205 const std::string &number) {
206 MessageParcel data;
207 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
208 HILOGE("BluetoothHfpHfObserverProxy::OnSubscriberNumberChanged WriteInterfaceToken error");
209 return;
210 }
211 if (!data.WriteParcelable(&device)) {
212 HILOGE("BluetoothHfpHfObserverProxy::OnSubscriberNumberChanged WriteParcelable error");
213 return;
214 }
215 if (!data.WriteString(number)) {
216 HILOGE("BluetoothHfpHfObserverProxy::OnSubscriberNumberChanged WriteString error");
217 return;
218 }
219 MessageParcel reply;
220 MessageOption option {
221 MessageOption::TF_ASYNC
222 };
223 int error = Remote()->SendRequest(
224 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_SUBSCRIBER_NUMBER_CHANGED, data, reply, option);
225 if (error != NO_ERROR) {
226 HILOGE("BluetoothHfpHfObserverProxy::OnSubscriberNumberChanged done fail, error: %{public}d", error);
227 return;
228 }
229 }
230
OnVoiceRecognitionStatusChanged(const BluetoothRawAddress & device,int status)231 void BluetoothHfpHfObserverProxy::OnVoiceRecognitionStatusChanged(const BluetoothRawAddress &device, int status) {
232 MessageParcel data;
233 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
234 HILOGE("BluetoothHfpHfObserverProxy::OnVoiceRecognitionStatusChanged WriteInterfaceToken error");
235 return;
236 }
237 if (!data.WriteParcelable(&device)) {
238 HILOGE("BluetoothHfpHfObserverProxy::OnVoiceRecognitionStatusChanged WriteParcelable error");
239 return;
240 }
241 if (!data.WriteInt32(status)) {
242 HILOGE("BluetoothHfpHfObserverProxy::OnVoiceRecognitionStatusChanged WriteInt32 error");
243 return;
244 }
245 MessageParcel reply;
246 MessageOption option {
247 MessageOption::TF_ASYNC
248 };
249 int error = Remote()->SendRequest(
250 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_VOICE_RECOGNITION_STATUS_CHANGED, data, reply, option);
251 if (error != NO_ERROR) {
252 HILOGE("BluetoothHfpHfObserverProxy::OnVoiceRecognitionStatusChanged done fail, error: %{public}d", error);
253 return;
254 }
255 }
256
OnInBandRingToneChanged(const BluetoothRawAddress & device,int status)257 void BluetoothHfpHfObserverProxy::OnInBandRingToneChanged(const BluetoothRawAddress &device, int status) {
258 MessageParcel data;
259 if (!data.WriteInterfaceToken(BluetoothHfpHfObserverProxy::GetDescriptor())) {
260 HILOGE("BluetoothHfpHfObserverProxy::OnInBandRingToneChanged WriteInterfaceToken error");
261 return;
262 }
263 if (!data.WriteParcelable(&device)) {
264 HILOGE("BluetoothHfpHfObserverProxy::OnInBandRingToneChanged WriteParcelable error");
265 return;
266 }
267 if (!data.WriteInt32(status)) {
268 HILOGE("BluetoothHfpHfObserverProxy::OnInBandRingToneChanged WriteInt32 error");
269 return;
270 }
271 MessageParcel reply;
272 MessageOption option {
273 MessageOption::TF_ASYNC
274 };
275 int error = Remote()->SendRequest(
276 IBluetoothHfpHfObserver::Code::BT_HFP_HF_OBSERVER_IN_BAND_RING_TONE_CHANGED, data, reply, option);
277 if (error != NO_ERROR) {
278 HILOGE("BluetoothHfpHfObserverProxy::OnInBandRingToneChanged done fail, error: %{public}d", error);
279 return;
280 }
281 }
282
283 } // namespace Bluetooth
284 } // namespace OHOS
285