home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.13k stars 605 forks source link

F-Droid: Geolocation #1511

Open newhinton opened 3 years ago

newhinton commented 3 years ago

Is your feature request related to a problem? Please describe. Geolocation is not available for F-Droid. See #1335

Describe the solution you'd like I found a newer library: Its last commit was from late 2020, so it seems active enough. Also, the implementation seems rather straitforward, implementing a sample application took less than 10 minutes.

Library

Describe alternatives you've considered, if any See #1335

Additional context

dshokouhi commented 3 years ago

Nice find! Will need to research this a bit. Also this won't just benefit the minimal flavor if it works we will use it for all flavors!

gdt commented 3 years ago

My impression is that UnifiedNLP is available on all the ROMs that don't have gmscore, and that it's straightforward to use. The only issue is not insisting that the provider of location services be signed by Google; on many ROMs there isn't "signature spoofing". As an example, OsmAnd (navigation) uses GPS and "network location" just fine on Lineage. In my case "network" is a plugin called DejaVu, that keeps on-device records of wifi/cell locations, basically like querying a network database except it's local.

stale[bot] commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

newhinton commented 2 years ago

Id like to keep this open as this creates feature parity between stores.

bd4 commented 2 years ago

I just ran into this with latest stable HA and app from f-droid, on CalyxOS Pixel 3a. Would be great to have location support on de-googled phones like Calyx and /e/.

d-two commented 2 years ago

Same here... My wife has a Huawei Honor 10 X without google apps and all stuff work except the Location :-(

mike-lloyd03 commented 1 year ago

I'd like to voice my support for this feature as well. I'm on CalyxOS.

mike-lloyd03 commented 1 year ago

Is it possible to implement something like UnifiedNlp or Mozilla's MLS on the minimal version?

gdt commented 1 year ago

Basically it needs to use the AOSP location API, which has both GPS and network, instead of using the Play Services API. Google's docs are buggy in that they tell people to use the Play APIs :-)

dshokouhi commented 1 year ago

Part of the reason why we went with Play Services is that its very battery friendly and also very easy to implement, it is not just a simple switch of the API.

Google does indeed recommend using play services API in this case as we can see from this link:

https://developer.android.com/reference/android/location/package-summary

We are open source so anyone who wants to develop this feature is more than welcome to.

answer35 commented 1 year ago

I am also using a De-googled android and I have to admit that if a solution can be found to get location working it would be amazing. It is really disappointing to be google dependant for a local home solution even if I understand also the reason. Just hoping that someone will be able to help on that part :)

gdt commented 1 year ago

Off topic for the issue, but on a ROM with microG, one can run the full version of HAC and get location reported. You don't need GDR/CloudMessaging enabled. This still has proprietary code in HAC, but it's talking to the API implemented by microG, and no location is sent to google as far as I know -- the standard belief is that google tracking happens inside play services. So I think this is safe. (It's definitely not safe to use a ROM with real play services and have any app have location in the background.)

answer35 commented 1 year ago

Off topic for the issue, but on a ROM with microG, one can run the full version of HAC and get location reported. You don't need GDR/CloudMessaging enabled. This still has proprietary code in HAC, but it's talking to the API implemented by microG, and no location is sent to google as far as I know -- the standard belief is that google tracking happens inside play services. So I think this is safe. (It's definitely not safe to use a ROM with real play services and have any app have location in the background.)

I am using a ROM with MicroG but still HA doesn't receive my location. Did you managed to have it working ?

gdt commented 1 year ago

Yes, but I am running the full verison of HAC, with the proprietary bits, not the f-droid version. And i think I had to configure precise location in HAC.

answer35 commented 1 year ago

I have full version also but still location not working. But I haven't find a way to get precise location in HAC ?!

mike-lloyd03 commented 1 year ago

@answer35 I am on a microG ROM as well (CalyxOS) and found that unless I enable the "Single Accurate Location" sensor, I will get no location reporting.

@gdt Is Home Assistant constantly using your location in the background? My green dot in the top right corner is on all day and it's always Home Assistant. I've opened an issue for this (#2695) but it sounds like this issue won't be supported since I'm not on a Google Android ROM.

I agree with your reasoning that the self-hosted community is also likely to have a number of de-Googled Android users in their midst but I understand that the developers already have a lot on their plate. I guess I need to learn Kotlin.

answer35 commented 1 year ago

Hmm ok I have found where to set this sensor so location start to work, thank you guys. Now I will check how much battery is getting drained and play with those to adjust it for my needs

gdt commented 1 year ago

Yes, the green dot is ~always on. I think the issue is that CalyxOS is much more aggressive about telling you that the location is in use. Really you have told HAC to keep track of where you are and report it to your HA, which is of course an ok tihing to do. The whole "location notification" scheme is built around the assumption that you have a bunch of sketchy apps that you don't really trust but you want to use them anyway, and it doesn't have support for labeling them trusted vs not trusted. But that's a CalyxOS lack of feature, not a HAC bug.

dshokouhi commented 1 year ago

I guess I need to learn Kotlin.

If you need any help or have any questions about the app architecture etc.. please join us on discord in #devs_mobile_apps we would be happy to help :)

The green dot feature I see being mentioned is very odd but if its to mean about an app that has an open request for location updates then yes I would expect to see that up all the time but it doesnt mean the app is actively getting updates that very second. You guys can look at the code and see how we request updates for normal updates and single accurate updates. On a stock Pixel there is no green dot for any location requests so its definitely added by that OS, I only see it for microphone and camera and only during active use. Have you guys reached out to ask them to turn that off or report a bug in how it reports? That would be a good place to start.

jp8311 commented 1 year ago

+1 for this feature In the interim, could a disclaimer please be provided that de-googled or microg reliant OS will not work with location features? I'm easily ~10 hours in the hole trying to debug this and following the trouble shooting docs before I stumbled onto a hint about the cause and pulled the string to find this feature request. I'm appreciative that this is volunteer led and don't really expect anyone to work on this as it's an edge case, but I think I got a few grey hairs trying to work out why my location was so glitchy. I'm sure it will save someone some time, and probably yourselves when people post issues/ask for help! edit: in the meantime GPSlogger on fdroid is easy to set up and working, albeit not as feature rich (arguably, since it works :P)

dshokouhi commented 1 year ago

It's already mentioned in the companion app docs and project readme.

jp8311 commented 1 year ago

That's interesting, because I've been referencing the companion app docs for the better part of a week and feel like I've read it back to back. I've just searched microg without any results, I've just double checked the installation, location and troubleshooting sections where I don't see it highlighted. I'm happy to be proven wrong, but feel free to take the feedback in the spirit it was meant and consider that it may not have the visibility you think it does.

dshokouhi commented 1 year ago

https://companion.home-assistant.io/docs/core/android-flavors

https://github.com/home-assistant/android#app-flavors

It's also mentioned in the f droid installation page

https://f-droid.org/en/packages/io.homeassistant.companion.android.minimal/

jp8311 commented 1 year ago

I thought that might be what you would cite. I did indeed read those, both initially and since our conversation started. My interpretation of those was "There are two flavour options, one is more light weight than the other". In retrospect I understand what you are trying to say; but without hindsight it's easy to miss your implication. It's not explicitly stated that location services will not work if you use the play store version without play store. The log does not report an error, and the app shows a notification that says high accuracy mode is enabled etc. Plenty of apps in the play store/aurora store work despite 'requiring' play store. That's the point of microg. It even appears to function without issue and sporadically even serves location data to home assistant. You're welcome to take my feedback or not. It's your project after all. I'm just providing insight into my user experience.

mike-lloyd03 commented 1 year ago

Okay I discovered today that normal, Googled Android hides the location notification from users. I wasn't aware of this. CalyxOS simply enables this feature. It can be toggled in developer settings but this is a system wide setting and cannot be toggled for trusted apps like HAC.

That being said, I still think there is something unique with how Home Assistant is getting my location. I have OwnTracks running in the background as well and I rarely get any location notifications from it. From the HAC logs, it appears location is updating every few seconds.

dshokouhi commented 1 year ago

From the HAC logs, it appears location is updating every few seconds.

As you are using the single accurate location sensor which you mentioned up above I assume you also needed to enable the setting update with sensors? If so then it would be difficult to predict when it updates as the request is tied to other sensors triggering an update. So indeed it could be updating that frequently based on your own usage. That's not how that sensor was designed to be used. Normal background updates from Google play certified devices get updates once per minute and are not a gps lock.

If you run a custom ROM there is no support for location services, that is why the minimal version exists.

mike-lloyd03 commented 1 year ago

Yes I suspect it's something to do with MicroG. I'd like to understand more about how this works so I can push for a fix on the MicroG side if needed.

Could you help me understand how other sensors could be triggering a location update in HAC?

@dshokouhi I understand that I'm working on an unsupported device so I really appreciate the input you've provided so far.

dshokouhi commented 1 year ago

Yes I suspect it's something to do with MicroG. I'd like to understand more about how this works so I can push for a fix on the MicroG side if needed.

FWIW on my amazon tablet I was able to sideload the play store and then installed google maps (opened and granted permissions) to get the device tracker updating. I simply followed the XDA instructions for that. More than likely MicoG is missing more important libraries and APIs.

Could you help me understand how other sensors could be triggering a location update in HAC?

if you use this option under the single accurate location sensor (Settings > Companion App > Manage Sensors > Single Accurate Location):

image

then any sensor (and its update frequency) will trigger a GPS location update

https://companion.home-assistant.io/docs/core/sensors#how-sensors-update

mike-lloyd03 commented 1 year ago

Yes I had "Include in sensor update" enabled. I just disabled it but it still appears that HA is always using location. I see there have been other HA users reporting similar issues in the MicroG repo as well.

https://github.com/microg/GmsCore/issues/1616

dshokouhi commented 1 year ago

Yes I had "Include in sensor update" enabled. I just disabled it but it still appears that HA is always using location.

May need to wait for all the requests to finish as it doesn't cancel when you turn that off. Also if requests are backed up that may take longer.

I think there is a reason why Google did not enable that green light on their devices, they dont even mention it in official android documentation. It probably doesn't work well. Honestly when dealing with custom ROMs there are too many factors to consider, this is why Google has a certification process to make sure things work as expected. Even if MicroG manages to fix that issue whose to say it wont break in the next dependency update or Android OS update?

mike-lloyd03 commented 1 year ago

I'm still not sure this is totally a MicroG issue since this problem doesn't happen with any other apps (including OwnTracks which has the same permissions enabled).

With Home Assistant aiming to be a privacy first application and seeking to help users to be free from big-tech vendor lock-in, I think it's reasonable that a good portion of HA's users will be in a similar situation as those of us here on custom ROMs.

I'll continue to work on this from both ends and see if we can find a resolution.

gdt commented 1 year ago

The real issue with the location indicator is that there are apps that do access location more or less continuously, and HA Companion is one of them. That's legitimate; the user asked for it. But because we have a culture of people running sketchy apps and then after the fact trying to sort of monitor and contain them, we have these mechanisms. The green dot really needs a toggle per app to be excluded. Basically, I know HA is accessing location because I told it to, and I'm ok with that. It would be nice to know if there was a different location access that was not expected. But telling me my phone is doing what I asked is not helpful.

So I think the "green light is on" is totally out of scope for HA Companion (and I'm a CalyxOS user that doesn't want to run proprietary software).

mike-lloyd03 commented 1 year ago

@gdt That very well may be. A per-app toggle in MicroG would be very helpful.

Do you have any idea why OwnTracks doesn't seem to have this issue though?

gdt commented 1 year ago

No, and I'm refraining from commenting further until I get around to understanding the APIs and reading the code. I don't mean to be unkind, but discussing this is not useful. The app maintainer has said they only care about official Google Android, and while I think that's unfortunate from both Free Software and privacy viewpoints, it's clear that the only useful way forward is a PR to adjust proprietary API usage to work with microg (or to fix microg; it remains to be seen which) and a PR to use the AOSP location APIs in the minimal version (or in both).

ale5000-git commented 1 year ago

microG can be used also in place of Google libraries to compile apps. I'm not sure if it contains everything needed for your app but have anyone tried to compile the full version with microG libs?

If it works maybe you can put two flavours on F-Droid: minimal and complete.

guttermonk commented 9 months ago

I'm also using the "Home Assistant Minimal" version of the companion app from F-droid on GrapheneOS and could benefit from the addition of location sensors. I agree with some of the comments above that users that want to roll their own home automation system should have the option for it to be as de-Googled as one chooses without losing functionality. It would be nice to see feature parity between the F-droid and Google Play versions of the app. I've been on the Home Assistant journey for over 4 years, and look forward to the continued development.

Forage commented 2 months ago

Not to continue the off-topic MicroG discussion, but just a quick heads-up for those with MicroG background location reporting issues, that's fixed when updating to a more recent version of MicroG: https://github.com/microg/GmsCore/issues/1616#issuecomment-2061736257.

(Please continue the MicroG discussion over there if needed)

i00 commented 2 months ago

I want this too! +100

kuba-orlik commented 2 months ago

I'm trying to understand why adding a google library is necessary for the companion app to access location? I know many applications that access location data and are available on F-Droid without any apparent restrictions :thinking:

gdt commented 2 months ago

It's not necessary. Basically, with AOSP interfaces, you can get GPS location and you can get network location. Google libraries in proprietary android have a fused interface that is apparently easier to use, and that's how the app was written. So someone just needs to write an alternate implementation to be used when building w/o proprietary libs.