• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "bluetooth_host_stub.h"
17 #include "bluetooth_log.h"
18 #include "bluetooth_errorcode.h"
19 #include "ipc_types.h"
20 #include "raw_address.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace Bluetooth {
25 const std::map<uint32_t, std::function<ErrCode(BluetoothHostStub *, MessageParcel &, MessageParcel &)>>
26     BluetoothHostStub::memberFuncMap_ = {
27         {BluetoothHostInterfaceCode::BT_REGISTER_OBSERVER,
28             std::bind(&BluetoothHostStub::RegisterObserverInner, std::placeholders::_1, std::placeholders::_2,
29                 std::placeholders::_3)},
30         {BluetoothHostInterfaceCode::BT_DEREGISTER_OBSERVER,
31             std::bind(&BluetoothHostStub::DeregisterObserverInner, std::placeholders::_1, std::placeholders::_2,
32                 std::placeholders::_3)},
33         {BluetoothHostInterfaceCode::BT_ENABLE,
34             std::bind(&BluetoothHostStub::EnableBtInner, std::placeholders::_1, std::placeholders::_2,
35                 std::placeholders::_3)},
36         {BluetoothHostInterfaceCode::BT_DISABLE,
37             std::bind(&BluetoothHostStub::DisableBtInner, std::placeholders::_1, std::placeholders::_2,
38                 std::placeholders::_3)},
39         {BluetoothHostInterfaceCode::BT_GETPROFILE,
40             std::bind(&BluetoothHostStub::GetProfileInner, std::placeholders::_1, std::placeholders::_2,
41                 std::placeholders::_3)},
42         {BluetoothHostInterfaceCode::BT_GET_BLE,
43             std::bind(&BluetoothHostStub::GetBleRemoteInner, std::placeholders::_1, std::placeholders::_2,
44                 std::placeholders::_3)},
45         {BluetoothHostInterfaceCode::BT_FACTORY_RESET,
46             std::bind(&BluetoothHostStub::BluetoothFactoryResetInner, std::placeholders::_1, std::placeholders::_2,
47                 std::placeholders::_3)},
48         {BluetoothHostInterfaceCode::BT_GETSTATE,
49             std::bind(&BluetoothHostStub::GetBtStateInner, std::placeholders::_1, std::placeholders::_2,
50                 std::placeholders::_3)},
51         {BluetoothHostInterfaceCode::BT_GET_LOCAL_ADDRESS,
52             std::bind(&BluetoothHostStub::GetLocalAddressInner, std::placeholders::_1, std::placeholders::_2,
53                 std::placeholders::_3)},
54         {BluetoothHostInterfaceCode::BT_DISABLE_BLE,
55             std::bind(&BluetoothHostStub::DisableBleInner, std::placeholders::_1, std::placeholders::_2,
56                 std::placeholders::_3)},
57         {BluetoothHostInterfaceCode::BT_ENABLE_BLE,
58             std::bind(&BluetoothHostStub::EnableBleInner, std::placeholders::_1, std::placeholders::_2,
59                 std::placeholders::_3)},
60         {BluetoothHostInterfaceCode::BT_IS_BR_ENABLED,
61             std::bind(&BluetoothHostStub::IsBrEnabledInner, std::placeholders::_1, std::placeholders::_2,
62                 std::placeholders::_3)},
63         {BluetoothHostInterfaceCode::BT_IS_BLE_ENABLED,
64             std::bind(&BluetoothHostStub::IsBleEnabledInner, std::placeholders::_1, std::placeholders::_2,
65                 std::placeholders::_3)},
66         {BluetoothHostInterfaceCode::BT_GET_PROFILE_LIST,
67             std::bind(&BluetoothHostStub::GetProfileListInner, std::placeholders::_1, std::placeholders::_2,
68                 std::placeholders::_3)},
69         {BluetoothHostInterfaceCode::BT_GET_MAXNUM_CONNECTED_AUDIODEVICES,
70             std::bind(&BluetoothHostStub::GetMaxNumConnectedAudioDevicesInner, std::placeholders::_1,
71                 std::placeholders::_2, std::placeholders::_3)},
72         {BluetoothHostInterfaceCode::BT_GET_BT_STATE,
73             std::bind(&BluetoothHostStub::GetBtConnectionStateInner, std::placeholders::_1, std::placeholders::_2,
74                 std::placeholders::_3)},
75         {BluetoothHostInterfaceCode::BT_GET_BT_PROFILE_CONNSTATE,
76             std::bind(&BluetoothHostStub::GetBtProfileConnStateInner, std::placeholders::_1, std::placeholders::_2,
77                 std::placeholders::_3)},
78         {BluetoothHostInterfaceCode::BT_GET_LOCAL_DEVICE_CLASS,
79             std::bind(&BluetoothHostStub::GetLocalDeviceClassInner, std::placeholders::_1, std::placeholders::_2,
80                 std::placeholders::_3)},
81         {BluetoothHostInterfaceCode::BT_SET_LOCAL_DEVICE_CLASS,
82             std::bind(&BluetoothHostStub::SetLocalDeviceClassInner, std::placeholders::_1, std::placeholders::_2,
83                 std::placeholders::_3)},
84         {BluetoothHostInterfaceCode::BT_GET_LOCAL_NAME,
85             std::bind(&BluetoothHostStub::GetLocalNameInner, std::placeholders::_1, std::placeholders::_2,
86                 std::placeholders::_3)},
87         {BluetoothHostInterfaceCode::BT_SET_LOCAL_NAME,
88             std::bind(&BluetoothHostStub::SetLocalNameInner, std::placeholders::_1, std::placeholders::_2,
89                 std::placeholders::_3)},
90         {BluetoothHostInterfaceCode::BT_GET_BT_SCAN_MODE,
91             std::bind(&BluetoothHostStub::GetBtScanModeInner, std::placeholders::_1, std::placeholders::_2,
92                 std::placeholders::_3)},
93         {BluetoothHostInterfaceCode::BT_SET_BT_SCAN_MODE,
94             std::bind(&BluetoothHostStub::SetBtScanModeInner, std::placeholders::_1, std::placeholders::_2,
95                 std::placeholders::_3)},
96         {BluetoothHostInterfaceCode::BT_GET_BONDABLE_MODE,
97             std::bind(&BluetoothHostStub::GetBondableModeInner, std::placeholders::_1, std::placeholders::_2,
98                 std::placeholders::_3)},
99         {BluetoothHostInterfaceCode::BT_SET_BONDABLE_MODE,
100             std::bind(&BluetoothHostStub::SetBondableModeInner, std::placeholders::_1, std::placeholders::_2,
101                 std::placeholders::_3)},
102         {BluetoothHostInterfaceCode::BT_START_BT_DISCOVERY,
103             std::bind(&BluetoothHostStub::StartBtDiscoveryInner, std::placeholders::_1, std::placeholders::_2,
104                 std::placeholders::_3)},
105         {BluetoothHostInterfaceCode::BT_CANCEL_BT_DISCOVERY,
106             std::bind(&BluetoothHostStub::CancelBtDiscoveryInner, std::placeholders::_1, std::placeholders::_2,
107                 std::placeholders::_3)},
108         {BluetoothHostInterfaceCode::BT_IS_BT_DISCOVERING,
109             std::bind(&BluetoothHostStub::IsBtDiscoveringInner, std::placeholders::_1, std::placeholders::_2,
110                 std::placeholders::_3)},
111         {BluetoothHostInterfaceCode::BT_GET_BT_DISCOVERY_END_MILLIS,
112             std::bind(&BluetoothHostStub::GetBtDiscoveryEndMillisInner, std::placeholders::_1, std::placeholders::_2,
113                 std::placeholders::_3)},
114         {BluetoothHostInterfaceCode::BT_GET_PAIRED_DEVICES,
115             std::bind(&BluetoothHostStub::GetPairedDevicesInner, std::placeholders::_1, std::placeholders::_2,
116                 std::placeholders::_3)},
117         {BluetoothHostInterfaceCode::BT_REMOVE_PAIR,
118             std::bind(&BluetoothHostStub::RemovePairInner, std::placeholders::_1, std::placeholders::_2,
119                 std::placeholders::_3)},
120         {BluetoothHostInterfaceCode::BT_REMOVE_ALL_PAIRS,
121             std::bind(&BluetoothHostStub::RemoveAllPairsInner, std::placeholders::_1, std::placeholders::_2,
122                 std::placeholders::_3)},
123         {BluetoothHostInterfaceCode::BT_REGISTER_REMOTE_DEVICE_OBSERVER,
124             std::bind(&BluetoothHostStub::RegisterRemoteDeviceObserverInner, std::placeholders::_1,
125                 std::placeholders::_2, std::placeholders::_3)},
126         {BluetoothHostInterfaceCode::BT_DEREGISTER_REMOTE_DEVICE_OBSERVER,
127             std::bind(&BluetoothHostStub::DeregisterRemoteDeviceObserverInner, std::placeholders::_1,
128                 std::placeholders::_2, std::placeholders::_3)},
129         {BluetoothHostInterfaceCode::BT_GET_BLE_MAX_ADVERTISING_DATALENGTH,
130             std::bind(&BluetoothHostStub::GetBleMaxAdvertisingDataLengthInner, std::placeholders::_1,
131                 std::placeholders::_2, std::placeholders::_3)},
132         {BluetoothHostInterfaceCode::GET_DEVICE_TYPE,
133             std::bind(&BluetoothHostStub::GetDeviceTypeInner, std::placeholders::_1, std::placeholders::_2,
134                 std::placeholders::_3)},
135         {BluetoothHostInterfaceCode::GET_PHONEBOOK_PERMISSION,
136             std::bind(&BluetoothHostStub::GetPhonebookPermissionInner, std::placeholders::_1, std::placeholders::_2,
137                 std::placeholders::_3)},
138         {BluetoothHostInterfaceCode::SET_PHONEBOOK_PERMISSION,
139             nullptr},
140         {BluetoothHostInterfaceCode::GET_MESSAGE_PERMISSION,
141             std::bind(&BluetoothHostStub::GetMessagePermissionInner, std::placeholders::_1, std::placeholders::_2,
142                 std::placeholders::_3)},
143         {BluetoothHostInterfaceCode::SET_MESSAGE_PERMISSION,
144             nullptr},
145         {BluetoothHostInterfaceCode::GET_POWER_MODE,
146             std::bind(&BluetoothHostStub::GetPowerModeInner, std::placeholders::_1, std::placeholders::_2,
147                 std::placeholders::_3)},
148         {BluetoothHostInterfaceCode::GET_DEVICE_NAME,
149             std::bind(&BluetoothHostStub::GetDeviceNameInner, std::placeholders::_1, std::placeholders::_2,
150                 std::placeholders::_3)},
151         {BluetoothHostInterfaceCode::GET_DEVICE_ALIAS,
152             std::bind(&BluetoothHostStub::GetDeviceAliasInner, std::placeholders::_1, std::placeholders::_2,
153                 std::placeholders::_3)},
154         {BluetoothHostInterfaceCode::SET_DEVICE_ALIAS,
155             std::bind(&BluetoothHostStub::SetDeviceAliasInner, std::placeholders::_1, std::placeholders::_2,
156                 std::placeholders::_3)},
157         {BluetoothHostInterfaceCode::GET_DEVICE_BATTERY_LEVEL,
158             std::bind(&BluetoothHostStub::GetDeviceBatteryLevelInner, std::placeholders::_1, std::placeholders::_2,
159                 std::placeholders::_3)},
160         {BluetoothHostInterfaceCode::GET_PAIR_STATE,
161             std::bind(&BluetoothHostStub::GetPairStateInner, std::placeholders::_1, std::placeholders::_2,
162                 std::placeholders::_3)},
163         {BluetoothHostInterfaceCode::START_PAIR,
164             std::bind(&BluetoothHostStub::StartPairInner, std::placeholders::_1, std::placeholders::_2,
165                 std::placeholders::_3)},
166         {BluetoothHostInterfaceCode::CANCEL_PAIRING,
167             std::bind(&BluetoothHostStub::CancelPairingInner, std::placeholders::_1, std::placeholders::_2,
168                 std::placeholders::_3)},
169         {BluetoothHostInterfaceCode::IS_BONDED_FROM_LOCAL,
170             std::bind(&BluetoothHostStub::IsBondedFromLocalInner, std::placeholders::_1, std::placeholders::_2,
171                 std::placeholders::_3)},
172         {BluetoothHostInterfaceCode::IS_ACL_CONNECTED,
173             std::bind(&BluetoothHostStub::IsAclConnectedInner, std::placeholders::_1, std::placeholders::_2,
174                 std::placeholders::_3)},
175         {BluetoothHostInterfaceCode::IS_ACL_ENCRYPTED,
176             std::bind(&BluetoothHostStub::IsAclEncryptedInner, std::placeholders::_1, std::placeholders::_2,
177                 std::placeholders::_3)},
178         {BluetoothHostInterfaceCode::GET_DEVICE_CLASS,
179             std::bind(&BluetoothHostStub::GetDeviceClassInner, std::placeholders::_1, std::placeholders::_2,
180                 std::placeholders::_3)},
181         {BluetoothHostInterfaceCode::SET_DEVICE_PIN,
182             std::bind(&BluetoothHostStub::SetDevicePinInner, std::placeholders::_1, std::placeholders::_2,
183                 std::placeholders::_3)},
184         {BluetoothHostInterfaceCode::SET_DEVICE_PAIRING_CONFIRMATION,
185             std::bind(&BluetoothHostStub::SetDevicePairingConfirmationInner, std::placeholders::_1,
186                 std::placeholders::_2, std::placeholders::_3)},
187         {BluetoothHostInterfaceCode::SET_DEVICE_PASSKEY,
188             std::bind(&BluetoothHostStub::SetDevicePasskeyInner, std::placeholders::_1, std::placeholders::_2,
189                 std::placeholders::_3)},
190         {BluetoothHostInterfaceCode::PAIR_REQUEST_PEPLY,
191             std::bind(&BluetoothHostStub::PairRequestReplyInner, std::placeholders::_1, std::placeholders::_2,
192                 std::placeholders::_3)},
193         {BluetoothHostInterfaceCode::READ_REMOTE_RSSI_VALUE,
194             std::bind(&BluetoothHostStub::ReadRemoteRssiValueInner, std::placeholders::_1, std::placeholders::_2,
195                 std::placeholders::_3)},
196         {BluetoothHostInterfaceCode::GET_LOCAL_SUPPORTED_UUIDS,
197             std::bind(&BluetoothHostStub::GetLocalSupportedUuidsInner, std::placeholders::_1, std::placeholders::_2,
198                 std::placeholders::_3)},
199         {BluetoothHostInterfaceCode::GET_DEVICE_UUIDS,
200             std::bind(&BluetoothHostStub::GetDeviceUuidsInner, std::placeholders::_1, std::placeholders::_2,
201                 std::placeholders::_3)},
202         {BluetoothHostInterfaceCode::GET_LOCAL_PROFILE_UUIDS,
203             std::bind(&BluetoothHostStub::GetLocalProfileUuidsInner, std::placeholders::_1, std::placeholders::_2,
204                 std::placeholders::_3)},
205         {BluetoothHostInterfaceCode::BT_REGISTER_BLE_ADAPTER_OBSERVER,
206             std::bind(&BluetoothHostStub::RegisterBleAdapterObserverInner, std::placeholders::_1, std::placeholders::_2,
207                 std::placeholders::_3)},
208         {BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_ADAPTER_OBSERVER,
209             std::bind(&BluetoothHostStub::DeregisterBleAdapterObserverInner, std::placeholders::_1,
210                 std::placeholders::_2, std::placeholders::_3)},
211         {BluetoothHostInterfaceCode::BT_REGISTER_BLE_PERIPHERAL_OBSERVER,
212             std::bind(&BluetoothHostStub::RegisterBlePeripheralCallbackInner, std::placeholders::_1,
213                 std::placeholders::_2, std::placeholders::_3)},
214         {BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_PERIPHERAL_OBSERVER,
215             std::bind(&BluetoothHostStub::DeregisterBlePeripheralCallbackInner, std::placeholders::_1,
216                 std::placeholders::_2, std::placeholders::_3)},
217         {BluetoothHostInterfaceCode::BT_SET_FAST_SCAN,
218             std::bind(&BluetoothHostStub::SetFastScanInner, std::placeholders::_1,
219                 std::placeholders::_2, std::placeholders::_3)},
220         {BluetoothHostInterfaceCode::GET_RANDOM_ADDRESS, std::bind(&BluetoothHostStub::GetRandomAddressInner,
221             std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
222         {BluetoothHostInterfaceCode::SYNC_RANDOM_ADDRESS, std::bind(&BluetoothHostStub::SyncRandomAddressInner,
223             std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
224 
225 };
226 
BluetoothHostStub()227 BluetoothHostStub::BluetoothHostStub(){};
~BluetoothHostStub()228 BluetoothHostStub::~BluetoothHostStub()
229 {}
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)230 int32_t BluetoothHostStub::OnRemoteRequest(
231     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
232 {
233     HILOGI("BluetoothHostStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
234     if (BluetoothHostStub::GetDescriptor() != data.ReadInterfaceToken()) {
235         HILOGE("BluetoothHostStub::OnRemoteRequest, local descriptor is not equal to remote");
236         return ERR_INVALID_STATE;
237     }
238     auto itFunc = memberFuncMap_.find(code);
239     if (itFunc != memberFuncMap_.end()) {
240         auto memberFunc = itFunc->second;
241         if (memberFunc != nullptr) {
242             return memberFunc(this, data, reply);
243         }
244     }
245     HILOGW("BluetoothHostStub::OnRemoteRequest, default case, need check.");
246     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
247 }
248 
RegisterObserverInner(MessageParcel & data,MessageParcel & reply)249 ErrCode BluetoothHostStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
250 {
251     HILOGI("BluetoothHostStub::RegisterObserverInner starts");
252     sptr<IRemoteObject> remote = data.ReadRemoteObject();
253     const sptr<IBluetoothHostObserver> observer = OHOS::iface_cast<IBluetoothHostObserver>(remote);
254     RegisterObserver(observer);
255     return NO_ERROR;
256 }
257 
DeregisterObserverInner(MessageParcel & data,MessageParcel & reply)258 ErrCode BluetoothHostStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
259 {
260     HILOGI("BluetoothHostStub::DeregisterObserverInner starts");
261     sptr<IRemoteObject> remote = data.ReadRemoteObject();
262     const sptr<IBluetoothHostObserver> observer = OHOS::iface_cast<IBluetoothHostObserver>(remote);
263     DeregisterObserver(observer);
264     return NO_ERROR;
265 }
266 
EnableBtInner(MessageParcel & data,MessageParcel & reply)267 int32_t BluetoothHostStub::EnableBtInner(MessageParcel &data, MessageParcel &reply)
268 {
269     int32_t result = EnableBt();
270     bool ret = reply.WriteInt32(result);
271     if (!ret) {
272         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
273         return ERR_INVALID_VALUE;
274     }
275     return NO_ERROR;
276 }
277 
DisableBtInner(MessageParcel & data,MessageParcel & reply)278 int32_t BluetoothHostStub::DisableBtInner(MessageParcel &data, MessageParcel &reply)
279 {
280     int32_t result = DisableBt();
281     bool ret = reply.WriteInt32(result);
282     if (!ret) {
283         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
284         return BT_ERR_IPC_TRANS_FAILED;
285     }
286     return NO_ERROR;
287 }
288 
GetProfileInner(MessageParcel & data,MessageParcel & reply)289 ErrCode BluetoothHostStub::GetProfileInner(MessageParcel &data, MessageParcel &reply)
290 {
291     HILOGI("BluetoothHostStub::GetProfileInner starts");
292     std::string name = data.ReadString();
293     sptr<IRemoteObject> result = GetProfile(name);
294     bool ret = reply.WriteRemoteObject(result);
295     if (!ret) {
296         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
297         return TRANSACTION_ERR;
298     }
299     return NO_ERROR;
300 }
301 
GetBleRemoteInner(MessageParcel & data,MessageParcel & reply)302 ErrCode BluetoothHostStub::GetBleRemoteInner(MessageParcel &data, MessageParcel &reply)
303 {
304     HILOGI("BluetoothHostStub::GetBleRemoteInner starts");
305     std::string name = data.ReadString();
306     sptr<IRemoteObject> result = GetBleRemote(name);
307     bool ret = reply.WriteRemoteObject(result);
308     if (!ret) {
309         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
310         return TRANSACTION_ERR;
311     }
312     return NO_ERROR;
313 }
314 
BluetoothFactoryResetInner(MessageParcel & data,MessageParcel & reply)315 ErrCode BluetoothHostStub::BluetoothFactoryResetInner(MessageParcel &data, MessageParcel &reply)
316 {
317     HILOGI("BluetoothHostStub::BluetoothFactoryResetInner starts");
318     bool result = BluetoothFactoryReset();
319     bool ret = reply.WriteBool(result);
320     if (!ret) {
321         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
322         return ERR_INVALID_VALUE;
323     }
324     return NO_ERROR;
325 }
326 
GetBtStateInner(MessageParcel & data,MessageParcel & reply)327 ErrCode BluetoothHostStub::GetBtStateInner(MessageParcel &data, MessageParcel &reply)
328 {
329     HILOGI("BluetoothHostStub::GetBtStateInner starts");
330     int32_t state = 0;
331     int32_t result = GetBtState(state);
332     (void)reply.WriteInt32(result);
333     (void)reply.WriteInt32(state);
334     return NO_ERROR;
335 }
336 
GetLocalAddressInner(MessageParcel & data,MessageParcel & reply)337 ErrCode BluetoothHostStub::GetLocalAddressInner(MessageParcel &data, MessageParcel &reply)
338 {
339     std::string result = GetLocalAddress();
340     bool ret = reply.WriteString(result);
341     if (!ret) {
342         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
343         return TRANSACTION_ERR;
344     }
345     return NO_ERROR;
346 }
347 
DisableBleInner(MessageParcel & data,MessageParcel & reply)348 int32_t BluetoothHostStub::DisableBleInner(MessageParcel &data, MessageParcel &reply)
349 {
350     int32_t result = DisableBle();
351     bool ret = reply.WriteInt32(result);
352     if (!ret) {
353         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
354         return BT_ERR_IPC_TRANS_FAILED;
355     }
356     return NO_ERROR;
357 }
358 
EnableBleInner(MessageParcel & data,MessageParcel & reply)359 int32_t BluetoothHostStub::EnableBleInner(MessageParcel &data, MessageParcel &reply)
360 {
361     int32_t result = EnableBle();
362     bool ret = reply.WriteInt32(result);
363     if (!ret) {
364         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
365         return BT_ERR_IPC_TRANS_FAILED;
366     }
367     return NO_ERROR;
368 }
369 
IsBrEnabledInner(MessageParcel & data,MessageParcel & reply)370 ErrCode BluetoothHostStub::IsBrEnabledInner(MessageParcel &data, MessageParcel &reply)
371 {
372     bool result = IsBrEnabled();
373     bool ret = reply.WriteBool(result);
374     if (!ret) {
375         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
376         return TRANSACTION_ERR;
377     }
378     return NO_ERROR;
379 }
380 
IsBleEnabledInner(MessageParcel & data,MessageParcel & reply)381 ErrCode BluetoothHostStub::IsBleEnabledInner(MessageParcel &data, MessageParcel &reply)
382 {
383     bool result = IsBleEnabled();
384     bool ret = reply.WriteBool(result);
385     if (!ret) {
386         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
387         return TRANSACTION_ERR;
388     }
389     return NO_ERROR;
390 }
391 
GetProfileListInner(MessageParcel & data,MessageParcel & reply)392 ErrCode BluetoothHostStub::GetProfileListInner(MessageParcel &data, MessageParcel &reply)
393 {
394     std::vector<uint32_t> result = GetProfileList();
395     bool ret = reply.WriteUInt32Vector(result);
396     if (!ret) {
397         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
398         return TRANSACTION_ERR;
399     }
400     return NO_ERROR;
401 }
402 
GetMaxNumConnectedAudioDevicesInner(MessageParcel & data,MessageParcel & reply)403 ErrCode BluetoothHostStub::GetMaxNumConnectedAudioDevicesInner(MessageParcel &data, MessageParcel &reply)
404 {
405     int32_t result = GetMaxNumConnectedAudioDevices();
406     bool ret = reply.WriteInt32(result);
407     if (!ret) {
408         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
409         return TRANSACTION_ERR;
410     }
411     return NO_ERROR;
412 }
413 
GetBtConnectionStateInner(MessageParcel & data,MessageParcel & reply)414 int32_t BluetoothHostStub::GetBtConnectionStateInner(MessageParcel &data, MessageParcel &reply)
415 {
416     HILOGI("BluetoothHostStub::GetBtConnectionStateInner starts");
417     int32_t state = 0;
418     int32_t result = GetBtConnectionState(state);
419     bool ret = reply.WriteInt32(result);
420     if (!ret) {
421         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
422         return BT_ERR_IPC_TRANS_FAILED;
423     }
424     ret = reply.WriteInt32(state);
425     if (!ret) {
426         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
427         return BT_ERR_IPC_TRANS_FAILED;
428     }
429     return NO_ERROR;
430 }
431 
GetBtProfileConnStateInner(MessageParcel & data,MessageParcel & reply)432 int32_t BluetoothHostStub::GetBtProfileConnStateInner(MessageParcel &data, MessageParcel &reply)
433 {
434     uint32_t profileId;
435     data.ReadUint32(profileId);
436     int32_t state = 0;
437     int32_t result = GetBtProfileConnState(profileId, state);
438     bool ret = reply.WriteInt32(result);
439     if (!ret) {
440         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
441         return BT_ERR_IPC_TRANS_FAILED;
442     }
443     ret = reply.WriteInt32(state);
444     if (!ret) {
445         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
446         return BT_ERR_IPC_TRANS_FAILED;
447     }
448     return NO_ERROR;
449 }
450 
GetLocalDeviceClassInner(MessageParcel & data,MessageParcel & reply)451 ErrCode BluetoothHostStub::GetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)
452 {
453     int32_t result = GetLocalDeviceClass();
454     bool ret = reply.WriteInt32(result);
455     if (!ret) {
456         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
457         return TRANSACTION_ERR;
458     }
459     return NO_ERROR;
460 }
461 
SetLocalDeviceClassInner(MessageParcel & data,MessageParcel & reply)462 ErrCode BluetoothHostStub::SetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)
463 {
464     int32_t deviceClass;
465     data.ReadInt32(deviceClass);
466     bool result = SetLocalDeviceClass(deviceClass);
467     bool ret = reply.WriteInt32(result);
468     if (!ret) {
469         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
470         return TRANSACTION_ERR;
471     }
472     return NO_ERROR;
473 }
474 
GetLocalNameInner(MessageParcel & data,MessageParcel & reply)475 int32_t BluetoothHostStub::GetLocalNameInner(MessageParcel &data, MessageParcel &reply)
476 {
477     std::string name = "";
478     int32_t result = GetLocalName(name);
479     bool ret = reply.WriteInt32(result);
480     if (!ret) {
481         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
482         return BT_ERR_IPC_TRANS_FAILED;
483     }
484     ret = reply.WriteString(name);
485     if (!ret) {
486         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
487         return BT_ERR_IPC_TRANS_FAILED;
488     }
489     return NO_ERROR;
490 }
491 
SetLocalNameInner(MessageParcel & data,MessageParcel & reply)492 int32_t BluetoothHostStub::SetLocalNameInner(MessageParcel &data, MessageParcel &reply)
493 {
494     std::string name;
495     data.ReadString(name);
496     int32_t result = SetLocalName(name);
497     bool ret = reply.WriteInt32(result);
498     if (!ret) {
499         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
500         return BT_ERR_IPC_TRANS_FAILED;
501     }
502 
503     return NO_ERROR;
504 }
505 
GetDeviceTypeInner(MessageParcel & data,MessageParcel & reply)506 ErrCode BluetoothHostStub::GetDeviceTypeInner(MessageParcel &data, MessageParcel &reply)
507 {
508     int32_t transport;
509     if (!data.ReadInt32(transport)) {
510         HILOGE("BluetoothHostStub::GetDeviceType transport failed");
511         return TRANSACTION_ERR;
512     }
513     std::string address;
514     if (!data.ReadString(address)) {
515         HILOGE("BluetoothHostStub::GetDeviceType address failed");
516         return TRANSACTION_ERR;
517     }
518     int result = GetDeviceType(transport, address);
519     bool ret = reply.WriteInt32(result);
520     if (!ret) {
521         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
522         return ERR_INVALID_VALUE;
523     }
524     return NO_ERROR;
525 }
526 
GetBtScanModeInner(MessageParcel & data,MessageParcel & reply)527 int32_t BluetoothHostStub::GetBtScanModeInner(MessageParcel &data, MessageParcel &reply)
528 {
529     int32_t scanMode = 0;
530     int32_t result = GetBtScanMode(scanMode);
531     bool ret = reply.WriteInt32(result);
532     if (!ret) {
533         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
534         return BT_ERR_IPC_TRANS_FAILED;
535     }
536     ret = reply.WriteInt32(scanMode);
537     if (!ret) {
538         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
539         return BT_ERR_IPC_TRANS_FAILED;
540     }
541     return NO_ERROR;
542 }
543 
GetPhonebookPermissionInner(MessageParcel & data,MessageParcel & reply)544 ErrCode BluetoothHostStub::GetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)
545 {
546     std::string address;
547     if (!data.ReadString(address)) {
548         HILOGE("BluetoothHostStub::GetPhonebookPermission address failed");
549         return TRANSACTION_ERR;
550     }
551     int result = GetPhonebookPermission(address);
552     bool ret = reply.WriteInt32(result);
553     if (!ret) {
554         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
555         return TRANSACTION_ERR;
556     }
557     return NO_ERROR;
558 }
559 
SetBtScanModeInner(MessageParcel & data,MessageParcel & reply)560 int32_t BluetoothHostStub::SetBtScanModeInner(MessageParcel &data, MessageParcel &reply)
561 {
562     int32_t mode;
563     data.ReadInt32(mode);
564     int32_t duration;
565     data.ReadInt32(duration);
566     int32_t result = SetBtScanMode(mode, duration);
567     bool ret = reply.WriteInt32(result);
568     if (!ret) {
569         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
570         return BT_ERR_IPC_TRANS_FAILED;
571     }
572     return NO_ERROR;
573 }
574 
SetPhonebookPermissionInner(MessageParcel & data,MessageParcel & reply)575 ErrCode BluetoothHostStub::SetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)
576 {
577     std::string address;
578     if (!data.ReadString(address)) {
579         HILOGE("BluetoothHostStub::SetPhonebookPermission address failed");
580         return TRANSACTION_ERR;
581     }
582     int32_t permission;
583     if (!data.ReadInt32(permission)) {
584         HILOGE("BluetoothHostStub::SetPhonebookPermission permission failed");
585         return TRANSACTION_ERR;
586     }
587     bool result = SetPhonebookPermission(address, permission);
588     bool ret = reply.WriteBool(result);
589     if (!ret) {
590         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
591         return ERR_INVALID_VALUE;
592     }
593     return NO_ERROR;
594 }
595 
GetBondableModeInner(MessageParcel & data,MessageParcel & reply)596 ErrCode BluetoothHostStub::GetBondableModeInner(MessageParcel &data, MessageParcel &reply)
597 {
598     int32_t transport;
599     data.ReadInt32(transport);
600     int32_t result = GetBondableMode(transport);
601     bool ret = reply.WriteInt32(result);
602     if (!ret) {
603         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
604         return TRANSACTION_ERR;
605     }
606     return NO_ERROR;
607 }
GetMessagePermissionInner(MessageParcel & data,MessageParcel & reply)608 ErrCode BluetoothHostStub::GetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)
609 {
610     std::string address;
611     if (!data.ReadString(address)) {
612         HILOGE("BluetoothHostStub::GetMessagePermission address failed");
613         return TRANSACTION_ERR;
614     }
615     int result = GetMessagePermission(address);
616     bool ret = reply.WriteInt32(result);
617     if (!ret) {
618         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
619         return TRANSACTION_ERR;
620     }
621     return NO_ERROR;
622 }
623 
SetBondableModeInner(MessageParcel & data,MessageParcel & reply)624 ErrCode BluetoothHostStub::SetBondableModeInner(MessageParcel &data, MessageParcel &reply)
625 {
626     int32_t transport;
627     data.ReadInt32(transport);
628     int32_t mode;
629     data.ReadInt32(mode);
630 
631     bool result = SetBondableMode(transport, mode);
632     bool ret = reply.WriteInt32(result);
633     if (!ret) {
634         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
635         return ERR_INVALID_VALUE;
636     }
637     return NO_ERROR;
638 }
639 
SetMessagePermissionInner(MessageParcel & data,MessageParcel & reply)640 ErrCode BluetoothHostStub::SetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)
641 {
642     std::string address;
643     if (!data.ReadString(address)) {
644         HILOGE("BluetoothHostStub::SetMessagePermission address failed");
645         return TRANSACTION_ERR;
646     }
647     int32_t permission;
648     if (!data.ReadInt32(permission)) {
649         HILOGE("BluetoothHostStub::SetMessagePermission permission failed");
650         return TRANSACTION_ERR;
651     }
652     bool result = SetMessagePermission(address, permission);
653     bool ret = reply.WriteBool(result);
654     if (!ret) {
655         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
656         return TRANSACTION_ERR;
657     }
658     return NO_ERROR;
659 }
660 
GetPowerModeInner(MessageParcel & data,MessageParcel & reply)661 ErrCode BluetoothHostStub::GetPowerModeInner(MessageParcel &data, MessageParcel &reply)
662 {
663     std::string address;
664     if (!data.ReadString(address)) {
665         HILOGE("BluetoothHostStub::GetPowerMode address failed");
666         return TRANSACTION_ERR;
667     }
668     int result = GetPowerMode(address);
669     bool ret = reply.WriteInt32(result);
670     if (!ret) {
671         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
672         return TRANSACTION_ERR;
673     }
674     return NO_ERROR;
675 }
676 
StartBtDiscoveryInner(MessageParcel & data,MessageParcel & reply)677 int32_t BluetoothHostStub::StartBtDiscoveryInner(MessageParcel &data, MessageParcel &reply)
678 {
679     int32_t result = StartBtDiscovery();
680     bool ret = reply.WriteInt32(result);
681     if (!ret) {
682         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
683         return BT_ERR_IPC_TRANS_FAILED;
684     }
685     return NO_ERROR;
686 }
687 
CancelBtDiscoveryInner(MessageParcel & data,MessageParcel & reply)688 int32_t BluetoothHostStub::CancelBtDiscoveryInner(MessageParcel &data, MessageParcel &reply)
689 {
690     int32_t result = CancelBtDiscovery();
691     bool ret = reply.WriteInt32(result);
692     if (!ret) {
693         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
694         return BT_ERR_IPC_TRANS_FAILED;
695     }
696     return NO_ERROR;
697 }
698 
GetDeviceNameInner(MessageParcel & data,MessageParcel & reply)699 int32_t BluetoothHostStub::GetDeviceNameInner(MessageParcel &data, MessageParcel &reply)
700 {
701     int32_t transport;
702     if (!data.ReadInt32(transport)) {
703         HILOGE("BluetoothHostStub::GetDeviceName transport failed");
704         return BT_ERR_IPC_TRANS_FAILED;
705     }
706     std::string address;
707     if (!data.ReadString(address)) {
708         HILOGE("BluetoothHostStub::GetDeviceName address failed");
709         return BT_ERR_IPC_TRANS_FAILED;
710     }
711     std::string name = "";
712     int32_t result = GetDeviceName(transport, address, name);
713     bool ret = reply.WriteInt32(result);
714     if (!ret) {
715         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
716         return BT_ERR_IPC_TRANS_FAILED;
717     }
718     ret = reply.WriteString(name);
719     if (!ret) {
720         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
721         return BT_ERR_IPC_TRANS_FAILED;
722     }
723     return NO_ERROR;
724 }
725 
GetDeviceAliasInner(MessageParcel & data,MessageParcel & reply)726 ErrCode BluetoothHostStub::GetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)
727 {
728     std::string address;
729     if (!data.ReadString(address)) {
730         HILOGE("BluetoothHostStub::GetDeviceAlias address failed");
731         return TRANSACTION_ERR;
732     }
733     std::string result = GetDeviceAlias(address);
734     bool ret = reply.WriteString(result);
735     if (!ret) {
736         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
737         return TRANSACTION_ERR;
738     }
739     return NO_ERROR;
740 }
741 
IsBtDiscoveringInner(MessageParcel & data,MessageParcel & reply)742 ErrCode BluetoothHostStub::IsBtDiscoveringInner(MessageParcel &data, MessageParcel &reply)
743 {
744     int32_t transport;
745     data.ReadInt32(transport);
746     bool result = IsBtDiscovering(transport);
747     bool ret = reply.WriteBool(result);
748     if (!ret) {
749         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
750         return TRANSACTION_ERR;
751     }
752     return NO_ERROR;
753 }
754 
SetDeviceAliasInner(MessageParcel & data,MessageParcel & reply)755 ErrCode BluetoothHostStub::SetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)
756 {
757     std::string address;
758     if (!data.ReadString(address)) {
759         HILOGE("BluetoothHostStub::SetDeviceAlias address failed");
760         return TRANSACTION_ERR;
761     }
762     std::string aliasName;
763     if (!data.ReadString(aliasName)) {
764         HILOGE("BluetoothHostStub::SetDeviceAlias aliasName failed");
765         return TRANSACTION_ERR;
766     }
767     bool result = SetDeviceAlias(address, aliasName);
768     bool ret = reply.WriteBool(result);
769     if (!ret) {
770         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
771         return TRANSACTION_ERR;
772     }
773     return NO_ERROR;
774 }
775 
GetDeviceBatteryLevelInner(MessageParcel & data,MessageParcel & reply)776 ErrCode BluetoothHostStub::GetDeviceBatteryLevelInner(MessageParcel &data, MessageParcel &reply)
777 {
778     std::string address;
779     if (!data.ReadString(address)) {
780         HILOGE("BluetoothHostStub::GetDeviceBatteryLevel address failed");
781         return TRANSACTION_ERR;
782     }
783     int result = GetDeviceBatteryLevel(address);
784     bool ret = reply.WriteInt32(result);
785     if (!ret) {
786         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
787         return TRANSACTION_ERR;
788     }
789     return NO_ERROR;
790 }
791 
GetBtDiscoveryEndMillisInner(MessageParcel & data,MessageParcel & reply)792 ErrCode BluetoothHostStub::GetBtDiscoveryEndMillisInner(MessageParcel &data, MessageParcel &reply)
793 {
794     int64_t result = GetBtDiscoveryEndMillis();
795     bool ret = reply.WriteInt64(result);
796     if (!ret) {
797         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
798         return TRANSACTION_ERR;
799     }
800     return NO_ERROR;
801 }
802 
GetPairStateInner(MessageParcel & data,MessageParcel & reply)803 ErrCode BluetoothHostStub::GetPairStateInner(MessageParcel &data, MessageParcel &reply)
804 {
805     int32_t transport;
806     if (!data.ReadInt32(transport)) {
807         HILOGE("BluetoothHostStub::GetPairState transport failed");
808         return TRANSACTION_ERR;
809     }
810     std::string address;
811     if (!data.ReadString(address)) {
812         HILOGE("BluetoothHostStub::GetPairState address failed");
813         return TRANSACTION_ERR;
814     }
815     int result = GetPairState(transport, address);
816     bool ret = reply.WriteInt32(result);
817     if (!ret) {
818         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
819         return TRANSACTION_ERR;
820     }
821     return NO_ERROR;
822 }
823 
GetPairedDevicesInner(MessageParcel & data,MessageParcel & reply)824 int32_t BluetoothHostStub::GetPairedDevicesInner(MessageParcel &data, MessageParcel &reply)
825 {
826     int32_t transport = data.ReadInt32();
827     std::vector<BluetoothRawAddress> pairDevice;
828     int32_t result = GetPairedDevices(transport, pairDevice);
829     bool ret = true;
830     if (!reply.WriteInt32(pairDevice.size())) {
831         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
832         return BT_ERR_IPC_TRANS_FAILED;
833     } else {
834         for (auto device : pairDevice) {
835             reply.WriteParcelable(&device);
836         }
837     }
838     ret = reply.WriteInt32(result);
839     if (!ret) {
840         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
841         return BT_ERR_IPC_TRANS_FAILED;
842     }
843     return NO_ERROR;
844 }
845 
StartPairInner(MessageParcel & data,MessageParcel & reply)846 int32_t BluetoothHostStub::StartPairInner(MessageParcel &data, MessageParcel &reply)
847 {
848     int32_t transport;
849     if (!data.ReadInt32(transport)) {
850         HILOGE("BluetoothHostStub::StartPair transport failed");
851         return BT_ERR_IPC_TRANS_FAILED;
852     }
853     std::string address;
854     if (!data.ReadString(address)) {
855         HILOGE("BluetoothHostStub::StartPair address failed");
856         return BT_ERR_IPC_TRANS_FAILED;
857     }
858     int32_t result = StartPair(transport, address);
859     bool ret = reply.WriteInt32(result);
860     if (!ret) {
861         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
862         return BT_ERR_IPC_TRANS_FAILED;
863     }
864     return NO_ERROR;
865 }
866 
RemovePairInner(MessageParcel & data,MessageParcel & reply)867 int32_t BluetoothHostStub::RemovePairInner(MessageParcel &data, MessageParcel &reply)
868 {
869     int32_t transport = data.ReadInt32();
870     sptr<BluetoothRawAddress> device = data.ReadStrongParcelable<BluetoothRawAddress>();
871     int32_t result = RemovePair(transport, device);
872     bool ret = reply.WriteInt32(result);
873     if (!ret) {
874         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
875         return TRANSACTION_ERR;
876     }
877     return NO_ERROR;
878 }
879 
CancelPairingInner(MessageParcel & data,MessageParcel & reply)880 ErrCode BluetoothHostStub::CancelPairingInner(MessageParcel &data, MessageParcel &reply)
881 {
882     int32_t transport;
883     if (!data.ReadInt32(transport)) {
884         HILOGE("BluetoothHostStub::CancelPairing transport failed");
885         return TRANSACTION_ERR;
886     }
887     std::string address;
888     if (!data.ReadString(address)) {
889         HILOGE("BluetoothHostStub::CancelPairing address failed");
890         return TRANSACTION_ERR;
891     }
892     bool result = CancelPairing(transport, address);
893     bool ret = reply.WriteBool(result);
894     if (!ret) {
895         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
896         return TRANSACTION_ERR;
897     }
898     return NO_ERROR;
899 }
900 
RemoveAllPairsInner(MessageParcel & data,MessageParcel & reply)901 ErrCode BluetoothHostStub::RemoveAllPairsInner(MessageParcel &data, MessageParcel &reply)
902 {
903     bool result = RemoveAllPairs();
904     bool ret = reply.WriteBool(result);
905     if (!ret) {
906         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
907         return TRANSACTION_ERR;
908     }
909 
910     return NO_ERROR;
911 }
912 
IsBondedFromLocalInner(MessageParcel & data,MessageParcel & reply)913 ErrCode BluetoothHostStub::IsBondedFromLocalInner(MessageParcel &data, MessageParcel &reply)
914 {
915     int32_t transport;
916     if (!data.ReadInt32(transport)) {
917         HILOGE("BluetoothHostStub::IsBondedFromLocal transport failed");
918         return TRANSACTION_ERR;
919     }
920     std::string address;
921     if (!data.ReadString(address)) {
922         HILOGE("BluetoothHostStub::IsBondedFromLocal address failed");
923         return TRANSACTION_ERR;
924     }
925     bool result = IsBondedFromLocal(transport, address);
926     bool ret = reply.WriteBool(result);
927     if (!ret) {
928         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
929         return TRANSACTION_ERR;
930     }
931     return NO_ERROR;
932 }
933 
SetDevicePinInner(MessageParcel & data,MessageParcel & reply)934 int32_t BluetoothHostStub::SetDevicePinInner(MessageParcel &data, MessageParcel &reply)
935 {
936     std::string address;
937     if (!data.ReadString(address)) {
938         HILOGE("BluetoothHostStub::SetDevicePin address failed");
939         return BT_ERR_IPC_TRANS_FAILED;
940     }
941     std::string pin;
942     if (!data.ReadString(pin)) {
943         HILOGE("BluetoothHostStub::SetDevicePin pin failed");
944         return BT_ERR_IPC_TRANS_FAILED;
945     }
946     int32_t result = SetDevicePin(address, pin);
947     bool ret = reply.WriteInt32(result);
948     if (!ret) {
949         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
950         return BT_ERR_IPC_TRANS_FAILED;
951     }
952     return NO_ERROR;
953 }
954 
IsAclConnectedInner(MessageParcel & data,MessageParcel & reply)955 ErrCode BluetoothHostStub::IsAclConnectedInner(MessageParcel &data, MessageParcel &reply)
956 {
957     int32_t transport;
958     if (!data.ReadInt32(transport)) {
959         HILOGE("BluetoothHostStub::IsAclConnected transport failed");
960         return TRANSACTION_ERR;
961     }
962     std::string address;
963     if (!data.ReadString(address)) {
964         HILOGE("BluetoothHostStub::IsAclConnected address failed");
965         return TRANSACTION_ERR;
966     }
967     bool result = IsAclConnected(transport, address);
968     bool ret = reply.WriteBool(result);
969     if (!ret) {
970         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
971         return TRANSACTION_ERR;
972     }
973     if (!ret) {
974         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
975         return TRANSACTION_ERR;
976     }
977     return NO_ERROR;
978 }
979 
RegisterRemoteDeviceObserverInner(MessageParcel & data,MessageParcel & reply)980 ErrCode BluetoothHostStub::RegisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)
981 {
982     auto tempObject = data.ReadRemoteObject();
983     sptr<IBluetoothRemoteDeviceObserver> observer;
984     observer = iface_cast<IBluetoothRemoteDeviceObserver>(tempObject);
985     RegisterRemoteDeviceObserver(observer);
986     return NO_ERROR;
987 }
988 
DeregisterRemoteDeviceObserverInner(MessageParcel & data,MessageParcel & reply)989 ErrCode BluetoothHostStub::DeregisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)
990 {
991     auto tempObject = data.ReadRemoteObject();
992     sptr<IBluetoothRemoteDeviceObserver> observer;
993     observer = iface_cast<IBluetoothRemoteDeviceObserver>(tempObject);
994     DeregisterRemoteDeviceObserver(observer);
995     return NO_ERROR;
996 }
997 
GetBleMaxAdvertisingDataLengthInner(MessageParcel & data,MessageParcel & reply)998 ErrCode BluetoothHostStub::GetBleMaxAdvertisingDataLengthInner(MessageParcel &data, MessageParcel &reply)
999 {
1000     int32_t result = GetBleMaxAdvertisingDataLength();
1001     bool ret = reply.WriteInt32(result);
1002     if (!ret) {
1003         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1004         return TRANSACTION_ERR;
1005     }
1006     return NO_ERROR;
1007 }
1008 
IsAclEncryptedInner(MessageParcel & data,MessageParcel & reply)1009 ErrCode BluetoothHostStub::IsAclEncryptedInner(MessageParcel &data, MessageParcel &reply)
1010 {
1011     int32_t transport;
1012     if (!data.ReadInt32(transport)) {
1013         HILOGE("BluetoothHostStub::IsAclEncrypted transport failed");
1014         return TRANSACTION_ERR;
1015     }
1016     std::string address;
1017     if (!data.ReadString(address)) {
1018         HILOGE("BluetoothHostStub::IsAclEncrypted address failed");
1019         return TRANSACTION_ERR;
1020     }
1021     bool result = IsAclEncrypted(transport, address);
1022     bool ret = reply.WriteBool(result);
1023     if (!ret) {
1024         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1025         return TRANSACTION_ERR;
1026     }
1027     return NO_ERROR;
1028 }
1029 
GetDeviceClassInner(MessageParcel & data,MessageParcel & reply)1030 int32_t BluetoothHostStub::GetDeviceClassInner(MessageParcel &data, MessageParcel &reply)
1031 {
1032     std::string address;
1033     if (!data.ReadString(address)) {
1034         HILOGE("BluetoothHostStub::GetDeviceClass address failed");
1035         return BT_ERR_IPC_TRANS_FAILED;
1036     }
1037     int32_t cod = 0;
1038     int result = GetDeviceClass(address, cod);
1039     bool ret = reply.WriteInt32(result);
1040     if (!ret) {
1041         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1042         return BT_ERR_IPC_TRANS_FAILED;
1043     }
1044     ret = reply.WriteInt32(cod);
1045     if (!ret) {
1046         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1047         return BT_ERR_IPC_TRANS_FAILED;
1048     }
1049     return NO_ERROR;
1050 }
1051 
SetDevicePairingConfirmationInner(MessageParcel & data,MessageParcel & reply)1052 int32_t BluetoothHostStub::SetDevicePairingConfirmationInner(MessageParcel &data, MessageParcel &reply)
1053 {
1054     int32_t transport;
1055     if (!data.ReadInt32(transport)) {
1056         HILOGE("BluetoothHostStub::SetDevicePairingConfirmation transport failed");
1057         return BT_ERR_IPC_TRANS_FAILED;
1058     }
1059     std::string address;
1060     if (!data.ReadString(address)) {
1061         HILOGE("BluetoothHostStub::SetDevicePairingConfirmation address failed");
1062         return BT_ERR_IPC_TRANS_FAILED;
1063     }
1064     bool accept = false;
1065     if (!data.ReadBool(accept)) {
1066         HILOGE("BluetoothHostStub::SetDevicePairingConfirmation accept failed");
1067         return BT_ERR_IPC_TRANS_FAILED;
1068     }
1069     int32_t result = SetDevicePairingConfirmation(transport, address, accept);
1070     bool ret = reply.WriteInt32(result);
1071     if (!ret) {
1072         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1073         return BT_ERR_IPC_TRANS_FAILED;
1074     }
1075     return NO_ERROR;
1076 }
1077 
SetDevicePasskeyInner(MessageParcel & data,MessageParcel & reply)1078 ErrCode BluetoothHostStub::SetDevicePasskeyInner(MessageParcel &data, MessageParcel &reply)
1079 {
1080     int32_t transport;
1081     if (!data.ReadInt32(transport)) {
1082         HILOGE("BluetoothHostStub::SetDevicePasskey transport failed");
1083         return TRANSACTION_ERR;
1084     }
1085     std::string address;
1086     if (!data.ReadString(address)) {
1087         HILOGE("BluetoothHostStub::SetDevicePasskey address failed");
1088         return TRANSACTION_ERR;
1089     }
1090     int32_t passkey;
1091     if (!data.ReadInt32(passkey)) {
1092         HILOGE("BluetoothHostStub::SetDevicePasskey passkey failed");
1093         return TRANSACTION_ERR;
1094     }
1095     bool accept = false;
1096     if (!data.ReadBool(accept)) {
1097         HILOGE("BluetoothHostStub::SetDevicePasskey accept failed");
1098         return TRANSACTION_ERR;
1099     }
1100     bool result = SetDevicePasskey(transport, address, passkey, accept);
1101     bool ret = reply.WriteBool(result);
1102     if (!ret) {
1103         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1104         return TRANSACTION_ERR;
1105     }
1106     return NO_ERROR;
1107 }
1108 
PairRequestReplyInner(MessageParcel & data,MessageParcel & reply)1109 ErrCode BluetoothHostStub::PairRequestReplyInner(MessageParcel &data, MessageParcel &reply)
1110 {
1111     int32_t transport;
1112     if (!data.ReadInt32(transport)) {
1113         HILOGE("BluetoothHostStub::PairRequestReply transport failed");
1114         return TRANSACTION_ERR;
1115     }
1116     std::string address;
1117     if (!data.ReadString(address)) {
1118         HILOGE("BluetoothHostStub::PairRequestReply address failed");
1119         return TRANSACTION_ERR;
1120     }
1121     bool accept = false;
1122     if (!data.ReadBool(accept)) {
1123         HILOGE("BluetoothHostStub::PairRequestReply accept failed");
1124         return TRANSACTION_ERR;
1125     }
1126     bool result = PairRequestReply(transport, address, accept);
1127     bool ret = reply.WriteBool(result);
1128     if (!ret) {
1129         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1130         return TRANSACTION_ERR;
1131     }
1132     return NO_ERROR;
1133 }
1134 
ReadRemoteRssiValueInner(MessageParcel & data,MessageParcel & reply)1135 ErrCode BluetoothHostStub::ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply)
1136 {
1137     std::string address;
1138     if (!data.ReadString(address)) {
1139         HILOGE("BluetoothHostStub::ReadRemoteRssiValue address failed");
1140         return TRANSACTION_ERR;
1141     }
1142     bool result = ReadRemoteRssiValue(address);
1143     bool ret = reply.WriteBool(result);
1144     if (!ret) {
1145         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1146         return TRANSACTION_ERR;
1147     }
1148     return NO_ERROR;
1149 }
1150 
GetLocalSupportedUuidsInner(MessageParcel & data,MessageParcel & reply)1151 ErrCode BluetoothHostStub::GetLocalSupportedUuidsInner(MessageParcel &data, MessageParcel &reply)
1152 {
1153     std::vector<std::string> uuids;
1154     GetLocalSupportedUuids(uuids);
1155     int32_t size = uuids.size();
1156     bool ret = reply.WriteInt32(size);
1157     if (!ret) {
1158         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1159         return TRANSACTION_ERR;
1160     }
1161     for (auto uuid : uuids) {
1162         if (!reply.WriteString(uuid)) {
1163             HILOGE("BluetoothHostStub: GetLocalSupportedUuidsInner write uuid error");
1164             return TRANSACTION_ERR;
1165         }
1166     }
1167     return NO_ERROR;
1168 }
1169 
GetDeviceUuidsInner(MessageParcel & data,MessageParcel & reply)1170 ErrCode BluetoothHostStub::GetDeviceUuidsInner(MessageParcel &data, MessageParcel &reply)
1171 {
1172     std::string address;
1173     std::vector<std::string> uuids;
1174     if (!data.ReadString(address)) {
1175         HILOGE("BluetoothHostProxy::GetDeviceUuids Read address error");
1176         return TRANSACTION_ERR;
1177     }
1178     int res = GetDeviceUuids(address, uuids);
1179     int32_t size = uuids.size();
1180     bool ret = reply.WriteInt32(size);
1181     if (!ret) {
1182         HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1183         return TRANSACTION_ERR;
1184     }
1185     for (auto uuid : uuids) {
1186         if (!reply.WriteString(uuid)) {
1187             HILOGE("BluetoothHostStub: GetDeviceUuidsInner write uuid error");
1188             return TRANSACTION_ERR;
1189         }
1190     }
1191     if (!reply.WriteInt32(res)) {
1192         HILOGE("BluetoothHostStub: GetDeviceUuidsInner write result error");
1193         return TRANSACTION_ERR;
1194     }
1195     return NO_ERROR;
1196 }
1197 
GetLocalProfileUuidsInner(MessageParcel & data,MessageParcel & reply)1198 ErrCode BluetoothHostStub::GetLocalProfileUuidsInner(MessageParcel &data, MessageParcel &reply)
1199 {
1200     return NO_ERROR;
1201 }
1202 
RegisterBleAdapterObserverInner(MessageParcel & data,MessageParcel & reply)1203 ErrCode BluetoothHostStub::RegisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)
1204 {
1205     auto tempObject = data.ReadRemoteObject();
1206     sptr<IBluetoothHostObserver> observer;
1207     observer = iface_cast<IBluetoothHostObserver>(tempObject);
1208     RegisterBleAdapterObserver(observer);
1209     return NO_ERROR;
1210 }
1211 
DeregisterBleAdapterObserverInner(MessageParcel & data,MessageParcel & reply)1212 ErrCode BluetoothHostStub::DeregisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)
1213 {
1214     auto tempObject = data.ReadRemoteObject();
1215     sptr<IBluetoothHostObserver> observer;
1216     observer = iface_cast<IBluetoothHostObserver>(tempObject);
1217     DeregisterBleAdapterObserver(observer);
1218     return NO_ERROR;
1219 }
1220 
RegisterBlePeripheralCallbackInner(MessageParcel & data,MessageParcel & reply)1221 ErrCode BluetoothHostStub::RegisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)
1222 {
1223     auto tempObject = data.ReadRemoteObject();
1224     sptr<IBluetoothBlePeripheralObserver> observer;
1225     observer = iface_cast<IBluetoothBlePeripheralObserver>(tempObject);
1226     RegisterBlePeripheralCallback(observer);
1227     return NO_ERROR;
1228 }
1229 
DeregisterBlePeripheralCallbackInner(MessageParcel & data,MessageParcel & reply)1230 ErrCode BluetoothHostStub::DeregisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)
1231 {
1232     auto tempObject = data.ReadRemoteObject();
1233     sptr<IBluetoothBlePeripheralObserver> observer;
1234     observer = iface_cast<IBluetoothBlePeripheralObserver>(tempObject);
1235     DeregisterBlePeripheralCallback(observer);
1236     return NO_ERROR;
1237 }
1238 
SetFastScanInner(MessageParcel & data,MessageParcel & reply)1239 int32_t BluetoothHostStub::SetFastScanInner(MessageParcel &data, MessageParcel &reply)
1240 {
1241     return NO_ERROR;
1242 }
1243 
GetRandomAddressInner(MessageParcel & data,MessageParcel & reply)1244 ErrCode BluetoothHostStub::GetRandomAddressInner(MessageParcel &data, MessageParcel &reply)
1245 {
1246     return NO_ERROR;
1247 }
1248 
SyncRandomAddressInner(MessageParcel & data,MessageParcel & reply)1249 ErrCode BluetoothHostStub::SyncRandomAddressInner(MessageParcel &data, MessageParcel &reply)
1250 {
1251     return NO_ERROR;
1252 }
1253 }  // namespace Bluetooth
1254 }  // namespace OHOS
1255