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 {BluetoothHostInterfaceCode::START_CREDIBLE_PAIR,
225 std::bind(&BluetoothHostStub::StartCrediblePairInner, std::placeholders::_1, std::placeholders::_2,
226 std::placeholders::_3)},
227 {BluetoothHostInterfaceCode::BT_COUNT_ENABLE_TIMES,
228 std::bind(&BluetoothHostStub::CountEnableTimesInner, std::placeholders::_1, std::placeholders::_2,
229 std::placeholders::_3)},
230 {BluetoothHostInterfaceCode::CONNECT_ALLOWED_PROFILES,
231 std::bind(&BluetoothHostStub::ConnectAllowedProfilesInner, std::placeholders::_1, std::placeholders::_2,
232 std::placeholders::_3)},
233 {BluetoothHostInterfaceCode::DISCONNECT_ALLOWED_PROFILES,
234 std::bind(&BluetoothHostStub::DisconnectAllowedProfilesInner, std::placeholders::_1, std::placeholders::_2,
235 std::placeholders::_3)},
236 };
237
BluetoothHostStub()238 BluetoothHostStub::BluetoothHostStub(){};
~BluetoothHostStub()239 BluetoothHostStub::~BluetoothHostStub()
240 {}
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)241 int32_t BluetoothHostStub::OnRemoteRequest(
242 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
243 {
244 HILOGI("BluetoothHostStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
245 if (BluetoothHostStub::GetDescriptor() != data.ReadInterfaceToken()) {
246 HILOGE("BluetoothHostStub::OnRemoteRequest, local descriptor is not equal to remote");
247 return ERR_INVALID_STATE;
248 }
249 auto itFunc = memberFuncMap_.find(code);
250 if (itFunc != memberFuncMap_.end()) {
251 auto memberFunc = itFunc->second;
252 if (memberFunc != nullptr) {
253 return memberFunc(this, data, reply);
254 }
255 }
256 HILOGW("BluetoothHostStub::OnRemoteRequest, default case, need check.");
257 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
258 }
259
RegisterObserverInner(MessageParcel & data,MessageParcel & reply)260 ErrCode BluetoothHostStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
261 {
262 HILOGI("BluetoothHostStub::RegisterObserverInner starts");
263 sptr<IRemoteObject> remote = data.ReadRemoteObject();
264 const sptr<IBluetoothHostObserver> observer = OHOS::iface_cast<IBluetoothHostObserver>(remote);
265 RegisterObserver(observer);
266 return NO_ERROR;
267 }
268
DeregisterObserverInner(MessageParcel & data,MessageParcel & reply)269 ErrCode BluetoothHostStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
270 {
271 HILOGI("BluetoothHostStub::DeregisterObserverInner starts");
272 sptr<IRemoteObject> remote = data.ReadRemoteObject();
273 const sptr<IBluetoothHostObserver> observer = OHOS::iface_cast<IBluetoothHostObserver>(remote);
274 DeregisterObserver(observer);
275 return NO_ERROR;
276 }
277
EnableBtInner(MessageParcel & data,MessageParcel & reply)278 int32_t BluetoothHostStub::EnableBtInner(MessageParcel &data, MessageParcel &reply)
279 {
280 int32_t result = EnableBt();
281 bool ret = reply.WriteInt32(result);
282 if (!ret) {
283 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
284 return ERR_INVALID_VALUE;
285 }
286 return NO_ERROR;
287 }
288
DisableBtInner(MessageParcel & data,MessageParcel & reply)289 int32_t BluetoothHostStub::DisableBtInner(MessageParcel &data, MessageParcel &reply)
290 {
291 int32_t result = DisableBt();
292 bool ret = reply.WriteInt32(result);
293 if (!ret) {
294 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
295 return BT_ERR_IPC_TRANS_FAILED;
296 }
297 return NO_ERROR;
298 }
299
GetProfileInner(MessageParcel & data,MessageParcel & reply)300 ErrCode BluetoothHostStub::GetProfileInner(MessageParcel &data, MessageParcel &reply)
301 {
302 HILOGI("BluetoothHostStub::GetProfileInner starts");
303 std::string name = data.ReadString();
304 sptr<IRemoteObject> result = GetProfile(name);
305 bool ret = reply.WriteRemoteObject(result);
306 if (!ret) {
307 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
308 return TRANSACTION_ERR;
309 }
310 return NO_ERROR;
311 }
312
GetBleRemoteInner(MessageParcel & data,MessageParcel & reply)313 ErrCode BluetoothHostStub::GetBleRemoteInner(MessageParcel &data, MessageParcel &reply)
314 {
315 HILOGI("BluetoothHostStub::GetBleRemoteInner starts");
316 std::string name = data.ReadString();
317 sptr<IRemoteObject> result = GetBleRemote(name);
318 bool ret = reply.WriteRemoteObject(result);
319 if (!ret) {
320 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
321 return TRANSACTION_ERR;
322 }
323 return NO_ERROR;
324 }
325
BluetoothFactoryResetInner(MessageParcel & data,MessageParcel & reply)326 int32_t BluetoothHostStub::BluetoothFactoryResetInner(MessageParcel &data, MessageParcel &reply)
327 {
328 int32_t result = BluetoothFactoryReset();
329 bool ret = reply.WriteInt32(result);
330 if (!ret) {
331 HILOGE("WriteInt32 failed");
332 return ERR_INVALID_VALUE;
333 }
334 return NO_ERROR;
335 }
336
GetBtStateInner(MessageParcel & data,MessageParcel & reply)337 ErrCode BluetoothHostStub::GetBtStateInner(MessageParcel &data, MessageParcel &reply)
338 {
339 HILOGI("BluetoothHostStub::GetBtStateInner starts");
340 int32_t state = 0;
341 int32_t result = GetBtState(state);
342 (void)reply.WriteInt32(result);
343 (void)reply.WriteInt32(state);
344 return NO_ERROR;
345 }
346
GetLocalAddressInner(MessageParcel & data,MessageParcel & reply)347 int32_t BluetoothHostStub::GetLocalAddressInner(MessageParcel &data, MessageParcel &reply)
348 {
349 std::string addr = "00:00:00:00:00:00";
350 int32_t result = GetLocalAddress(addr);
351
352 CHECK_AND_RETURN_LOG_RET(reply.WriteInt32(result), BT_ERR_IPC_TRANS_FAILED, "writing res failed");
353 CHECK_AND_RETURN_LOG_RET((result == BT_NO_ERROR), NO_ERROR, "get local addr failed");
354 CHECK_AND_RETURN_LOG_RET(reply.WriteString(addr), BT_ERR_IPC_TRANS_FAILED, "writing addr failed");
355 return NO_ERROR;
356 }
357
DisableBleInner(MessageParcel & data,MessageParcel & reply)358 int32_t BluetoothHostStub::DisableBleInner(MessageParcel &data, MessageParcel &reply)
359 {
360 int32_t result = DisableBle();
361 bool ret = reply.WriteInt32(result);
362 if (!ret) {
363 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
364 return BT_ERR_IPC_TRANS_FAILED;
365 }
366 return NO_ERROR;
367 }
368
EnableBleInner(MessageParcel & data,MessageParcel & reply)369 int32_t BluetoothHostStub::EnableBleInner(MessageParcel &data, MessageParcel &reply)
370 {
371 int32_t result = EnableBle();
372 bool ret = reply.WriteInt32(result);
373 if (!ret) {
374 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
375 return BT_ERR_IPC_TRANS_FAILED;
376 }
377 return NO_ERROR;
378 }
379
IsBrEnabledInner(MessageParcel & data,MessageParcel & reply)380 ErrCode BluetoothHostStub::IsBrEnabledInner(MessageParcel &data, MessageParcel &reply)
381 {
382 bool result = IsBrEnabled();
383 bool ret = reply.WriteBool(result);
384 if (!ret) {
385 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
386 return TRANSACTION_ERR;
387 }
388 return NO_ERROR;
389 }
390
IsBleEnabledInner(MessageParcel & data,MessageParcel & reply)391 ErrCode BluetoothHostStub::IsBleEnabledInner(MessageParcel &data, MessageParcel &reply)
392 {
393 bool result = IsBleEnabled();
394 bool ret = reply.WriteBool(result);
395 if (!ret) {
396 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
397 return TRANSACTION_ERR;
398 }
399 return NO_ERROR;
400 }
401
GetProfileListInner(MessageParcel & data,MessageParcel & reply)402 ErrCode BluetoothHostStub::GetProfileListInner(MessageParcel &data, MessageParcel &reply)
403 {
404 std::vector<uint32_t> result = GetProfileList();
405 bool ret = reply.WriteUInt32Vector(result);
406 if (!ret) {
407 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
408 return TRANSACTION_ERR;
409 }
410 return NO_ERROR;
411 }
412
GetMaxNumConnectedAudioDevicesInner(MessageParcel & data,MessageParcel & reply)413 ErrCode BluetoothHostStub::GetMaxNumConnectedAudioDevicesInner(MessageParcel &data, MessageParcel &reply)
414 {
415 int32_t result = GetMaxNumConnectedAudioDevices();
416 bool ret = reply.WriteInt32(result);
417 if (!ret) {
418 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
419 return TRANSACTION_ERR;
420 }
421 return NO_ERROR;
422 }
423
GetBtConnectionStateInner(MessageParcel & data,MessageParcel & reply)424 int32_t BluetoothHostStub::GetBtConnectionStateInner(MessageParcel &data, MessageParcel &reply)
425 {
426 HILOGI("BluetoothHostStub::GetBtConnectionStateInner starts");
427 int32_t state = 0;
428 int32_t result = GetBtConnectionState(state);
429 bool ret = reply.WriteInt32(result);
430 if (!ret) {
431 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
432 return BT_ERR_IPC_TRANS_FAILED;
433 }
434 ret = reply.WriteInt32(state);
435 if (!ret) {
436 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
437 return BT_ERR_IPC_TRANS_FAILED;
438 }
439 return NO_ERROR;
440 }
441
GetBtProfileConnStateInner(MessageParcel & data,MessageParcel & reply)442 int32_t BluetoothHostStub::GetBtProfileConnStateInner(MessageParcel &data, MessageParcel &reply)
443 {
444 uint32_t profileId;
445 data.ReadUint32(profileId);
446 int32_t state = 0;
447 int32_t result = GetBtProfileConnState(profileId, state);
448 bool ret = reply.WriteInt32(result);
449 if (!ret) {
450 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
451 return BT_ERR_IPC_TRANS_FAILED;
452 }
453 ret = reply.WriteInt32(state);
454 if (!ret) {
455 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
456 return BT_ERR_IPC_TRANS_FAILED;
457 }
458 return NO_ERROR;
459 }
460
GetLocalDeviceClassInner(MessageParcel & data,MessageParcel & reply)461 ErrCode BluetoothHostStub::GetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)
462 {
463 int32_t result = GetLocalDeviceClass();
464 bool ret = reply.WriteInt32(result);
465 if (!ret) {
466 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
467 return TRANSACTION_ERR;
468 }
469 return NO_ERROR;
470 }
471
SetLocalDeviceClassInner(MessageParcel & data,MessageParcel & reply)472 ErrCode BluetoothHostStub::SetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)
473 {
474 int32_t deviceClass;
475 data.ReadInt32(deviceClass);
476 bool result = SetLocalDeviceClass(deviceClass);
477 bool ret = reply.WriteInt32(result);
478 if (!ret) {
479 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
480 return TRANSACTION_ERR;
481 }
482 return NO_ERROR;
483 }
484
GetLocalNameInner(MessageParcel & data,MessageParcel & reply)485 int32_t BluetoothHostStub::GetLocalNameInner(MessageParcel &data, MessageParcel &reply)
486 {
487 std::string name = "";
488 int32_t result = GetLocalName(name);
489 bool ret = reply.WriteInt32(result);
490 if (!ret) {
491 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
492 return BT_ERR_IPC_TRANS_FAILED;
493 }
494 ret = reply.WriteString(name);
495 if (!ret) {
496 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
497 return BT_ERR_IPC_TRANS_FAILED;
498 }
499 return NO_ERROR;
500 }
501
SetLocalNameInner(MessageParcel & data,MessageParcel & reply)502 int32_t BluetoothHostStub::SetLocalNameInner(MessageParcel &data, MessageParcel &reply)
503 {
504 std::string name;
505 data.ReadString(name);
506 int32_t result = SetLocalName(name);
507 bool ret = reply.WriteInt32(result);
508 if (!ret) {
509 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
510 return BT_ERR_IPC_TRANS_FAILED;
511 }
512
513 return NO_ERROR;
514 }
515
GetDeviceTypeInner(MessageParcel & data,MessageParcel & reply)516 ErrCode BluetoothHostStub::GetDeviceTypeInner(MessageParcel &data, MessageParcel &reply)
517 {
518 int32_t transport;
519 if (!data.ReadInt32(transport)) {
520 HILOGE("BluetoothHostStub::GetDeviceType transport failed");
521 return TRANSACTION_ERR;
522 }
523 std::string address;
524 if (!data.ReadString(address)) {
525 HILOGE("BluetoothHostStub::GetDeviceType address failed");
526 return TRANSACTION_ERR;
527 }
528 int result = GetDeviceType(transport, address);
529 bool ret = reply.WriteInt32(result);
530 if (!ret) {
531 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
532 return ERR_INVALID_VALUE;
533 }
534 return NO_ERROR;
535 }
536
GetBtScanModeInner(MessageParcel & data,MessageParcel & reply)537 int32_t BluetoothHostStub::GetBtScanModeInner(MessageParcel &data, MessageParcel &reply)
538 {
539 int32_t scanMode = 0;
540 int32_t result = GetBtScanMode(scanMode);
541 bool ret = reply.WriteInt32(result);
542 if (!ret) {
543 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
544 return BT_ERR_IPC_TRANS_FAILED;
545 }
546 ret = reply.WriteInt32(scanMode);
547 if (!ret) {
548 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
549 return BT_ERR_IPC_TRANS_FAILED;
550 }
551 return NO_ERROR;
552 }
553
GetPhonebookPermissionInner(MessageParcel & data,MessageParcel & reply)554 ErrCode BluetoothHostStub::GetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)
555 {
556 std::string address;
557 if (!data.ReadString(address)) {
558 HILOGE("BluetoothHostStub::GetPhonebookPermission address failed");
559 return TRANSACTION_ERR;
560 }
561 int result = GetPhonebookPermission(address);
562 bool ret = reply.WriteInt32(result);
563 if (!ret) {
564 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
565 return TRANSACTION_ERR;
566 }
567 return NO_ERROR;
568 }
569
SetBtScanModeInner(MessageParcel & data,MessageParcel & reply)570 int32_t BluetoothHostStub::SetBtScanModeInner(MessageParcel &data, MessageParcel &reply)
571 {
572 int32_t mode;
573 data.ReadInt32(mode);
574 int32_t duration;
575 data.ReadInt32(duration);
576 int32_t result = SetBtScanMode(mode, duration);
577 bool ret = reply.WriteInt32(result);
578 if (!ret) {
579 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
580 return BT_ERR_IPC_TRANS_FAILED;
581 }
582 return NO_ERROR;
583 }
584
SetPhonebookPermissionInner(MessageParcel & data,MessageParcel & reply)585 ErrCode BluetoothHostStub::SetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)
586 {
587 std::string address;
588 if (!data.ReadString(address)) {
589 HILOGE("BluetoothHostStub::SetPhonebookPermission address failed");
590 return TRANSACTION_ERR;
591 }
592 int32_t permission;
593 if (!data.ReadInt32(permission)) {
594 HILOGE("BluetoothHostStub::SetPhonebookPermission permission failed");
595 return TRANSACTION_ERR;
596 }
597 bool result = SetPhonebookPermission(address, permission);
598 bool ret = reply.WriteBool(result);
599 if (!ret) {
600 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
601 return ERR_INVALID_VALUE;
602 }
603 return NO_ERROR;
604 }
605
GetBondableModeInner(MessageParcel & data,MessageParcel & reply)606 ErrCode BluetoothHostStub::GetBondableModeInner(MessageParcel &data, MessageParcel &reply)
607 {
608 int32_t transport;
609 data.ReadInt32(transport);
610 int32_t result = GetBondableMode(transport);
611 bool ret = reply.WriteInt32(result);
612 if (!ret) {
613 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
614 return TRANSACTION_ERR;
615 }
616 return NO_ERROR;
617 }
GetMessagePermissionInner(MessageParcel & data,MessageParcel & reply)618 ErrCode BluetoothHostStub::GetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)
619 {
620 std::string address;
621 if (!data.ReadString(address)) {
622 HILOGE("BluetoothHostStub::GetMessagePermission address failed");
623 return TRANSACTION_ERR;
624 }
625 int result = GetMessagePermission(address);
626 bool ret = reply.WriteInt32(result);
627 if (!ret) {
628 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
629 return TRANSACTION_ERR;
630 }
631 return NO_ERROR;
632 }
633
SetBondableModeInner(MessageParcel & data,MessageParcel & reply)634 ErrCode BluetoothHostStub::SetBondableModeInner(MessageParcel &data, MessageParcel &reply)
635 {
636 int32_t transport;
637 data.ReadInt32(transport);
638 int32_t mode;
639 data.ReadInt32(mode);
640
641 bool result = SetBondableMode(transport, mode);
642 bool ret = reply.WriteInt32(result);
643 if (!ret) {
644 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
645 return ERR_INVALID_VALUE;
646 }
647 return NO_ERROR;
648 }
649
SetMessagePermissionInner(MessageParcel & data,MessageParcel & reply)650 ErrCode BluetoothHostStub::SetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)
651 {
652 std::string address;
653 if (!data.ReadString(address)) {
654 HILOGE("BluetoothHostStub::SetMessagePermission address failed");
655 return TRANSACTION_ERR;
656 }
657 int32_t permission;
658 if (!data.ReadInt32(permission)) {
659 HILOGE("BluetoothHostStub::SetMessagePermission permission failed");
660 return TRANSACTION_ERR;
661 }
662 bool result = SetMessagePermission(address, permission);
663 bool ret = reply.WriteBool(result);
664 if (!ret) {
665 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
666 return TRANSACTION_ERR;
667 }
668 return NO_ERROR;
669 }
670
GetPowerModeInner(MessageParcel & data,MessageParcel & reply)671 ErrCode BluetoothHostStub::GetPowerModeInner(MessageParcel &data, MessageParcel &reply)
672 {
673 std::string address;
674 if (!data.ReadString(address)) {
675 HILOGE("BluetoothHostStub::GetPowerMode address failed");
676 return TRANSACTION_ERR;
677 }
678 int result = GetPowerMode(address);
679 bool ret = reply.WriteInt32(result);
680 if (!ret) {
681 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
682 return TRANSACTION_ERR;
683 }
684 return NO_ERROR;
685 }
686
StartBtDiscoveryInner(MessageParcel & data,MessageParcel & reply)687 int32_t BluetoothHostStub::StartBtDiscoveryInner(MessageParcel &data, MessageParcel &reply)
688 {
689 int32_t result = StartBtDiscovery();
690 bool ret = reply.WriteInt32(result);
691 if (!ret) {
692 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
693 return BT_ERR_IPC_TRANS_FAILED;
694 }
695 return NO_ERROR;
696 }
697
CancelBtDiscoveryInner(MessageParcel & data,MessageParcel & reply)698 int32_t BluetoothHostStub::CancelBtDiscoveryInner(MessageParcel &data, MessageParcel &reply)
699 {
700 int32_t result = CancelBtDiscovery();
701 bool ret = reply.WriteInt32(result);
702 if (!ret) {
703 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
704 return BT_ERR_IPC_TRANS_FAILED;
705 }
706 return NO_ERROR;
707 }
708
GetDeviceNameInner(MessageParcel & data,MessageParcel & reply)709 int32_t BluetoothHostStub::GetDeviceNameInner(MessageParcel &data, MessageParcel &reply)
710 {
711 int32_t transport;
712 if (!data.ReadInt32(transport)) {
713 HILOGE("BluetoothHostStub::GetDeviceName transport failed");
714 return BT_ERR_IPC_TRANS_FAILED;
715 }
716 std::string address;
717 if (!data.ReadString(address)) {
718 HILOGE("BluetoothHostStub::GetDeviceName address failed");
719 return BT_ERR_IPC_TRANS_FAILED;
720 }
721 std::string name = "";
722 int32_t result = GetDeviceName(transport, address, name);
723 bool ret = reply.WriteInt32(result);
724 if (!ret) {
725 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
726 return BT_ERR_IPC_TRANS_FAILED;
727 }
728 ret = reply.WriteString(name);
729 if (!ret) {
730 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
731 return BT_ERR_IPC_TRANS_FAILED;
732 }
733 return NO_ERROR;
734 }
735
GetDeviceAliasInner(MessageParcel & data,MessageParcel & reply)736 ErrCode BluetoothHostStub::GetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)
737 {
738 std::string address;
739 if (!data.ReadString(address)) {
740 HILOGE("BluetoothHostStub::GetDeviceAlias address failed");
741 return TRANSACTION_ERR;
742 }
743 std::string result = GetDeviceAlias(address);
744 bool ret = reply.WriteString(result);
745 if (!ret) {
746 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
747 return TRANSACTION_ERR;
748 }
749 return NO_ERROR;
750 }
751
IsBtDiscoveringInner(MessageParcel & data,MessageParcel & reply)752 ErrCode BluetoothHostStub::IsBtDiscoveringInner(MessageParcel &data, MessageParcel &reply)
753 {
754 bool isDiscovering = false;
755 int32_t transport;
756 data.ReadInt32(transport);
757 int32_t result = IsBtDiscovering(isDiscovering, transport);
758 bool ret = reply.WriteInt32(result);
759 if (!ret) {
760 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
761 return BT_ERR_IPC_TRANS_FAILED;
762 }
763 ret = reply.WriteBool(isDiscovering);
764 if (!ret) {
765 HILOGE("BluetoothHostStub: reply isDiscovering writing failed in: %{public}s.", __func__);
766 return BT_ERR_IPC_TRANS_FAILED;
767 }
768 return BT_NO_ERROR;
769 }
770
SetDeviceAliasInner(MessageParcel & data,MessageParcel & reply)771 ErrCode BluetoothHostStub::SetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)
772 {
773 std::string address;
774 if (!data.ReadString(address)) {
775 HILOGE("BluetoothHostStub::SetDeviceAlias address failed");
776 return TRANSACTION_ERR;
777 }
778 std::string aliasName;
779 if (!data.ReadString(aliasName)) {
780 HILOGE("BluetoothHostStub::SetDeviceAlias aliasName failed");
781 return TRANSACTION_ERR;
782 }
783 bool result = SetDeviceAlias(address, aliasName);
784 bool ret = reply.WriteBool(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
GetDeviceBatteryLevelInner(MessageParcel & data,MessageParcel & reply)792 ErrCode BluetoothHostStub::GetDeviceBatteryLevelInner(MessageParcel &data, MessageParcel &reply)
793 {
794 std::string address;
795 if (!data.ReadString(address)) {
796 HILOGE("BluetoothHostStub::GetDeviceBatteryLevel address failed");
797 return TRANSACTION_ERR;
798 }
799 int result = GetDeviceBatteryLevel(address);
800 bool ret = reply.WriteInt32(result);
801 if (!ret) {
802 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
803 return TRANSACTION_ERR;
804 }
805 return NO_ERROR;
806 }
807
GetBtDiscoveryEndMillisInner(MessageParcel & data,MessageParcel & reply)808 ErrCode BluetoothHostStub::GetBtDiscoveryEndMillisInner(MessageParcel &data, MessageParcel &reply)
809 {
810 int64_t result = GetBtDiscoveryEndMillis();
811 bool ret = reply.WriteInt64(result);
812 if (!ret) {
813 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
814 return TRANSACTION_ERR;
815 }
816 return NO_ERROR;
817 }
818
GetPairStateInner(MessageParcel & data,MessageParcel & reply)819 ErrCode BluetoothHostStub::GetPairStateInner(MessageParcel &data, MessageParcel &reply)
820 {
821 int32_t transport;
822 if (!data.ReadInt32(transport)) {
823 HILOGE("BluetoothHostStub::GetPairState transport failed");
824 return TRANSACTION_ERR;
825 }
826 std::string address;
827 if (!data.ReadString(address)) {
828 HILOGE("BluetoothHostStub::GetPairState address failed");
829 return TRANSACTION_ERR;
830 }
831 int32_t pairState;
832 int result = GetPairState(transport, address, pairState);
833 bool ret = reply.WriteInt32(result);
834 if (!ret) {
835 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
836 return BT_ERR_IPC_TRANS_FAILED;
837 }
838 ret = reply.WriteInt32(pairState);
839 if (!ret) {
840 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
841 return BT_ERR_IPC_TRANS_FAILED;
842 }
843 return BT_NO_ERROR;
844 }
845
GetPairedDevicesInner(MessageParcel & data,MessageParcel & reply)846 int32_t BluetoothHostStub::GetPairedDevicesInner(MessageParcel &data, MessageParcel &reply)
847 {
848 std::vector<BluetoothRawAddress> pairDevice;
849 int32_t result = GetPairedDevices(pairDevice);
850 bool ret = true;
851 if (!reply.WriteInt32(pairDevice.size())) {
852 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
853 return BT_ERR_IPC_TRANS_FAILED;
854 } else {
855 for (auto device : pairDevice) {
856 reply.WriteParcelable(&device);
857 }
858 }
859 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
StartPairInner(MessageParcel & data,MessageParcel & reply)867 int32_t BluetoothHostStub::StartPairInner(MessageParcel &data, MessageParcel &reply)
868 {
869 int32_t transport;
870 if (!data.ReadInt32(transport)) {
871 HILOGE("BluetoothHostStub::StartPair transport failed");
872 return BT_ERR_IPC_TRANS_FAILED;
873 }
874 std::string address;
875 if (!data.ReadString(address)) {
876 HILOGE("BluetoothHostStub::StartPair address failed");
877 return BT_ERR_IPC_TRANS_FAILED;
878 }
879 int32_t result = StartPair(transport, address);
880 bool ret = reply.WriteInt32(result);
881 if (!ret) {
882 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
883 return BT_ERR_IPC_TRANS_FAILED;
884 }
885 return NO_ERROR;
886 }
887
RemovePairInner(MessageParcel & data,MessageParcel & reply)888 int32_t BluetoothHostStub::RemovePairInner(MessageParcel &data, MessageParcel &reply)
889 {
890 int32_t transport = data.ReadInt32();
891 sptr<BluetoothRawAddress> device = data.ReadStrongParcelable<BluetoothRawAddress>();
892 int32_t result = RemovePair(transport, device);
893 bool ret = reply.WriteInt32(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
CancelPairingInner(MessageParcel & data,MessageParcel & reply)901 ErrCode BluetoothHostStub::CancelPairingInner(MessageParcel &data, MessageParcel &reply)
902 {
903 int32_t transport;
904 if (!data.ReadInt32(transport)) {
905 HILOGE("BluetoothHostStub::CancelPairing transport failed");
906 return TRANSACTION_ERR;
907 }
908 std::string address;
909 if (!data.ReadString(address)) {
910 HILOGE("BluetoothHostStub::CancelPairing address failed");
911 return TRANSACTION_ERR;
912 }
913 bool result = CancelPairing(transport, address);
914 bool ret = reply.WriteBool(result);
915 if (!ret) {
916 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
917 return TRANSACTION_ERR;
918 }
919 return NO_ERROR;
920 }
921
RemoveAllPairsInner(MessageParcel & data,MessageParcel & reply)922 ErrCode BluetoothHostStub::RemoveAllPairsInner(MessageParcel &data, MessageParcel &reply)
923 {
924 bool result = RemoveAllPairs();
925 bool ret = reply.WriteBool(result);
926 if (!ret) {
927 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
928 return TRANSACTION_ERR;
929 }
930
931 return NO_ERROR;
932 }
933
IsBondedFromLocalInner(MessageParcel & data,MessageParcel & reply)934 ErrCode BluetoothHostStub::IsBondedFromLocalInner(MessageParcel &data, MessageParcel &reply)
935 {
936 int32_t transport;
937 if (!data.ReadInt32(transport)) {
938 HILOGE("BluetoothHostStub::IsBondedFromLocal transport failed");
939 return TRANSACTION_ERR;
940 }
941 std::string address;
942 if (!data.ReadString(address)) {
943 HILOGE("BluetoothHostStub::IsBondedFromLocal address failed");
944 return TRANSACTION_ERR;
945 }
946 bool result = IsBondedFromLocal(transport, address);
947 bool ret = reply.WriteBool(result);
948 if (!ret) {
949 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
950 return TRANSACTION_ERR;
951 }
952 return NO_ERROR;
953 }
954
SetDevicePinInner(MessageParcel & data,MessageParcel & reply)955 int32_t BluetoothHostStub::SetDevicePinInner(MessageParcel &data, MessageParcel &reply)
956 {
957 std::string address;
958 if (!data.ReadString(address)) {
959 HILOGE("BluetoothHostStub::SetDevicePin address failed");
960 return BT_ERR_IPC_TRANS_FAILED;
961 }
962 std::string pin;
963 if (!data.ReadString(pin)) {
964 HILOGE("BluetoothHostStub::SetDevicePin pin failed");
965 return BT_ERR_IPC_TRANS_FAILED;
966 }
967 int32_t result = SetDevicePin(address, pin);
968 bool ret = reply.WriteInt32(result);
969 if (!ret) {
970 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
971 return BT_ERR_IPC_TRANS_FAILED;
972 }
973 return NO_ERROR;
974 }
975
IsAclConnectedInner(MessageParcel & data,MessageParcel & reply)976 ErrCode BluetoothHostStub::IsAclConnectedInner(MessageParcel &data, MessageParcel &reply)
977 {
978 int32_t transport;
979 if (!data.ReadInt32(transport)) {
980 HILOGE("BluetoothHostStub::IsAclConnected transport failed");
981 return TRANSACTION_ERR;
982 }
983 std::string address;
984 if (!data.ReadString(address)) {
985 HILOGE("BluetoothHostStub::IsAclConnected address failed");
986 return TRANSACTION_ERR;
987 }
988 bool result = IsAclConnected(transport, address);
989 bool ret = reply.WriteBool(result);
990 if (!ret) {
991 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
992 return TRANSACTION_ERR;
993 }
994 if (!ret) {
995 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
996 return TRANSACTION_ERR;
997 }
998 return NO_ERROR;
999 }
1000
RegisterRemoteDeviceObserverInner(MessageParcel & data,MessageParcel & reply)1001 ErrCode BluetoothHostStub::RegisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)
1002 {
1003 auto tempObject = data.ReadRemoteObject();
1004 sptr<IBluetoothRemoteDeviceObserver> observer;
1005 observer = iface_cast<IBluetoothRemoteDeviceObserver>(tempObject);
1006 RegisterRemoteDeviceObserver(observer);
1007 return NO_ERROR;
1008 }
1009
DeregisterRemoteDeviceObserverInner(MessageParcel & data,MessageParcel & reply)1010 ErrCode BluetoothHostStub::DeregisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)
1011 {
1012 auto tempObject = data.ReadRemoteObject();
1013 sptr<IBluetoothRemoteDeviceObserver> observer;
1014 observer = iface_cast<IBluetoothRemoteDeviceObserver>(tempObject);
1015 DeregisterRemoteDeviceObserver(observer);
1016 return NO_ERROR;
1017 }
1018
GetBleMaxAdvertisingDataLengthInner(MessageParcel & data,MessageParcel & reply)1019 ErrCode BluetoothHostStub::GetBleMaxAdvertisingDataLengthInner(MessageParcel &data, MessageParcel &reply)
1020 {
1021 int32_t result = GetBleMaxAdvertisingDataLength();
1022 bool ret = reply.WriteInt32(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
IsAclEncryptedInner(MessageParcel & data,MessageParcel & reply)1030 ErrCode BluetoothHostStub::IsAclEncryptedInner(MessageParcel &data, MessageParcel &reply)
1031 {
1032 int32_t transport;
1033 if (!data.ReadInt32(transport)) {
1034 HILOGE("BluetoothHostStub::IsAclEncrypted transport failed");
1035 return TRANSACTION_ERR;
1036 }
1037 std::string address;
1038 if (!data.ReadString(address)) {
1039 HILOGE("BluetoothHostStub::IsAclEncrypted address failed");
1040 return TRANSACTION_ERR;
1041 }
1042 bool result = IsAclEncrypted(transport, address);
1043 bool ret = reply.WriteBool(result);
1044 if (!ret) {
1045 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1046 return TRANSACTION_ERR;
1047 }
1048 return NO_ERROR;
1049 }
1050
GetDeviceClassInner(MessageParcel & data,MessageParcel & reply)1051 int32_t BluetoothHostStub::GetDeviceClassInner(MessageParcel &data, MessageParcel &reply)
1052 {
1053 std::string address;
1054 if (!data.ReadString(address)) {
1055 HILOGE("BluetoothHostStub::GetDeviceClass address failed");
1056 return BT_ERR_IPC_TRANS_FAILED;
1057 }
1058 int32_t cod = 0;
1059 int result = GetDeviceClass(address, cod);
1060 bool ret = reply.WriteInt32(result);
1061 if (!ret) {
1062 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1063 return BT_ERR_IPC_TRANS_FAILED;
1064 }
1065 ret = reply.WriteInt32(cod);
1066 if (!ret) {
1067 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1068 return BT_ERR_IPC_TRANS_FAILED;
1069 }
1070 return NO_ERROR;
1071 }
1072
SetDevicePairingConfirmationInner(MessageParcel & data,MessageParcel & reply)1073 int32_t BluetoothHostStub::SetDevicePairingConfirmationInner(MessageParcel &data, MessageParcel &reply)
1074 {
1075 int32_t transport;
1076 if (!data.ReadInt32(transport)) {
1077 HILOGE("BluetoothHostStub::SetDevicePairingConfirmation transport failed");
1078 return BT_ERR_IPC_TRANS_FAILED;
1079 }
1080 std::string address;
1081 if (!data.ReadString(address)) {
1082 HILOGE("BluetoothHostStub::SetDevicePairingConfirmation address failed");
1083 return BT_ERR_IPC_TRANS_FAILED;
1084 }
1085 bool accept = false;
1086 if (!data.ReadBool(accept)) {
1087 HILOGE("BluetoothHostStub::SetDevicePairingConfirmation accept failed");
1088 return BT_ERR_IPC_TRANS_FAILED;
1089 }
1090 int32_t result = SetDevicePairingConfirmation(transport, address, accept);
1091 bool ret = reply.WriteInt32(result);
1092 if (!ret) {
1093 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1094 return BT_ERR_IPC_TRANS_FAILED;
1095 }
1096 return NO_ERROR;
1097 }
1098
SetDevicePasskeyInner(MessageParcel & data,MessageParcel & reply)1099 ErrCode BluetoothHostStub::SetDevicePasskeyInner(MessageParcel &data, MessageParcel &reply)
1100 {
1101 int32_t transport;
1102 if (!data.ReadInt32(transport)) {
1103 HILOGE("BluetoothHostStub::SetDevicePasskey transport failed");
1104 return TRANSACTION_ERR;
1105 }
1106 std::string address;
1107 if (!data.ReadString(address)) {
1108 HILOGE("BluetoothHostStub::SetDevicePasskey address failed");
1109 return TRANSACTION_ERR;
1110 }
1111 int32_t passkey;
1112 if (!data.ReadInt32(passkey)) {
1113 HILOGE("BluetoothHostStub::SetDevicePasskey passkey failed");
1114 return TRANSACTION_ERR;
1115 }
1116 bool accept = false;
1117 if (!data.ReadBool(accept)) {
1118 HILOGE("BluetoothHostStub::SetDevicePasskey accept failed");
1119 return TRANSACTION_ERR;
1120 }
1121 bool result = SetDevicePasskey(transport, address, passkey, accept);
1122 bool ret = reply.WriteBool(result);
1123 if (!ret) {
1124 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1125 return TRANSACTION_ERR;
1126 }
1127 return NO_ERROR;
1128 }
1129
PairRequestReplyInner(MessageParcel & data,MessageParcel & reply)1130 ErrCode BluetoothHostStub::PairRequestReplyInner(MessageParcel &data, MessageParcel &reply)
1131 {
1132 int32_t transport;
1133 if (!data.ReadInt32(transport)) {
1134 HILOGE("BluetoothHostStub::PairRequestReply transport failed");
1135 return TRANSACTION_ERR;
1136 }
1137 std::string address;
1138 if (!data.ReadString(address)) {
1139 HILOGE("BluetoothHostStub::PairRequestReply address failed");
1140 return TRANSACTION_ERR;
1141 }
1142 bool accept = false;
1143 if (!data.ReadBool(accept)) {
1144 HILOGE("BluetoothHostStub::PairRequestReply accept failed");
1145 return TRANSACTION_ERR;
1146 }
1147 bool result = PairRequestReply(transport, address, accept);
1148 bool ret = reply.WriteBool(result);
1149 if (!ret) {
1150 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1151 return TRANSACTION_ERR;
1152 }
1153 return NO_ERROR;
1154 }
1155
ReadRemoteRssiValueInner(MessageParcel & data,MessageParcel & reply)1156 ErrCode BluetoothHostStub::ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply)
1157 {
1158 std::string address;
1159 if (!data.ReadString(address)) {
1160 HILOGE("BluetoothHostStub::ReadRemoteRssiValue address failed");
1161 return TRANSACTION_ERR;
1162 }
1163 bool result = ReadRemoteRssiValue(address);
1164 bool ret = reply.WriteBool(result);
1165 if (!ret) {
1166 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1167 return TRANSACTION_ERR;
1168 }
1169 return NO_ERROR;
1170 }
1171
GetLocalSupportedUuidsInner(MessageParcel & data,MessageParcel & reply)1172 ErrCode BluetoothHostStub::GetLocalSupportedUuidsInner(MessageParcel &data, MessageParcel &reply)
1173 {
1174 std::vector<std::string> uuids;
1175 GetLocalSupportedUuids(uuids);
1176 int32_t size = uuids.size();
1177 bool ret = reply.WriteInt32(size);
1178 if (!ret) {
1179 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1180 return TRANSACTION_ERR;
1181 }
1182 for (auto uuid : uuids) {
1183 if (!reply.WriteString(uuid)) {
1184 HILOGE("BluetoothHostStub: GetLocalSupportedUuidsInner write uuid error");
1185 return TRANSACTION_ERR;
1186 }
1187 }
1188 return NO_ERROR;
1189 }
1190
GetDeviceUuidsInner(MessageParcel & data,MessageParcel & reply)1191 ErrCode BluetoothHostStub::GetDeviceUuidsInner(MessageParcel &data, MessageParcel &reply)
1192 {
1193 std::string address;
1194 std::vector<std::string> uuids;
1195 if (!data.ReadString(address)) {
1196 HILOGE("BluetoothHostProxy::GetDeviceUuids Read address error");
1197 return TRANSACTION_ERR;
1198 }
1199 int res = GetDeviceUuids(address, uuids);
1200 int32_t size = uuids.size();
1201 bool ret = reply.WriteInt32(size);
1202 if (!ret) {
1203 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1204 return TRANSACTION_ERR;
1205 }
1206 for (auto uuid : uuids) {
1207 if (!reply.WriteString(uuid)) {
1208 HILOGE("BluetoothHostStub: GetDeviceUuidsInner write uuid error");
1209 return TRANSACTION_ERR;
1210 }
1211 }
1212 if (!reply.WriteInt32(res)) {
1213 HILOGE("BluetoothHostStub: GetDeviceUuidsInner write result error");
1214 return TRANSACTION_ERR;
1215 }
1216 return NO_ERROR;
1217 }
1218
GetLocalProfileUuidsInner(MessageParcel & data,MessageParcel & reply)1219 ErrCode BluetoothHostStub::GetLocalProfileUuidsInner(MessageParcel &data, MessageParcel &reply)
1220 {
1221 return NO_ERROR;
1222 }
1223
RegisterBleAdapterObserverInner(MessageParcel & data,MessageParcel & reply)1224 ErrCode BluetoothHostStub::RegisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)
1225 {
1226 auto tempObject = data.ReadRemoteObject();
1227 sptr<IBluetoothHostObserver> observer;
1228 observer = iface_cast<IBluetoothHostObserver>(tempObject);
1229 RegisterBleAdapterObserver(observer);
1230 return NO_ERROR;
1231 }
1232
DeregisterBleAdapterObserverInner(MessageParcel & data,MessageParcel & reply)1233 ErrCode BluetoothHostStub::DeregisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)
1234 {
1235 auto tempObject = data.ReadRemoteObject();
1236 sptr<IBluetoothHostObserver> observer;
1237 observer = iface_cast<IBluetoothHostObserver>(tempObject);
1238 DeregisterBleAdapterObserver(observer);
1239 return NO_ERROR;
1240 }
1241
RegisterBlePeripheralCallbackInner(MessageParcel & data,MessageParcel & reply)1242 ErrCode BluetoothHostStub::RegisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)
1243 {
1244 auto tempObject = data.ReadRemoteObject();
1245 sptr<IBluetoothBlePeripheralObserver> observer;
1246 observer = iface_cast<IBluetoothBlePeripheralObserver>(tempObject);
1247 RegisterBlePeripheralCallback(observer);
1248 return NO_ERROR;
1249 }
1250
DeregisterBlePeripheralCallbackInner(MessageParcel & data,MessageParcel & reply)1251 ErrCode BluetoothHostStub::DeregisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)
1252 {
1253 auto tempObject = data.ReadRemoteObject();
1254 sptr<IBluetoothBlePeripheralObserver> observer;
1255 observer = iface_cast<IBluetoothBlePeripheralObserver>(tempObject);
1256 DeregisterBlePeripheralCallback(observer);
1257 return NO_ERROR;
1258 }
1259
SetFastScanInner(MessageParcel & data,MessageParcel & reply)1260 int32_t BluetoothHostStub::SetFastScanInner(MessageParcel &data, MessageParcel &reply)
1261 {
1262 return NO_ERROR;
1263 }
1264
GetRandomAddressInner(MessageParcel & data,MessageParcel & reply)1265 ErrCode BluetoothHostStub::GetRandomAddressInner(MessageParcel &data, MessageParcel &reply)
1266 {
1267 return NO_ERROR;
1268 }
1269
SyncRandomAddressInner(MessageParcel & data,MessageParcel & reply)1270 ErrCode BluetoothHostStub::SyncRandomAddressInner(MessageParcel &data, MessageParcel &reply)
1271 {
1272 return NO_ERROR;
1273 }
1274
StartCrediblePairInner(MessageParcel & data,MessageParcel & reply)1275 ErrCode BluetoothHostStub::StartCrediblePairInner(MessageParcel &data, MessageParcel &reply)
1276 {
1277 std::string address = data.ReadString();
1278 int32_t transport = data.ReadInt32();
1279 int result = StartCrediblePair(transport, address);
1280 bool ret = reply.WriteInt32(result);
1281 if (!ret) {
1282 HILOGE("BluetoothHostStub: reply writing failed in: %{public}s.", __func__);
1283 }
1284 return NO_ERROR;
1285 }
1286
CountEnableTimesInner(MessageParcel & data,MessageParcel & reply)1287 ErrCode BluetoothHostStub::CountEnableTimesInner(MessageParcel &data, MessageParcel &reply)
1288 {
1289 return NO_ERROR;
1290 }
1291
ConnectAllowedProfilesInner(MessageParcel & data,MessageParcel & reply)1292 int32_t BluetoothHostStub::ConnectAllowedProfilesInner(MessageParcel &data, MessageParcel &reply)
1293 {
1294 return BT_ERR_API_NOT_SUPPORT;
1295 }
1296
DisconnectAllowedProfilesInner(MessageParcel & data,MessageParcel & reply)1297 int32_t BluetoothHostStub::DisconnectAllowedProfilesInner(MessageParcel &data, MessageParcel &reply)
1298 {
1299 return BT_ERR_API_NOT_SUPPORT;
1300 }
1301 } // namespace Bluetooth
1302 } // namespace OHOS
1303