From 625ff2face1cef73757f58d7d961c59da031aa40 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 17 Dec 2020 15:45:48 +0200 Subject: [PATCH] Add ability to add and remove avoid roads via aidl --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 10 +++- ...ockedRoadParams.aidl => ABlockedRoad.aidl} | 2 +- ...ockedRoadParams.java => ABlockedRoad.java} | 16 +++---- .../navigation/AddBlockedRoadParams.aidl | 3 ++ .../navigation/AddBlockedRoadParams.java | 46 +++++++++++++++++++ .../navigation/RemoveBlockedRoadParams.aidl | 3 ++ .../navigation/RemoveBlockedRoadParams.java | 46 +++++++++++++++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 17 +++++-- .../net/osmand/aidl/OsmandAidlServiceV2.java | 38 ++++++++++++++- .../plus/helpers/AvoidSpecificRoads.java | 3 +- 10 files changed, 167 insertions(+), 17 deletions(-) rename OsmAnd-api/src/net/osmand/aidlapi/navigation/{ABlockedRoadParams.aidl => ABlockedRoad.aidl} (57%) rename OsmAnd-api/src/net/osmand/aidlapi/navigation/{ABlockedRoadParams.java => ABlockedRoad.java} (74%) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.java create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 0325c2a723..92115f873b 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -92,7 +92,9 @@ import net.osmand.aidlapi.copyfile.CopyFileParams; import net.osmand.aidlapi.navigation.ANavigationUpdateParams; import net.osmand.aidlapi.navigation.ANavigationVoiceRouterMessageParams; -import net.osmand.aidlapi.navigation.ABlockedRoadParams; +import net.osmand.aidlapi.navigation.ABlockedRoad; +import net.osmand.aidlapi.navigation.AddBlockedRoadParams; +import net.osmand.aidlapi.navigation.RemoveBlockedRoadParams; import net.osmand.aidlapi.contextmenu.ContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.UpdateContextMenuButtonsParams; @@ -894,5 +896,9 @@ interface IOsmAndAidlInterface { boolean getProfiles(out List profiles); - boolean getBlockedRoads(out List blockedRoads); + boolean getBlockedRoads(out List blockedRoads); + + boolean addRoadBlock(in AddBlockedRoadParams params); + + boolean removeRoadBlock(in RemoveBlockedRoadParams params); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoadParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.aidl similarity index 57% rename from OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoadParams.aidl rename to OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.aidl index ff967858c0..23c31596d5 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoadParams.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.aidl @@ -1,3 +1,3 @@ package net.osmand.aidlapi.navigation; -parcelable ABlockedRoadParams; \ No newline at end of file +parcelable ABlockedRoad; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoadParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.java similarity index 74% rename from OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoadParams.java rename to OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.java index a6dd2a18b5..e83f64334b 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoadParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.java @@ -5,7 +5,7 @@ import android.os.Parcel; import net.osmand.aidlapi.AidlParams; -public class ABlockedRoadParams extends AidlParams { +public class ABlockedRoad extends AidlParams { private long roadId; private double latitude; @@ -14,7 +14,7 @@ public class ABlockedRoadParams extends AidlParams { private String name; private String appModeKey; - public ABlockedRoadParams(long roadId, double latitude, double longitude, double direction, String name, String appModeKey) { + public ABlockedRoad(long roadId, double latitude, double longitude, double direction, String name, String appModeKey) { this.roadId = roadId; this.latitude = latitude; this.longitude = longitude; @@ -23,19 +23,19 @@ public class ABlockedRoadParams extends AidlParams { this.appModeKey = appModeKey; } - protected ABlockedRoadParams(Parcel in) { + protected ABlockedRoad(Parcel in) { readFromParcel(in); } - public static final Creator CREATOR = new Creator() { + public static final Creator CREATOR = new Creator() { @Override - public ABlockedRoadParams createFromParcel(Parcel in) { - return new ABlockedRoadParams(in); + public ABlockedRoad createFromParcel(Parcel in) { + return new ABlockedRoad(in); } @Override - public ABlockedRoadParams[] newArray(int size) { - return new ABlockedRoadParams[size]; + public ABlockedRoad[] newArray(int size) { + return new ABlockedRoad[size]; } }; diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.aidl new file mode 100644 index 0000000000..5eb74b0b53 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.navigation; + +parcelable AddBlockedRoadParams; diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.java new file mode 100644 index 0000000000..b64a9d32ce --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.java @@ -0,0 +1,46 @@ +package net.osmand.aidlapi.navigation; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class AddBlockedRoadParams extends AidlParams { + + private ABlockedRoad blockedRoad; + + public AddBlockedRoadParams(ABlockedRoad blockedRoad) { + this.blockedRoad = blockedRoad; + } + + public AddBlockedRoadParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AddBlockedRoadParams createFromParcel(Parcel in) { + return new AddBlockedRoadParams(in); + } + + @Override + public AddBlockedRoadParams[] newArray(int size) { + return new AddBlockedRoadParams[size]; + } + }; + + public ABlockedRoad getBlockedRoad() { + return blockedRoad; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putParcelable("blockedRoad", blockedRoad); + } + + @Override + protected void readFromBundle(Bundle bundle) { + bundle.setClassLoader(ABlockedRoad.class.getClassLoader()); + blockedRoad = bundle.getParcelable("blockedRoad"); + } +} \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.aidl new file mode 100644 index 0000000000..02c9f36f0c --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.navigation; + +parcelable RemoveBlockedRoadParams; diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.java new file mode 100644 index 0000000000..1cb4e2e6a5 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.java @@ -0,0 +1,46 @@ +package net.osmand.aidlapi.navigation; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class RemoveBlockedRoadParams extends AidlParams { + + private ABlockedRoad blockedRoad; + + public RemoveBlockedRoadParams(ABlockedRoad blockedRoad) { + this.blockedRoad = blockedRoad; + } + + public RemoveBlockedRoadParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public RemoveBlockedRoadParams createFromParcel(Parcel in) { + return new RemoveBlockedRoadParams(in); + } + + @Override + public RemoveBlockedRoadParams[] newArray(int size) { + return new RemoveBlockedRoadParams[size]; + } + }; + + public ABlockedRoad getBlockedRoad() { + return blockedRoad; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putParcelable("blockedRoad", blockedRoad); + } + + @Override + protected void readFromBundle(Bundle bundle) { + bundle.setClassLoader(ABlockedRoad.class.getClassLoader()); + blockedRoad = bundle.getParcelable("blockedRoad"); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 864a128114..2f105a7318 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -43,7 +43,7 @@ import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.aidlapi.customization.AProfile; import net.osmand.aidlapi.info.AppInfoParams; import net.osmand.aidlapi.map.ALatLon; -import net.osmand.aidlapi.navigation.ABlockedRoadParams; +import net.osmand.aidlapi.navigation.ABlockedRoad; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -2376,14 +2376,25 @@ public class OsmandAidlApi { return true; } - public boolean getBlockedRoads(List blockedRoads) { + public boolean getBlockedRoads(List blockedRoads) { Map impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads(); for (AvoidRoadInfo info : impassableRoads.values()) { - blockedRoads.add(new ABlockedRoadParams(info.id, info.latitude, info.longitude, info.direction, info.name, info.appModeKey)); + blockedRoads.add(new ABlockedRoad(info.id, info.latitude, info.longitude, info.direction, info.name, info.appModeKey)); } return true; } + public boolean addRoadBlock(ABlockedRoad road) { + LatLon latLon = new LatLon(road.getLatitude(), road.getLongitude()); + app.getAvoidSpecificRoads().addImpassableRoad(null, latLon, false, false, null); + return true; + } + + public boolean removeRoadBlock(ABlockedRoad road) { + app.getAvoidSpecificRoads().removeImpassableRoad(new LatLon(road.getLatitude(), road.getLongitude())); + return true; + } + private static class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index c28ef2842b..2cd422873d 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -73,14 +73,16 @@ import net.osmand.aidlapi.navdrawer.NavDrawerFooterParams; import net.osmand.aidlapi.navdrawer.NavDrawerHeaderParams; import net.osmand.aidlapi.navdrawer.NavDrawerItem; import net.osmand.aidlapi.navdrawer.SetNavDrawerItemsParams; -import net.osmand.aidlapi.navigation.ABlockedRoadParams; +import net.osmand.aidlapi.navigation.ABlockedRoad; import net.osmand.aidlapi.navigation.ANavigationUpdateParams; import net.osmand.aidlapi.navigation.ANavigationVoiceRouterMessageParams; +import net.osmand.aidlapi.navigation.AddBlockedRoadParams; import net.osmand.aidlapi.navigation.MuteNavigationParams; import net.osmand.aidlapi.navigation.NavigateGpxParams; import net.osmand.aidlapi.navigation.NavigateParams; import net.osmand.aidlapi.navigation.NavigateSearchParams; import net.osmand.aidlapi.navigation.PauseNavigationParams; +import net.osmand.aidlapi.navigation.RemoveBlockedRoadParams; import net.osmand.aidlapi.navigation.ResumeNavigationParams; import net.osmand.aidlapi.navigation.StopNavigationParams; import net.osmand.aidlapi.navigation.UnmuteNavigationParams; @@ -1399,7 +1401,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener } @Override - public boolean getBlockedRoads(List blockedRoads) { + public boolean getBlockedRoads(List blockedRoads) { try { OsmandAidlApi api = getApi("getBlockedRoads"); return api != null && api.getBlockedRoads(blockedRoads); @@ -1408,6 +1410,38 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return false; } } + + @Override + public boolean addRoadBlock(AddBlockedRoadParams params) { + try { + OsmandAidlApi api = getApi("addRoadBlock"); + if (params != null && api != null) { + ABlockedRoad road = params.getBlockedRoad(); + if (road != null) { + return api.addRoadBlock(road); + } + } + } catch (Exception e) { + handleException(e); + } + return false; + } + + @Override + public boolean removeRoadBlock(RemoveBlockedRoadParams params) { + try { + OsmandAidlApi api = getApi("removeRoadBlock"); + if (params != null && api != null) { + ABlockedRoad road = params.getBlockedRoad(); + if (road != null) { + return api.removeRoadBlock(road); + } + } + } catch (Exception e) { + handleException(e); + } + return false; + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java index 690c990589..bfa84b8474 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java +++ b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java @@ -393,6 +393,7 @@ public class AvoidSpecificRoads { if (object != null) { avoidRoadInfo.id = object.id; // avoidRoadInfo.direction = object.directionRoute(0, true); + avoidRoadInfo.direction = Double.NaN; } else { avoidRoadInfo.id = 0; avoidRoadInfo.direction = Double.NaN; @@ -406,7 +407,7 @@ public class AvoidSpecificRoads { public static class AvoidRoadInfo { public long id; - public double direction; + public double direction = Double.NaN; public double latitude; public double longitude; public String name;