Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand Down