Tracking the position of your Android phone without Google
Posted on January 16, 2018 in Smartphone • 5 min read
TL;DR: Use OwnTracks! Yes, even if it
is unmaintained and has anti-features! It works flawlessly with
Apple UnifiedNIP
backend and Nominatim Geocoder
backend (for reverse
geolocation lookup).
I recently moved to Lineage OS + microg (it’s
very cool btw, it mostly works out of the box with the whole microg
stuff!)
on my smartphone. In parallel, I was working on
infotuyo (think self-hosted
IFTTT) and home automation using
Home-Assistant, and at some point I realized it
would be awesome if I could have an estimate of my position stored online
(where I am, with a few tens of meters precision and a few minutes resolution).
I know Google is offering it out of the box if you have an Android account on your phone, but I don’t. And I don’t want anything this sensitive to be stored on Google’s servers. So my ultimate goal is to have a selfhosted system I control which could store my location and eventually pipe it to Home-Assistant or infotuyo to send me reminders when I should leave for an appointment, with itinerary, or shut power plugs at home when I leave.
Server part
First, I had to find a server part to handle the storage. I already had a NextCloud selfhosted and I came across the Phonetrack-OC NextCloud app.
It’s dumb simple (too simple sometimes) but also easy to extend. It is compatible with most clients out there and it simply does the job, so I did not look any further.
Client part
Here comes the difficult part, looking for a client to run on my Android. This was an incredibly difficult part, in part due to limitations in Android system.
UnifiedNIP
provider
First, you have to choose and setup a UnifiedNIP
provider in your microg
settings. I initially chose to use Mozilla UnifiedNIP
backend to get a
network position (much faster and battery-efficient solution than GPS, with
good enough accuracy in Paris for this use case) and Nominatim Geocoder
backend for reverse geolocation (getting address from names).
When I got into troubles finding an app to keep track of my position, I heard
that Mozilla might be throttling calls from Mozilla UnifiedNIP
backend, as
it can get quite heavy on their infrastructure. In the end, I decided to go
for the Apple UnifiedNIP
backend which should not be affected by this and
tends to give better results.
First try, uLogger
My first try was using uLogger (from F-Droid). The app had a few major issues:
- Sometimes it was crashing without reason (I guess it was when it could not fetch the position, for some reason).
- There was a setting in the app to choose which location mode one wanted to
use (GPS / network / balanced). The same settings is also available in the
system settings, and they had to match! That means I could not set
“balanced” in
uLogger
, hoping that it would use the best option available, as enabled in system settings (so that if system settings is “power saving”, it would use network and if it is “high power” it would use the GPS). - The app was logging quite erratically, throttling updates some time. I was expecting to have a point every 5 mins but it could be one hour between two successive points sometimes.
I tried to investigate it a bit, but could not find anything to fix these throttling issues (disabled “battery optimization” for the app without success, etc) and did not get feedback from the Github issues.
Second try, traccar
Traccar was really
interesting as it was a free software, available on F-Droid. Additionally, it
relies on LOST, a replacement for Google
Play services FusedLocationProvider
(the Android API to fetch user
position), written by Mapzen. It should be the perfect candidate.
However, same thing once again, the updates of positions were throttled and
sometimes I did not get a single point for a couple of hours. I could not find
any reason for this (not sure whether this is coming from LOST
or
traccar
). Moving to the next solution…
OwnTracks
In the end, I came across OwnTracks which is free but not available on F-Droid as it depends on proprietary stuff (Google Play Services and other similar libs).
Best way to get it is to clone the Git repository and then build the app locally in Android Studio. I had never touched Android development before, and it’s actually super simple to build an app from source code in Android Studio (open the project and click “Build APKs” basically). Then, you can upload it through “USB debugging” directly to your phone.
I followed closely the instructions in their booklet to maximize performance of position tracking (basically, it boils down to disabling “battery optimization”) and so far, for the last week, I got a point every 5 minutes or so (my update frequency) except when I could not obtain a location for obvious reasons (subway, airplane mode). The app seems to take great care of tracking position and is very resilient to loss of network or location. Plus, their doc is really well written.
The only downside is that I have a permanent notification on my phone now,
otherwise the app would be closed by the system. Good point is that
OwnTracks
does not simply a dummy notification but uses it to show my
current position with reverse geolocation through Nominatim. Completely
useless, so it’s obviously a need! :)
So far, I sticked with UnifiedNIP
backends and OwnTracks
disabled from
battery optimization and a position logged every 5 mins (without any minimal
displacement) and battery usage as displayed by Android is:
- Around 5% for the
Apple UnifiedNIP
backend. - Around 2% for the
Nominatim Geocoder
backend. - Usage for
OwnTracks
is not displayed.
To compare, my screen battery usage is almost the same as the one from Apple
Unified NIP
and Nominatim
is less than “sleep mode” (3%) or Whatsapp (4%).
Additionally, I mentioned that OwnTracks
requires Google Play Services,
but actually it works perfectly fine with microg
. The only downside is that
the map in the main view, showing your current position, is using Google Maps
and does not work (this panel is empty). As I only use it to log in the
background, I don’t care (and when I’m lost, I can always open OsmAnd~
which
would fetch position faster as OwnTracks
almost certainly requested it recently).
It would be super cool to see OwnTracks
on F-Droid, but it uses non-free
features (firebase-jobdispatcher
and Google Play Services and embed some
precompiled libraries) :/ So it’s quite a job to make it publishable on
F-Droid and sadly I don’t know enough about Android development to handle it :/
Hope this helps!