diff --git a/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GMSGeofencingClient.kt b/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GMSGeofencingClient.kt index 1da5db1de2..a0861c6162 100644 --- a/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GMSGeofencingClient.kt +++ b/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GMSGeofencingClient.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.os.Build import androidx.annotation.RequiresPermission import com.google.android.gms.location.LocationServices +import timber.log.Timber import org.owntracks.android.location.geofencing.GeofencingClient import org.owntracks.android.location.geofencing.GeofencingRequest import org.owntracks.android.services.BackgroundService @@ -15,11 +16,17 @@ class GMSGeofencingClient( ) : GeofencingClient { override fun removeGeofences(context: Context) { this.geofencingClient.removeGeofences(getPendingIntent(context)) + .addOnSuccessListener { Timber.d("Geofences removed successfully") } + .addOnFailureListener { Timber.e(it, "Failed to remove geofences") } } @RequiresPermission(anyOf = ["android.permission.ACCESS_FINE_LOCATION"]) override fun addGeofences(request: GeofencingRequest, context: Context) { - this.geofencingClient.addGeofences(request.toGMSGeofencingRequest(), getPendingIntent(context)) + val gmsRequest = request.toGMSGeofencingRequest() + Timber.d("Adding ${gmsRequest.geofences?.size ?: 0} geofences via GMS") + this.geofencingClient.addGeofences(gmsRequest, getPendingIntent(context)) + .addOnSuccessListener { Timber.i("Geofences added successfully") } + .addOnFailureListener { Timber.e(it, "Failed to add geofences") } } private fun getPendingIntent(context: Context): PendingIntent { diff --git a/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GeofencingRequest.kt b/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GeofencingRequest.kt index 103373baf2..05cdc74cff 100644 --- a/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GeofencingRequest.kt +++ b/project/app/src/gms/java/org/owntracks/android/gms/location/geofencing/GeofencingRequest.kt @@ -24,7 +24,15 @@ fun Geofence.toGMSGeofence(): com.google.android.gms.location.Geofence { } } } - this.expirationDuration?.run(builder::setExpirationDuration) + + this.expirationDuration?.run { + builder.setExpirationDuration( + if (this == org.owntracks.android.location.geofencing.Geofence.NEVER_EXPIRE) + com.google.android.gms.location.Geofence.NEVER_EXPIRE + else + this + ) + } this.transitionTypes?.run(builder::setTransitionTypes) this.notificationResponsiveness?.run(builder::setNotificationResponsiveness) this.loiteringDelay?.run(builder::setLoiteringDelay)