From 4aa7cd75fa59ec34f6e6c98761ec59ebb6fb882f Mon Sep 17 00:00:00 2001 From: Jenna Antilla <46546946+jennantilla@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:34:44 -0800 Subject: [PATCH] Update cancelLocationUpdates to check for googleApiClient connection instead of try/catch --- .../internal/controller/impl/GmsLocationController.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OneSignalSDK/onesignal/location/src/main/java/com/onesignal/location/internal/controller/impl/GmsLocationController.kt b/OneSignalSDK/onesignal/location/src/main/java/com/onesignal/location/internal/controller/impl/GmsLocationController.kt index 4945393a73..e40923a88a 100644 --- a/OneSignalSDK/onesignal/location/src/main/java/com/onesignal/location/internal/controller/impl/GmsLocationController.kt +++ b/OneSignalSDK/onesignal/location/src/main/java/com/onesignal/location/internal/controller/impl/GmsLocationController.kt @@ -231,10 +231,10 @@ internal class GmsLocationController( googleApiClient: GoogleApiClient, locationListener: LocationListener, ) { - try { + if (googleApiClient.isConnected) { LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, locationListener) - } catch (e: IllegalStateException) { - Logging.warn("Caught IllegalStateException in cancelLocationUpdates", e) + } else { + Logging.warn("GoogleApiClient is not connected. Unable to cancel location updates.") } }