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_avrcp_tg_observer_proxy.h"
17 #include "bluetooth_log.h"
18
19 namespace OHOS {
20 namespace Bluetooth {
OnConnectionStateChanged(const BluetoothRawAddress & device,int32_t state,int32_t cause)21 void BluetoothAvrcpTgObserverProxy::OnConnectionStateChanged(const BluetoothRawAddress &device,
22 int32_t state, int32_t cause)
23 {
24 HILOGI("BluetoothAvrcpTgObserverProxy::OnConnectionStateChanged Triggered!");
25 MessageParcel data;
26 if (!data.WriteInterfaceToken(BluetoothAvrcpTgObserverProxy::GetDescriptor())) {
27 HILOGE("BluetoothAvrcpTgObserverProxy::OnConnectionStateChanged WriteInterfaceToken error");
28 return;
29 }
30 if (!data.WriteParcelable(&device)) {
31 HILOGE("BluetoothAvrcpTgObserverProxy::OnConnectionStateChanged device error");
32 return;
33 }
34 if (!data.WriteInt32(state)) {
35 HILOGE("BluetoothAvrcpTgObserverProxy::OnConnectionStateChanged state error");
36 return;
37 }
38 if (!data.WriteInt32(cause)) {
39 HILOGE("BluetoothAvrcpTgObserverProxy::OnConnectionStateChanged cause error");
40 return;
41 }
42
43 MessageParcel reply;
44 MessageOption option = { MessageOption::TF_ASYNC };
45 int error = Remote()->SendRequest(
46 BluetoothAvrcpTgObserverInterfaceCode::BT_AVRCP_TG_OBSERVER_CONNECTION_STATE_CHANGED, data, reply, option);
47 if (error != NO_ERROR) {
48 HILOGE("BluetoothAvrcpTgObserverProxy::OnConnectionStateChanged done fail, error: %{public}d", error);
49 return;
50 }
51 }
52 } // namespace Bluetooth
53 } // namespace OHOS