1 /*
2 * Copyright (C) 2021-2022 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 #ifndef LOG_TAG
16 #define LOG_TAG "bt_ipc_a2dp_sink_observer_stub"
17 #endif
18
19 #include "bluetooth_a2dp_sink_observer_stub.h"
20 #include "bluetooth_log.h"
21 #include "raw_address.h"
22
23 namespace OHOS {
24 namespace Bluetooth {
25 using namespace OHOS::bluetooth;
BluetoothA2dpSinkObserverStub()26 BluetoothA2dpSinkObserverStub::BluetoothA2dpSinkObserverStub()
27 {
28 HILOGD("start.");
29 }
30
~BluetoothA2dpSinkObserverStub()31 BluetoothA2dpSinkObserverStub::~BluetoothA2dpSinkObserverStub()
32 {
33 HILOGD("start.");
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int BluetoothA2dpSinkObserverStub::OnRemoteRequest(
37 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
38 {
39 HILOGE("cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
40
41 if (BluetoothA2dpSinkObserverStub::GetDescriptor() != data.ReadInterfaceToken()) {
42 HILOGI("local descriptor is not equal to remote");
43 return ERR_INVALID_STATE;
44 }
45
46 ErrCode errCode = NO_ERROR;
47 switch (code) {
48 case static_cast<uint32_t>(
49 BluetoothA2dpSinkObserverInterfaceCode::BT_A2DP_SINK_OBSERVER_CONNECTION_STATE_CHANGED):
50 errCode = OnConnectionStateChangedInner(data, reply);
51 break;
52 default:
53 HILOGW("default case, need check.");
54 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
55 }
56
57 return errCode;
58 }
59
OnConnectionStateChangedInner(MessageParcel & data,MessageParcel & reply)60 ErrCode BluetoothA2dpSinkObserverStub::OnConnectionStateChangedInner(MessageParcel &data, MessageParcel &reply)
61 {
62 if (BluetoothA2dpSinkObserverStub::GetDescriptor() != data.ReadInterfaceToken()) {
63 HILOGE("check interface token failed");
64 return ERR_INVALID_STATE;
65 }
66 std::string addr = data.ReadString();
67 int state = data.ReadInt32();
68 int cause = data.ReadInt32();
69
70 OnConnectionStateChanged(RawAddress(addr), state, cause);
71
72 return NO_ERROR;
73 }
74 } // namespace Bluetooth
75 } // namespace OHOS