From d014c7a8419ef7caa24ffe94669ceed1e279ae88 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Fri, 5 Apr 2019 17:16:05 +0300 Subject: [PATCH 01/15] Add api method to subscribe for updates on next turn type and distance via callback. --- .../net/osmand/aidl/IOsmAndAidlCallback.aidl | 3 + .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 4 +- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 76 ++++++++++++++++++- .../net/osmand/aidl/OsmandAidlConstants.java | 15 ++++ .../net/osmand/aidl/OsmandAidlService.java | 20 +++++ .../aidl/navigation/ADirectionInfo.aidl | 3 + .../aidl/navigation/ADirectionInfo.java | 73 ++++++++++++++++++ .../navigation/ANavigationUpdateParams.aidl | 4 + .../navigation/ANavigationUpdateParams.java | 57 ++++++++++++++ .../osmand/plus/routing/RoutingHelper.java | 3 + 10 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.java diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl index 6f0cb8f65b..eb12810adb 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl @@ -2,6 +2,7 @@ package net.osmand.aidl; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.gpx.AGpxBitmap; +import net.osmand.aidl.navigation.ADirectionInfo; interface IOsmAndAidlCallback { void onSearchComplete(in List resultSet); @@ -11,4 +12,6 @@ interface IOsmAndAidlCallback { void onAppInitialized(); void onGpxBitmapCreated(in AGpxBitmap bitmap); + + void updateNavigationInfo(in ADirectionInfo directionInfo); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index d8aa037510..f418b2b561 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -81,7 +81,7 @@ import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.aidl.plugins.PluginParams; import net.osmand.aidl.copyfile.CopyFileParams; - +import net.osmand.aidl.navigation.ANavigationUpdateParams; // NOTE: Add new methods at the end of file!!! @@ -182,4 +182,6 @@ interface IOsmAndAidlInterface { boolean getBitmapForGpx(in CreateGpxBitmapParams file, IOsmAndAidlCallback callback); int copyFile(in CopyFileParams filePart); + + long registerForNavigationUpdates(in ANavigationUpdateParams params, IOsmAndAidlCallback callback); } \ 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 cb5a26b35e..ff47cee9d6 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -42,6 +42,8 @@ import net.osmand.aidl.maplayer.point.AMapPoint; import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapwidget.AMapWidget; import net.osmand.aidl.navdrawer.NavDrawerFooterParams; +import net.osmand.aidl.navigation.ADirectionInfo; +import net.osmand.aidl.navigation.ANavigationUpdateParams; import net.osmand.aidl.plugins.PluginParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; @@ -75,6 +77,7 @@ import net.osmand.plus.helpers.ExternalApiHelper; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.TrackBitmapDrawer; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.AidlMapLayer; import net.osmand.plus.views.MapInfoLayer; @@ -83,6 +86,7 @@ import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.mapwidgets.TextInfoWidget; +import net.osmand.router.TurnType; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -191,6 +195,9 @@ public class OsmandAidlApi { private boolean mapActivityActive = false; + private Map callbacks; + private long updateCallbackId = 0; + public OsmandAidlApi(OsmandApplication app) { this.app = app; loadConnectedApps(); @@ -238,6 +245,12 @@ public class OsmandAidlApi { receivers = new TreeMap<>(); } + + public static boolean isAidlSubscribedForUpdates() { +// return !callbacks.isEmpty(); + return true; + } + public boolean isUpdateAllowed() { return mapActivityActive; } @@ -1918,6 +1931,57 @@ public class OsmandAidlApi { return app.getAppCustomization().changePluginStatus(params); } + public long registerForNavigationUpdates(ANavigationUpdateParams params, IOsmAndAidlCallback callback) { + if (params.isSubscribeToUpdates()) { + updateCallbackId++; + callbacks.put(updateCallbackId, callback); + startNavigationalUpdates(updateCallbackId); + return updateCallbackId; + } else { + callbacks.remove(params.getCallbackId()); + return -1; + } + } + + public NavUpdateListener navUpdateListener = null; + + public boolean isActiveListeners() { + return callbacks.size() > 0; + } + + private void startNavigationalUpdates(final long updateCallbackId) { + final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); + final NextDirectionInfo baseNdi = new NextDirectionInfo(); + navUpdateListener = new NavUpdateListener() { + @Override + public void onNavUpdate() { + RoutingHelper rh = app.getRoutingHelper(); + if (callbacks.containsKey(updateCallbackId)) { + if (rh.isDeviatedFromRoute()) { + directionInfo.setTurnType(TurnType.OFFR); + directionInfo.setDistanceTo((int) rh.getRouteDeviation()); + } else { + NextDirectionInfo ndi = rh.getNextRouteDirectionInfo(baseNdi, true); + if (ndi != null && ndi.distanceTo > 0 && ndi.directionInfo != null) { + directionInfo.setDistanceTo(ndi.distanceTo); + directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); + } + } + try { + callbacks.get(updateCallbackId).updateNavigationInfo(directionInfo); + } catch (Exception e) { + LOG.debug(e.getMessage(), e); + } + } + } + }; + } + + public interface NavUpdateListener { + void onNavUpdate(); + } + + boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { if (gpxUri == null || callback == null) { return false; @@ -2103,6 +2167,8 @@ public class OsmandAidlApi { } } + + private static AGpxFileDetails createGpxFileDetails(@NonNull GPXTrackAnalysis a) { return new AGpxFileDetails(a.totalDistance, a.totalTracks, a.startTime, a.endTime, a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown, @@ -2179,6 +2245,12 @@ public class OsmandAidlApi { } public interface OsmandAppInitCallback { - void onAppInitialized(); - } + void onAppInitialized(); + } + + public interface DirectionsUpdateCallback { + void onDirectionsUpdate(ADirectionInfo directionInfo); + } + + } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlConstants.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlConstants.java index a74fb67b5a..583a77c4e1 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlConstants.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlConstants.java @@ -18,4 +18,19 @@ public interface OsmandAidlConstants { int COPY_FILE_WRITE_LOCK_ERROR = -1003; int COPY_FILE_IO_ERROR = -1004; int COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR = -1005; + + int TURN_TYPE_C = 1;//"C"; // continue (go straight) //$NON-NLS-1$ + int TURN_TYPE_TL = 2; // turn left //$NON-NLS-1$ + int TURN_TYPE_TSLL = 3; // turn slightly left //$NON-NLS-1$ + int TURN_TYPE_TSHL = 4; // turn sharply left //$NON-NLS-1$ + int TURN_TYPE_TR = 5; // turn right //$NON-NLS-1$ + int TURN_TYPE_TSLR = 6; // turn slightly right //$NON-NLS-1$ + int TURN_TYPE_TSHR = 7; // turn sharply right //$NON-NLS-1$ + int TURN_TYPE_KL = 8; // keep left //$NON-NLS-1$ + int TURN_TYPE_KR = 9; // keep right//$NON-NLS-1$ + int TURN_TYPE_TU = 10; // U-turn //$NON-NLS-1$ + int TURN_TYPE_TRU = 11; // Right U-turn //$NON-NLS-1$ + int TURN_TYPE_OFFR = 12; // Off route //$NON-NLS-1$ + int TURN_TYPE_RNDB = 13; // Roundabout + int TURN_TYPE_RNLB = 14; // Roundabout left } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 846ebad253..f334494ba5 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -11,6 +11,7 @@ import android.os.RemoteException; import android.support.annotation.Nullable; import net.osmand.PlatformUtil; +import net.osmand.aidl.OsmandAidlApi.DirectionsUpdateCallback; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback; @@ -50,6 +51,8 @@ import net.osmand.aidl.mapwidget.UpdateMapWidgetParams; import net.osmand.aidl.navdrawer.NavDrawerFooterParams; import net.osmand.aidl.navdrawer.NavDrawerHeaderParams; import net.osmand.aidl.navdrawer.SetNavDrawerItemsParams; +import net.osmand.aidl.navigation.ADirectionInfo; +import net.osmand.aidl.navigation.ANavigationUpdateParams; import net.osmand.aidl.navigation.MuteNavigationParams; import net.osmand.aidl.navigation.NavigateGpxParams; import net.osmand.aidl.navigation.NavigateParams; @@ -68,6 +71,8 @@ import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.aidl.copyfile.CopyFileParams; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; +import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -992,5 +997,20 @@ public class OsmandAidlService extends Service { return UNKNOWN_API_ERROR; } } + + @Override + public long registerForNavigationUpdates(ANavigationUpdateParams params, final IOsmAndAidlCallback callback) { + try { + OsmandAidlApi api = getApi("registerForNavUpdates"); + if (api != null) { + return api.registerForNavigationUpdates(params, callback); + } else { + return -1; + } + } catch (Exception e) { + handleException(e); + return UNKNOWN_API_ERROR; + } + } }; } diff --git a/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.aidl b/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.aidl new file mode 100644 index 0000000000..b0793d6e1a --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable ADirectionInfo; diff --git a/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java b/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java new file mode 100644 index 0000000000..f83c9c5764 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java @@ -0,0 +1,73 @@ +package net.osmand.aidl.navigation; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ADirectionInfo implements Parcelable { + + private int distanceTo; //distance to next turn + private int turnType; //turn type + private boolean isLeftSide; //is movement leftsided + + public ADirectionInfo(int distanceTo, int turnType, boolean isLeftSide) { + this.distanceTo = distanceTo; + this.turnType = turnType; + this.isLeftSide = isLeftSide; + } + + protected ADirectionInfo(Parcel in) { + distanceTo = in.readInt(); + turnType = in.readInt(); + isLeftSide = in.readByte() != 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public ADirectionInfo createFromParcel(Parcel in) { + return new ADirectionInfo(in); + } + + @Override + public ADirectionInfo[] newArray(int size) { + return new ADirectionInfo[size]; + } + }; + + public int getDistanceTo() { + return distanceTo; + } + + public int getTurnType() { + return turnType; + } + + public boolean isLeftSide() { + return isLeftSide; + } + + public void setDistanceTo(int distanceTo) { + this.distanceTo = distanceTo; + } + + public void setTurnType(int turnType) { + this.turnType = turnType; + } + + public void setLeftSide(boolean leftSide) { + isLeftSide = leftSide; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(distanceTo); + dest.writeInt(turnType); + dest.writeByte((byte) (isLeftSide ? 1 : 0)); + } + + +} diff --git a/OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.aidl new file mode 100644 index 0000000000..43f370d024 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.aidl @@ -0,0 +1,4 @@ + +package net.osmand.aidl.navigation; + +parcelable ANavigationUpdateParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.java b/OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.java new file mode 100644 index 0000000000..38c8f5ffe4 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/ANavigationUpdateParams.java @@ -0,0 +1,57 @@ +package net.osmand.aidl.navigation; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ANavigationUpdateParams implements Parcelable { + + private boolean subscribeToUpdates = true; + private long callbackId = -1L; + + public ANavigationUpdateParams() { + } + + public long getCallbackId() { + return callbackId; + } + + public void setCallbackId(long callbackId) { + this.callbackId = callbackId; + } + + public void setSubscribeToUpdates(boolean subscribeToUpdates) { + this.subscribeToUpdates = subscribeToUpdates; + } + + public boolean isSubscribeToUpdates() { + return subscribeToUpdates; + } + + protected ANavigationUpdateParams(Parcel in) { + callbackId = in.readLong(); + subscribeToUpdates = in.readByte() != 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeLong(callbackId); + dest.writeByte((byte) (subscribeToUpdates ? 1 : 0)); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public ANavigationUpdateParams createFromParcel(Parcel in) { + return new ANavigationUpdateParams(in); + } + + @Override + public ANavigationUpdateParams[] newArray(int size) { + return new ANavigationUpdateParams[size]; + } + }; +} diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 6a0f46a52e..71e03f02d4 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -502,6 +502,9 @@ public class RoutingHelper { route.updateCurrentRoute(newCurrentRoute + 1); currentRoute = newCurrentRoute + 1; app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION); + if (app.getAidlApi().isActiveListeners() && app.getAidlApi().navUpdateListener != null) { + app.getAidlApi().navUpdateListener.onNavUpdate(); + } } else { break; } From 2cbe465fe8d40278d9ecb4b9caa951ec0b4c4efc Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Fri, 5 Apr 2019 18:04:16 +0300 Subject: [PATCH 02/15] documenting aidl --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 87 +++++++++++++++++-- 1 file changed, 82 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index f418b2b561..71e0214604 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -104,25 +104,102 @@ interface IOsmAndAidlInterface { boolean removeMapLayer(in RemoveMapLayerParams params); boolean updateMapLayer(in UpdateMapLayerParams params); - boolean importGpx(in ImportGpxParams params); - boolean showGpx(in ShowGpxParams params); - boolean hideGpx(in HideGpxParams params); - boolean getActiveGpx(out List files); + boolean importGpx(in ImportGpxParams params); + boolean showGpx(in ShowGpxParams params); + boolean hideGpx(in HideGpxParams params); + boolean getActiveGpx(out List files); - boolean setMapLocation(in SetMapLocationParams params); + boolean setMapLocation(in SetMapLocationParams params); boolean calculateRoute(in CalculateRouteParams params); + /** + * Refresh the map (UI) + */ boolean refreshMap(); + /** + * Add favorite group with given params. + * + * @param name - group name. + * @param color - group color. Can be one of: "red", "orange", "yellow", + * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". + * @param visible - group visibility. + */ boolean addFavoriteGroup(in AddFavoriteGroupParams params); + + /** + * Update favorite group with given params. + * + * @param namePrev - group name (current). + * @param colorPrev - group color (current). + * @param visiblePrev - group visibility (current). + * @param nameNew - group name (new). + * @param colorNew - group color (new). + * @param visibleNew - group visibility (new). + */ boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params); + + /** + * Remove favorite group with given name. + * + * @param name - name of favorite group. + */ boolean updateFavoriteGroup(in UpdateFavoriteGroupParams params); + /** + * Add favorite at given location with given params. + * + * @param lat - latitude. + * @param lon - longitude. + * @param name - name of favorite item. + * @param description - description of favorite item. + * @param category - category of favorite item. + * @param color - color of favorite item. Can be one of: "red", "orange", "yellow", + * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". + * @param visible - should favorite item be visible after creation. + */ boolean addFavorite(in AddFavoriteParams params); + + /** + * Update favorite at given location with given params. + * + * @param latPrev - latitude (current favorite). + * @param lonPrev - longitude (current favorite). + * @param namePrev - name of favorite item (current favorite). + * @param categoryPrev - category of favorite item (current favorite). + * @param latNew - latitude (new favorite). + * @param lonNew - longitude (new favorite). + * @param nameNew - name of favorite item (new favorite). + * @param descriptionNew - description of favorite item (new favorite). + * @param categoryNew - category of favorite item (new favorite). Use only to create a new category, + * not to update an existing one. If you want to update an existing category, + * use the {@link #updateFavoriteGroup(String, String, boolean, String, String, boolean)} method. + * @param colorNew - color of new category. Can be one of: "red", "orange", "yellow", + * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". + * @param visibleNew - should new category be visible after creation. + */ boolean removeFavorite(in RemoveFavoriteParams params); + + /** + * Remove favorite at given location with given params. + * + * @param lat - latitude. + * @param lon - longitude. + * @param name - name of favorite item. + * @param category - category of favorite item. + */ boolean updateFavorite(in UpdateFavoriteParams params); + /** + * Add map marker at given location. + * + * @param lat - latitude. + * @param lon - longitude. + * @param name - name. + */ boolean startGpxRecording(in StartGpxRecordingParams params); + + boolean stopGpxRecording(in StopGpxRecordingParams params); boolean takePhotoNote(in TakePhotoNoteParams params); From 408e6b94a4092f24923a1d11b33be469224e3856 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 8 Apr 2019 11:33:20 +0300 Subject: [PATCH 03/15] AIDL documentation --- .../net/osmand/aidl/IOsmAndAidlCallback.aidl | 24 +- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 446 +++++++++++++++++- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 6 - .../aidl/navigation/ADirectionInfo.java | 2 +- 4 files changed, 462 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl index eb12810adb..87f6de79c4 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl @@ -5,13 +5,35 @@ import net.osmand.aidl.gpx.AGpxBitmap; import net.osmand.aidl.navigation.ADirectionInfo; interface IOsmAndAidlCallback { + + /** + * Callback for search requests. + * + * @return resultSet - set of SearchResult + */ void onSearchComplete(in List resultSet); - + + /** + * Callback for {@link IOsmAndAidlInterface} registerForUpdates() method. + */ void onUpdate(); + /** + * Callback for {@link IOsmAndAidlInterface} registerForOsmandInitListener() method. + */ void onAppInitialized(); + /** + * Callback for {@link IOsmAndAidlInterface} getBitmapForGpx() method. + * + * @return bitmap - snapshot image of gpx track on map + */ void onGpxBitmapCreated(in AGpxBitmap bitmap); + /** + * Callback for {@link IOsmAndAidlInterface} registerForNavigationUpdates() method. + * + * @return directionInfo - update on distance to next turn and turns type. + */ void updateNavigationInfo(in ADirectionInfo directionInfo); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 71e0214604..5f5a01ad88 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -88,28 +88,188 @@ import net.osmand.aidl.navigation.ANavigationUpdateParams; interface IOsmAndAidlInterface { + /** + * Add map marker at given location. + * + * @param lat - latitude. + * @param lon - longitude. + * @param name - name. + */ boolean addMapMarker(in AddMapMarkerParams params); + + /** + * Remove map marker at given location with name. + * + * @param lat - latitude. + * @param lon - longitude. + * @param name - name. + */ boolean removeMapMarker(in RemoveMapMarkerParams params); + + /** + * Update map marker at given location with name. + * + * @param latPrev - latitude (current marker). + * @param lonPrev - longitude (current marker). + * @param namePrev - name (current marker). + * @param latNew - latitude (new marker). + * @param lonNew - longitude (new marker). + * @param nameNew - name (new marker). + */ boolean updateMapMarker(in UpdateMapMarkerParams params); + /** + * Add map widget to the right side of the main screen. + * Note: any specified icon should exist in OsmAnd app resources. + * + * @param id - widget id. + * @param menuIconName - icon name (configure map menu). + * @param menuTitle - widget name (configure map menu). + * @param lightIconName - icon name for the light theme (widget). + * @param darkIconName - icon name for the dark theme (widget). + * @param text - main widget text. + * @param description - sub text, like "km/h". + * @param order - order position in the widgets list. + * @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent). + */ boolean addMapWidget(in AddMapWidgetParams params); + + /** + * Remove map widget. + * + * @param id - widget id. + */ boolean removeMapWidget(in RemoveMapWidgetParams params); + + /** + * Update map widget. + * Note: any specified icon should exist in OsmAnd app resources. + * + * @param id - widget id. + * @param menuIconName - icon name (configure map menu). + * @param menuTitle - widget name (configure map menu). + * @param lightIconName - icon name for the light theme (widget). + * @param darkIconName - icon name for the dark theme (widget). + * @param text - main widget text. + * @param description - sub text, like "km/h". + * @param order - order position in the widgets list. + * @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent). + */ boolean updateMapWidget(in UpdateMapWidgetParams params); + /** + * Add point to user layer. + * + * @param layerId - layer id. Note: layer should be added first. + * @param pointId - point id. + * @param shortName - short name (single char). Displayed on the map. + * @param fullName - full name. Displayed in the context menu on first row. + * @param typeName - type name. Displayed in context menu on second row. + * @param color - color of circle's background. + * @param location - location of the point. + * @param details - list of details. Displayed under context menu. + * @param params - optional map of params for point. + */ boolean addMapPoint(in AddMapPointParams params); + + + /** + * Remove point. + * + * @param layerId - layer id. + * @param pointId - point id. + */ boolean removeMapPoint(in RemoveMapPointParams params); + + /** + * Update point. + * + * @param layerId - layer id. + * @param pointId - point id. + * @param shortName - short name (single char). Displayed on the map. + * @param fullName - full name. Displayed in the context menu on first row. + * @param typeName - type name. Displayed in context menu on second row. + * @param color - color of circle's background. + * @param location - location of the point. + * @param details - list of details. Displayed under context menu. + * @param params - optional map of params for point. + */ boolean updateMapPoint(in UpdateMapPointParams params); + /** + * Add user layer on the map. + * + * @param id - layer id. + * @param name - layer name. + * @param zOrder - z-order position of layer. Default value is 5.5f + * @param points - initial list of points. Nullable. + * @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited. + */ boolean addMapLayer(in AddMapLayerParams params); + + /** + * Remove user layer. + * + * @param id - layer id. + */ boolean removeMapLayer(in RemoveMapLayerParams params); + + /** + * Update user layer. + * + * @param id - layer id. + * @param name - layer name. + * @param zOrder - z-order position of layer. Default value is 5.5f + * @param points - list of points. Nullable. + * @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited. + */ boolean updateMapLayer(in UpdateMapLayerParams params); + /** + * Import GPX file to OsmAnd (from URI or file). + * + * @param gpxUri - URI created by FileProvider (preferable method). + * @param file - File which represents GPX track (not recomended, OsmAnd should have rights to access file location). + * @param fileName - Destination file name. May contain dirs. + * @param color - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple", + * "translucent_red", "translucent_orange", "translucent_lightblue", + * "translucent_blue", "translucent_purple" + * @param show - show track on the map after import + */ boolean importGpx(in ImportGpxParams params); + + /** + * Show GPX file on map. + * + * @param fileName - file name to show. Must be imported first. + */ boolean showGpx(in ShowGpxParams params); + + /** + * Hide GPX file. + * + * @param fileName - file name to hide. + */ boolean hideGpx(in HideGpxParams params); + + /** + * Get list of active GPX files. + * + * @return list of active gpx files. + */ boolean getActiveGpx(out List files); + /** + * Set map view to current location. + * + * @param latitude - latitude of new map center. + * @param longitude - longitude of new map center. + * @param zoom - map zoom level. Set 0 to keep zoom unchanged. + * @param animated - set true to animate changes. + */ boolean setMapLocation(in SetMapLocationParams params); + + boolean calculateRoute(in CalculateRouteParams params); /** @@ -190,75 +350,345 @@ interface IOsmAndAidlInterface { */ boolean updateFavorite(in UpdateFavoriteParams params); - /** - * Add map marker at given location. - * - * @param lat - latitude. - * @param lon - longitude. - * @param name - name. - */ + /** + * Start gpx recording. + */ boolean startGpxRecording(in StartGpxRecordingParams params); - + /** + * Stop gpx recording. + */ boolean stopGpxRecording(in StopGpxRecordingParams params); + /** + * Take photo note. + * + * @param lat - latutude of photo note. + * @param lon - longitude of photo note. + */ boolean takePhotoNote(in TakePhotoNoteParams params); + + /** + * Start video note recording. + * + * @param lat - latutude of video note point. + * @param lon - longitude of video note point. + */ boolean startVideoRecording(in StartVideoRecordingParams params); + + /** + * Start audio note recording. + * + * @param lat - latutude of audio note point. + * @param lon - longitude of audio note point. + */ boolean startAudioRecording(in StartAudioRecordingParams params); + + /** + * Stop Audio/Video recording. + */ boolean stopRecording(in StopRecordingParams params); + /** + * Start navigation. + * + * @param startName - name of the start point as it displays in OsmAnd's UI. Nullable. + * @param startLat - latitude of the start point. If 0 - current location is used. + * @param startLon - longitude of the start point. If 0 - current location is used. + * @param destName - name of the start point as it displays in OsmAnd's UI. + * @param destLat - latitude of a destination point. + * @param destLon - longitude of a destination point. + * @param profile - One of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). + * @param force - ask to stop current navigation if any. False - ask. True - don't ask. + */ boolean navigate(in NavigateParams params); + + /** + * Start navigation using gpx file. User need to grant Uri permission to OsmAnd. + * + * @param gpxUri - URI created by FileProvider. + * @param force - ask to stop current navigation if any. False - ask. True - don't ask. + */ boolean navigateGpx(in NavigateGpxParams params); + /** + * Remove GPX file. + * + * @param fileName - file name to remove; + */ boolean removeGpx(in RemoveGpxParams params); + + /** + * Show AMapPoint on map in OsmAnd. + * + * @param layerId - layer id. Note: layer should be added first. + * @param pointId - point id. + * @param shortName - short name (single char). Displayed on the map. + * @param fullName - full name. Displayed in the context menu on first row. + * @param typeName - type name. Displayed in context menu on second row. + * @param color - color of circle's background. + * @param location - location of the point. + * @param details - list of details. Displayed under context menu. + * @param params - optional map of params for point. + */ boolean showMapPoint(in ShowMapPointParams params); + /** + * Method for adding up to 3 items to the OsmAnd navigation drawer. + * + * @param appPackage - current application package. + * @param names - list of names for items. + * @param uris - list of uris for intents. + * @param iconNames - list of icon names for items. + * @param flags - list of flags for intents. Use -1 if no flags needed. + */ boolean setNavDrawerItems(in SetNavDrawerItemsParams params); + /** + * Put navigation on pause. + */ boolean pauseNavigation(in PauseNavigationParams params); + + /** + * Resume navigation if it was paused before. + */ boolean resumeNavigation(in ResumeNavigationParams params); + + /** + * Stop navigation. Removes target / intermediate points and route path from the map. + */ boolean stopNavigation(in StopNavigationParams params); + + + /** + * Mute voice guidance. Stays muted until unmute manually or via the api. + */ boolean muteNavigation(in MuteNavigationParams params); + + /** + * Unmute voice guidance. + */ boolean unmuteNavigation(in UnmuteNavigationParams params); + /** + * Run search for POI / Address. + * + * @param searchQuery - search query string. + * @param searchType - type of search. Values: + * SearchParams.SEARCH_TYPE_ALL - all kind of search + * SearchParams.SEARCH_TYPE_POI - POIs only + * SearchParams.SEARCH_TYPE_ADDRESS - addresses only + * + * @param latitude - latitude of original search location. + * @param longitude - longitude of original search location. + * @param radiusLevel - value from 1 to 7. Default value = 1. + * @param totalLimit - limit of returned search result rows. Default value = -1 (unlimited). + */ boolean search(in SearchParams params, IOsmAndAidlCallback callback); + + /** + * Do search and start navigation. + * + * @param startName - name of the start point as it displays in OsmAnd's UI. Nullable. + * @param startLat - latitude of the start point. If 0 - current location is used. + * @param startLon - longitude of the start point. If 0 - current location is used. + * @param searchQuery - Text of a query for searching a destination point. Sent as URI parameter. + * @param searchLat - original location of search (latitude). Sent as URI parameter. + * @param searchLon - original location of search (longitude). Sent as URI parameter. + * @param profile - one of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). + * @param force - ask to stop current navigation if any. False - ask. True - don't ask. + */ boolean navigateSearch(in NavigateSearchParams params); + /** + * Method to register for periodical callbacks from OsmAnd + * + * @param updateTimeMS - period of time in millisecond after which callback is triggered + * @param callback - create and provide instance of {@link IOsmAndAidlCallback} interface + * @return id of callback in OsmAnd. Needed to unsubscribe from updates. + */ long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback); + + /** + * Method to unregister from periodical callbacks from OsmAnd + * + * @param callbackId - id of registered callback (provided by OsmAnd + * in {@link OsmAndAidlHelper#registerForUpdates(long, IOsmAndAidlCallback)}) + */ boolean unregisterFromUpdates(in long callbackId); + /** + * Method for adding image to the top of Osmand's NavDrawer. + * + * @param imageUri - image's URI.toString + * + * @deprecated + * Use the {@link #setNavDrawerLogoWithParams(NavDrawerHeaderParams params)} method. + */ boolean setNavDrawerLogo(in String imageUri); + /** + * Method for selected UI elements (like QuickSearch button) to show. + * + * @param ids - list of menu items keys from {@link OsmAndCustomizationConstants} + */ boolean setEnabledIds(in List ids); + + /** + * Method for selected UI elements (like QuickSearch button) to hide. + * + * @param ids - list of menu items keys from {@link OsmAndCustomizationConstants} + */ boolean setDisabledIds(in List ids); + + /** + * Method to show selected NavDrawer's menu items. + * + * @param patterns - list of menu items names from {@link OsmAndCustomizationConstants} + */ boolean setEnabledPatterns(in List patterns); + + /** + * Method to hide selected NavDrawer's menu items. + * + * @param patterns - list of menu items names from {@link OsmAndCustomizationConstants} + */ boolean setDisabledPatterns(in List patterns); + /** + * Register OsmAnd widgets for visibility. + * + * @param widgetKey - widget id. + * @param appModKeys - list of OsmAnd Application modes widget active with. Could be "null" for all modes. + */ boolean regWidgetVisibility(in SetWidgetsParams params); + + /** + * Register OsmAnd widgets for availability. + * + * @param widgetKey - widget id. + * @param appModKeys - ist of OsmAnd Application modes widget active with. Could be "null" for all modes. + */ boolean regWidgetAvailability(in SetWidgetsParams params); + /** + * Add custom parameters for OsmAnd settings to associate with client app. + * + * @param sharedPreferencesName - string with name of clint's app for shared preferences key + * @param bundle - bundle with keys from Settings IDs {@link OsmAndCustomizationConstants} and Settings params + */ boolean customizeOsmandSettings(in OsmandSettingsParams params); + /** + * Method to get list of gpx files currently registered (imported or created) in OsmAnd; + * + * @return list of gpx files + */ boolean getImportedGpx(out List files); + /** + * Method to get list of sqlitedb files registered in OsmAnd; + * + * @return list of sqlitedb files + */ boolean getSqliteDbFiles(out List files); + + /** + * Method to get list of currently active sqlitedb files + * + * @return list of sqlitedb files + */ boolean getActiveSqliteDbFiles(out List files); + + /** + * Method to show selected sqlitedb file as map overlay. + * + * @param fileName - name of sqlitedb file + */ boolean showSqliteDbFile(String fileName); + + /** + * Method to hide sqlitedb file from map overlay. + * + * @param fileName - name of sqlitedb file + */ boolean hideSqliteDbFile(String fileName); + /** + * Method for adding image to the top of OsmAnd's NavDrawer with additional params + * + * @param imageUri - image's URI.toString + * @param packageName - client's app package name + * @param intent - intent for additional functionality on image click + * + */ boolean setNavDrawerLogoWithParams(in NavDrawerHeaderParams params); + + /** + * Method for adding functionality to "Powered by Osmand" logo in NavDrawer's footer + * (reset OsmAnd settings to pre-clinet app's state) + * + * @param packageName - package name + * @param intent - intent + * @param appName - client's app name + */ boolean setNavDrawerFooterWithParams(in NavDrawerFooterParams params); + /** + * Restore default (pre-client) OsmAnd settings and state: + * clears features, widgets and settings customization, NavDraw logo. + */ boolean restoreOsmand(); + /** + * Method to change state of plug-ins in OsmAnd. + * + * @param pluginId - id (name) of plugin. + * @param newState - new state (0 - off, 1 - on). + */ boolean changePluginState(in PluginParams params); + /** + * Method to register for callback on OsmAnd initialization + * @param callback - create and provide instance of {@link IOsmAndAidlCallback} interface + */ boolean registerForOsmandInitListener(in IOsmAndAidlCallback callback); + /** + * Requests bitmap snap-shot of map with GPX file from provided URI in its center. + * You can set bitmap size, density and GPX lines color, but you need + * to manually download appropriate map in OsmAnd or background will be empty. + * Bitmap will be returned through callback {@link IOsmAndAidlCallback#onGpxBitmapCreated(AGpxBitmap)} + * + * @param gpxUri - Uri for gpx file + * @param density - image density. Recommended to use default metrics for device's display. + * @param widthPixels - width of bitmap + * @param heightPixels - height of bitmap + * @param color - color in ARGB format + * @param callback - instance of callback from OsmAnd. + */ boolean getBitmapForGpx(in CreateGpxBitmapParams file, IOsmAndAidlCallback callback); + /** + * Method to copy files to OsmAnd part by part. For now supports only sqlitedb format. + * Part size (bytearray) should not exceed 256k. + * + * @param copyPart.fileName - name of file + * @param copyPart.filePartData - parts of file, byte[] with size 256k or less. + * @param copyPart.startTime - timestamp of copying start. + * @param copyPart.isDone - boolean to mark end of copying. + * @return number of last successfully received file part or error(-1). + */ int copyFile(in CopyFileParams filePart); + + /** + * Method to register for updates during navgation. Notifies user about distance to the next turn and its type. + * + * @params params.subscribeToUpdates - boolean flag to subscribe or unsubscribe from updates + * @params params.callbackId - id of callback, needed to unsubscribe from updates + * @params callback - callback to notify user on navigation data change + */ long registerForNavigationUpdates(in ANavigationUpdateParams params, IOsmAndAidlCallback callback); } \ 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 ff47cee9d6..c45b6931ef 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1981,7 +1981,6 @@ public class OsmandAidlApi { void onNavUpdate(); } - boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { if (gpxUri == null || callback == null) { return false; @@ -2248,9 +2247,4 @@ public class OsmandAidlApi { void onAppInitialized(); } - public interface DirectionsUpdateCallback { - void onDirectionsUpdate(ADirectionInfo directionInfo); - } - - } diff --git a/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java b/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java index f83c9c5764..a5e7074f0e 100644 --- a/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java +++ b/OsmAnd/src/net/osmand/aidl/navigation/ADirectionInfo.java @@ -7,7 +7,7 @@ public class ADirectionInfo implements Parcelable { private int distanceTo; //distance to next turn private int turnType; //turn type - private boolean isLeftSide; //is movement leftsided + private boolean isLeftSide; //is movement left-sided public ADirectionInfo(int distanceTo, int turnType, boolean isLeftSide) { this.distanceTo = distanceTo; From 44885666e11919124c9b578c63c56335d953b229 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 8 Apr 2019 11:40:46 +0300 Subject: [PATCH 04/15] typo fix --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index c45b6931ef..2ee46a73eb 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -25,6 +25,7 @@ import android.text.TextUtils; import android.view.View; import android.widget.ArrayAdapter; +import java.util.HashMap; import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -195,7 +196,7 @@ public class OsmandAidlApi { private boolean mapActivityActive = false; - private Map callbacks; + private Map callbacks = new HashMap<>(); private long updateCallbackId = 0; public OsmandAidlApi(OsmandApplication app) { @@ -245,12 +246,6 @@ public class OsmandAidlApi { receivers = new TreeMap<>(); } - - public static boolean isAidlSubscribedForUpdates() { -// return !callbacks.isEmpty(); - return true; - } - public boolean isUpdateAllowed() { return mapActivityActive; } From 9284983fefeab06e1e6b9748dee0e21e8bbc8968 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 8 Apr 2019 12:31:21 +0300 Subject: [PATCH 05/15] add option to remove of inner callback from RoutingHelper if no aidl callbacks registered. --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 2ee46a73eb..34dbc38793 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -26,6 +26,7 @@ import android.view.View; import android.widget.ArrayAdapter; import java.util.HashMap; +import java.util.Map.Entry; import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -1930,10 +1931,13 @@ public class OsmandAidlApi { if (params.isSubscribeToUpdates()) { updateCallbackId++; callbacks.put(updateCallbackId, callback); - startNavigationalUpdates(updateCallbackId); + startNavigationalUpdates(); return updateCallbackId; } else { callbacks.remove(params.getCallbackId()); + if (callbacks.size() == 0) { + navUpdateListener = null; + } return -1; } } @@ -1944,14 +1948,14 @@ public class OsmandAidlApi { return callbacks.size() > 0; } - private void startNavigationalUpdates(final long updateCallbackId) { + private void startNavigationalUpdates() { final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); final NextDirectionInfo baseNdi = new NextDirectionInfo(); - navUpdateListener = new NavUpdateListener() { - @Override - public void onNavUpdate() { - RoutingHelper rh = app.getRoutingHelper(); - if (callbacks.containsKey(updateCallbackId)) { + if (navUpdateListener == null) { + navUpdateListener = new NavUpdateListener() { + @Override + public void onNavUpdate() { + RoutingHelper rh = app.getRoutingHelper(); if (rh.isDeviatedFromRoute()) { directionInfo.setTurnType(TurnType.OFFR); directionInfo.setDistanceTo((int) rh.getRouteDeviation()); @@ -1962,14 +1966,16 @@ public class OsmandAidlApi { directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); } } - try { - callbacks.get(updateCallbackId).updateNavigationInfo(directionInfo); - } catch (Exception e) { - LOG.debug(e.getMessage(), e); + for (Entry cb : callbacks.entrySet()) { + try { + cb.getValue().updateNavigationInfo(directionInfo); + } catch (Exception e) { + LOG.debug(e.getMessage(), e); + } } } - } - }; + }; + } } public interface NavUpdateListener { From cf10d7394b7fed08a4bdba4b77f549354514f18f Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 8 Apr 2019 12:31:21 +0300 Subject: [PATCH 06/15] add option to remove of inner callback from RoutingHelper if no aidl callbacks registered. --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 32 +++++++++++-------- .../net/osmand/aidl/OsmandAidlService.java | 1 - 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 2ee46a73eb..34dbc38793 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -26,6 +26,7 @@ import android.view.View; import android.widget.ArrayAdapter; import java.util.HashMap; +import java.util.Map.Entry; import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -1930,10 +1931,13 @@ public class OsmandAidlApi { if (params.isSubscribeToUpdates()) { updateCallbackId++; callbacks.put(updateCallbackId, callback); - startNavigationalUpdates(updateCallbackId); + startNavigationalUpdates(); return updateCallbackId; } else { callbacks.remove(params.getCallbackId()); + if (callbacks.size() == 0) { + navUpdateListener = null; + } return -1; } } @@ -1944,14 +1948,14 @@ public class OsmandAidlApi { return callbacks.size() > 0; } - private void startNavigationalUpdates(final long updateCallbackId) { + private void startNavigationalUpdates() { final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); final NextDirectionInfo baseNdi = new NextDirectionInfo(); - navUpdateListener = new NavUpdateListener() { - @Override - public void onNavUpdate() { - RoutingHelper rh = app.getRoutingHelper(); - if (callbacks.containsKey(updateCallbackId)) { + if (navUpdateListener == null) { + navUpdateListener = new NavUpdateListener() { + @Override + public void onNavUpdate() { + RoutingHelper rh = app.getRoutingHelper(); if (rh.isDeviatedFromRoute()) { directionInfo.setTurnType(TurnType.OFFR); directionInfo.setDistanceTo((int) rh.getRouteDeviation()); @@ -1962,14 +1966,16 @@ public class OsmandAidlApi { directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); } } - try { - callbacks.get(updateCallbackId).updateNavigationInfo(directionInfo); - } catch (Exception e) { - LOG.debug(e.getMessage(), e); + for (Entry cb : callbacks.entrySet()) { + try { + cb.getValue().updateNavigationInfo(directionInfo); + } catch (Exception e) { + LOG.debug(e.getMessage(), e); + } } } - } - }; + }; + } } public interface NavUpdateListener { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index f334494ba5..42f74164b9 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -11,7 +11,6 @@ import android.os.RemoteException; import android.support.annotation.Nullable; import net.osmand.PlatformUtil; -import net.osmand.aidl.OsmandAidlApi.DirectionsUpdateCallback; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback; From 94f1da830a670c645b1a4f48364d2441d9b6bd9d Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Fri, 12 Apr 2019 17:42:48 +0300 Subject: [PATCH 07/15] changes to aidl nav update method. need testing. --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 75 ++++++------------ .../net/osmand/aidl/OsmandAidlService.java | 77 +++++++++++++++---- .../routing/IRoutingDataUpdateListener.java | 5 ++ .../osmand/plus/routing/RoutingHelper.java | 13 +++- 4 files changed, 104 insertions(+), 66 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/routing/IRoutingDataUpdateListener.java diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 34dbc38793..fa8e6480a3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -79,6 +79,7 @@ import net.osmand.plus.helpers.ExternalApiHelper; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.TrackBitmapDrawer; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.routing.IRoutingDataUpdateListener; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.AidlMapLayer; @@ -1927,62 +1928,36 @@ public class OsmandAidlApi { return app.getAppCustomization().changePluginStatus(params); } - public long registerForNavigationUpdates(ANavigationUpdateParams params, IOsmAndAidlCallback callback) { - if (params.isSubscribeToUpdates()) { - updateCallbackId++; - callbacks.put(updateCallbackId, callback); - startNavigationalUpdates(); - return updateCallbackId; - } else { - callbacks.remove(params.getCallbackId()); - if (callbacks.size() == 0) { - navUpdateListener = null; - } - return -1; - } - } - - public NavUpdateListener navUpdateListener = null; - - public boolean isActiveListeners() { - return callbacks.size() > 0; - } - - private void startNavigationalUpdates() { + public void registerForNavigationUpdates() { final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); final NextDirectionInfo baseNdi = new NextDirectionInfo(); - if (navUpdateListener == null) { - navUpdateListener = new NavUpdateListener() { - @Override - public void onNavUpdate() { - RoutingHelper rh = app.getRoutingHelper(); - if (rh.isDeviatedFromRoute()) { - directionInfo.setTurnType(TurnType.OFFR); - directionInfo.setDistanceTo((int) rh.getRouteDeviation()); - } else { - NextDirectionInfo ndi = rh.getNextRouteDirectionInfo(baseNdi, true); - if (ndi != null && ndi.distanceTo > 0 && ndi.directionInfo != null) { - directionInfo.setDistanceTo(ndi.distanceTo); - directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); - } - } - for (Entry cb : callbacks.entrySet()) { - try { - cb.getValue().updateNavigationInfo(directionInfo); - } catch (Exception e) { - LOG.debug(e.getMessage(), e); - } + app.getRoutingHelper().addDataUpdateListener(new IRoutingDataUpdateListener(){ + @Override + public void onRoutingDataUpdate() { + RoutingHelper rh = app.getRoutingHelper(); + if (rh.isDeviatedFromRoute()) { + directionInfo.setTurnType(TurnType.OFFR); + directionInfo.setDistanceTo((int) rh.getRouteDeviation()); + } else { + NextDirectionInfo ndi = rh.getNextRouteDirectionInfo(baseNdi, true); + if (ndi != null && ndi.distanceTo > 0 && ndi.directionInfo != null) { + directionInfo.setDistanceTo(ndi.distanceTo); + directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); } } - }; - } + for (Entry cb : callbacks.entrySet()) { + try { + cb.getValue().updateNavigationInfo(directionInfo); + } catch (Exception e) { + LOG.debug(e.getMessage(), e); + } + } + } + }); } - public interface NavUpdateListener { - void onNavUpdate(); - } - - boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { + boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, + final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { if (gpxUri == null || callback == null) { return false; } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 42f74164b9..ddcce504ae 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -10,6 +10,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.support.annotation.Nullable; +import java.util.concurrent.ConcurrentHashMap; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; @@ -50,7 +51,6 @@ import net.osmand.aidl.mapwidget.UpdateMapWidgetParams; import net.osmand.aidl.navdrawer.NavDrawerFooterParams; import net.osmand.aidl.navdrawer.NavDrawerHeaderParams; import net.osmand.aidl.navdrawer.SetNavDrawerItemsParams; -import net.osmand.aidl.navigation.ADirectionInfo; import net.osmand.aidl.navigation.ANavigationUpdateParams; import net.osmand.aidl.navigation.MuteNavigationParams; import net.osmand.aidl.navigation.NavigateGpxParams; @@ -70,8 +70,6 @@ import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.aidl.copyfile.CopyFileParams; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; -import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -79,7 +77,6 @@ import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import static net.osmand.aidl.OsmandAidlConstants.CANNOT_ACCESS_API_ERROR; import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS; @@ -92,16 +89,34 @@ public class OsmandAidlService extends Service { private static final String DATA_KEY_RESULT_SET = "resultSet"; - private Map callbacks; + public static final int KEY_ON_SEARCH_COMPLETE = 1; + public static final int KEY_ON_UPDATE = 2; + public static final int KEY_ON_APP_INIT = 3; + public static final int KEY_ON_GPX_BMP_CREATED = 4; + public static final int KEY_ON_NAV_DATA_UPDATE = 5; + + private static Map callbacks; private Handler mHandler = null; HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread"); - private long updateCallbackId = 0; + private static long aidlCallbackId = 0; private OsmandApplication getApp() { return (OsmandApplication) getApplication(); } + public static void addAidlCallback(IOsmAndAidlCallback callback, long id, long key) { + callbacks.put(id, new AidlCallbackParams(callback, key)); + } + + public static boolean removeAidlCallback (long id){ + return callbacks.remove(id) != null; + } + + public static Map getAidlCallbacks() { + return callbacks; + } + @Nullable private OsmandAidlApi getApi(String reason) { LOG.info("Request AIDL API for " + reason); @@ -720,10 +735,10 @@ public class OsmandAidlService extends Service { public long registerForUpdates(long updateTimeMS, IOsmAndAidlCallback callback) { try { if (updateTimeMS >= MIN_UPDATE_TIME_MS) { - updateCallbackId++; - callbacks.put(updateCallbackId, callback); - startRemoteUpdates(updateTimeMS, updateCallbackId, callback); - return updateCallbackId; + aidlCallbackId++; + addAidlCallback(callback, aidlCallbackId, KEY_ON_UPDATE); + startRemoteUpdates(updateTimeMS, aidlCallbackId, callback); + return aidlCallbackId; } else { return MIN_UPDATE_TIME_MS_ERROR; } @@ -736,7 +751,7 @@ public class OsmandAidlService extends Service { @Override public boolean unregisterFromUpdates(long callbackId) { try { - return callbacks.remove(callbackId) != null; + return removeAidlCallback(callbackId); } catch (Exception e) { handleException(e); return false; @@ -1000,9 +1015,18 @@ public class OsmandAidlService extends Service { @Override public long registerForNavigationUpdates(ANavigationUpdateParams params, final IOsmAndAidlCallback callback) { try { + aidlCallbackId++; OsmandAidlApi api = getApi("registerForNavUpdates"); - if (api != null) { - return api.registerForNavigationUpdates(params, callback); + if (api != null ) { + if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) { + removeAidlCallback(params.getCallbackId()); + return -1; + } else { + addAidlCallback(callback, aidlCallbackId, KEY_ON_NAV_DATA_UPDATE); + } + + api.registerForNavigationUpdates(); + return aidlCallbackId; } else { return -1; } @@ -1012,4 +1036,31 @@ public class OsmandAidlService extends Service { } } }; + + private static class AidlCallbackParams { + private IOsmAndAidlCallback callback; + private long key; + + AidlCallbackParams(IOsmAndAidlCallback callback, long key) { + this.callback = callback; + + this.key = key; + } + + public IOsmAndAidlCallback getCallback() { + return callback; + } + + public void setCallback(IOsmAndAidlCallback callback) { + this.callback = callback; + } + + public long getKey() { + return key; + } + + public void setKey(long key) { + this.key = key; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/routing/IRoutingDataUpdateListener.java b/OsmAnd/src/net/osmand/plus/routing/IRoutingDataUpdateListener.java new file mode 100644 index 0000000000..c4fb23084e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/routing/IRoutingDataUpdateListener.java @@ -0,0 +1,5 @@ +package net.osmand.plus.routing; + +public interface IRoutingDataUpdateListener { + void onRoutingDataUpdate(); +} diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 71e03f02d4..0f84f947a9 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -39,7 +39,7 @@ public class RoutingHelper { private static final float POSITION_TOLERANCE = 60; private List> listeners = new LinkedList<>(); - + private List> updateListeners = new LinkedList<>(); private OsmandApplication app; private TransportRoutingHelper transportRoutingHelper; @@ -265,6 +265,10 @@ public class RoutingHelper { transportRoutingHelper.addListener(l); } + public void addDataUpdateListener(IRoutingDataUpdateListener listener) { + updateListeners.add(new WeakReference(listener)); + } + public boolean removeListener(IRouteInformationListener lt){ Iterator> it = listeners.iterator(); while(it.hasNext()) { @@ -502,9 +506,12 @@ public class RoutingHelper { route.updateCurrentRoute(newCurrentRoute + 1); currentRoute = newCurrentRoute + 1; app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION); - if (app.getAidlApi().isActiveListeners() && app.getAidlApi().navUpdateListener != null) { - app.getAidlApi().navUpdateListener.onNavUpdate(); + if (!updateListeners.isEmpty()) { + for (WeakReference ref : updateListeners) { + ref.get().onRoutingDataUpdate(); + } } + } else { break; } From 575e936d2ea832e7763f0648001caf1ab22d0351 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 15 Apr 2019 09:52:06 +0300 Subject: [PATCH 08/15] Navigation Update aidl method refactoring. --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 17 ++++++++--------- .../src/net/osmand/aidl/OsmandAidlService.java | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index fa8e6480a3..c8f56080fe 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -45,7 +45,6 @@ import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapwidget.AMapWidget; import net.osmand.aidl.navdrawer.NavDrawerFooterParams; import net.osmand.aidl.navigation.ADirectionInfo; -import net.osmand.aidl.navigation.ANavigationUpdateParams; import net.osmand.aidl.plugins.PluginParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; @@ -124,6 +123,7 @@ import static net.osmand.aidl.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT_ERRO import static net.osmand.aidl.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR; import static net.osmand.aidl.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR; import static net.osmand.aidl.OsmandAidlConstants.OK_RESPONSE; +import static net.osmand.aidl.OsmandAidlService.KEY_ON_NAV_DATA_UPDATE; import static net.osmand.plus.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME; public class OsmandAidlApi { @@ -198,9 +198,6 @@ public class OsmandAidlApi { private boolean mapActivityActive = false; - private Map callbacks = new HashMap<>(); - private long updateCallbackId = 0; - public OsmandAidlApi(OsmandApplication app) { this.app = app; loadConnectedApps(); @@ -1945,11 +1942,13 @@ public class OsmandAidlApi { directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); } } - for (Entry cb : callbacks.entrySet()) { - try { - cb.getValue().updateNavigationInfo(directionInfo); - } catch (Exception e) { - LOG.debug(e.getMessage(), e); + for (Entry cb : OsmandAidlService.getAidlCallbacks().entrySet()) { + if (cb.getValue().getKey() == KEY_ON_NAV_DATA_UPDATE) { //add bitwise check instead + try { + cb.getValue().getCallback().updateNavigationInfo(directionInfo); + } catch (Exception e) { + LOG.debug(e.getMessage(), e); + } } } } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index ddcce504ae..8165a9b932 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -1037,7 +1037,7 @@ public class OsmandAidlService extends Service { } }; - private static class AidlCallbackParams { + public static class AidlCallbackParams { private IOsmAndAidlCallback callback; private long key; From f7f6dec1b3dba9e97c41af5002f502bf6962ae64 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Mon, 15 Apr 2019 11:27:53 +0300 Subject: [PATCH 09/15] changes to aidl nav update method. need testing. --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 2 +- OsmAnd/src/net/osmand/aidl/OsmandAidlService.java | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index c8f56080fe..8777f9a91e 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1943,7 +1943,7 @@ public class OsmandAidlApi { } } for (Entry cb : OsmandAidlService.getAidlCallbacks().entrySet()) { - if (cb.getValue().getKey() == KEY_ON_NAV_DATA_UPDATE) { //add bitwise check instead + if ((cb.getValue().getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) { try { cb.getValue().getCallback().updateNavigationInfo(directionInfo); } catch (Exception e) { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 8165a9b932..832bb281b2 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -89,11 +89,8 @@ public class OsmandAidlService extends Service { private static final String DATA_KEY_RESULT_SET = "resultSet"; - public static final int KEY_ON_SEARCH_COMPLETE = 1; - public static final int KEY_ON_UPDATE = 2; - public static final int KEY_ON_APP_INIT = 3; - public static final int KEY_ON_GPX_BMP_CREATED = 4; - public static final int KEY_ON_NAV_DATA_UPDATE = 5; + public static final int KEY_ON_UPDATE = 1; + public static final int KEY_ON_NAV_DATA_UPDATE = 2; private static Map callbacks; private Handler mHandler = null; From b1e236bdad71aabfc14b945b66903c83a10053b8 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Wed, 17 Apr 2019 10:36:16 +0300 Subject: [PATCH 10/15] pr changes - removed static method, add callback to aidl service, fixed concurrency issue to RouteHelper, add types to params in javadoc --- .../net/osmand/aidl/AidlCallbackListener.java | 9 + .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 368 +++++++++--------- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 34 +- .../net/osmand/aidl/OsmandAidlService.java | 62 +-- .../osmand/plus/routing/RoutingHelper.java | 26 +- 5 files changed, 279 insertions(+), 220 deletions(-) create mode 100644 OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java diff --git a/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java new file mode 100644 index 0000000000..82556a7e59 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java @@ -0,0 +1,9 @@ +package net.osmand.aidl; + +import java.util.Map; + +public interface AidlCallbackListener{ + void addAidlCallback(IOsmAndAidlCallback callback, int key); + boolean removeAidlCallback(long id); + Map getAidlCallbacks(); +} diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 5f5a01ad88..1ac8569bfc 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -91,30 +91,30 @@ interface IOsmAndAidlInterface { /** * Add map marker at given location. * - * @param lat - latitude. - * @param lon - longitude. - * @param name - name. + * @param lat (double) - latitude. + * @param lon (double) - longitude. + * @param name (String)- name of marker. */ boolean addMapMarker(in AddMapMarkerParams params); /** - * Remove map marker at given location with name. + * Add map marker at given location. * - * @param lat - latitude. - * @param lon - longitude. - * @param name - name. + * @param lat (double) - latitude. + * @param lon (double) - longitude. + * @param name (String)- name of marker. */ boolean removeMapMarker(in RemoveMapMarkerParams params); /** * Update map marker at given location with name. * - * @param latPrev - latitude (current marker). - * @param lonPrev - longitude (current marker). - * @param namePrev - name (current marker). - * @param latNew - latitude (new marker). - * @param lonNew - longitude (new marker). - * @param nameNew - name (new marker). + * @param latPrev (double) - latitude (current marker). + * @param lonPrev (double) - longitude (current marker). + * @param namePrev (String) - name (current marker). + * @param latNew (double) - latitude (new marker). + * @param lonNew (double) - longitude (new marker). + * @param nameNew (String) - name (new marker). */ boolean updateMapMarker(in UpdateMapMarkerParams params); @@ -122,22 +122,22 @@ interface IOsmAndAidlInterface { * Add map widget to the right side of the main screen. * Note: any specified icon should exist in OsmAnd app resources. * - * @param id - widget id. - * @param menuIconName - icon name (configure map menu). - * @param menuTitle - widget name (configure map menu). - * @param lightIconName - icon name for the light theme (widget). - * @param darkIconName - icon name for the dark theme (widget). - * @param text - main widget text. - * @param description - sub text, like "km/h". - * @param order - order position in the widgets list. - * @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent). + * @param id (String) - widget id. + * @param menuIconName (String) - icon name (configure map menu). + * @param menuTitle (String) - widget name (configure map menu). + * @param lightIconName (String) - icon name for the light theme (widget). + * @param darkIconName (String) - icon name for the dark theme (widget). + * @param text (String) - main widget text. + * @param description (String) - sub text, like "km/h". + * @param order (int) - order position in the widgets list. + * @param intentOnClick (String) - onClick intent. Called after click on widget as startActivity(Intent intent). */ boolean addMapWidget(in AddMapWidgetParams params); /** * Remove map widget. * - * @param id - widget id. + * @param (String) id - widget id. */ boolean removeMapWidget(in RemoveMapWidgetParams params); @@ -145,30 +145,30 @@ interface IOsmAndAidlInterface { * Update map widget. * Note: any specified icon should exist in OsmAnd app resources. * - * @param id - widget id. - * @param menuIconName - icon name (configure map menu). - * @param menuTitle - widget name (configure map menu). - * @param lightIconName - icon name for the light theme (widget). - * @param darkIconName - icon name for the dark theme (widget). - * @param text - main widget text. - * @param description - sub text, like "km/h". - * @param order - order position in the widgets list. - * @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent). + * @param id (String) - widget id. + * @param menuIconName (String) - icon name (configure map menu). + * @param menuTitle (String) - widget name (configure map menu). + * @param lightIconName (String) - icon name for the light theme (widget). + * @param darkIconName (String) - icon name for the dark theme (widget). + * @param text (String) - main widget text. + * @param description (String) - sub text, like "km/h". + * @param order (int) - order position in the widgets list. + * @param intentOnClick (String) - onClick intent. Called after click on widget as startActivity(Intent intent). */ boolean updateMapWidget(in UpdateMapWidgetParams params); /** * Add point to user layer. * - * @param layerId - layer id. Note: layer should be added first. - * @param pointId - point id. - * @param shortName - short name (single char). Displayed on the map. - * @param fullName - full name. Displayed in the context menu on first row. - * @param typeName - type name. Displayed in context menu on second row. - * @param color - color of circle's background. - * @param location - location of the point. - * @param details - list of details. Displayed under context menu. - * @param params - optional map of params for point. + * @param layerId (String) - layer id. Note: layer should be added first. + * @param pointId (String) - point id. + * @param shortName (String) - short name (single char). Displayed on the map. + * @param fullName (String) - full name. Displayed in the context menu on first row. + * @param typeName (String) - type name. Displayed in context menu on second row. + * @param color (int) - color of circle's background. + * @param location (ALatLon) - location of the point. + * @param details (List)- list of details. Displayed under context menu. + * @param params (Map) - optional map of params for point. */ boolean addMapPoint(in AddMapPointParams params); @@ -176,79 +176,79 @@ interface IOsmAndAidlInterface { /** * Remove point. * - * @param layerId - layer id. - * @param pointId - point id. + * @param layerId (String) - layer id. + * @param pointId (String) - point id. */ boolean removeMapPoint(in RemoveMapPointParams params); /** * Update point. * - * @param layerId - layer id. - * @param pointId - point id. - * @param shortName - short name (single char). Displayed on the map. - * @param fullName - full name. Displayed in the context menu on first row. - * @param typeName - type name. Displayed in context menu on second row. - * @param color - color of circle's background. - * @param location - location of the point. - * @param details - list of details. Displayed under context menu. - * @param params - optional map of params for point. + * @param layerId (String) - layer id. + * @param pointId (String) - point id. + * @param shortName (String) - short name (single char). Displayed on the map. + * @param fullName (String) - full name. Displayed in the context menu on first row. + * @param typeName (String) - type name. Displayed in context menu on second row. + * @param color (String) - color of circle's background. + * @param location (ALatLon)- location of the point. + * @param details (List) - list of details. Displayed under context menu. + * @param params (Map) - optional map of params for point. */ boolean updateMapPoint(in UpdateMapPointParams params); /** * Add user layer on the map. * - * @param id - layer id. - * @param name - layer name. - * @param zOrder - z-order position of layer. Default value is 5.5f - * @param points - initial list of points. Nullable. - * @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited. + * @param id (String) - layer id. + * @param name (String) - layer name. + * @param zOrder (float) - z-order position of layer. Default value is 5.5f + * @param points Map - initial list of points. Nullable. + * @param imagePoints (boolean) - use new style for points on map or not. Also default zoom bounds for new style can be edited. */ boolean addMapLayer(in AddMapLayerParams params); /** * Remove user layer. * - * @param id - layer id. + * @param id (String) - layer id. */ boolean removeMapLayer(in RemoveMapLayerParams params); /** * Update user layer. * - * @param id - layer id. - * @param name - layer name. - * @param zOrder - z-order position of layer. Default value is 5.5f - * @param points - list of points. Nullable. - * @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited. + * @param id (String) - layer id. + * @param name (String) - layer name. + * @param zOrder (float) - z-order position of layer. Default value is 5.5f + * @param points Map - list of points. Nullable. + * @param imagePoints (boolean) - use new style for points on map or not. Also default zoom bounds for new style can be edited. */ boolean updateMapLayer(in UpdateMapLayerParams params); /** * Import GPX file to OsmAnd (from URI or file). * - * @param gpxUri - URI created by FileProvider (preferable method). - * @param file - File which represents GPX track (not recomended, OsmAnd should have rights to access file location). - * @param fileName - Destination file name. May contain dirs. - * @param color - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple", + * @param gpxUri (Uri) - URI created by FileProvider (preferable method). + * @param file (File) - File which represents GPX track (not recomended, OsmAnd should have rights to access file location). + * @param fileName (String) - Destination file name. May contain dirs. + * @param color (String) - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple", * "translucent_red", "translucent_orange", "translucent_lightblue", * "translucent_blue", "translucent_purple" - * @param show - show track on the map after import + * @param show (boolean) - show track on the map after import */ boolean importGpx(in ImportGpxParams params); /** * Show GPX file on map. * - * @param fileName - file name to show. Must be imported first. + * @param fileName (String) - file name to show. Must be imported first. */ boolean showGpx(in ShowGpxParams params); /** * Hide GPX file. * - * @param fileName - file name to hide. + * @param fileName (String) - file name to hide. */ boolean hideGpx(in HideGpxParams params); @@ -262,10 +262,10 @@ interface IOsmAndAidlInterface { /** * Set map view to current location. * - * @param latitude - latitude of new map center. - * @param longitude - longitude of new map center. - * @param zoom - map zoom level. Set 0 to keep zoom unchanged. - * @param animated - set true to animate changes. + * @param latitude (double) - latitude of new map center. + * @param longitude (double) - longitude of new map center. + * @param zoom (float) - map zoom level. Set 0 to keep zoom unchanged. + * @param animated (boolean) - set true to animate changes. */ boolean setMapLocation(in SetMapLocationParams params); @@ -280,73 +280,73 @@ interface IOsmAndAidlInterface { /** * Add favorite group with given params. * - * @param name - group name. - * @param color - group color. Can be one of: "red", "orange", "yellow", + * @param name (String) - group name. + * @param color (String) - group color. Can be one of: "red", "orange", "yellow", * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". - * @param visible - group visibility. + * @param visible (boolean) - group visibility. */ boolean addFavoriteGroup(in AddFavoriteGroupParams params); /** * Update favorite group with given params. * - * @param namePrev - group name (current). - * @param colorPrev - group color (current). - * @param visiblePrev - group visibility (current). - * @param nameNew - group name (new). - * @param colorNew - group color (new). - * @param visibleNew - group visibility (new). + * @param namePrev (String) - group name (current). + * @param colorPrev (String) - group color (current). + * @param visiblePrev (boolean) - group visibility (current). + * @param nameNew (String) - group name (new). + * @param colorNew (String) - group color (new). + * @param visibleNew (boolean) - group visibility (new). */ boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params); /** * Remove favorite group with given name. * - * @param name - name of favorite group. + * @param name (String) - name of favorite group. */ boolean updateFavoriteGroup(in UpdateFavoriteGroupParams params); /** * Add favorite at given location with given params. * - * @param lat - latitude. - * @param lon - longitude. - * @param name - name of favorite item. - * @param description - description of favorite item. - * @param category - category of favorite item. - * @param color - color of favorite item. Can be one of: "red", "orange", "yellow", + * @param lat (double) - latitude. + * @param lon (double) - longitude. + * @param name (String) - name of favorite item. + * @param description (String) - description of favorite item. + * @param category (String) - category of favorite item. + * @param color (String) - color of favorite item. Can be one of: "red", "orange", "yellow", * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". - * @param visible - should favorite item be visible after creation. + * @param visible (boolean) - should favorite item be visible after creation. */ boolean addFavorite(in AddFavoriteParams params); /** * Update favorite at given location with given params. * - * @param latPrev - latitude (current favorite). - * @param lonPrev - longitude (current favorite). - * @param namePrev - name of favorite item (current favorite). - * @param categoryPrev - category of favorite item (current favorite). - * @param latNew - latitude (new favorite). - * @param lonNew - longitude (new favorite). - * @param nameNew - name of favorite item (new favorite). - * @param descriptionNew - description of favorite item (new favorite). - * @param categoryNew - category of favorite item (new favorite). Use only to create a new category, + * @param latPrev (double) - latitude (current favorite). + * @param lonPrev (double) - longitude (current favorite). + * @param namePrev (String) - name of favorite item (current favorite). + * @param categoryPrev (String) - category of favorite item (current favorite). + * @param latNew (double) - latitude (new favorite). + * @param lonNew (double) - longitude (new favorite). + * @param nameNew (String) - name of favorite item (new favorite). + * @param descriptionNew (String) - description of favorite item (new favorite). + * @param categoryNew (String) - category of favorite item (new favorite). Use only to create a new category, * not to update an existing one. If you want to update an existing category, * use the {@link #updateFavoriteGroup(String, String, boolean, String, String, boolean)} method. - * @param colorNew - color of new category. Can be one of: "red", "orange", "yellow", + * @param colorNew (String) - color of new category. Can be one of: "red", "orange", "yellow", * "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown". - * @param visibleNew - should new category be visible after creation. + * @param visibleNew (boolean) - should new category be visible after creation. */ boolean removeFavorite(in RemoveFavoriteParams params); /** * Remove favorite at given location with given params. * - * @param lat - latitude. - * @param lon - longitude. - * @param name - name of favorite item. - * @param category - category of favorite item. + * @param lat (double) - latitude. + * @param lon (double) - longitude. + * @param name (String) - name of favorite item. + * @param category (String) - category of favorite item. */ boolean updateFavorite(in UpdateFavoriteParams params); @@ -363,24 +363,24 @@ interface IOsmAndAidlInterface { /** * Take photo note. * - * @param lat - latutude of photo note. - * @param lon - longitude of photo note. + * @param lat (double) - latutude of photo note. + * @param lon (double) - longitude of photo note. */ boolean takePhotoNote(in TakePhotoNoteParams params); /** * Start video note recording. * - * @param lat - latutude of video note point. - * @param lon - longitude of video note point. + * @param lat (double) - latutude of video note point. + * @param lon (double) - longitude of video note point. */ boolean startVideoRecording(in StartVideoRecordingParams params); /** * Start audio note recording. * - * @param lat - latutude of audio note point. - * @param lon - longitude of audio note point. + * @param lat (double) - latutude of audio note point. + * @param lon (double) - longitude of audio note point. */ boolean startAudioRecording(in StartAudioRecordingParams params); @@ -392,29 +392,29 @@ interface IOsmAndAidlInterface { /** * Start navigation. * - * @param startName - name of the start point as it displays in OsmAnd's UI. Nullable. - * @param startLat - latitude of the start point. If 0 - current location is used. - * @param startLon - longitude of the start point. If 0 - current location is used. - * @param destName - name of the start point as it displays in OsmAnd's UI. - * @param destLat - latitude of a destination point. - * @param destLon - longitude of a destination point. - * @param profile - One of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). - * @param force - ask to stop current navigation if any. False - ask. True - don't ask. + * @param startName (String) - name of the start point as it displays in OsmAnd's UI. Nullable. + * @param startLat (double) - latitude of the start point. If 0 - current location is used. + * @param startLon (double) - longitude of the start point. If 0 - current location is used. + * @param destName (String) - name of the start point as it displays in OsmAnd's UI. + * @param destLat (double) - latitude of a destination point. + * @param destLon (double) - longitude of a destination point. + * @param profile (String) - One of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). + * @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask. */ boolean navigate(in NavigateParams params); /** * Start navigation using gpx file. User need to grant Uri permission to OsmAnd. * - * @param gpxUri - URI created by FileProvider. - * @param force - ask to stop current navigation if any. False - ask. True - don't ask. + * @param gpxUri (Uri) - URI created by FileProvider. + * @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask. */ boolean navigateGpx(in NavigateGpxParams params); /** * Remove GPX file. * - * @param fileName - file name to remove; + * @param fileName (String) - file name to remove; */ boolean removeGpx(in RemoveGpxParams params); @@ -422,15 +422,15 @@ interface IOsmAndAidlInterface { /** * Show AMapPoint on map in OsmAnd. * - * @param layerId - layer id. Note: layer should be added first. - * @param pointId - point id. - * @param shortName - short name (single char). Displayed on the map. - * @param fullName - full name. Displayed in the context menu on first row. - * @param typeName - type name. Displayed in context menu on second row. - * @param color - color of circle's background. - * @param location - location of the point. - * @param details - list of details. Displayed under context menu. - * @param params - optional map of params for point. + * @param layerId (String) - layer id. Note: layer should be added first. + * @param pointId (String) - point id. + * @param shortName (String) - short name (single char). Displayed on the map. + * @param fullName (String) - full name. Displayed in the context menu on first row. + * @param typeName (String) - type name. Displayed in context menu on second row. + * @param color (int) - color of circle's background. + * @param location (ALatLon) - location of the point. + * @param details List - list of details. Displayed under context menu. + * @param params Map - optional map of params for point. */ boolean showMapPoint(in ShowMapPointParams params); @@ -474,46 +474,46 @@ interface IOsmAndAidlInterface { /** * Run search for POI / Address. * - * @param searchQuery - search query string. - * @param searchType - type of search. Values: + * @param searchQuery (String) - search query string. + * @param searchType (int) - type of search. Values: * SearchParams.SEARCH_TYPE_ALL - all kind of search * SearchParams.SEARCH_TYPE_POI - POIs only * SearchParams.SEARCH_TYPE_ADDRESS - addresses only * - * @param latitude - latitude of original search location. - * @param longitude - longitude of original search location. - * @param radiusLevel - value from 1 to 7. Default value = 1. - * @param totalLimit - limit of returned search result rows. Default value = -1 (unlimited). + * @param latitude (double) - latitude of original search location. + * @param longitude (double) - longitude of original search location. + * @param radiusLevel (int) - value from 1 to 7. Default value = 1. + * @param totalLimit (int) - limit of returned search result rows. Default value = -1 (unlimited). */ boolean search(in SearchParams params, IOsmAndAidlCallback callback); /** * Do search and start navigation. * - * @param startName - name of the start point as it displays in OsmAnd's UI. Nullable. - * @param startLat - latitude of the start point. If 0 - current location is used. - * @param startLon - longitude of the start point. If 0 - current location is used. - * @param searchQuery - Text of a query for searching a destination point. Sent as URI parameter. - * @param searchLat - original location of search (latitude). Sent as URI parameter. - * @param searchLon - original location of search (longitude). Sent as URI parameter. - * @param profile - one of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). - * @param force - ask to stop current navigation if any. False - ask. True - don't ask. + * @param startName (String) - name of the start point as it displays in OsmAnd's UI. Nullable. + * @param startLat (double) - latitude of the start point. If 0 - current location is used. + * @param startLon (double) - longitude of the start point. If 0 - current location is used. + * @param searchQuery (String) - Text of a query for searching a destination point. Sent as URI parameter. + * @param searchLat (double) - original location of search (latitude). Sent as URI parameter. + * @param searchLon (double) - original location of search (longitude). Sent as URI parameter. + * @param profile (String) - one of: "default", "car", "bicycle", "pedestrian", "aircraft", "boat", "hiking", "motorcycle", "truck". Nullable (default). + * @param force (boolean) - ask to stop current navigation if any. False - ask. True - don't ask. */ boolean navigateSearch(in NavigateSearchParams params); /** * Method to register for periodical callbacks from OsmAnd * - * @param updateTimeMS - period of time in millisecond after which callback is triggered - * @param callback - create and provide instance of {@link IOsmAndAidlCallback} interface - * @return id of callback in OsmAnd. Needed to unsubscribe from updates. + * @param updateTimeMS (long)- period of time in millisecond after which callback is triggered + * @param callback (IOsmAndCallback)- create and provide instance of {@link IOsmAndAidlCallback} interface + * @return id (long) - id of callback in OsmAnd. Needed to unsubscribe from updates. */ long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback); /** * Method to unregister from periodical callbacks from OsmAnd * - * @param callbackId - id of registered callback (provided by OsmAnd + * @param callbackId (long)- id of registered callback (provided by OsmAnd * in {@link OsmAndAidlHelper#registerForUpdates(long, IOsmAndAidlCallback)}) */ boolean unregisterFromUpdates(in long callbackId); @@ -521,7 +521,7 @@ interface IOsmAndAidlInterface { /** * Method for adding image to the top of Osmand's NavDrawer. * - * @param imageUri - image's URI.toString + * @param imageUri (String)- image's URI.toString * * @deprecated * Use the {@link #setNavDrawerLogoWithParams(NavDrawerHeaderParams params)} method. @@ -531,35 +531,35 @@ interface IOsmAndAidlInterface { /** * Method for selected UI elements (like QuickSearch button) to show. * - * @param ids - list of menu items keys from {@link OsmAndCustomizationConstants} + * @param ids (List)- list of menu items keys from {@link OsmAndCustomizationConstants} */ boolean setEnabledIds(in List ids); /** * Method for selected UI elements (like QuickSearch button) to hide. * - * @param ids - list of menu items keys from {@link OsmAndCustomizationConstants} + * @param ids (List)- list of menu items keys from {@link OsmAndCustomizationConstants} */ boolean setDisabledIds(in List ids); /** * Method to show selected NavDrawer's menu items. * - * @param patterns - list of menu items names from {@link OsmAndCustomizationConstants} + * @param patterns (List) - list of menu items names from {@link OsmAndCustomizationConstants} */ boolean setEnabledPatterns(in List patterns); /** * Method to hide selected NavDrawer's menu items. * - * @param patterns - list of menu items names from {@link OsmAndCustomizationConstants} + * @param patterns (List)- list of menu items names from {@link OsmAndCustomizationConstants} */ boolean setDisabledPatterns(in List patterns); /** * Register OsmAnd widgets for visibility. * - * @param widgetKey - widget id. + * @param widgetKey ()- widget id. * @param appModKeys - list of OsmAnd Application modes widget active with. Could be "null" for all modes. */ boolean regWidgetVisibility(in SetWidgetsParams params); @@ -567,16 +567,16 @@ interface IOsmAndAidlInterface { /** * Register OsmAnd widgets for availability. * - * @param widgetKey - widget id. - * @param appModKeys - ist of OsmAnd Application modes widget active with. Could be "null" for all modes. + * @param widgetKey (String) - widget id. + * @param appModKeys (List)- ist of OsmAnd Application modes widget active with. Could be "null" for all modes. */ boolean regWidgetAvailability(in SetWidgetsParams params); /** * Add custom parameters for OsmAnd settings to associate with client app. * - * @param sharedPreferencesName - string with name of clint's app for shared preferences key - * @param bundle - bundle with keys from Settings IDs {@link OsmAndCustomizationConstants} and Settings params + * @param sharedPreferencesName (String)- string with name of clint's app for shared preferences key + * @param bundle (Bundle)- bundle with keys from Settings IDs {@link OsmAndCustomizationConstants} and Settings params */ boolean customizeOsmandSettings(in OsmandSettingsParams params); @@ -604,23 +604,23 @@ interface IOsmAndAidlInterface { /** * Method to show selected sqlitedb file as map overlay. * - * @param fileName - name of sqlitedb file + * @param fileName (String) - name of sqlitedb file */ boolean showSqliteDbFile(String fileName); /** * Method to hide sqlitedb file from map overlay. * - * @param fileName - name of sqlitedb file + * @param fileName (String) - name of sqlitedb file */ boolean hideSqliteDbFile(String fileName); /** * Method for adding image to the top of OsmAnd's NavDrawer with additional params * - * @param imageUri - image's URI.toString - * @param packageName - client's app package name - * @param intent - intent for additional functionality on image click + * @param imageUri (String) - image's URI.toString + * @param packageName (String) - client's app package name + * @param intent (String) - intent for additional functionality on image click * */ boolean setNavDrawerLogoWithParams(in NavDrawerHeaderParams params); @@ -629,9 +629,9 @@ interface IOsmAndAidlInterface { * Method for adding functionality to "Powered by Osmand" logo in NavDrawer's footer * (reset OsmAnd settings to pre-clinet app's state) * - * @param packageName - package name - * @param intent - intent - * @param appName - client's app name + * @param packageName (String) - package name + * @param intent (String) - intent + * @param appName (String) - client's app name */ boolean setNavDrawerFooterWithParams(in NavDrawerFooterParams params); @@ -644,14 +644,14 @@ interface IOsmAndAidlInterface { /** * Method to change state of plug-ins in OsmAnd. * - * @param pluginId - id (name) of plugin. - * @param newState - new state (0 - off, 1 - on). + * @param pluginId (String) - id (name) of plugin. + * @param newState (int) - new state (0 - off, 1 - on). */ boolean changePluginState(in PluginParams params); /** * Method to register for callback on OsmAnd initialization - * @param callback - create and provide instance of {@link IOsmAndAidlCallback} interface + * @param callback (IOsmAndAidlCallback) - create and provide instance of {@link IOsmAndAidlCallback} interface */ boolean registerForOsmandInitListener(in IOsmAndAidlCallback callback); @@ -661,12 +661,12 @@ interface IOsmAndAidlInterface { * to manually download appropriate map in OsmAnd or background will be empty. * Bitmap will be returned through callback {@link IOsmAndAidlCallback#onGpxBitmapCreated(AGpxBitmap)} * - * @param gpxUri - Uri for gpx file - * @param density - image density. Recommended to use default metrics for device's display. - * @param widthPixels - width of bitmap - * @param heightPixels - height of bitmap - * @param color - color in ARGB format - * @param callback - instance of callback from OsmAnd. + * @param gpxUri (Uri/File) - Uri for gpx file + * @param density (float) - image density. Recommended to use default metrics for device's display. + * @param widthPixels (int) - width of bitmap + * @param heightPixels (int) - height of bitmap + * @param color (int) - color in ARGB format + * @param callback (IOsmAndAidlCallback) - instance of callback from OsmAnd. */ boolean getBitmapForGpx(in CreateGpxBitmapParams file, IOsmAndAidlCallback callback); @@ -674,10 +674,10 @@ interface IOsmAndAidlInterface { * Method to copy files to OsmAnd part by part. For now supports only sqlitedb format. * Part size (bytearray) should not exceed 256k. * - * @param copyPart.fileName - name of file - * @param copyPart.filePartData - parts of file, byte[] with size 256k or less. - * @param copyPart.startTime - timestamp of copying start. - * @param copyPart.isDone - boolean to mark end of copying. + * @param fileName (String) - name of file + * @param filePartData (byte[]) - parts of file, byte[] with size 256k or less. + * @param startTime (long) - timestamp of copying start. + * @param isDone (boolean) - boolean to mark end of copying. * @return number of last successfully received file part or error(-1). */ int copyFile(in CopyFileParams filePart); @@ -686,9 +686,9 @@ interface IOsmAndAidlInterface { /** * Method to register for updates during navgation. Notifies user about distance to the next turn and its type. * - * @params params.subscribeToUpdates - boolean flag to subscribe or unsubscribe from updates - * @params params.callbackId - id of callback, needed to unsubscribe from updates - * @params callback - callback to notify user on navigation data change + * @params subscribeToUpdates (boolean) - boolean flag to subscribe or unsubscribe from updates + * @params callbackId (long) - id of callback, needed to unsubscribe from updates + * @params callback (IOsmAndAidlCallback) - callback to notify user on navigation data change */ long registerForNavigationUpdates(in ANavigationUpdateParams params, IOsmAndAidlCallback callback); } \ 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 8777f9a91e..f51e292677 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -127,6 +127,9 @@ import static net.osmand.aidl.OsmandAidlService.KEY_ON_NAV_DATA_UPDATE; import static net.osmand.plus.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME; public class OsmandAidlApi { + + AidlCallbackListener aidlCallbackListener = null; + private static final Log LOG = PlatformUtil.getLog(OsmandAidlApi.class); private static final String AIDL_REFRESH_MAP = "aidl_refresh_map"; private static final String AIDL_SET_MAP_LOCATION = "aidl_set_map_location"; @@ -1925,10 +1928,12 @@ public class OsmandAidlApi { return app.getAppCustomization().changePluginStatus(params); } - public void registerForNavigationUpdates() { + private Map navUpdateCallbacks = new ConcurrentHashMap<>(); + + void registerForNavigationUpdates(long id) { final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false); final NextDirectionInfo baseNdi = new NextDirectionInfo(); - app.getRoutingHelper().addDataUpdateListener(new IRoutingDataUpdateListener(){ + IRoutingDataUpdateListener listener = new IRoutingDataUpdateListener() { @Override public void onRoutingDataUpdate() { RoutingHelper rh = app.getRoutingHelper(); @@ -1942,19 +1947,29 @@ public class OsmandAidlApi { directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue()); } } - for (Entry cb : OsmandAidlService.getAidlCallbacks().entrySet()) { - if ((cb.getValue().getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) { - try { - cb.getValue().getCallback().updateNavigationInfo(directionInfo); - } catch (Exception e) { - LOG.debug(e.getMessage(), e); + if (aidlCallbackListener != null) { + for (OsmandAidlService.AidlCallbackParams cb : aidlCallbackListener.getAidlCallbacks().values()) { + if (!aidlCallbackListener.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_NAV_DATA_UPDATE) > 0) { + try { + cb.getCallback().updateNavigationInfo(directionInfo); + } catch (Exception e) { + LOG.debug(e.getMessage(), e); + } } } } } - }); + }; + navUpdateCallbacks.put(id, listener); + app.getRoutingHelper().addDataUpdateListener(listener); } + public void unregisterFromUpdates(long id) { + app.getRoutingHelper().removeDataUpdateListener(navUpdateCallbacks.get(id)); + navUpdateCallbacks.remove(id); + } + + boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { if (gpxUri == null || callback == null) { @@ -2014,6 +2029,7 @@ public class OsmandAidlApi { private Map copyFilesCache = new ConcurrentHashMap<>(); + private class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 832bb281b2..c31d68fcf1 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -10,6 +10,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.support.annotation.Nullable; +import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; @@ -83,7 +84,7 @@ import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS; import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS_ERROR; import static net.osmand.aidl.OsmandAidlConstants.UNKNOWN_API_ERROR; -public class OsmandAidlService extends Service { +public class OsmandAidlService extends Service implements AidlCallbackListener { private static final Log LOG = PlatformUtil.getLog(OsmandAidlService.class); @@ -92,28 +93,16 @@ public class OsmandAidlService extends Service { public static final int KEY_ON_UPDATE = 1; public static final int KEY_ON_NAV_DATA_UPDATE = 2; - private static Map callbacks; + private Map callbacks = new ConcurrentHashMap<>(); private Handler mHandler = null; HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread"); - private static long aidlCallbackId = 0; + private long aidlCallbackId = 0; private OsmandApplication getApp() { return (OsmandApplication) getApplication(); } - public static void addAidlCallback(IOsmAndAidlCallback callback, long id, long key) { - callbacks.put(id, new AidlCallbackParams(callback, key)); - } - - public static boolean removeAidlCallback (long id){ - return callbacks.remove(id) != null; - } - - public static Map getAidlCallbacks() { - return callbacks; - } - @Nullable private OsmandAidlApi getApi(String reason) { LOG.info("Request AIDL API for " + reason); @@ -137,7 +126,11 @@ public class OsmandAidlService extends Service { @Override public void onCreate() { super.onCreate(); - callbacks = new ConcurrentHashMap<>(); + OsmandAidlApi api = getApi("setting_listener"); + if(api != null) { + LOG.debug("aidl api not null!"); + api.aidlCallbackListener = this; + } } @Override @@ -147,6 +140,29 @@ public class OsmandAidlService extends Service { callbacks.clear(); } + + @Override + public void addAidlCallback(IOsmAndAidlCallback callback, int key) { + aidlCallbackId++; + callbacks.put(aidlCallbackId, new AidlCallbackParams(callback, key)); + } + + @Override + public boolean removeAidlCallback(long id) { + for (Long key : callbacks.keySet()) { + if (key == id) { + callbacks.remove(id); + return true; + } + } + return false; + } + + @Override + public Map getAidlCallbacks() { + return callbacks; + } + private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() { private void handleException(Exception e) { @@ -733,7 +749,7 @@ public class OsmandAidlService extends Service { try { if (updateTimeMS >= MIN_UPDATE_TIME_MS) { aidlCallbackId++; - addAidlCallback(callback, aidlCallbackId, KEY_ON_UPDATE); + addAidlCallback(callback, KEY_ON_UPDATE); startRemoteUpdates(updateTimeMS, aidlCallbackId, callback); return aidlCallbackId; } else { @@ -1012,18 +1028,17 @@ public class OsmandAidlService extends Service { @Override public long registerForNavigationUpdates(ANavigationUpdateParams params, final IOsmAndAidlCallback callback) { try { - aidlCallbackId++; OsmandAidlApi api = getApi("registerForNavUpdates"); if (api != null ) { if (!params.isSubscribeToUpdates() && params.getCallbackId() != -1) { + api.unregisterFromUpdates(params.getCallbackId()); removeAidlCallback(params.getCallbackId()); return -1; } else { - addAidlCallback(callback, aidlCallbackId, KEY_ON_NAV_DATA_UPDATE); + addAidlCallback(callback, KEY_ON_NAV_DATA_UPDATE); + api.registerForNavigationUpdates(aidlCallbackId); + return aidlCallbackId; } - - api.registerForNavigationUpdates(); - return aidlCallbackId; } else { return -1; } @@ -1034,6 +1049,7 @@ public class OsmandAidlService extends Service { } }; + public static class AidlCallbackParams { private IOsmAndAidlCallback callback; private long key; @@ -1060,4 +1076,6 @@ public class OsmandAidlService extends Service { this.key = key; } } + + } diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 0f84f947a9..7921b164a7 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -29,6 +29,7 @@ import java.lang.ref.WeakReference; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION; @@ -38,8 +39,8 @@ public class RoutingHelper { private static final float POSITION_TOLERANCE = 60; - private List> listeners = new LinkedList<>(); - private List> updateListeners = new LinkedList<>(); + private List> listeners = new CopyOnWriteArrayList<>(); + private List> updateListeners = new CopyOnWriteArrayList<>(); private OsmandApplication app; private TransportRoutingHelper transportRoutingHelper; @@ -266,7 +267,20 @@ public class RoutingHelper { } public void addDataUpdateListener(IRoutingDataUpdateListener listener) { - updateListeners.add(new WeakReference(listener)); + updateListeners.add(new WeakReference<>(listener)); + } + + public boolean removeDataUpdateListener(IRoutingDataUpdateListener listener) { + Iterator> it = updateListeners.iterator(); + while(it.hasNext()) { + WeakReference wrl = it.next(); + IRoutingDataUpdateListener l = wrl.get(); + if(listener == l) { + it.remove(); + return true; + } + } + return false; } public boolean removeListener(IRouteInformationListener lt){ @@ -274,7 +288,7 @@ public class RoutingHelper { while(it.hasNext()) { WeakReference ref = it.next(); IRouteInformationListener l = ref.get(); - if(l == null || lt == l) { + if(l == lt) { it.remove(); return true; } @@ -508,7 +522,9 @@ public class RoutingHelper { app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION); if (!updateListeners.isEmpty()) { for (WeakReference ref : updateListeners) { - ref.get().onRoutingDataUpdate(); + if (ref.get() != null) { + ref.get().onRoutingDataUpdate(); + } } } From a8f6aadcc2a9766a8c3a78c004f137c74cdbfb39 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Wed, 17 Apr 2019 11:36:09 +0300 Subject: [PATCH 11/15] fix old method' id incrementation --- OsmAnd/src/net/osmand/aidl/OsmandAidlService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index c31d68fcf1..c8a530746c 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -748,7 +748,6 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public long registerForUpdates(long updateTimeMS, IOsmAndAidlCallback callback) { try { if (updateTimeMS >= MIN_UPDATE_TIME_MS) { - aidlCallbackId++; addAidlCallback(callback, KEY_ON_UPDATE); startRemoteUpdates(updateTimeMS, aidlCallbackId, callback); return aidlCallbackId; From 6df0ffe005584bf1ff0a082b598d7845359e1b43 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Wed, 17 Apr 2019 17:45:22 +0300 Subject: [PATCH 12/15] fixed concurrency issues --- .../net/osmand/aidl/AidlCallbackListener.java | 2 +- .../net/osmand/aidl/OsmandAidlService.java | 36 ++++++++++++------- .../osmand/plus/routing/RoutingHelper.java | 31 ++++++++-------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java index 82556a7e59..95d958fb39 100644 --- a/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java +++ b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java @@ -3,7 +3,7 @@ package net.osmand.aidl; import java.util.Map; public interface AidlCallbackListener{ - void addAidlCallback(IOsmAndAidlCallback callback, int key); + long addAidlCallback(IOsmAndAidlCallback callback, int key); boolean removeAidlCallback(long id); Map getAidlCallbacks(); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index c8a530746c..f70bbc76d3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -78,6 +78,7 @@ import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; import static net.osmand.aidl.OsmandAidlConstants.CANNOT_ACCESS_API_ERROR; import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS; @@ -97,7 +98,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { private Handler mHandler = null; HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread"); - private long aidlCallbackId = 0; + private final AtomicLong aidlCallbackId = new AtomicLong(0); private OsmandApplication getApp() { return (OsmandApplication) getApplication(); @@ -128,7 +129,6 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { super.onCreate(); OsmandAidlApi api = getApi("setting_listener"); if(api != null) { - LOG.debug("aidl api not null!"); api.aidlCallbackListener = this; } } @@ -136,15 +136,27 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { @Override public void onDestroy() { super.onDestroy(); - mHandlerThread.quit(); + callbacks.clear(); + OsmandAidlApi api = getApi("clear_listener"); + if(api != null) { + api.aidlCallbackListener = null; + } + mHandlerThread.quit(); } + private long getCallbackId() { + return aidlCallbackId.get(); + } + + private long getAndIncrementCallbackId() { + return aidlCallbackId.getAndIncrement(); + } @Override - public void addAidlCallback(IOsmAndAidlCallback callback, int key) { - aidlCallbackId++; - callbacks.put(aidlCallbackId, new AidlCallbackParams(callback, key)); + public long addAidlCallback(IOsmAndAidlCallback callback, int key) { + callbacks.put(getAndIncrementCallbackId(), new AidlCallbackParams(callback, key)); + return getCallbackId(); } @Override @@ -748,9 +760,9 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public long registerForUpdates(long updateTimeMS, IOsmAndAidlCallback callback) { try { if (updateTimeMS >= MIN_UPDATE_TIME_MS) { - addAidlCallback(callback, KEY_ON_UPDATE); - startRemoteUpdates(updateTimeMS, aidlCallbackId, callback); - return aidlCallbackId; + long id = addAidlCallback(callback, KEY_ON_UPDATE); + startRemoteUpdates(updateTimeMS, id, callback); + return getCallbackId(); } else { return MIN_UPDATE_TIME_MS_ERROR; } @@ -1034,9 +1046,9 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { removeAidlCallback(params.getCallbackId()); return -1; } else { - addAidlCallback(callback, KEY_ON_NAV_DATA_UPDATE); - api.registerForNavigationUpdates(aidlCallbackId); - return aidlCallbackId; + long id = addAidlCallback(callback, KEY_ON_NAV_DATA_UPDATE); + api.registerForNavigationUpdates(id); + return id; } } else { return -1; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 7921b164a7..f9bac930d9 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -26,6 +26,7 @@ import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -39,8 +40,8 @@ public class RoutingHelper { private static final float POSITION_TOLERANCE = 60; - private List> listeners = new CopyOnWriteArrayList<>(); - private List> updateListeners = new CopyOnWriteArrayList<>(); + private List> listeners = new LinkedList<>(); + private List> updateListeners = new LinkedList<>(); private OsmandApplication app; private TransportRoutingHelper transportRoutingHelper; @@ -267,28 +268,25 @@ public class RoutingHelper { } public void addDataUpdateListener(IRoutingDataUpdateListener listener) { - updateListeners.add(new WeakReference<>(listener)); - } - - public boolean removeDataUpdateListener(IRoutingDataUpdateListener listener) { - Iterator> it = updateListeners.iterator(); - while(it.hasNext()) { - WeakReference wrl = it.next(); - IRoutingDataUpdateListener l = wrl.get(); - if(listener == l) { - it.remove(); - return true; + List> copy = new ArrayList<>(updateListeners); + List> tmp = new ArrayList<>(); + for (WeakReference ref : copy) { + IRoutingDataUpdateListener l = ref.get(); + if (l != null) { + tmp.add(ref); } } - return false; + tmp.add(new WeakReference<>(listener)); + updateListeners = tmp; } + public boolean removeListener(IRouteInformationListener lt){ Iterator> it = listeners.iterator(); while(it.hasNext()) { WeakReference ref = it.next(); IRouteInformationListener l = ref.get(); - if(l == lt) { + if(l == null || lt == l) { it.remove(); return true; } @@ -521,7 +519,8 @@ public class RoutingHelper { currentRoute = newCurrentRoute + 1; app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION); if (!updateListeners.isEmpty()) { - for (WeakReference ref : updateListeners) { + final ArrayList> tmp = new ArrayList<>(updateListeners); + for (WeakReference ref : tmp) { if (ref.get() != null) { ref.get().onRoutingDataUpdate(); } From 39e55340720eb74ab580e497fab2e94b24c01de4 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Wed, 17 Apr 2019 17:45:22 +0300 Subject: [PATCH 13/15] fixed concurrency issues --- .../net/osmand/aidl/AidlCallbackListener.java | 2 +- .../net/osmand/aidl/OsmandAidlService.java | 36 ++++++++----- .../osmand/plus/routing/RoutingHelper.java | 53 ++++++++++++------- 3 files changed, 60 insertions(+), 31 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java index 82556a7e59..95d958fb39 100644 --- a/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java +++ b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java @@ -3,7 +3,7 @@ package net.osmand.aidl; import java.util.Map; public interface AidlCallbackListener{ - void addAidlCallback(IOsmAndAidlCallback callback, int key); + long addAidlCallback(IOsmAndAidlCallback callback, int key); boolean removeAidlCallback(long id); Map getAidlCallbacks(); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index c8a530746c..f70bbc76d3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -78,6 +78,7 @@ import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; import static net.osmand.aidl.OsmandAidlConstants.CANNOT_ACCESS_API_ERROR; import static net.osmand.aidl.OsmandAidlConstants.MIN_UPDATE_TIME_MS; @@ -97,7 +98,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { private Handler mHandler = null; HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread"); - private long aidlCallbackId = 0; + private final AtomicLong aidlCallbackId = new AtomicLong(0); private OsmandApplication getApp() { return (OsmandApplication) getApplication(); @@ -128,7 +129,6 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { super.onCreate(); OsmandAidlApi api = getApi("setting_listener"); if(api != null) { - LOG.debug("aidl api not null!"); api.aidlCallbackListener = this; } } @@ -136,15 +136,27 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { @Override public void onDestroy() { super.onDestroy(); - mHandlerThread.quit(); + callbacks.clear(); + OsmandAidlApi api = getApi("clear_listener"); + if(api != null) { + api.aidlCallbackListener = null; + } + mHandlerThread.quit(); } + private long getCallbackId() { + return aidlCallbackId.get(); + } + + private long getAndIncrementCallbackId() { + return aidlCallbackId.getAndIncrement(); + } @Override - public void addAidlCallback(IOsmAndAidlCallback callback, int key) { - aidlCallbackId++; - callbacks.put(aidlCallbackId, new AidlCallbackParams(callback, key)); + public long addAidlCallback(IOsmAndAidlCallback callback, int key) { + callbacks.put(getAndIncrementCallbackId(), new AidlCallbackParams(callback, key)); + return getCallbackId(); } @Override @@ -748,9 +760,9 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public long registerForUpdates(long updateTimeMS, IOsmAndAidlCallback callback) { try { if (updateTimeMS >= MIN_UPDATE_TIME_MS) { - addAidlCallback(callback, KEY_ON_UPDATE); - startRemoteUpdates(updateTimeMS, aidlCallbackId, callback); - return aidlCallbackId; + long id = addAidlCallback(callback, KEY_ON_UPDATE); + startRemoteUpdates(updateTimeMS, id, callback); + return getCallbackId(); } else { return MIN_UPDATE_TIME_MS_ERROR; } @@ -1034,9 +1046,9 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { removeAidlCallback(params.getCallbackId()); return -1; } else { - addAidlCallback(callback, KEY_ON_NAV_DATA_UPDATE); - api.registerForNavigationUpdates(aidlCallbackId); - return aidlCallbackId; + long id = addAidlCallback(callback, KEY_ON_NAV_DATA_UPDATE); + api.registerForNavigationUpdates(id); + return id; } } else { return -1; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 7921b164a7..c3117224f3 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -26,6 +26,7 @@ import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -39,8 +40,8 @@ public class RoutingHelper { private static final float POSITION_TOLERANCE = 60; - private List> listeners = new CopyOnWriteArrayList<>(); - private List> updateListeners = new CopyOnWriteArrayList<>(); + private List> listeners = new LinkedList<>(); + private List> updateListeners = new LinkedList<>(); private OsmandApplication app; private TransportRoutingHelper transportRoutingHelper; @@ -267,20 +268,30 @@ public class RoutingHelper { } public void addDataUpdateListener(IRoutingDataUpdateListener listener) { - updateListeners.add(new WeakReference<>(listener)); - } - - public boolean removeDataUpdateListener(IRoutingDataUpdateListener listener) { - Iterator> it = updateListeners.iterator(); - while(it.hasNext()) { - WeakReference wrl = it.next(); - IRoutingDataUpdateListener l = wrl.get(); - if(listener == l) { + List> copyList = new ArrayList<>(updateListeners); + Iterator> it = copyList.iterator(); + while (it.hasNext()) { + WeakReference ref = it.next(); + IRoutingDataUpdateListener l = ref.get(); + if (l == null) { it.remove(); - return true; } } - return false; + copyList.add(new WeakReference<>(listener)); + updateListeners = copyList; + } + + public void removeDataUpdateListener(IRoutingDataUpdateListener listener) { + List> copyList = new ArrayList<>(updateListeners); + Iterator> it = copyList.iterator(); + while (it.hasNext()) { + WeakReference ref = it.next(); + IRoutingDataUpdateListener l = ref.get(); + if (l == null || l == listener) { + it.remove(); + } + } + updateListeners = copyList; } public boolean removeListener(IRouteInformationListener lt){ @@ -288,7 +299,7 @@ public class RoutingHelper { while(it.hasNext()) { WeakReference ref = it.next(); IRouteInformationListener l = ref.get(); - if(l == lt) { + if(l == null || lt == l) { it.remove(); return true; } @@ -521,13 +532,19 @@ public class RoutingHelper { currentRoute = newCurrentRoute + 1; app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION); if (!updateListeners.isEmpty()) { - for (WeakReference ref : updateListeners) { - if (ref.get() != null) { - ref.get().onRoutingDataUpdate(); + ArrayList> tmp = new ArrayList<>(updateListeners); + Iterator> it = tmp.iterator(); + while (it.hasNext()) { + WeakReference ref = it.next(); + IRoutingDataUpdateListener l = ref.get(); + if (l == null) { + it.remove(); + } else { + l.onRoutingDataUpdate(); } + updateListeners = tmp; } } - } else { break; } From 055c403f14a2a3c676555b99f2d0e355875d26fc Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Fri, 19 Apr 2019 10:24:53 +0300 Subject: [PATCH 14/15] add pr fixes, add AidlCallbackListener documentation --- .../net/osmand/aidl/AidlCallbackListener.java | 30 +++++++++++++- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 6 +-- .../osmand/plus/routing/RoutingHelper.java | 40 ++++++++----------- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java index 95d958fb39..71fe1f1b8f 100644 --- a/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java +++ b/OsmAnd/src/net/osmand/aidl/AidlCallbackListener.java @@ -2,8 +2,36 @@ package net.osmand.aidl; import java.util.Map; -public interface AidlCallbackListener{ +public interface AidlCallbackListener { + + /** + * Add AidlCallbackListener to OsmandAidlService's map of listeners. Key is unique to each AIDL + * method that wants to register callback and used to access only "own" callbacks. + * + * @param callback + * @param key - every AIDL method which uses that register callbacks in service need to use its own bit key + * 1 - key for registerForUpdates(...) + * 2 - key for registerForNavigationUpdates(...) + * 4 - key for onContextMenuButtonClicked(...) + * 8 - key for... future use + * 16 - key for... future use + * @return long - unique id of callback. Could be used for unregistering callback + */ long addAidlCallback(IOsmAndAidlCallback callback, int key); + + + /** + * Unregister AidlCallbackListener from OsmandAidlService's map + * + * @param id - unique id of callback + * @return - true if callback successfully unregistered + */ boolean removeAidlCallback(long id); + + /** + * + * @return map of all callbacks. AidlCallbackParams contains method key and callback. + */ Map getAidlCallbacks(); + } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index f51e292677..a8cd1acfcc 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -25,8 +25,6 @@ import android.text.TextUtils; import android.view.View; import android.widget.ArrayAdapter; -import java.util.HashMap; -import java.util.Map.Entry; import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -1961,11 +1959,11 @@ public class OsmandAidlApi { } }; navUpdateCallbacks.put(id, listener); - app.getRoutingHelper().addDataUpdateListener(listener); + app.getRoutingHelper().addRouteDataListener(listener); } public void unregisterFromUpdates(long id) { - app.getRoutingHelper().removeDataUpdateListener(navUpdateCallbacks.get(id)); + app.getRoutingHelper().removeRouteDataListener(navUpdateCallbacks.get(id)); navUpdateCallbacks.remove(id); } diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index c3117224f3..86ceb4f8e6 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION; @@ -267,31 +266,29 @@ public class RoutingHelper { transportRoutingHelper.addListener(l); } - public void addDataUpdateListener(IRoutingDataUpdateListener listener) { - List> copyList = new ArrayList<>(updateListeners); - Iterator> it = copyList.iterator(); - while (it.hasNext()) { - WeakReference ref = it.next(); - IRoutingDataUpdateListener l = ref.get(); - if (l == null) { - it.remove(); - } - } - copyList.add(new WeakReference<>(listener)); - updateListeners = copyList; + public void addRouteDataListener(IRoutingDataUpdateListener listener) { + updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, true); } - public void removeDataUpdateListener(IRoutingDataUpdateListener listener) { - List> copyList = new ArrayList<>(updateListeners); + public void removeRouteDataListener(IRoutingDataUpdateListener listener) { + updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, false); + } + + private List> updateListenersList( + List> copyList, + IRoutingDataUpdateListener listener, boolean isNewListener) { Iterator> it = copyList.iterator(); while (it.hasNext()) { WeakReference ref = it.next(); IRoutingDataUpdateListener l = ref.get(); - if (l == null || l == listener) { + if (l == null || (l == listener)) { it.remove(); } } - updateListeners = copyList; + if (isNewListener) { + copyList.add(new WeakReference<>(listener)); + } + return copyList; } public boolean removeListener(IRouteInformationListener lt){ @@ -533,16 +530,11 @@ public class RoutingHelper { app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION); if (!updateListeners.isEmpty()) { ArrayList> tmp = new ArrayList<>(updateListeners); - Iterator> it = tmp.iterator(); - while (it.hasNext()) { - WeakReference ref = it.next(); + for (WeakReference ref : tmp) { IRoutingDataUpdateListener l = ref.get(); - if (l == null) { - it.remove(); - } else { + if (l != null) { l.onRoutingDataUpdate(); } - updateListeners = tmp; } } } else { From 347d9358b295ed2ed37f1b14c5ceb7404b3e088b Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Fri, 19 Apr 2019 13:28:27 +0300 Subject: [PATCH 15/15] fixed older code. --- .../osmand/plus/routing/RoutingHelper.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 86ceb4f8e6..bae4c245fb 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -261,10 +261,6 @@ public class RoutingHelper { return lastProjection; } - public void addListener(IRouteInformationListener l){ - listeners.add(new WeakReference<>(l)); - transportRoutingHelper.addListener(l); - } public void addRouteDataListener(IRoutingDataUpdateListener listener) { updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, true); @@ -281,7 +277,7 @@ public class RoutingHelper { while (it.hasNext()) { WeakReference ref = it.next(); IRoutingDataUpdateListener l = ref.get(); - if (l == null || (l == listener)) { + if (l == null || l == listener) { it.remove(); } } @@ -291,20 +287,34 @@ public class RoutingHelper { return copyList; } - public boolean removeListener(IRouteInformationListener lt){ - Iterator> it = listeners.iterator(); - while(it.hasNext()) { + public void addListener(IRouteInformationListener l){ + listeners = updateInformationListeners(new ArrayList<>(listeners), l, true); + transportRoutingHelper.addListener(l); + } + + public void removeListener(IRouteInformationListener lt){ + listeners = updateInformationListeners(new ArrayList<>(listeners), lt, false); + } + + private List> updateInformationListeners( + List> copyList, + IRouteInformationListener listener, boolean isNewListener) { + Iterator> it = copyList.iterator(); + while (it.hasNext()) { WeakReference ref = it.next(); IRouteInformationListener l = ref.get(); - if(l == null || lt == l) { + if (l == null || l == listener) { it.remove(); - return true; } } - transportRoutingHelper.removeListener(lt); - return false; + + if (isNewListener) { + copyList.add(new WeakReference<>(listener)); + } + return copyList; } + public void updateLocation(Location currentLocation) { if (settings.getPointToStart() == null && settings.getMyLocationToStart() == null && currentLocation != null) { app.getTargetPointsHelper().setMyLocationPoint(