[Help Wanted]: Geofence exit event is triggered multiple times
Required Reading
- [x] Confirmed
Plugin Version
4.16.1
Mobile operating-system(s)
- [ ] iOS
- [x] Android
Device Manufacturer(s) and Model(s)
Pixel 5a
Device operating-systems(s)
Android 13,14,15
What do you require assistance about?
I have released an app related to geofencing. Starting in September, I began noticing anomalies in the geofence exit events uploaded to the backend. Under certain conditions, all set geofences trigger exit events simultaneously, even though these areas are separated by as much as 100 kilometers. Since this is a production environment, I cannot obtain additional log information and can only detect this anomaly through backend data monitoring. Could you please advise on the possible causes of this issue?
[Optional] Plugin Code and/or Config
[Optional] Relevant log output
Google's play services library is completely responsible for geofencing events.
Its performance should be affected by which version of play-services you use (ext.playServicesLocationVersion).
That being said, I experienced a strange anomaly on a brand new Pixel 10 I obtained yesterday, that several others reported: the stationary geofence (that geofence created around the last known position when the SDK turns off location updates to enter the stationary state) EXIT event fired immediately after creation, even though the reported trigger location was within just a meter of the geofence center position. So I added a defensive distance check to ignore these spurious results and recreate the geofence. I suspected it would keep firing these spurious events but fortunately, it did not.
Android geofencing has been messed up for years, but this is particularly messed up: a geofence exit where the trigger location is less than a meter from the geofence center position.
It also seems device-related, since this same app with same version of play-services:location does not exhibit this phenomenon on a Pixel 6 running Android 15.
Thank you for your response. Would using the latest version of the plugin help avoid similar issues?
I just experienced another strange anomaly on Pixel 10 @ 15. Suddenly all currently-monitored geofences fired their EXIT event. I captured logs from com.google.android.gms leading up to it, which seems to indicated it did a face-plant (Scheduling restart of crashed service com.google.android.gms) before suddenly firing EXIT on all geofences.
This is a ludicrous thing for play-services to do. Clearly a bug, somehow related to newer hardware.
11-24 12:59:41.303 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.auth.trustagent.GoogleTrustAgent in 1000ms for connection
11-24 12:59:41.304 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/com.google.android.location.internal.GoogleLocationManagerService in 11000ms for start-requested
11-24 12:59:41.304 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/com.google.android.location.internal.server.HardwareArProviderService in 21000ms for connection
11-24 12:59:41.304 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.fido.authenticator.service.AuthenticatorService in 31000ms for start-requested
11-24 12:59:41.304 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.chimera.PersistentInternalBoundBrokerService in 41000ms for connection
11-24 12:59:41.304 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/com.google.android.location.reporting.service.ReportingAndroidService in 50999ms for connection
11-24 12:59:41.304 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.magictether.service.TetherService in 60999ms for start-requested
11-24 12:59:41.304 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/com.google.android.location.fused.FusedLocationService in 70999ms for connection
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.personalsafety.service.LockingTrustAgentService in 80999ms for connection
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.gcm.GcmService in 90999ms for start-requested
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.advancedprotection.service.AdvancedProtectionSyncService in 100999ms for start-requested
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.auth.setup.devicesignals.LockScreenService in 110999ms for start-requested
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/com.google.android.location.network.NetworkLocationService in 120999ms for connection
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.nearby.presence.service.LifeCycleService in 130998ms for start-requested
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.play.integrity.api.service.IntegrityApiPersistentService in 140998ms for start-requested
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.findmydevice.spot.bleadvertising.OfflineBeaconService_Persistent in 150998ms for start-requested
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.auth.trustagent.ActiveUnlockTrustAgent in 160998ms for connection
11-24 12:59:41.305 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.personalsafety.service.PersonalSafetyService in 170998ms for start-requested
11-24 12:59:41.306 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.location.provider.gnss.GnssLocationService in 180998ms for connection
11-24 12:59:41.306 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/com.google.android.contextmanager.service.ContextManagerService in 190998ms for start-requested
11-24 12:59:41.306 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.personalsafety.service.SndDetectionService in 200997ms for start-requested
11-24 12:59:41.306 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.location.persistent.LocationPersistentService in 210997ms for start-requested
11-24 12:59:41.306 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/com.google.android.location.internal.server.GoogleLocationService in 220997ms for start-requested
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.tapandpay.hce.service.TpHceService in 230997ms for connection
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.chimera.PersistentBoundBrokerService in 240997ms for connection
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.dtdi.lifecycle.LifecycleService in 250997ms for start-requested
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.thunderbird.EmergencyPersistentService in 260997ms for start-requested
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.geotimezone.GeoTimeZoneService in 270997ms for connection
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.crisisalerts.init.CrisisAlertsPersistentService in 280996ms for start-requested
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.nearby.sharing.ReceiveSurfaceService in 290996ms for start-requested
11-24 12:59:41.307 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.stats.eastworld.EastworldService in 300996ms for start-requested
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.nearby.sharing.SendSurfaceService in 310996ms for start-requested
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.chimera.PersistentApiService in 320996ms for connection
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.chimera.PersistentDirectBootAwareApiService in 330996ms for connection
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.location.geocode.GeocodeService in 340996ms for connection
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.wearable.service.WearableService in 350996ms for start-requested
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.clearcut.debug.ClearcutDebugDumpService in 360996ms for start-requested
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.home.wifipresence.WifiPresencePersistentService in 370996ms for start-requested
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.chimera.PersistentIntentOperationService in 380996ms for start-requested
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.gcm.nts.SchedulerService in 390996ms for start-requested
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.instantapps.service.InstantAppsService in 400995ms for connection
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.chimera.PersistentApiServiceNoInstantApps in 410995ms for connection
11-24 12:59:41.308 1687 1834 W ActivityManager: Scheduling restart of crashed service com.google.android.gms/.common.stats.GmsCoreStatsService in 420995ms for start-requested
11-24 12:59:41.317 1687 4279 W ActivityManager: pid 2784 com.google.android.bluetooth sent binder code 3 with flags 1 and got error -32
11-24 12:59:41.317 1687 4279 W ActivityManager: pid 32736 com.google.android.gms sent binder code 31 with flags 2 and got error -32
11-24 12:59:41.317 1687 4279 D ActivityManager: Too many transaction errors, throttling freezer binder callback.
11-24 12:59:41.349 1687 1840 I ActivityManager: Start proc 792:com.google.android.gms.persistent/u0a183 for service {com.google.android.gms/com.google.android.gms.chimera.PersistentBoundBrokerService}
11-24 12:59:41.791 1687 2494 D ActivityManager: freezing 5529 com.google.android.rkpdapp
11-24 12:59:43.536 1687 3151 W ActivityManager: Unable to start service Intent { xflg=0x4 cmp=com.google.android.apps.nest.castauth/.contentservice.CastAuthContentService } U=0: not found
11-24 12:59:44.445 1687 3151 D ActivityManager: sync unfroze 23404 com.transistorsoft.flutterbackgroundgeolocationexample for 10
11-24 12:59:44.460 1687 3151 I ActivityManager: Background started FGS: Allowed [callingPackage: com.transistorsoft.flutterbackgroundgeolocationexample; callingUid: 10352; uidState: TRNB; uidBFSL: n/a; intent: Intent { xflg=0x4 cmp=com.transistorsoft.flutterbackgroundgeolocationexample/com.transistorsoft.locationmanager.service.GeofencingService (has extras) }; code:GEOFENCING; tempAllowListReason:<null,reasonCode:GEOFENCING,duration:20000,callingUid:10183>; allowWiu:-1; targetSdkVersion:36; callerTargetSdkVersion:36; startForegroundCount:0; bindFromPackage:null: isBindService:false]
11-24 12:59:44.489 1687 3151 W ActivityManager: Foreground service started from background can not have location/camera/microphone access: service com.transistorsoft.flutterbackgroundgeolocationexample/com.transistorsoft.locationmanager.service.GeofencingService
11-24 12:59:44.497 1687 3151 D ActivityManager: sync unfroze 23784 com.transistorsoft.tslocationmanager.demo for 10
11-24 12:59:44.497 23404 23404 D TSLocationManager: [c.t.l.service.AbstractService a]
11-24 12:59:44.497 23404 23404 D TSLocationManager: 🎾 start [GeofencingService startId: 1, eventCount: 1]
11-24 12:59:44.498 1687 3151 I ActivityManager: Background started FGS: Allowed [callingPackage: com.transistorsoft.tslocationmanager.demo; callingUid: 10342; uidState: LAST; uidBFSL: n/a; intent: Intent { xflg=0x4 cmp=com.transistorsoft.tslocationmanager.demo/com.transistorsoft.locationmanager.service.GeofencingService (has extras) }; code:SYSTEM_ALLOW_LISTED; tempAllowListReason:<,reasonCode:SYSTEM_ALLOW_LISTED,duration:9223372036854775807,callingUid:-1>; allowWiu:-1; targetSdkVersion:36; callerTargetSdkVersion:36; startForegroundCount:0; bindFromPackage:null: isBindService:false]
11-24 12:59:44.499 23404 23404 D TSBackgroundFetch: - Background Fetch event received: com.transistorsoft.customtask
11-24 12:59:44.510 23404 23404 I flutter : [BackgroundFetch] received event com.transistorsoft.customtask
11-24 12:59:44.517 23404 23404 I flutter : [BackgroundFetch] count: 1343
11-24 12:59:44.523 23404 23404 D TSLocationManager: [c.t.l.logger.TSLog log] 🔔 [BackgroundFetch start] com.transistorsoft.customtask
11-24 12:59:44.525 23404 23404 D TSLocationManager: [c.t.l.logger.TSLog log] 🔔 [BackgroundFetch finish] com.transistorsoft.customtask
11-24 12:59:44.526 23404 23404 D TSBackgroundFetch: - finish: com.transistorsoft.customtask
11-24 12:59:44.526 23404 23404 D TSBackgroundFetch: - jobFinished
11-24 12:59:44.536 1687 3151 W ActivityManager: Foreground service started from background can not have location/camera/microphone access: service com.transistorsoft.tslocationmanager.demo/com.transistorsoft.locationmanager.service.GeofencingService
11-24 12:59:44.541 23784 23784 D TSLocationManager: [c.t.l.service.AbstractService start]
11-24 12:59:44.541 23784 23784 D TSLocationManager: 🎾 start [GeofencingService startId: 1, eventCount: 1]
11-24 12:59:44.544 23784 23784 I TSLocationManager: [c.t.l.d.DeviceSettings$PowerSaveChangeReceiver onReceive]
11-24 12:59:44.544 23784 23784 I TSLocationManager: 🔴 PowerSaveMode
11-24 12:59:44.578 1687 1839 D ActivityManager: sync unfroze 23435 com.google.android.apps.wellbeing for 3
11-24 12:59:44.621 23404 32553 W TSLocationManager: [c.t.l.g.TSGeofence$Builder build]
11-24 12:59:44.621 23404 32553 W TSLocationManager: ⚠️ Geofence radius: 134.0: recommended geofence radius is >= 150.0meters
11-24 12:59:44.621 23404 32553 W TSLocationManager: [c.t.l.g.TSGeofence$Builder build]
11-24 12:59:44.621 23404 32553 W TSLocationManager: ⚠️ Geofence radius: 85.0: recommended geofence radius is >= 150.0meters
11-24 12:59:44.622 23404 32553 W TSLocationManager: [c.t.l.g.TSGeofence$Builder build]
11-24 12:59:44.622 23404 32553 W TSLocationManager: ⚠️ Geofence radius: 147.0: recommended geofence radius is >= 150.0meters
11-24 12:59:44.622 23404 32553 I TSLocationManager: [c.t.l.s.GeofencingService a]
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╔═════════════════════════════════════════════
11-24 12:59:44.622 23404 32553 I TSLocationManager: ║ Geofencing Event: EXIT
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╠═════════════════════════════════════════════
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: Mtn 1
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: Mtn 2
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: Mtn 3
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: Parc Jeanne Mance
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: Marche ODA
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: Place des Arts
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: Ave Mt Royal / St. Denis
11-24 12:59:44.622 23404 32553 I TSLocationManager: ╚═════════════════════════════════════════════
11-24 12:59:44.622 23404 32553 D TSLocationManager: [c.t.l.service.AbstractService a]
11-24 12:59:44.622 23404 32553 D TSLocationManager: ⚙️︎ FINISH [GeofencingService startId: 1, eventCount: 0, sticky: false]
11-24 12:59:44.629 1687 4279 D ActivityManager: sync unfroze 5629 com.google.android.gms.ui for 6
11-24 12:59:44.655 23784 1162 W TSLocationManager: [c.t.l.g.TSGeofence$Builder build]
11-24 12:59:44.655 23784 1162 W TSLocationManager: ⚠️ Geofence radius: 92.0: recommended geofence radius is >= 150.0meters
11-24 12:59:44.655 23784 1162 I TSLocationManager: [c.t.l.s.GeofencingService handleGeofencingEvent]
11-24 12:59:44.655 23784 1162 I TSLocationManager: ╔═════════════════════════════════════════════
11-24 12:59:44.655 23784 1162 I TSLocationManager: ║ Geofencing Event: EXIT
11-24 12:59:44.655 23784 1162 I TSLocationManager: ╠═════════════════════════════════════════════
11-24 12:59:44.655 23784 1162 I TSLocationManager: ╟─ LP-1759858450laurier
11-24 12:59:44.655 23784 1162 I TSLocationManager: ╟─ LP-1759858440gamba
11-24 12:59:44.655 23784 1162 I TSLocationManager: ╟─ LP-1763913444
11-24 12:59:44.655 23784 1162 I TSLocationManager: ╟─ EXIT containing geofence of Polygon: PG-1762275600
11-24 12:59:44.655 23784 1162 I TSLocationManager: ╚═════════════════════════════════════════════
Fortunately, in the latest version 5.0.0-beta, I'd added a new attribute, in support of Polygon Geofencing, on monitored geofences called entryState (0=OUTSIDE, 1=INSIDE), which gets updated and persistd in the plugin's SQLite database whenever the device enters/exits a geofence. Therefore, it's possible for the SDK to know when a geofence EXIT event from the OS is invalid, and defensively guard against spurious events.
The log confirms the issue I encountered. I will verify it using the latest plugin. Thank you for your prompt response.
It's only available in the new 5.0.0-beta:
https://github.com/transistorsoft/flutter_background_geolocation/tree/5.0.0-beta
Got it, I've noticed the changelog. Thank you for the reminder.
Your app might just work with 5.0.0-beta. The old "flat" config is still supported (new compound config is encouraged).
The state returned by the plugin is backwards-compatible (both flat and compound).
To find the api docs for 5.0.0, you currently have to browse to them from the pub.dev page.
https://pub.dev/documentation/flutter_background_geolocation/5.0.0-beta.2/flt_background_geolocation/
There are three new readonly, persisted state attributes with Geofence in 5.0.0:
-
hits: number of times this geofence has been entered. -
entryState: when geofence ENTER event fires, this is set to1and persisted to SQLite.0on EXIT. -
stateUpdatedAt: timestamp of last event.
Regarding version 5.0.0, when creating new License Keys, should they be created under the License Keys (v4) section in the Customer Dashboard?
Yes, of course. The other tab is labelled "Legacy", which means "old".