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

Improve location updates without having battery optimizations switched off #420

Closed
Kisty opened this issue Feb 13, 2020 · 11 comments · Fixed by #753
Closed

Improve location updates without having battery optimizations switched off #420

Kisty opened this issue Feb 13, 2020 · 11 comments · Fixed by #753
Labels
enhancement New feature or request location-tracking

Comments

@Kisty
Copy link
Contributor

Kisty commented Feb 13, 2020

Home Assistant Android version: 1.7.1

Android version: 9.0

Phone model: OnePlus 3T

Home Assistant version: 0.105.3

Last working Home Assistant release (if known):

Description of problem: I'm looking at improving background location updates by using the Google codelab as a template. Mainly looking at the background location updates, especially with Android 10 changes. What do you think? https://codelabs.developers.google.com/codelabs/while-in-use-location/index.html#0

Traceback (if applicable):


Additional information:

@dshokouhi dshokouhi added enhancement New feature or request location-tracking labels Feb 13, 2020
@robbiet480 robbiet480 changed the title [Feature Request] Improve location updates without having battery optimisations switched off Improve location updates without having battery optimisations switched off Feb 13, 2020
@robbiet480 robbiet480 changed the title Improve location updates without having battery optimisations switched off Improve location updates without having battery optimizations switched off Feb 13, 2020
@balloob
Copy link
Member

balloob commented Feb 13, 2020

I have no idea what you're proposing. Can you be more specific on what you want to see or what you want to change?

@Kisty
Copy link
Contributor Author

Kisty commented Feb 17, 2020

Sorry I didn't make myself clear.

At the moment, to get location updates working reliably, you have to disable battery optimisations in the app. This is due to Android 8.0 changes. I think I can remove this limitation by using a foreground service. Without this, the Android system would not allow location updates via the BroadcastReceiver once the app is in the background and killed by the system.

See https://developer.android.com/guide/background

@scottismyname
Copy link

The WorkManager option sounds very promising

@JBassett
Copy link
Collaborator

It does still receive updates when in the background, just not always at the rate desired. I know you could do a foreground service with a persistent notification but I'm curious why you would want to do that over disabling battery optimizations? Once you do that you have to instruct people how to hide the notification which I think is a worse user experience. If enough people are still not happy with the update rate we still have more options to increase the priority of our location updates: https://github.com/home-assistant/home-assistant-android/blob/master/app/src/main/java/io/homeassistant/companion/android/background/LocationBroadcastReceiver.kt#L208

@quthla
Copy link
Contributor

quthla commented Feb 18, 2020

If enough people are still not happy with the update rate we still have more options to increase the priority of our location updates: https://github.com/home-assistant/home-assistant-android/blob/master/app/src/main/java/io/homeassistant/companion/android/background/LocationBroadcastReceiver.kt#L208

https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest

Apparently that is only related to the accuracy and not the rate at which updates happen.

Also it does not seem as if there is huge demand for any changes anyway.

@Kisty
Copy link
Contributor Author

Kisty commented Feb 18, 2020

The other issue, moving forward is that in Android 10 they've introduced a new background location permission which is required in order to get location updates in the background.

Once you do that you have to instruct people how to hide the notification which I think is a worse user experience.

I don't think this is true. You can make a notification of the lowest priority show as a collapsed notification, though I'd need to double check.

@dshokouhi
Copy link
Member

@Kisty most people don't want an additional undismissable notification and you would need to instruct them on how to hide it completely and not just keep it minimized. To them disabling battery optimizations is a much cleaner route than congesting the notification panel.

@Kisty
Copy link
Contributor Author

Kisty commented Feb 18, 2020

@dshokouhi I see your point. The reason I wanted to try and improve this is for a few reasons.

  1. My wife's phone, Nexus 5X - 9.0, isn't updating location even though battery optimisations are off
  2. Our tablet battery doesn't update ever becuase there's no location changes (Nexus 9 - 7.0) battery optimisations are off here too
  3. There's a lot of issues reporting about issues with battery reporting, location updates here.

This came out more as an attempt to standardise the device reporting, starting with locations. I've seen advice on reseting the device tracker which I haven't tried with my wife's phone.

@scottismyname
Copy link

The problem with simply disabling battery optimizations, is that this doesn't always work....especially after a device is restarted and the app is never launched.

@KBerstene
Copy link
Contributor

@dshokouhi Can't you create a low-priority (silent/collapsed) notification when the location update is triggered to happen, then dismiss it once the update is complete? I believe this is how Google Maps handles doing its location updates.

@dshokouhi
Copy link
Member

@KBerstene that notification can be turned off by the user so I don't think its required for location updates, then again we are guessing at this lol. Tasker is a good example because it needs the persistent notification to allow the foreground service to run all the time. I think that as we add more sensors and those sensors update on their own interval (i.e. phone being unplugged) the persistent notification may be needed. If we find that it improves location updates better than disabling battery optimization then I am sure most users will accept it

@scottismyname the location service should start up again when you restart the device, if its not please file a separate issue for that because I think its supposed to start on device boot.

@Kisty for location check these steps to make sure its able to update as often as it can: https://companion.home-assistant.io/docs/troubleshooting/faqs#location-is-not-updating-in-android-app I also agree that getting more frequent updates would be great too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request location-tracking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants