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