From 1e136a12452405d752048160b0a460feffe3ab6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Duda?= Date: Wed, 17 Feb 2021 19:39:56 +0100 Subject: [PATCH] [android] disconnect device before a new connection is made (#4896) --- .../chiptool/provisioning/DeviceProvisioningFragment.kt | 1 + src/controller/CHIPDeviceController_deprecated.cpp | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt index d3a85aff3517e0..8eaa3f647ba152 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt @@ -98,6 +98,7 @@ class DeviceProvisioningFragment : Fragment() { showMessage(R.string.rendezvous_over_ble_pairing_text) deviceController.setCompletionListener(ConnectionCallback()) + deviceController.disconnectDevice(); deviceController.beginConnectDeviceBle(gatt, deviceInfo.setupPinCode); } } diff --git a/src/controller/CHIPDeviceController_deprecated.cpp b/src/controller/CHIPDeviceController_deprecated.cpp index b05aaafcae56f2..0b84b74072731a 100644 --- a/src/controller/CHIPDeviceController_deprecated.cpp +++ b/src/controller/CHIPDeviceController_deprecated.cpp @@ -176,8 +176,7 @@ bool ChipDeviceController::GetIpAddress(Inet::IPAddress & addr) if (!IsConnected()) return false; - if (mDevice == nullptr) - InitDevice(); + InitDevice(); return mDevice != nullptr && mDevice->GetIpAddress(addr); } @@ -206,10 +205,7 @@ CHIP_ERROR ChipDeviceController::SendMessage(void * appReqState, PacketBufferHan } VerifyOrExit(mRemoteDeviceId != kUndefinedNodeId, err = CHIP_ERROR_INCORRECT_STATE); - if (mDevice == nullptr) - { - SuccessOrExit(InitDevice()); - } + SuccessOrExit(InitDevice()); VerifyOrExit(mDevice != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); mDevice->SetDelegate(this);