From 5fd5c19b0ecd5bea78dd19c2e9b7e48fe4cd25c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Gwizda=C5=82a?= Date: Tue, 19 May 2026 22:34:25 +0200 Subject: [PATCH 1/2] feat(geofence): add success/failure log to Google Play Services geofence registration --- .../gms/location/geofencing/GMSGeofencingClient.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 { From a32c953bc3d026fadcec699514be4a82da2a0903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Gwizda=C5=82a?= Date: Tue, 19 May 2026 22:35:01 +0200 Subject: [PATCH 2/2] fix(geofence): cap expiration duration to prevent Long.MAX_VALUE overflow --- .../android/gms/location/geofencing/GeofencingRequest.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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..edfedb2f1c 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 @@ -1,5 +1,6 @@ package org.owntracks.android.gms.location.geofencing +import android.os.SystemClock import org.owntracks.android.location.geofencing.Geofence import org.owntracks.android.location.geofencing.GeofencingRequest @@ -24,7 +25,10 @@ fun Geofence.toGMSGeofence(): com.google.android.gms.location.Geofence { } } } - this.expirationDuration?.run(builder::setExpirationDuration) + this.expirationDuration?.run { + builder.setExpirationDuration( + minOf(this, Long.MAX_VALUE - SystemClock.elapsedRealtime())) + } this.transitionTypes?.run(builder::setTransitionTypes) this.notificationResponsiveness?.run(builder::setNotificationResponsiveness) this.loiteringDelay?.run(builder::setLoiteringDelay)