Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] GPS 10-bit week rollover bug #296

Closed
endolith opened this issue Sep 29, 2022 · 6 comments
Closed

[BUG] GPS 10-bit week rollover bug #296

endolith opened this issue Sep 29, 2022 · 6 comments
Labels
Addressed The issue has been either Patched, or fixed in a Release.

Comments

@endolith
Copy link

endolith commented Sep 29, 2022

Describe the bug
Erratic behavior with GPS apps on Exynos Samsung S7

To Reproduce
Steps to reproduce the behavior:

  1. Start Maprika app
  2. Switch to OpenStreetMap mode
  3. Start recording a track
  4. Drive around
  5. Red track will be correct, but blue arrow will be inaccurate and update infrequently

image

Expected behavior
Blue arrow should show current location correctly, at head of red line

image

To Reproduce

  1. Start barbeuDev GPSTest app
  2. After it gets a fix, reported time will be 1024 weeks before actual current time, shown in red
  3. Click the time
  4. It will show GNSS time wrong error (Actual time was 2022-09-27 02:29 PM EST, 1024 weeks later):

image

Smartphone (please complete the following information):

  • Device: Galaxy S7
  • Model: G930F (Exynos)

Additional context
https://github.com/barbeau/gpstest/blob/master/FAQ.md#why-is-my-gps-time-wrong

https://www.cisa.gov/gps-week-number-roll-over

https://forum.xda-developers.com/t/rom-10-0-oneui-2-5-g930x-g935x-n930x-n935x-floydq-v7-0.4085667/page-221#post-87479433

Maybe the same issue: https://www.androidauthority.com/samsung-galaxy-s7-s8-updates-3198409/

I suspect the blue arrow is a "fused location", and when it gets the wrong timestamp from the GPS module it rejects the GPS sensor and only uses Wi-Fi/cell for location, which is why it's so inaccurate and updates rarely? Turning off Wi-Fi and turning on Airplane mode cause it to stop updating at all.

I would guess that the reason EU and China satellites don't appear is some kind of "majority rule" algorithm? So the first satellites it sees are US, it gets the wrong timestamp from them, then rejects other satellites with different timestamps? But occasionally it works correctly because the first satellites it sees are EU, and it gets the right timetamps, and then rejects the US ones? I'm just wildly guessing, though.

@ananjaser1211
Copy link
Owner

ananjaser1211 commented Sep 30, 2022

Hello mate, Thanks for the excellent report,

This will be very verbose, however i think it might be useful to people in the future who come across this issue, which is likely to happen with all the custom ROMs out there that will never receive updates.

If you want to skip directly to the patch, it will be down below

Test Environment :

  1. All the devices are running Custom ROMs except the GALAXY NOTE 5
  2. All the devices tested have GPS Drivers that are pre Samsung's 2022 August
  3. Devices are NOT using their stock GPS Drivers unless stated otherwise
  4. I currently reside in the United Arab Emirates (Middle East)
  5. All tests were done on my balcony with clear view to the sky and available GPS Location FIX
  6. The NOTE 5 Serves as a baseline as it is both running Stock, And has an update available
  7. I am unable to test Maprika and precise location tracking as it does not seem to be supported in dubai

Device Information :

  1. Galaxy Note 5 Stock Android 7.0 August 2018 Security Patch
  2. Galaxy S7 Edge Android 10 Floyd Q Based on Galaxy Note 9 MAY 2022 Security Patch
  3. Galaxy Note 8 Android 10 Hades Q Based on Galaxy Note 9 November 2021 Security Patch
  4. Galaxy S9+ Android 11 Private OneUI R ROM Based on Galaxy Note 10+ December 2021 Patch

Additional Device Information :

  1. The Note 5 will be tested Before and After the August 2022 Update samsung provided
  2. The S7 And Note 8 Android Q projects are built on the same base (minus the note 8 being on an older security patch, i.e Floyd Q V6.0 Level)
  3. The S9+ ROM is built from 2 devices, the Galaxy N10+ And N10 Lite, both are December patches.

GPS HAL Information :

  1. The note 5 is running Stock GPS Drivers
  2. The S7 is running Galaxy Note 9/S9+ GPS Driver from Android Q Firmware
  3. The Note 8 is running Galaxy Note 9/S9+ GPS Driver from Android Q Firmware
  4. The S9+ is running Galaxy Note 9/S9+ GPS Driver from Android Q Firmware

So basically, while all these phones are running different android versions / security patches, they are all using the SAME GPS Daemon / HAL / FusedLocation, so in theory when conducting tests, they all should have the same bug with rollover

Few Facts to know :
Last month, samsung rolled out an update to pretty much their entire lineup of pre Galaxy S10 Devices that mentioned "GPS Stability and security Improvement" and looked something like this :

Note 5

I have actually diffed the Note 8 August 2022 update to figure out what was changed, And it is as follows :

system/vendor/bin/hw/gpsd
system/vendor/bin/hw/lhd
system/vendor/lib64/hw/gps.default.so
system/vendor/lib64/hw/flp.default.so
system/vendor/lib64/hw/android.hardware.gnss@1.1-impl.so
system/vendor/lib64/hw/vendor.samsung.hardware.gnss@1.0-impl.so

More or less the same changes were found in the Note 9 Diff N960FXXS9FVE1 (May 2022) and N960FXXU9FVH1 (Aug 2022)

GPSD Is the main GPS Daemon in Samsung, gps.default.so is the GPS HAL, flp.default.so is the fused location HAL, *.gnss is the Android HIDL interface

Now we dont really know what actually changed inside these binaries, or WHY, at first i speculated it is some critical security exploit, However looking at the links you have shared and Samsung Forum | Article it seems that there is an expected GPS Issue in September 2022 that required some critical update

For more details i have included the Before of all 4 devices in imgur, but i will highlight the S7 only here

Tests Prior to patching / Updating :

https://imgur.com/a/rGX42u1

S7E_B1

S7E_B2

Tests After patching / Updating :

S7E_A
N5_A

Conclusion :

Samsung's recent patch was made to address this issue for sure, and possibly others, we can see that the satellite count significantly increased after the fix (phones were tested in the SAME location) and hopefully this will fix the issue you had.

Important : The S9+ And Note 8 Did not work after the patch, while the N5 And S7 Did, my suspension is it is something in the kernel, i will have to dig and figure that out, but since we are dealing with S7 here, the patch "should" fix this issue hopefully and might improve accuracy of your map.

I should also mention now GPS works indoors in my room on the S7 And note 5 while previously it did not, possibly due to the increased satellites. I have also conducted the same test on the S7 And note 5 with no Wifi / bluetooth and the location did not have time issues

Patch for Floyd :

Please test it out and let me know.

FloydQ_GPS-Rollout-Fix.zip

@endolith
Copy link
Author

Wow, that's the fastest response I've ever seen on a bug report! :)

I'm not sure if it's fixed, though. I tried the fix this morning and rebooted, and GPSTest still showed the wrong timestamp and only showed US and RU satellites. I left it running while driving to work and nothing changed.

Then I tried installing it a second time to make sure I did it right:

  1. I rebooted into TWRP 3.6.2_9-0
  2. press Install button
  3. scroll to FloydQ_GPS-Rollout-Fix.zip on external SD card, click it
  4. disable all three checkboxes (zip signature verification, etc)
  5. swipe to confirm flash
  6. @ Successfully flashed!
  7. result was [ ]
  8. wipe dalvik cache
  9. reboot system

This is the same thing I did this morning, and same messages.

Now it shows the correct time, but still only shows a smaller number of US and RU satellites (and when it was randomly working for an hour the other day, it showed a lot more, including Chinese and EU).

As I mentioned on the forum, I also have a Verizon S7 for testing at work and it has worked fine every time I try it, and has no updates available for it. Sitting next to my S7, it sees 25 satellites while mine only sees 11.

After another reboot, and turning GPS on and off a bunch, mine still shows the correct time. So maybe it's fixed now, and just needed time to update something? Or maybe it's just randomly working a bit better randomly like it did the other day? I will test outside later and see if anything changes.

@ananjaser1211
Copy link
Owner

ananjaser1211 commented Sep 30, 2022

Alright so i did a 2 hour drive for some errands and used the S7 And S9+ for navigation, The S9+ Initially did not show the correct time stamp, However just as i was going to start driving the Time was updated and it no longer shows Red.

Both the S7E And S9+ Navigated with no issues. (the main difference was that the S7 Had its pointer almost upside down, but this is due to a different bug found here if you were not aware of it, Basically this is mostly noticeable while using navigation and walking, as the direction pointed on the map would not be synced with the phone's orientation)

Perhaps it indeed tales extra time to show the proper GPS time ? i am not sure as i have no idea how any of this actually works, its just magic radio waves to me. or that SOME satellites work fine with the incorrect time, while others reject the connection from the phone perhaps as sort of fallback for devices that are likely to never get such updates, once the time was updated, satellites have no issues connecting back to the device.

with the new files + proper time my S9+ Is connected to a bunch of chinese and European satalites, and it started working in my room, previously it did not when the time was in red, Pretty much mimics the behavior i faced on all devices, after the patch signal was better, and more countries showed up. here is a screen shot for reference from the S9 (can be compared to this where only Russian and american satalites were visible.

Also to avoid AGPS (assisted GPS I.e with Wifi / bluetooth, / Radio) I enabled Airplane mode and navigation had zero issues

Here is a screen shot from my balcony at the same position the previous S9+ Picture came from. now with more countries showing up

image

What i did notice however was how much faster GPS Locked on, and then maintained its position, i have a bug with google maps on pretty much all my phones were if i am driving with offline gps (so no mobile data connection is enabled) and then i miss a turn, the map does NOT update with new direction, and just keeps going without the blue line marker.

And the cursor drifts very regularly to different lanes on the highway. ofcourse all these issues vanish when mobile data is enabled, However after our experiments with the patch, driving even with airplane mode on, the position was locked on and did not drift to nearby lanes

its only a two hour drive so this is all inconclusive, so i must test it in depth, i drive daily for about 4 Hours so i will let you know if i have noticed significant improvements

Regarding S7 Verizon, my guess is it is using a different GPS Chip perhaps that is not affected by this roll over problem, all the devices i tested that got the update are using the same exact GPS Chip / Driver in the kernel)

Exynos uses these :
CONFIG_GPS_BCM47531=y
CONFIG_GPS_BCM4773=y

however the Qualcomm S7 Edge is not (G930A/G930V I.e USA Models)

It does not even include the sec_gps driver package, so it is using a different implementation.

Side note :
the Galaxy Note 10 Lite that was released after the Galaxy 10 series Received this mysterious GPS Update in August

The Note 10 Lite (Running Exynos9810) Shares the same development pipeline as The Galaxy S10 / N10 (With Exynos982*) internally based on firmware / kernel features and updates

However, the S10/N10 Did NOT receive this update, looking at their kernel source, they are also not using the SEC_BCM Driver, even though it is the "same" GPS CHIP (bcm477), however it is under a totally different implementation

CONFIG_BCM_GPS_SPI_DRIVER

So who knows, perhaps samsung found it is easier to fix this in userspace instead of tackling it at the kernel level. but thats beyond my knowledge

Tangents aside, do let me know how GPS performs over time, and if it improved (or gotten worse), i will also share any issues i face

P.S : Sorry for the newspaper sized replies but i am trying to cram as much information i can find for future wanderers who might come across this issue.

@endolith
Copy link
Author

I used it outside while going to lunch and it seems to work perfectly now! I guess it just needed some time to adjust or something.

The time is still correct, it saw ~30 satellites, including EU and Chinese, and both apps showed my path very accurately.

Thank you so much for fixing this! I use it for climbing/hiking/OpenStreetMap/etc and it was very frustrating how wrong and slow it was.

while others reject the connection from the phone

FYI, your phone doesn't send anything to the satellites. :) They constantly broadcast their position and (very precise) time of day down to the earth, and your phone listens to all of the ones it can hear, calculates how far away they are from the time delay, and then calculates its position with a bunch of complicated math. That's why it can still find your position with no internet connection at all, in Airplane mode, etc.

@ananjaser1211
Copy link
Owner

Thank you so much for fixing this! I use it for climbing/hiking/OpenStreetMap/etc and it was very frustrating how wrong and slow it was.

Most welcome mate, glad it improved

FYI, your phone doesn't send anything to the satellites. :) They constantly broadcast their position and (very precise) time of day down to the earth, and your phone listens to all of the ones it can hear, calculates how far away they are from the time delay, and then calculates its position with a bunch of complicated math. That's why it can still find your position with no internet connection at all, in Airplane mode, etc.

Today i learned something new, thanks for sharing! quite fascinating how all this works

@ananjaser1211 ananjaser1211 added patched The BUG has been resolved in a patch or in a comment Addressed The issue has been either Patched, or fixed in a Release. labels Oct 4, 2022
@ananjaser1211
Copy link
Owner

Closed as V8 is now out with a fix for this bug https://xdaforums.com/t/rom-10-0-oneui-2-5-g930x-g935x-n930x-n935x-floydq-v8-0.4085667/post-89144172

@ananjaser1211 ananjaser1211 added Fixed in next release Bug has been resolved and will be shipped with the next release Addressed The issue has been either Patched, or fixed in a Release. and removed patched The BUG has been resolved in a patch or in a comment Addressed The issue has been either Patched, or fixed in a Release. Fixed in next release Bug has been resolved and will be shipped with the next release labels Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Addressed The issue has been either Patched, or fixed in a Release.
Projects
None yet
Development

No branches or pull requests

2 participants