GPS won't fix on cancro (Xiaomi mi4)

Fresh install of /e/ on my old Xiaomi MI4(cancro) from e-0.13-n-2020120989402-dev-cancro.zip

First installed F-Droid and OpenTracks and went for a walk - noticed that it doesn’t record the distance.

Back home I installed GPSTest and found out that it won’t get a fix - not even after 10-15 minutes.

The following errors are repeatedly displayed in adb logcat while GPSTest is running:

01-04 17:38:53.878 831 1334 E LocSvc_utils_q: D/msg_q_snd: Sending message with handle = 0x8FC9E900
01-04 17:38:53.878 831 1334 E LocSvc_utils_ll: D/linked_list_add: Adding to list data_obj = 0x8FC9E900
01-04 17:38:53.878 831 1334 E LocSvc_utils_q: D/msg_q_snd: Finished Sending message with handle = 0x8FC9E900
01-04 17:38:53.878 831 1320 E LocSvc_utils_ll: D/linked_list_remove: Removing from list
01-04 17:38:53.878 831 1320 E LocSvc_utils_q: D/msg_q_rcv: Received message 0x8FC9E900 rv = 0
01-04 17:38:53.879 831 1320 E LocSvc_eng: V/flags: 35
01-04 17:38:53.879 831 1320 E LocSvc_eng: source: 2
01-04 17:38:53.879 831 1320 E LocSvc_eng: latitude: 31.409998
01-04 17:38:53.879 831 1320 E LocSvc_eng: longitude: 35.070001
01-04 17:38:53.879 831 1320 E LocSvc_eng: altitude: 0.000000
01-04 17:38:53.879 831 1320 E LocSvc_eng: speed: 0.000000
01-04 17:38:53.879 831 1320 E LocSvc_eng: bearing: 0.000000
01-04 17:38:53.879 831 1320 E LocSvc_eng: accuracy: 0.000000
01-04 17:38:53.879 831 1320 E LocSvc_eng: timestamp: 1609774733847
01-04 17:38:53.879 831 1320 E LocSvc_eng: rawDataSize: 0
01-04 17:38:53.879 831 1320 E LocSvc_eng: rawData: 0x0
01-04 17:38:53.879 831 1320 E LocSvc_eng: Session status: 1
01-04 17:38:53.879 831 1320 E LocSvc_eng: Technology mask: 2
01-04 17:38:53.879 831 1320 E LocSvc_afw: V/Entering void local_loc_cb(UlpLocation*, void*) line 1089
01-04 17:38:53.879 831 1320 E LocSvc_afw: I/<=== location_cb - from line 1091 2
01-04 17:38:53.880 831 1320 W LocationManagerService: Dropping incomplete location: Location[gps 31.409998,35.070001 acc=??? et=+26m47s972ms alt=0.0 {Bundle[{satellites=0}]}]
01-04 17:38:53.880 831 1320 E LocSvc_afw: V/Exiting void local_loc_cb(UlpLocation*, void*) line 1097 None
01-04 17:38:53.881 831 1320 E LocSvc_MsgTask: D/MsgTask::loop() 1453 listening …
01-04 17:38:53.881 831 1320 E LocSvc_utils_q: D/msg_q_rcv: Waiting on message
01-04 17:38:54.275 2785 2785 D GpsOutputNmea: 1609774733867,$GPGSV,4,1,15,02,00,000,09,32,319,11,32,063,14,34,296,*72
01-04 17:38:54.275 2785 2785 D GpsOutputNmea: 1609774733868,$GPGSV,4,2,15,16,05,067,17,70,202,20,00,000,21,00,000,*78
01-04 17:38:54.276 2785 2785 D GpsOutputNmea: 1609774733868,$GPGSV,4,3,15,23,10,317,24,23,081,26,00,000,27,00,000,*70
01-04 17:38:54.276 2785 2785 D GpsOutputNmea: 1609774733869,$GPGSV,4,4,15,28,35,049,29,00,000,31,40,322,*42
01-04 17:38:54.284 2785 2785 D GpsOutputNmea: 1609774733869,$GLGSV,3,1,10,78,37,074,70,09,310,82,29,180,77,00,000,*6A
01-04 17:38:54.286 2785 2785 D GpsOutputNmea: 1609774733869,$GLGSV,3,2,10,80,09,307,69,16,254,88,31,036,87,00,000,*63
01-04 17:38:54.287 2785 2785 D GpsOutputNmea: 1609774733870,$GLGSV,3,3,10,81,66,113,68,01,208,*6B
01-04 17:38:54.289 2785 2785 W NmeaUtils: Empty DOP values in NMEA: $GPGSA,A,1,1E
01-04 17:38:54.289 2785 2785 D GpsOutputNmea: 1609774733870,$GPGSA,A,1,1E
01-04 17:38:54.290 2785 2785 D GpsOutputNmea: 1609774733870,$GPVTG,T,M,N,K,N
2C
01-04 17:38:54.291 2785 2785 D GpsOutputNmea: 1609774733871,$GPRMC,V,N
53
01-04 17:38:54.291 2785 2785 W NmeaUtils: Couldn’t parse geoid altitude from NMEA: $GPGGA,0,*66
01-04 17:38:54.291 2785 2785 D GpsOutputNmea: 1609774733871,$GPGGA,0,*66

Here’s a screenshot showing lots of satellites visible, but not getting location fix.

How can I make GPS work reliably? Main reason for using this device is to record hikes and runs (the Xiaomi ROMs usually disables the location service to save power, unless you turn on the screen every couple of minutes - and I was hoping to avoid that).

After (lots) of fiddling and trial and error, which included referencing my Note 5 gps.conf and flashing xiaomi.eu and mokee ROM on this poor Mi4, I’ve got something that works, eventually (first time the fix took 510 seconds, now even more).

Of course, now time to test how it behaves with Battery Optimization turned off for OruxMaps and runner apps.

In hopes it helps someone in the future, here’s the gist file

Hi @Burchalka,

I have an issue with my GPS on Sony Xperia Z3 Compact for a while.
While I saw some fixes proposed on some forums (XDA forums), I didn’t test yet.
Indeed, based on what I understood, you need to be root on your phone to do such changes?

image

In addition, I’m a little bit worried about some lines I see in the default gps.conf file:

# Worldwide
NTP_SERVER=1.android.pool.ntp.org
################################
##### AGPS server settings #####
################################

# FOR SUPL SUPPORT, set the following
SUPL_HOST=supl.google.com
SUPL_PORT=7275

So one clear reference to google server? and another one to Android. Is this last one also Google server?
Do you have inputs about that?
Thanks
Max

NTP server is the reliable time source for GPS to work, you may try 0.pool.ntp.org, 1.pool.ntp.org, and so on.
1.android.pool.ntp.org is working, but may not be the fastest :wink:

SUPL is for A-GPS, please read here https://docs.broadcom.com/doc/1211168566155 and here Assisted GPS (A-GPS) Overview - Cisco.
Only Google and Vodaphone (supl.vodaphone.com) are known to provide public SUPL services by now.
If you find any alternative, please share :smile_cat:

Best way to change/replace gps.conf file without root is to boot to recovery (TWRP) and push/pull file.

Hi @smu44,

thanks for the links. I will look at them.
at the end, I used the method proposed by @Sacripant here.
That works fine and i find that way easier and quite fast.
just one question because I don’t want to pollute original @Burchalka’s post (perhaps I would have to open another one for my issue?):
for NTP sevrer list, is there a difference if you set (I saw both here or on XDA):

NTP_SERVER=0.asia.pool.ntp.org
NTP_SERVER=1.asia.pool.ntp.org
NTP_SERVER=2.asia.pool.ntp.org
NTP_SERVER=0.asia.pool.ntp.org
NTP_SERVER_1=1.asia.pool.ntp.org
NTP_SERVER_2=2.asia.pool.ntp.org

At the end, I understand that 1.android.pool.ntp.org & supl.google.com can help but if there are managed by Google, not sure to understand why we have them in /e/, an ungoogled OS

For NTP servers list, I think that the correct syntax is the 2nd.
With the first one, you may have only one NTP server at the end (2.asia.pool.ntp.org)

About NTP servers : 1.android.pool.ntp.org does not belong to Google, and AFAIK does not resolve to Google servers. It may work but resolves to U.S. providers, which may not accurate if your are not using your device in North America.
You should use the nearest NTP pool, example for Europe : pool.ntp.org: NTP Servers in Europe, europe.pool.ntp.org
If traveling planet-wide, you may use the defaults pool.ntp.org: How do I setup NTP to use the pool?
The goal is to get the fastest response, as GPS is very time-sensitive.
NTP servers are mandatory for a good & quick GPS fix.

SUPL is something else, part of A-GPS protocol, which aims to help for positioning.
You may disable it, but you should expect some troubles in getting a accurate fix.
AFAIK, at this time only Google is providing reliable public SUPL … So it’s your choice to use it, or not :wink:
Interesting readings :

If don’t want to use SUPL from Google, you may set it to “localhost” and try some location providers in MicroG, for example F-Droid Search: nlp.