Skip to content

Commit

Permalink
Fix:vehicle/android:Never use fused provider for precise location (#1202
Browse files Browse the repository at this point in the history
)

Signed-off-by: mvglasow <michael -at- vonglasow.com>

Signed-off-by: mvglasow <michael -at- vonglasow.com>
Co-authored-by: mvglasow <michael -at- vonglasow.com>
  • Loading branch information
mvglasow committed Oct 15, 2022
1 parent 54df123 commit aae00d4
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions navit/android/src/org/navitproject/navit/NavitVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.support.v4.content.ContextCompat;
import android.util.Log;

import java.util.HashSet;
import java.util.List;


Expand Down Expand Up @@ -163,10 +164,78 @@ public void onReceive(Context context, Intent intent) {

Log.d("NavitVehicle", "Providers " + sLocationManager.getAllProviders());

String mPreciseProvider = sLocationManager.getBestProvider(highCriteria, false);
HashSet<String> preciseProviders;
try {
preciseProviders = new HashSet<String>(sLocationManager.getProviders(highCriteria, false));
} catch (NullPointerException e) {
preciseProviders = new HashSet<String>();
}
HashSet<String> fastProviders;
try {
fastProviders = new HashSet<String>(sLocationManager.getProviders(lowCriteria, false));
} catch (NullPointerException e) {
fastProviders = new HashSet<String>();
}
/*
* Never use the passive and fused providers for the precise providers.
* These merge data from multiple sources, which can lead to your location skipping back and
* forth between two places. While that may be acceptable for the fast provider (just to get a
* first location), it may render navigation unusable if such a provider were to be used as the
* precise provider.
*/
preciseProviders.remove(LocationManager.PASSIVE_PROVIDER);
preciseProviders.remove("fused");

/*
* Some magic to pick the precise provider:
* If Android’s best chosen provider is on our list, use that.
* Otherwise, if the list has only one candidate, use that.
* Otherwise, prefer GPS for the precise provider, if available.
* Otherwise, just pick a random provider from the list.
*/
Log.d("NavitVehicle", "Precise Provider candidates " + preciseProviders);
String mPreciseProvider = null;
if (preciseProviders.contains(sLocationManager.getBestProvider(highCriteria, false)))
mPreciseProvider = sLocationManager.getBestProvider(highCriteria, false);
else if (preciseProviders.size() == 1)
for (String provider : preciseProviders)
mPreciseProvider = provider;
else if (preciseProviders.contains(LocationManager.GPS_PROVIDER))
mPreciseProvider = LocationManager.GPS_PROVIDER;
else
/*
* Multiple providers, but no GPS, nor any fused/passive providers, and we can’t use the
* best provider suggested by the OS.
* If we ever get here, we’re on a very exotic device.
* This may need some more tweaks – right now, we just pick one at random.
*/
for (String provider : preciseProviders) {
mPreciseProvider = provider;
break;
}
Log.d("NavitVehicle", "Precise Provider " + mPreciseProvider);
mFastProvider = sLocationManager.getBestProvider(lowCriteria, false);

/*
* Similar magic to pick the fast provider:
* Eliminate the precise provider from our list so we get to use two providers.
* If Android’s best chosen provider is on our list, use that.
* Otherwise, if the list has only one candidate, use that.
* Otherwise, just pick a random provider from the list.
*/
fastProviders.remove(mPreciseProvider);
Log.d("NavitVehicle", "Fast Provider candidates " + fastProviders);
if (fastProviders.contains(sLocationManager.getBestProvider(lowCriteria, false)))
mFastProvider = sLocationManager.getBestProvider(lowCriteria, false);
else if (fastProviders.size() == 1)
for (String provider: fastProviders)
mFastProvider = provider;
else
for (String provider: fastProviders) {
mFastProvider = provider;
break;
}
Log.d("NavitVehicle", "Fast Provider " + mFastProvider);

mVehiclePcbid = pcbid;
mVehicleScbid = scbid;
mVehicleFcbid = fcbid;
Expand Down

0 comments on commit aae00d4

Please sign in to comment.