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