From cc8a4f5879b88547cdb5b1539154382c7f873852 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 6 Nov 2023 13:05:51 +0100 Subject: [PATCH 1/2] Added addOnFailureListener to prevent crashes --- geolocator_android/CHANGELOG.md | 4 ++++ .../java/com/baseflow/geolocator/errors/ErrorCodes.java | 5 +++++ .../baseflow/geolocator/location/FusedLocationClient.java | 8 ++++++++ geolocator_android/pubspec.yaml | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/geolocator_android/CHANGELOG.md b/geolocator_android/CHANGELOG.md index 2252b527..b167e9fe 100644 --- a/geolocator_android/CHANGELOG.md +++ b/geolocator_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.4.1 + +- Adds addOnFailureListener to getSettingsClient to prevent crashes. + ## 4.4.0 - Adds `color` to `ForegroundNotificationConfig` to set the color of the notification icon. diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java index cea4141e..81086b4c 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java @@ -4,6 +4,7 @@ public enum ErrorCodes { activityMissing, errorWhileAcquiringPosition, locationServicesDisabled, + locationServicesFailed, permissionDefinitionsNotFound, permissionDenied, permissionRequestInProgress; @@ -16,6 +17,8 @@ public String toString() { return "ERROR_WHILE_ACQUIRING_POSITION"; case locationServicesDisabled: return "LOCATION_SERVICES_DISABLED"; + case locationServicesFailed: + return "LOCATION_SERVICES_FAILED"; case permissionDefinitionsNotFound: return "PERMISSION_DEFINITIONS_NOT_FOUND"; case permissionDenied: @@ -35,6 +38,8 @@ public String toDescription() { return "An unexpected error occurred while trying to acquire the device's position."; case locationServicesDisabled: return "Location services are disabled. To receive location updates the location services should be enabled."; + case locationServicesFailed: + return "Location services failed."; case permissionDefinitionsNotFound: return "No location permissions are defined in the manifest. Make sure at least ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION are defined in the manifest."; case permissionDenied: diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java index 4aa640dd..6dcb6e89 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java @@ -28,6 +28,7 @@ import com.google.android.gms.location.LocationSettingsStatusCodes; import com.google.android.gms.location.Priority; import com.google.android.gms.location.SettingsClient; +import com.google.android.gms.tasks.OnFailureListener; import java.security.SecureRandom; @@ -168,6 +169,13 @@ public void isLocationServiceEnabled(LocationServiceListener listener) { } else { listener.onLocationServiceError(ErrorCodes.locationServicesDisabled); } + }) + .addOnFailureListener( + new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + listener.onLocationServiceError(ErrorCodes.locationServicesFailed); + } }); } diff --git a/geolocator_android/pubspec.yaml b/geolocator_android/pubspec.yaml index 5b98eb57..62d51482 100644 --- a/geolocator_android/pubspec.yaml +++ b/geolocator_android/pubspec.yaml @@ -2,7 +2,7 @@ name: geolocator_android description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator. repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen -version: 4.4.0 +version: 4.4.1 environment: sdk: ">=2.15.0 <4.0.0" From c6aa4cc049cbddcf441d8d24e2065fe2a533cc8e Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Mon, 6 Nov 2023 14:59:32 +0100 Subject: [PATCH 2/2] no message --- .../com/baseflow/geolocator/errors/ErrorCodes.java | 10 +++++----- .../baseflow/geolocator/location/LocationMapper.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java index 81086b4c..a8151c58 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/errors/ErrorCodes.java @@ -4,7 +4,7 @@ public enum ErrorCodes { activityMissing, errorWhileAcquiringPosition, locationServicesDisabled, - locationServicesFailed, + locationServicesFailed, permissionDefinitionsNotFound, permissionDenied, permissionRequestInProgress; @@ -17,8 +17,8 @@ public String toString() { return "ERROR_WHILE_ACQUIRING_POSITION"; case locationServicesDisabled: return "LOCATION_SERVICES_DISABLED"; - case locationServicesFailed: - return "LOCATION_SERVICES_FAILED"; + case locationServicesFailed: + return "LOCATION_SERVICES_FAILED"; case permissionDefinitionsNotFound: return "PERMISSION_DEFINITIONS_NOT_FOUND"; case permissionDenied: @@ -38,8 +38,8 @@ public String toDescription() { return "An unexpected error occurred while trying to acquire the device's position."; case locationServicesDisabled: return "Location services are disabled. To receive location updates the location services should be enabled."; - case locationServicesFailed: - return "Location services failed."; + case locationServicesFailed: + return "Location services failed."; case permissionDefinitionsNotFound: return "No location permissions are defined in the manifest. Make sure at least ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION are defined in the manifest."; case permissionDenied: diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java index 1afaf40d..eaedd60a 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java @@ -21,11 +21,11 @@ public static Map toHashMap(Location location) { if (location.hasAltitude()) position.put("altitude", location.getAltitude()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasVerticalAccuracy()) - position.put("altitude_accuracy", location.getVerticalAccuracyMeters()); + position.put("altitude_accuracy", location.getVerticalAccuracyMeters()); if (location.hasAccuracy()) position.put("accuracy", (double) location.getAccuracy()); if (location.hasBearing()) position.put("heading", (double) location.getBearing()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasBearingAccuracy()) - position.put("heading_accuracy", location.getBearingAccuracyDegrees()); + position.put("heading_accuracy", location.getBearingAccuracyDegrees()); if (location.hasSpeed()) position.put("speed", (double) location.getSpeed()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasSpeedAccuracy()) position.put("speed_accuracy", (double) location.getSpeedAccuracyMetersPerSecond());