Minor fixes

This commit is contained in:
Vitaliy 2021-01-22 16:34:24 +02:00
parent 2327f84af7
commit 91a3098f8d
5 changed files with 31 additions and 34 deletions

View file

@ -1,6 +1,5 @@
package net.osmand.aidlapi.map;
import android.location.Location;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

View file

@ -42,13 +42,13 @@ public class SetLocationParams extends AidlParams {
@Override
public void writeToBundle(Bundle bundle) {
bundle.putParcelable("location", location);
bundle.putLong("aidl_time_to_not_use_other_gps", timeToNotUseOtherGPS);
bundle.putLong("timeToNotUseOtherGPS", timeToNotUseOtherGPS);
}
@Override
protected void readFromBundle(Bundle bundle) {
bundle.setClassLoader(ALocation.class.getClassLoader());
location = bundle.getParcelable("location");
timeToNotUseOtherGPS = bundle.getLong("aidl_time_to_not_use_other_gps");
timeToNotUseOtherGPS = bundle.getLong("timeToNotUseOtherGPS");
}
}

View file

@ -58,7 +58,6 @@ import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.SQLiteTileSource;
@ -124,8 +123,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
@ -915,11 +912,13 @@ public class OsmandAidlApi {
BroadcastReceiver setLocationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
ALocation aLocation = intent.getParcelableExtra(AIDL_LOCATION);
long timeToNotUseOtherGPS = intent.getLongExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, 0);
if (aLocation != null && !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) {
Location location = new Location(app.getPackageName());
if (!Algorithms.isEmpty(packName) && aLocation != null
&& !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) {
Location location = new Location(packName);
location.setLatitude(aLocation.getLatitude());
location.setLongitude(aLocation.getLongitude());
location.setTime(aLocation.getTime());
@ -938,14 +937,7 @@ public class OsmandAidlApi {
if (aLocation.hasVerticalAccuracy()) {
location.setVerticalAccuracy(aLocation.getVerticalAccuracy());
}
app.getLocationProvider().setCustomLocation(location);
app.runInUIThread(new Runnable() {
@Override
public void run() {
app.getLocationProvider().setCustomLocation(null);
}
}, timeToNotUseOtherGPS);
app.getLocationProvider().setCustomLocation(location, timeToNotUseOtherGPS);
}
}
};
@ -2454,10 +2446,11 @@ public class OsmandAidlApi {
return true;
}
public boolean setLocation(ALocation location, long timeToNotUseOtherGPS) {
public boolean setLocation(String packName, ALocation location, long timeToNotUseOtherGPS) {
Intent intent = new Intent();
intent.setAction(AIDL_SET_LOCATION);
intent.putExtra(AIDL_LOCATION, location);
intent.putExtra(AIDL_PACKAGE_NAME, packName);
intent.putExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, timeToNotUseOtherGPS);
app.sendBroadcast(intent);
return true;

View file

@ -1450,7 +1450,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
try {
if (params != null) {
OsmandAidlApi api = getApi("setLocation");
return api != null && api.setLocation(params.getLocation(), params.getTimeToNotUseOtherGPS());
String packName = getCallingAppPackName();
return api != null && api.setLocation(packName, params.getLocation(), params.getTimeToNotUseOtherGPS());
}
} catch (Exception e) {
handleException(e);

View file

@ -45,6 +45,7 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.router.RouteSegmentResult;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
@ -93,6 +94,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
private SimulationProvider simulatePosition = null;
private long cachedLocationTimeFix = 0;
private long timeToNotUseOtherGPS = 0;
private net.osmand.Location cachedLocation;
private net.osmand.Location customLocation;
@ -727,11 +729,21 @@ public class OsmAndLocationProvider implements SensorEventListener {
}
}
public void setLocationFromService(net.osmand.Location location) {
if (locationSimulation.isRouteAnimating()) {
return;
public void setCustomLocation(net.osmand.Location location, long ignoreLocationsTime) {
timeToNotUseOtherGPS = System.currentTimeMillis() + ignoreLocationsTime;
customLocation = location;
setLocation(location);
}
private boolean shouldIgnoreLocation(net.osmand.Location location) {
if (customLocation != null && timeToNotUseOtherGPS >= System.currentTimeMillis()) {
return location == null || !Algorithms.stringsEqual(customLocation.getProvider(), location.getProvider());
}
if (hasCustomLocation() && isNotSimulatedLocation(location)) {
return false;
}
public void setLocationFromService(net.osmand.Location location) {
if (locationSimulation.isRouteAnimating() || shouldIgnoreLocation(location)) {
return;
}
if (location != null) {
@ -745,27 +757,19 @@ public class OsmAndLocationProvider implements SensorEventListener {
app.getRoutingHelper().updateLocation(location);
app.getWaypointHelper().locationChanged(location);
}
public void setCustomLocation(net.osmand.Location location) {
customLocation = location;
setLocation(location);
}
private boolean hasCustomLocation() {
return customLocation != null;
}
public void setLocationFromSimulation(net.osmand.Location location) {
setLocation(location);
}
private void setLocation(net.osmand.Location location) {
if (shouldIgnoreLocation(location)) {
return;
}
if (location == null) {
updateGPSInfo(null);
}
if (hasCustomLocation() && isNotSimulatedLocation(location)) {
return;
}
if (location != null) {
// // use because there is a bug on some devices with location.getTime()
lastTimeLocationFixed = System.currentTimeMillis();