microg / GmsCore

Free implementation of Play Services
https://microg.org
Apache License 2.0
7.75k stars 1.63k forks source link

[io.homeassistant.companion.android] Home-Assistant cannot access location update result #1616

Open Zocker1999NET opened 2 years ago

Zocker1999NET commented 2 years ago

Affected app Name: Home-Assistant Package id: io.homeassistant.companion.android

Describe the bug Home-Assistant uses gms libraries to handle location updates coming via indent, but the gms library seems not to be able to parse microG's intents to extract the location information

To Reproduce Steps to reproduce the behavior:

  1. Install Home-Assistant Companion App, connect to instance
  2. Enable the "Background Location" sensor in Companion App and further allow all location permission requests
  3. View in Home-Assistant that location never gets updated (see screenshot)

Expected behavior Location should be sent to Home-Assistant instance after the intent was parsed correctly.

Screenshots Screenshot of device_tracker / sensor in Home-Assistant web ui: image

System Android Version: 11 Custom ROM: LineageOS 18.1 with microg (18.1-20211021-microG-oneplus3)

microG microG Core version: 0.2.22.212658 microG Self-Check results: All ticked

Additional context I debugged the app in Android Studio and used logcat to determine the buggy code lines (hopefully the correct ones):

https://github.com/home-assistant/android/blob/ff20e4502b0f202d13323d4211c2c475c1d62bc8/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt#L445-L471

While debugging, I found out, that LocationResult.extractResult(intent) returns null and so subsequent ?. calls default to null. So I think, that LocationResult from gms cannot parse the intent given by microG.

See my issue report there: home-assistant/android#1833

Weird Good2Know The author of the similar issue #1273 seems to have solved this issue by re-enabling the sensor, but further has problems with the geocoded location. On my device, geocoded location works just fine, but the real location does not even after re-installing the app and re-enabling the sensor multiple times.

Neurocranium commented 2 years ago

Have you enabled a location module in the microG settings? I had exactly the problem you described on my recently installed LineageOS (18.1-20211222-microG-sake) and only after activating the Nominatim module as a location module the geo-coded location and the device tracker started to work as expected.

I also tried to enable and disable the sensor for accurate_location. Not sure though, whether that had any role in making it work.

renekuehl commented 2 years ago

I have exactly the same Problem with the Companion App. I use /e ROM with microG. My Location got updated 10 Hours ago (and only that Time) but way off like 300m Distance. At the Moment it never gets updated. Even Disabling and Enabling the Sensor in the Companion App never results in an Update. In MicroG I have 3 Location Modules enabled (Apple Wi-Fi, Mozilla Location Service and Nomination). If I use GPS Test my Location gets pinpointed correctly. I'm glad this is a Test Phone its running on, otherwise some of my Automations would not work :D Would be glad if this gets sorted out.

ale5000-git commented 2 years ago

Have you tried with microG GmsCore 0.2.23.214816?

renekuehl commented 2 years ago

Have you tried with microG GmsCore 0.2.23.214816?

Can not update my MicroG due to the Fact that it is bundled with the OS. Have to wait for an Update.

ale5000-git commented 2 years ago

Apps bundled with the OS can be updated like any other app. The only case when it isn't possible it when that maker of the ROM use a cutom GmsCore that has a different signature.

LineageOS for microG use the official microG GmsCore so it can be updated.

Edit: Just reading now you are using /e, in this case yes you have to wait.

renekuehl commented 2 years ago

Thanks for your Reply. Perhaps I will test LineageOs for microG. Atm its just a Test on my Mi8. Still got a LeEco Le Pro3 at Home. Gonna do some tests there ;)

felschr commented 2 years ago

I've got the same issue. Currently running CalyxOS 3.2.0 with microG 0.2.24.214816-23. Active location modules: Déjà Vu, GSM, Nominatim

gdt commented 1 year ago

I wonder if the issue is HA not parsing a reply that validly contains coordinates but not address, if nominatim is disabled, or if having a partial answer is not actually allowed. One could try a debug microg build that returns something made up like 1600 Pennsylvania Avenue when there is no geocoder.

Zocker1999NET commented 1 year ago

got a new phone in the meantime, LOS 19 / Android 12 on Fairphone 4 with microg 0.2.26.223616, and it magically works know, but only if the "Single Accurate Location" sensor is enabled with the option "include in sensor update" like another user stated here already. Has anyone else similar experiences when configuring the app like that?

nathaniel-bennett commented 10 months ago

@Zocker1999NET The configuration you described is precisely what made my phone work. I have a Pixel 3 running CalyxOS/MicroG, and no combination of permissions toggling or HA settings made any difference until I read your comment and turned on Single Accurate Location + "include in sensor update". Maybe it's a viable workaround more generally?

ale5000-git commented 10 months ago

For all: try to update microG, maybe the situation improve => https://github.com/micro5k/gmscore-info

PylotLight commented 10 months ago

Would this work for grapheneOS at all with microG installed?

ale5000-git commented 10 months ago

It depends whether you are able to install microG correctly under GrapheneOS.

I may be wrong but if I remember correctly it is the ROM where it is most complicate. You need to have signature spoofing working properly.

ale5000-git commented 10 months ago

Could all of you please try with the latest official nightly build?

Forage commented 3 months ago

To quickly respond to @ale5000-git, the issue remains with the following setup: OnePlus 6 LineageOS 21 MicroG Core 0.2.27.223616 Home Assistant 2024.4.1-full

Background Location reporting through the app fails. The "Single Accurate Location" + "include in sensor update" work-around does work, but implies reporting all over the place and increased battery drain.

This would be with the latest stable release of MicroG. I just noticed 0.28.231657 has "Entirely new, rewritten location stack" as one of the changes, which could be promising. Though, I'm a bit hesitant to install a non-stable version.

Forage commented 3 months ago

...I just went for it. After updating to MicroG 3.1.240913 I can confirm that the background location issue is fixed! I can disable the "include in sensor update" option under "Single Accurate Location" and the HA location app log is nicely listing "Background Location" submissions. No constant, though still often, green location usage indication dot either any longer.

Note that this was on a lineageos4microg build, so you can just use F-droid to manually install the latest MicroG version. The MicroG repository is already included by default. Do not forget to update the MicroG Services together with the MicroG Companion app to their latest versions.