• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_pbap_pse_observer_proxy.h"
17 #include "bluetooth_log.h"
18 #include "i_bluetooth_pbap_pse_observer.h"
19 #include "bluetooth_errorcode.h"
20 
21 namespace OHOS {
22 namespace Bluetooth {
OnServiceConnectionStateChanged(const BluetoothRawAddress & device,int state)23 void BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged(const BluetoothRawAddress &device, int state)
24 {
25     HILOGD("[%{public}s]: %{public}s(): Enter!", __FILE__, __FUNCTION__);
26     MessageParcel data;
27     if (!data.WriteInterfaceToken(BluetoothPbapPseObserverProxy::GetDescriptor())) {
28         HILOGE("BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged WriteInterfaceToken error");
29         return;
30     }
31 
32     if (!data.WriteParcelable(&device)) {
33         HILOGE("BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged error");
34         return;
35     }
36 
37     if (!data.WriteInt32(state)) {
38         HILOGE("BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged error");
39         return;
40     }
41 
42     MessageParcel reply;
43     MessageOption option {
44         MessageOption::TF_SYNC
45     };
46 
47     int error = Remote()->SendRequest(
48         BluetoothPbapPseObserverInterfaceCode::PBAP_PSE_ON_SERVICE_CONNECTION_STATE_CHANGE, data, reply, option);
49     if (error != NO_ERROR) {
50         HILOGE("BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged done fail, error: %d", error);
51         return;
52     }
53     return;
54 }
55 
OnServicePermission(const BluetoothRawAddress & device)56 void BluetoothPbapPseObserverProxy::OnServicePermission(const BluetoothRawAddress &device)
57 {
58     HILOGD("[%{public}s]: %{public}s(): Enter!", __FILE__, __FUNCTION__);
59     MessageParcel data;
60     if (!data.WriteInterfaceToken(BluetoothPbapPseObserverProxy::GetDescriptor())) {
61         HILOGE("BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged WriteInterfaceToken error");
62         return;
63     }
64 
65     if (!data.WriteParcelable(&device)) {
66         HILOGE("BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged error");
67         return;
68     }
69     MessageParcel reply;
70     MessageOption option {
71         MessageOption::TF_SYNC
72     };
73 
74     int error = Remote()->SendRequest(
75         BluetoothPbapPseObserverInterfaceCode::PBAP_PSE_ON_SERVICE_PERMISSION, data, reply, option);
76     if (error != NO_ERROR) {
77         HILOGE("BluetoothPbapPseObserverProxy::OnServiceConnectionStateChanged done fail, error: %d", error);
78         return;
79     }
80     return;
81 }
82 
OnServicePasswordRequired(const BluetoothRawAddress & device,const::std::vector<uint8_t> & description,int8_t charset,bool fullAccess)83 void BluetoothPbapPseObserverProxy::OnServicePasswordRequired(
84         const BluetoothRawAddress &device, const ::std::vector<uint8_t> &description, int8_t charset, bool fullAccess)
85 {
86     HILOGD("[%{public}s]: %{public}s(): Enter!", __FILE__, __FUNCTION__);
87     MessageParcel data;
88     if (!data.WriteInterfaceToken(BluetoothPbapPseObserverProxy::GetDescriptor())) {
89         HILOGE("BluetoothPbapPseObserverProxy::OnServicePasswordRequired WriteInterfaceToken error");
90         return;
91     }
92 
93     if (!data.WriteParcelable(&device)) {
94         HILOGE("BluetoothPbapPseObserverProxy::OnServicePasswordRequired error");
95         return;
96     }
97 
98     if (!data.WriteUInt8Vector(description)) {
99         HILOGE("BluetoothPbapPseObserverProxy::OnServicePasswordRequired error");
100         return;
101     }
102 
103     if (!data.WriteInt8(charset)) {
104         HILOGE("BluetoothPbapPseObserverProxy::OnServicePasswordRequired error");
105         return;
106     }
107 
108     if (!data.WriteBool(fullAccess)) {
109         HILOGE("BluetoothPbapPseObserverProxy::OnServicePasswordRequired error");
110         return;
111     }
112 
113     MessageParcel reply;
114     MessageOption option {
115         MessageOption::TF_SYNC
116     };
117 
118     int error = Remote()->SendRequest(
119         BluetoothPbapPseObserverInterfaceCode::PBAP_PSE_ON_SERVICE_PASSWORD_REQUIRED, data, reply, option);
120     if (error != NO_ERROR) {
121         HILOGE("BluetoothPbapPseObserverProxy::OnServicePasswordRequired done fail, error: %d", error);
122         return;
123     }
124     return;
125 }
126 }  // namespace Bluetooth
127 }  // namespace OHOS