Minor fixes
This commit is contained in:
parent
2327f84af7
commit
91a3098f8d
5 changed files with 31 additions and 34 deletions
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.aidlapi.map;
|
package net.osmand.aidlapi.map;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
|
@ -42,13 +42,13 @@ public class SetLocationParams extends AidlParams {
|
||||||
@Override
|
@Override
|
||||||
public void writeToBundle(Bundle bundle) {
|
public void writeToBundle(Bundle bundle) {
|
||||||
bundle.putParcelable("location", location);
|
bundle.putParcelable("location", location);
|
||||||
bundle.putLong("aidl_time_to_not_use_other_gps", timeToNotUseOtherGPS);
|
bundle.putLong("timeToNotUseOtherGPS", timeToNotUseOtherGPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readFromBundle(Bundle bundle) {
|
protected void readFromBundle(Bundle bundle) {
|
||||||
bundle.setClassLoader(ALocation.class.getClassLoader());
|
bundle.setClassLoader(ALocation.class.getClassLoader());
|
||||||
location = bundle.getParcelable("location");
|
location = bundle.getParcelable("location");
|
||||||
timeToNotUseOtherGPS = bundle.getLong("aidl_time_to_not_use_other_gps");
|
timeToNotUseOtherGPS = bundle.getLong("timeToNotUseOtherGPS");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -58,7 +58,6 @@ import net.osmand.plus.FavouritesDbHelper;
|
||||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.OsmAndLocationProvider;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.SQLiteTileSource;
|
import net.osmand.plus.SQLiteTileSource;
|
||||||
|
@ -124,8 +123,6 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -915,11 +912,13 @@ public class OsmandAidlApi {
|
||||||
BroadcastReceiver setLocationReceiver = new BroadcastReceiver() {
|
BroadcastReceiver setLocationReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
|
||||||
ALocation aLocation = intent.getParcelableExtra(AIDL_LOCATION);
|
ALocation aLocation = intent.getParcelableExtra(AIDL_LOCATION);
|
||||||
long timeToNotUseOtherGPS = intent.getLongExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, 0);
|
long timeToNotUseOtherGPS = intent.getLongExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, 0);
|
||||||
|
|
||||||
if (aLocation != null && !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) {
|
if (!Algorithms.isEmpty(packName) && aLocation != null
|
||||||
Location location = new Location(app.getPackageName());
|
&& !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) {
|
||||||
|
Location location = new Location(packName);
|
||||||
location.setLatitude(aLocation.getLatitude());
|
location.setLatitude(aLocation.getLatitude());
|
||||||
location.setLongitude(aLocation.getLongitude());
|
location.setLongitude(aLocation.getLongitude());
|
||||||
location.setTime(aLocation.getTime());
|
location.setTime(aLocation.getTime());
|
||||||
|
@ -938,14 +937,7 @@ public class OsmandAidlApi {
|
||||||
if (aLocation.hasVerticalAccuracy()) {
|
if (aLocation.hasVerticalAccuracy()) {
|
||||||
location.setVerticalAccuracy(aLocation.getVerticalAccuracy());
|
location.setVerticalAccuracy(aLocation.getVerticalAccuracy());
|
||||||
}
|
}
|
||||||
app.getLocationProvider().setCustomLocation(location);
|
app.getLocationProvider().setCustomLocation(location, timeToNotUseOtherGPS);
|
||||||
|
|
||||||
app.runInUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
app.getLocationProvider().setCustomLocation(null);
|
|
||||||
}
|
|
||||||
}, timeToNotUseOtherGPS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2454,10 +2446,11 @@ public class OsmandAidlApi {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setLocation(ALocation location, long timeToNotUseOtherGPS) {
|
public boolean setLocation(String packName, ALocation location, long timeToNotUseOtherGPS) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(AIDL_SET_LOCATION);
|
intent.setAction(AIDL_SET_LOCATION);
|
||||||
intent.putExtra(AIDL_LOCATION, location);
|
intent.putExtra(AIDL_LOCATION, location);
|
||||||
|
intent.putExtra(AIDL_PACKAGE_NAME, packName);
|
||||||
intent.putExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, timeToNotUseOtherGPS);
|
intent.putExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, timeToNotUseOtherGPS);
|
||||||
app.sendBroadcast(intent);
|
app.sendBroadcast(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1450,7 +1450,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
|
||||||
try {
|
try {
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
OsmandAidlApi api = getApi("setLocation");
|
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) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.router.RouteSegmentResult;
|
import net.osmand.router.RouteSegmentResult;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -93,6 +94,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
private SimulationProvider simulatePosition = null;
|
private SimulationProvider simulatePosition = null;
|
||||||
|
|
||||||
private long cachedLocationTimeFix = 0;
|
private long cachedLocationTimeFix = 0;
|
||||||
|
private long timeToNotUseOtherGPS = 0;
|
||||||
private net.osmand.Location cachedLocation;
|
private net.osmand.Location cachedLocation;
|
||||||
private net.osmand.Location customLocation;
|
private net.osmand.Location customLocation;
|
||||||
|
|
||||||
|
@ -727,11 +729,21 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationFromService(net.osmand.Location location) {
|
public void setCustomLocation(net.osmand.Location location, long ignoreLocationsTime) {
|
||||||
if (locationSimulation.isRouteAnimating()) {
|
timeToNotUseOtherGPS = System.currentTimeMillis() + ignoreLocationsTime;
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
|
@ -745,27 +757,19 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
app.getRoutingHelper().updateLocation(location);
|
app.getRoutingHelper().updateLocation(location);
|
||||||
app.getWaypointHelper().locationChanged(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) {
|
public void setLocationFromSimulation(net.osmand.Location location) {
|
||||||
setLocation(location);
|
setLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLocation(net.osmand.Location location) {
|
private void setLocation(net.osmand.Location location) {
|
||||||
|
if (shouldIgnoreLocation(location)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
updateGPSInfo(null);
|
updateGPSInfo(null);
|
||||||
}
|
}
|
||||||
if (hasCustomLocation() && isNotSimulatedLocation(location)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
// // use because there is a bug on some devices with location.getTime()
|
// // use because there is a bug on some devices with location.getTime()
|
||||||
lastTimeLocationFixed = System.currentTimeMillis();
|
lastTimeLocationFixed = System.currentTimeMillis();
|
||||||
|
|
Loading…
Reference in a new issue