Location updates blocking when in battery saver mode on Android #2342

Closed
opened 2022-04-04 13:14:58 +00:00 by smartyw · 12 comments
smartyw commented 2022-04-04 13:14:58 +00:00 (Migrated from github.com)

I always have my Android phone in Battery Saver mode when using Organic Maps. I've been using the application for about 18 months and it has historically worked well with Battery Saver mode. I have the display set to sleep after 60 seconds and the usual behaviour is that if I want to check the map I double tap my phone's screen to wake it up and show the Organic Maps map. Location services are suspended when the screen is asleep and Battery Saver mode is enabled so I am accustomed to then waiting for around 5 - 10 seconds for a location update to be acquired at which point the map centres on my current location.

I am currently hiking a multi-day 100 mile trail and the application on this trip is behaving differently to the previous description. When I wake the screen and show Organic Maps (which is already in foreground), when a location update starts it seems to block and never complete. This does not happen every time but it does happen about 90% of the time (I have Battery Saver enabled again). I sometimes also see a dialogue which says Please Enable Location Services" but they are already enabled. Again, this does not happen every time.

Screenshot_20220403-134058

To resolve the issue I have to kill the application and restart it. On restarting, my location is obtained pretty much instantaneously.

I have not looked at code but suspect a race condition. When the application comes into foreground on awakening the phone from its sleeping state, it seem to request a location update but maybe this is before Android has re-enabled the service on coming out of the Battery Saver sleep state. My theory may not be correct but it should give a good sense of the behaviour I'm experiencing on this trip. It has never been like this before and it's over six months since I last used the app on a trip so I'm thinking something has changed.

It's easy to recreate as described but make sure no other sources of location (e.g. Wi-Fi scanning) are enabled in the Android Settings Location screen otherwise you may find you cannot recreate the problem. I'm assuming it relates to GPS specifically.

My phone runs Android 10 on a OnePlus 5.

The Help screen says 2022-03.23-4-Google.

Happy to help look for a solution if this is accepted as a bug.

I always have my Android phone in Battery Saver mode when using Organic Maps. I've been using the application for about 18 months and it has historically worked well with Battery Saver mode. I have the display set to sleep after 60 seconds and the usual behaviour is that if I want to check the map I double tap my phone's screen to wake it up and show the Organic Maps map. Location services are suspended when the screen is asleep and Battery Saver mode is enabled so I am accustomed to then waiting for around 5 - 10 seconds for a location update to be acquired at which point the map centres on my current location. I am currently hiking a multi-day 100 mile trail and the application on this trip is behaving differently to the previous description. When I wake the screen and show Organic Maps (which is already in foreground), when a location update starts it seems to block and never complete. This does not happen every time but it does happen about 90% of the time (I have Battery Saver enabled again). I sometimes also see a dialogue which says Please Enable Location Services" but they are already enabled. Again, this does not happen every time. ![Screenshot_20220403-134058](https://user-images.githubusercontent.com/1387793/161552797-f678d4e9-3e83-469b-be10-a59c5db6459b.jpg) To resolve the issue I have to kill the application and restart it. On restarting, my location is obtained pretty much instantaneously. I have not looked at code but suspect a race condition. When the application comes into foreground on awakening the phone from its sleeping state, it seem to request a location update but maybe this is before Android has re-enabled the service on coming out of the Battery Saver sleep state. My theory may not be correct but it should give a good sense of the behaviour I'm experiencing on this trip. It has never been like this before and it's over six months since I last used the app on a trip so I'm thinking something has changed. It's easy to recreate as described but make sure no other sources of location (e.g. Wi-Fi scanning) are enabled in the Android Settings Location screen otherwise you may find you cannot recreate the problem. I'm assuming it relates to GPS specifically. My phone runs Android 10 on a OnePlus 5. The Help screen says 2022-03.23-4-Google. Happy to help look for a solution if this is accepted as a bug.
biodranik commented 2022-04-04 13:29:04 +00:00 (Migrated from github.com)

Thank you for such a detailed description! Can you please temporarily enable logs recording in OM settings, reproduce the issue, and "Report a bug" to us via email, using the "?" toolbar button?

Thank you for such a detailed description! Can you please temporarily enable logs recording in OM settings, reproduce the issue, and "Report a bug" to us via email, using the "?" toolbar button?
smartyw commented 2022-04-04 13:32:58 +00:00 (Migrated from github.com)

You're welcome. And thank you for such a fast response :-)

Will do. Currently cloning the repo to my Chromebook so I can take a look at the code out of interest if nothing else.

I'll do as you ask and you should have the details tomorrow when I resume my hike at the latest. I have another trip planned for late June this time cycling so hoping to resolve this by then.

All the best,

M

You're welcome. And thank you for such a fast response :-) Will do. Currently cloning the repo to my Chromebook so I can take a look at the code out of interest if nothing else. I'll do as you ask and you should have the details tomorrow when I resume my hike at the latest. I have another trip planned for late June this time cycling so hoping to resolve this by then. All the best, M
biodranik commented 2022-04-06 10:54:51 +00:00 (Migrated from github.com)

Thank you for the logs. Looks like the issue is caused by the enabled Power Saving mode that blocks using high precision location permission and requires the app to ask a user about explicitly granting this permission.
The error in our log:
GoogleFusedLocationProvider: Service is not available: com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED

The possible fix:

@Override
  public void onFailure(@NonNull Exception e) {
    int statusCode = ((ApiException) e).getStatusCode();
    if (statusCode
        == LocationSettingsStatusCodes
        .RESOLUTION_REQUIRED) {
      // Location settings are not satisfied, but this can
      // be fixed by showing the user a dialog
      try {
        // Show the dialog by calling
        // startResolutionForResult(), and check the
        // result in onActivityResult()
        ResolvableApiException resolvable =
            (ResolvableApiException) e;
        resolvable.startResolutionForResult
            ((Activity) context,
                REQUEST_CODE);
      } catch (IntentSender.SendIntentException sendEx) {
        // Ignore the error
      }
    }
  }
});
Thank you for the logs. Looks like the issue is caused by the enabled Power Saving mode that blocks using high precision location permission and requires the app to ask a user about explicitly granting this permission. The error in our log: `GoogleFusedLocationProvider: Service is not available: com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED` The possible fix: ```Java @Override public void onFailure(@NonNull Exception e) { int statusCode = ((ApiException) e).getStatusCode(); if (statusCode == LocationSettingsStatusCodes .RESOLUTION_REQUIRED) { // Location settings are not satisfied, but this can // be fixed by showing the user a dialog try { // Show the dialog by calling // startResolutionForResult(), and check the // result in onActivityResult() ResolvableApiException resolvable = (ResolvableApiException) e; resolvable.startResolutionForResult ((Activity) context, REQUEST_CODE); } catch (IntentSender.SendIntentException sendEx) { // Ignore the error } } } }); ```
smartyw commented 2022-04-06 15:04:51 +00:00 (Migrated from github.com)

I would still guess that this is a race condition and that the power saving mode is only found to be enabled sometimes (which then causes the permissions issue that the logs show). I have no possibility of testing this at present but wonder if an alternative solution might be to simply retry the location update after a short delay, giving the Google location services time to become available again?

If the permission you indicate was granted by the user would that result in the location service remaining active always, even when "battery saver" mode is enabled by the user? This would not be good if it is the case. Better to find a way to wait for the transition out of the power saving mode when the user has brought the app into foreground again so that the permission is not needed at all. Just thinking aloud here.

I would still guess that this is a race condition and that the power saving mode is only found to be enabled sometimes (which then causes the permissions issue that the logs show). I have no possibility of testing this at present but wonder if an alternative solution might be to simply retry the location update after a short delay, giving the Google location services time to become available again? If the permission you indicate was granted by the user would that result in the location service remaining active always, even when "battery saver" mode is enabled by the user? This would not be good if it is the case. Better to find a way to wait for the transition out of the power saving mode when the user has brought the app into foreground again so that the permission is not needed at all. Just thinking aloud here.
biodranik commented 2022-04-06 15:15:30 +00:00 (Migrated from github.com)

Nobody speaks about "always" permission. As far as I understood, the user should confirm that he allows "precise" permission instead of a "rough" one even when the battery saving mode is enabled, and still only when the app is active. You expect to see a precise location on the map after turning the screen on again, right?

Nobody speaks about "always" permission. As far as I understood, the user should confirm that he allows "precise" permission instead of a "rough" one even when the battery saving mode is enabled, and still _only when the app is active_. You expect to see a precise location on the map after turning the screen on again, right?
smartyw commented 2022-04-06 15:17:22 +00:00 (Migrated from github.com)

Yes, absolutely :-) I'm just wondering if granting the permission would have any impact on the effectiveness of battery saver mode.

Yes, absolutely :-) I'm just wondering if granting the permission would have any impact on the effectiveness of battery saver mode.
biodranik commented 2022-04-06 15:23:23 +00:00 (Migrated from github.com)

For most apps, an optimized (not precise) positioning is ok when in power-saving mode. But not for the maps app. So it should be an optimal balance of a precise position vs using the battery only when the app is active.

For most apps, an optimized (not precise) positioning is ok when in power-saving mode. But not for the maps app. So it should be an optimal balance of a precise position vs using the battery only when the app is active.
smartyw commented 2022-04-06 15:30:53 +00:00 (Migrated from github.com)

Sounds good to me :-)

Sounds good to me :-)
Owner

Relevant discussion: https://github.com/android/location-samples/issues/193#issuecomment-482646718

I tested two Android 12 devices with Google Location Provider and Power Save mode - both works Ok. It seems that this issue only reproduces on specific devices and/or older Android versions.

So, before Android 9.0 Pie there were 3 levels of localisation accuracy that the user can define in his own settings of the device :

  • ONLY GPS (Device Only)
  • WIFI AND NETWORK (Battery saving)
  • GPS, WIFI AND NETWORK (High)

@smartyw do you have "Use High-precision mode" in Location settings? If yes, could you please how this option affects the behaviour?

Relevant discussion: https://github.com/android/location-samples/issues/193#issuecomment-482646718 I tested two Android 12 devices with Google Location Provider and Power Save mode - both works Ok. It seems that this issue only reproduces on specific devices and/or older Android versions. > So, before Android 9.0 Pie there were 3 levels of localisation accuracy that the user can define in his own settings of the device : > > - ONLY GPS (Device Only) > - WIFI AND NETWORK (Battery saving) > - GPS, WIFI AND NETWORK (High) @smartyw do you have "Use High-precision mode" in Location settings? If yes, could you please how this option affects the behaviour?
smartyw commented 2022-04-11 13:48:09 +00:00 (Migrated from github.com)

Hi @rtsisyk ,

I'm running Android 10 and in Settings/Location have "Wi-Fi and Bluetooth scanning" with Wi-Fi Scanning enabled and Bluetooth off. In Settings/Location/Advanced I have Google Location Accuracy which is either on or off and I have it set to ON.

Screenshot_20220411-143253

I already tested with Wi-Fi scanning and when it was enabled and I was in a place with Wi-Fi the problem did not occur. If I disabled Wi-Fi scanning then it did occur. So I concluded it only related to the time it takes to re-enable GPS under the facade of the Google Location Services. I guess the exception in the logs illustrates clearly that an attempt to use GPS was taking place whilst still in a power saving mode. So the app is coming into foreground and the Android activity lifecycle call takes place before the power saving mode has been exited. Or something like that :-)

Hi @rtsisyk , I'm running Android 10 and in Settings/Location have "Wi-Fi and Bluetooth scanning" with Wi-Fi Scanning enabled and Bluetooth off. In Settings/Location/Advanced I have Google Location Accuracy which is either on or off and I have it set to ON. ![Screenshot_20220411-143253](https://user-images.githubusercontent.com/1387793/162752273-1cf5fa25-7964-4f83-8433-51987a502df0.jpg) I already tested with Wi-Fi scanning and when it was enabled and I was in a place with Wi-Fi the problem did not occur. If I disabled Wi-Fi scanning then it did occur. So I concluded it only related to the time it takes to re-enable GPS under the facade of the Google Location Services. I guess the exception in the logs illustrates clearly that an attempt to use GPS was taking place whilst still in a power saving mode. So the app is coming into foreground and the Android activity lifecycle call takes place before the power saving mode has been exited. Or something like that :-)
Owner

We fixed com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED by #2342. Actually, this new dialog just advise you to enable Wi-Fi and doesn't bring any other value. It will be available in the next release. The original problem has been resolved by 44260ae3df which is included since May 2022 release.

We fixed `com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED` by #2342. Actually, this new dialog just advise you to enable Wi-Fi and doesn't bring any other value. It will be available in the next release. The original problem has been resolved by 44260ae3dfde048f4ad11f68c57aa1a6a5290d1c which is included since May 2022 release.
smartyw commented 2022-10-12 08:13:34 +00:00 (Migrated from github.com)

Excellent, thank you. FYI I recently completed a 4,700 Km bikepacking trip around Europe and used Organic Maps for all navigation. It was invaluable!

See https://the-bikepacker.blogspot.com/p/europe-2022-index.html

Excellent, thank you. FYI I recently completed a 4,700 Km bikepacking trip around Europe and used Organic Maps for all navigation. It was invaluable! See [https://the-bikepacker.blogspot.com/p/europe-2022-index.html](https://the-bikepacker.blogspot.com/p/europe-2022-index.html)
This repo is archived. You cannot comment on issues.
No labels
Accessibility
Accessibility
Address
Address
Android
Android
Android Auto
Android Auto
Android Automotive (AAOS)
Android Automotive (AAOS)
API
API
AppGallery
AppGallery
AppStore
AppStore
Battery and Performance
Battery and Performance
Blocker
Blocker
Bookmarks and Tracks
Bookmarks and Tracks
Borders
Borders
Bug
Bug
Build
Build
CarPlay
CarPlay
Classificator
Classificator
Community
Community
Core
Core
CrashReports
CrashReports
Cycling
Cycling
Desktop
Desktop
DevEx
DevEx
DevOps
DevOps
dev_sandbox
dev_sandbox
Directions
Directions
Documentation
Documentation
Downloader
Downloader
Drape
Drape
Driving
Driving
Duplicate
Duplicate
Editor
Editor
Elevation
Elevation
Enhancement
Enhancement
Epic
Epic
External Map Datasets
External Map Datasets
F-Droid
F-Droid
Fonts
Fonts
Frequently User Reported
Frequently User Reported
Fund
Fund
Generator
Generator
Good first issue
Good first issue
Google Play
Google Play
GPS
GPS
GSoC
GSoC
iCloud
iCloud
Icons
Icons
iOS
iOS
Legal
Legal
Linux Desktop
Linux Desktop
Linux packaging
Linux packaging
Linux Phone
Linux Phone
Mac OS
Mac OS
Map Data
Map Data
Metro
Metro
Navigation
Navigation
Need Feedback
Need Feedback
Night Mode
Night Mode
NLnet 2024-06-281
NLnet 2024-06-281
No Feature Parity
No Feature Parity
Opening Hours
Opening Hours
Outdoors
Outdoors
POI Info
POI Info
Privacy
Privacy
Public Transport
Public Transport
Raw Idea
Raw Idea
Refactoring
Refactoring
Regional
Regional
Regression
Regression
Releases
Releases
RoboTest
RoboTest
Route Planning
Route Planning
Routing
Routing
Ruler
Ruler
Search
Search
Security
Security
Styles
Styles
Tests
Tests
Track Recording
Track Recording
Translations
Translations
TTS
TTS
UI
UI
UX
UX
Walk Navigation
Walk Navigation
Watches
Watches
Web
Web
Wikipedia
Wikipedia
Windows
Windows
Won't fix
Won't fix
World Map
World Map
No milestone
No project
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: organicmaps/organicmaps-tmp#2342
No description provided.