[android] Always try all providers even if fused is available

Certain LineageOS ROMs have broken fused location provider that pretends
to be enabled, but in the reality does absolutely nothing. The system just
misreports that fused provider is available, but it doesn't return any
location updates. This behavior is affected by privacy-related checkboxes
offered during initial onboarding screens.

This PR always tries all three providers (fused, gps and network) even
if fused is reported to be available.

Closes #4158

Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
This commit is contained in:
Roman Tsisyk 2023-04-23 12:54:57 +03:00
parent 1ad8df1965
commit a22e306212

View file

@ -14,11 +14,9 @@ import androidx.core.location.LocationManagerCompat;
import androidx.core.location.LocationRequestCompat;
import app.organicmaps.MwmApplication;
import app.organicmaps.util.LocationUtils;
import app.organicmaps.util.log.Logger;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class AndroidNativeProvider extends BaseLocationProvider
@ -88,21 +86,17 @@ class AndroidNativeProvider extends BaseLocationProvider
.setQuality(LocationRequestCompat.QUALITY_HIGH_ACCURACY)
.build();
if (mLocationManager.isProviderEnabled(LocationUtils.FUSED_PROVIDER))
{
// The FUSED provider takes into account both GPS and NETWORK and potentially other sensors as well.
// https://issuetracker.google.com/issues/215186921#comment3
mProviders.add(LocationUtils.FUSED_PROVIDER);
}
else
{
if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
mProviders.add(LocationManager.GPS_PROVIDER);
if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
mProviders.add(LocationManager.NETWORK_PROVIDER);
}
// API 31+ provides `fused` provider which aggregates `gps` and `network` and potentially other sensors as well.
// Unfortunately, certain LineageOS ROMs have broken `fused` provider that pretends to be enabled, but in
// reality it does absolutely nothing and doesn't return any location updates. For this reason, we try all
// (`fused`, `network`, `gps`) providers here, but prefer `fused` in LocationHelper.onLocationChanged().
//
// https://developer.android.com/reference/android/location/LocationManager#FUSED_PROVIDER
// https://issuetracker.google.com/issues/215186921#comment3
// https://github.com/organicmaps/organicmaps/issues/4158
//
mProviders.addAll(mLocationManager.getProviders(true));
mProviders.remove(LocationManager.PASSIVE_PROVIDER); // not really useful if other providers are enabled.
if (mProviders.isEmpty())
{
// Call this callback in the next event loop to allow LocationHelper::start() to finish.