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