From ab864e5c79aaef76f582f18dbb5a8017a9cf20f9 Mon Sep 17 00:00:00 2001 From: Oleksii Frolov Date: Fri, 12 Dec 2014 11:06:43 -0800 Subject: [PATCH] Fix failure connection event --- src/com/connectsdk/device/ConnectableDevice.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/connectsdk/device/ConnectableDevice.java b/src/com/connectsdk/device/ConnectableDevice.java index 74358797..a06b902e 100644 --- a/src/com/connectsdk/device/ConnectableDevice.java +++ b/src/com/connectsdk/device/ConnectableDevice.java @@ -409,7 +409,7 @@ public boolean hasCapability(String capability) { boolean hasCap = false; for (DeviceService service: services.values()) { - if ( service.hasCapability(capability) ) { + if ( service.hasCapability(capability) && service.isConnected() ) { hasCap = true; break; } @@ -947,7 +947,11 @@ public void onCapabilitiesUpdated(DeviceService service, List added, Lis DiscoveryManager.getInstance().onCapabilityUpdated(this, added, removed); } - @Override public void onConnectionFailure(DeviceService service, Error error) { + + @Override + public void onConnectionFailure(DeviceService service, Error error) { + // disconnect device if all services are not connected + onDisconnect(service, error); } @Override public void onConnectionRequired(DeviceService service) { @@ -956,7 +960,7 @@ public void onCapabilitiesUpdated(DeviceService service, List added, Lis @Override public void onConnectionSuccess(DeviceService service) { // TODO: iOS is passing to a function for when each service is ready on a device. This is not implemented on Android. - + if (isConnected()) { ConnectableDeviceStore deviceStore = DiscoveryManager.getInstance().getConnectableDeviceStore(); if (deviceStore != null) {