9

I am debugging a location aware application and I would like to get a list of Geofences that are currently being monitored by the system -- even if I can only see Geofences for my own package(s). The code is using GoogleApiClient and thus FusedLocation.

I have tried adb shell dumpsys location which has an output section for "Geofences:" but it is always empty. I assume that is for legacy location/geofences/proximity.

I also tried just adb shell dumpsys and searched through that file for geofences, but I found nothing.

Both of these commands were run after starting the application and successfully adding the fences to be monitored. An example of the implementation can be found here: https://github.com/androidfu/GeofenceExample

Bill Mote
  • 12,644
  • 7
  • 58
  • 82
  • 1
    Since geofencing is a Play Services thing, not an Android thing, I am not surprised that **`adb shell dumpsys`** cannot help you. I haven't looked at the geofencing API, but if it allows you to query for outstanding registrations, you could always create a `BroadcastReceiver` that does the query and dumps the stuff to LogCat. Then, issue the broadcast from **`adb`** when you need to see the log. If you're using Android Studio, you could put that stuff in the `debug/` sourceset and not have it clutter up the release build. – CommonsWare Apr 06 '15 at 11:25
  • There is no "get", "list" or similar functionality on the GeofenceApi. Crazy. I haven't been able to construct an intent that will fire my fence receiver (but I haven't tried very hard either) ;) Thanks for the response Mark. – Bill Mote Apr 09 '15 at 13:15
  • 1
    Yeah, Google has a propensity for write-only APIs (see: `NotificationManager`, `AlarmManager`). It's very aggravating. – CommonsWare Apr 09 '15 at 13:18

1 Answers1

1

I found a way to find active geofences from this forum.

Use

adb shell service dumpsys activity service com.google.android.gms/com.google.android.location.internal.GoogleLocationManagerService

Since Geofences are handled by Google's Play Services API, it makes sense that you could find active Geofences from this service.

Some parts of the output that may be of interest to you:

View geofences registered, grouped by package:

Geofencer State:
Registered geofences:
Active Geofences:
    Package: com.google.android.gms  Tag: geotimezone, count: 4
        Geofence[CIRCLE id:time-zone-00e3f64-2 transitions:1 0.000000, 00.332665 10001260m, resp=900s, dwell=-1ms, @-1] it=5, d=UNKNOWN ? com.google.android.gms
        Geofence[CIRCLE id:time-zone-00e3f64-3 transitions:1 00.170901, 00.000000 10001260m, resp=900s, dwell=-1ms, @-1] it=5, d=UNKNOWN ? com.google.android.gms
        Geofence[CIRCLE id:time-zone-00e3f64-1 transitions:1 -00.209155, -00.000000 10001260m, resp=900s, dwell=-1ms, @-1] it=5, d=UNKNOWN ? com.google.android.gms
        Geofence[CIRCLE id:time-zone-00e3f64-0 transitions:1 0.000000, -161.714795 10001260m, resp=900s, dwell=-1ms, @-1] it=5, d=UNKNOWN ? com.google.android.gms
...

Counters (how many times certain geofence activities are registered):

Counters:
  locationRequests: 2
  locationReceived: 0
  sentinelFenceUpdatesNonChre: 0
  sentinelFenceUpdatesChre: 0
  geofenceCountMaximum: 8

  com.google.android.gms:geotimezone:
    addGeofenceRequests: 1
    removeGeofenceRequests: 0
    geofenceEnters: 0
    geofenceExits: 0
    geofenceDwells: 0
    geofenceCountMaximum: 4
    transition/initial(1/5): 8

There's a lot more to the output of this particular activity's sysdump, but I just extracted what seemed to me were the most relevant for debugging an application with geofencing capabilities.

You could probably also filter what you want with dumpsys ... | grep if that's important to you.

gorilla_glue
  • 315
  • 2
  • 13