From 4c7f39abb8bd79d17a2f27822d96fbe7dbe9c164 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 17 Dec 2020 17:16:01 +0200 Subject: [PATCH] Fix #10396 --- .../aidlapi/navigation/NavigateGpxParams.java | 13 +++++- .../aidlapi/navigation/NavigateParams.java | 11 ++++- .../navigation/NavigateSearchParams.java | 12 +++++- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 33 +++++++++------ .../net/osmand/aidl/OsmandAidlService.java | 12 +++--- .../net/osmand/aidl/OsmandAidlServiceV2.java | 7 ++-- .../aidl/navigation/NavigateGpxParams.java | 14 +++++-- .../aidl/navigation/NavigateParams.java | 12 +++++- .../aidl/navigation/NavigateSearchParams.java | 11 ++++- .../plus/helpers/ExternalApiHelper.java | 40 +++++++++++-------- 10 files changed, 117 insertions(+), 48 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateGpxParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateGpxParams.java index 8b4901b35e..e6fad0c1b1 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateGpxParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateGpxParams.java @@ -11,15 +11,18 @@ public class NavigateGpxParams extends AidlParams { private String data; private Uri uri; private boolean force; + private boolean needLocationPermission; - public NavigateGpxParams(String data, boolean force) { + public NavigateGpxParams(String data, boolean force, boolean needLocationPermission) { this.data = data; this.force = force; + this.needLocationPermission = needLocationPermission; } - public NavigateGpxParams(Uri uri, boolean force) { + public NavigateGpxParams(Uri uri, boolean force, boolean needLocationPermission) { this.uri = uri; this.force = force; + this.needLocationPermission = needLocationPermission; } public NavigateGpxParams(Parcel in) { @@ -50,11 +53,16 @@ public class NavigateGpxParams extends AidlParams { return force; } + public boolean isNeedLocationPermission() { + return needLocationPermission; + } + @Override public void writeToBundle(Bundle bundle) { bundle.putString("data", data); bundle.putParcelable("uri", uri); bundle.putBoolean("force", force); + bundle.putBoolean("needLocationPermission", needLocationPermission); } @Override @@ -62,5 +70,6 @@ public class NavigateGpxParams extends AidlParams { data = bundle.getString("data"); uri = bundle.getParcelable("uri"); force = bundle.getBoolean("force"); + needLocationPermission = bundle.getBoolean("needLocationPermission"); } } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateParams.java index 6dff82b7e4..ad83489f17 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateParams.java @@ -17,8 +17,10 @@ public class NavigateParams extends AidlParams { private double destLon; private boolean force; + private boolean needLocationPermission; - public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat, double destLon, String profile, boolean force) { + public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat, + double destLon, String profile, boolean force, boolean needLocationPermission) { this.startName = startName; this.startLat = startLat; this.startLon = startLon; @@ -27,6 +29,7 @@ public class NavigateParams extends AidlParams { this.destLon = destLon; this.profile = profile; this.force = force; + this.needLocationPermission = needLocationPermission; } public NavigateParams(Parcel in) { @@ -77,6 +80,10 @@ public class NavigateParams extends AidlParams { return force; } + public boolean isNeedLocationPermission() { + return needLocationPermission; + } + @Override public void writeToBundle(Bundle bundle) { bundle.putString("startName", startName); @@ -87,6 +94,7 @@ public class NavigateParams extends AidlParams { bundle.putDouble("destLon", destLon); bundle.putString("profile", profile); bundle.putBoolean("force", force); + bundle.putBoolean("needLocationPermission", needLocationPermission); } @Override @@ -99,5 +107,6 @@ public class NavigateParams extends AidlParams { destLon = bundle.getDouble("destLon"); profile = bundle.getString("profile"); force = bundle.getBoolean("force"); + needLocationPermission = bundle.getBoolean("needLocationPermission"); } } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateSearchParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateSearchParams.java index d548dab2f3..a5edc7524c 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateSearchParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigateSearchParams.java @@ -17,10 +17,11 @@ public class NavigateSearchParams extends AidlParams { private double searchLon; private boolean force; + private boolean needLocationPermission; public NavigateSearchParams(String startName, double startLat, double startLon, - String searchQuery, double searchLat, double searchLon, - String profile, boolean force) { + String searchQuery, double searchLat, double searchLon, + String profile, boolean force, boolean needLocationPermission) { this.startName = startName; this.startLat = startLat; this.startLon = startLon; @@ -29,6 +30,7 @@ public class NavigateSearchParams extends AidlParams { this.searchLon = searchLon; this.profile = profile; this.force = force; + this.needLocationPermission = needLocationPermission; } public NavigateSearchParams(Parcel in) { @@ -79,6 +81,10 @@ public class NavigateSearchParams extends AidlParams { return force; } + public boolean isNeedLocationPermission() { + return needLocationPermission; + } + @Override public void writeToBundle(Bundle bundle) { bundle.putString("startName", startName); @@ -89,6 +95,7 @@ public class NavigateSearchParams extends AidlParams { bundle.putBoolean("force", force); bundle.putDouble("searchLat", searchLat); bundle.putDouble("searchLon", searchLon); + bundle.putBoolean("needLocationPermission", needLocationPermission); } @Override @@ -101,5 +108,6 @@ public class NavigateSearchParams extends AidlParams { force = bundle.getBoolean("force"); searchLat = bundle.getDouble("searchLat"); searchLon = bundle.getDouble("searchLon"); + needLocationPermission = bundle.getBoolean("needLocationPermission"); } } \ 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 6b9bb29dea..a332a7fd97 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -177,6 +177,7 @@ public class OsmandAidlApi { private static final String AIDL_DATA = "aidl_data"; private static final String AIDL_URI = "aidl_uri"; private static final String AIDL_FORCE = "aidl_force"; + private static final String AIDL_LOCATION_PERMISSION = "aidl_location_permission"; private static final String AIDL_SEARCH_QUERY = "aidl_search_query"; private static final String AIDL_SEARCH_LAT = "aidl_search_lat"; private static final String AIDL_SEARCH_LON = "aidl_search_lon"; @@ -208,7 +209,7 @@ public class OsmandAidlApi { private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR; - private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ + private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[] { ApplicationMode.CAR, ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN @@ -287,7 +288,7 @@ public class OsmandAidlApi { } private void initOsmandTelegram() { - String[] packages = new String[]{"net.osmand.telegram", "net.osmand.telegram.debug"}; + String[] packages = new String[] {"net.osmand.telegram", "net.osmand.telegram.debug"}; Intent intent = new Intent("net.osmand.telegram.InitApp"); for (String pack : packages) { intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver")); @@ -601,6 +602,7 @@ public class OsmandAidlApi { final RoutingHelper routingHelper = app.getRoutingHelper(); boolean force = intent.getBooleanExtra(AIDL_FORCE, true); + final boolean locationPermission = intent.getBooleanExtra(AIDL_LOCATION_PERMISSION, false); if (routingHelper.isFollowingMode() && !force) { mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { @@ -608,12 +610,12 @@ public class OsmandAidlApi { public void onDismiss(DialogInterface dialog) { MapActivity mapActivity = mapActivityRef.get(); if (mapActivity != null && !routingHelper.isFollowingMode()) { - ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); + ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission); } } }); } else { - ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); + ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission); } } } @@ -667,6 +669,7 @@ public class OsmandAidlApi { if (searchLocation != null) { final RoutingHelper routingHelper = app.getRoutingHelper(); boolean force = intent.getBooleanExtra(AIDL_FORCE, true); + final boolean locationPermission = intent.getBooleanExtra(AIDL_LOCATION_PERMISSION, false); if (routingHelper.isFollowingMode() && !force) { mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { @@ -674,12 +677,14 @@ public class OsmandAidlApi { public void onDismiss(DialogInterface dialog) { MapActivity mapActivity = mapActivityRef.get(); if (mapActivity != null && !routingHelper.isFollowingMode()) { - ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, false); + ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, + startDesc, profile, searchQuery, false, locationPermission); } } }); } else { - ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, false); + ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, + startDesc, profile, searchQuery, false, locationPermission); } } } @@ -698,7 +703,8 @@ public class OsmandAidlApi { GPXFile gpx = loadGpxFileFromIntent(mapActivity, intent); if (gpx != null) { boolean force = intent.getBooleanExtra(AIDL_FORCE, false); - ExternalApiHelper.saveAndNavigateGpx(mapActivity, gpx, force); + boolean locationPermission = intent.getBooleanExtra(AIDL_LOCATION_PERMISSION, false); + ExternalApiHelper.saveAndNavigateGpx(mapActivity, gpx, force, locationPermission); } } } @@ -1652,8 +1658,8 @@ public class OsmandAidlApi { } boolean navigate(String startName, double startLat, double startLon, - String destName, double destLat, double destLon, - String profile, boolean force) { + String destName, double destLat, double destLon, + String profile, boolean force, boolean requestLocationPermission) { Intent intent = new Intent(); intent.setAction(AIDL_NAVIGATE); intent.putExtra(AIDL_START_NAME, startName); @@ -1664,13 +1670,14 @@ public class OsmandAidlApi { intent.putExtra(AIDL_DEST_LON, destLon); intent.putExtra(AIDL_PROFILE, profile); intent.putExtra(AIDL_FORCE, force); + intent.putExtra(AIDL_LOCATION_PERMISSION, requestLocationPermission); app.sendBroadcast(intent); return true; } boolean navigateSearch(String startName, double startLat, double startLon, - String searchQuery, double searchLat, double searchLon, - String profile, boolean force) { + String searchQuery, double searchLat, double searchLon, + String profile, boolean force, boolean requestLocationPermission) { Intent intent = new Intent(); intent.setAction(AIDL_NAVIGATE_SEARCH); intent.putExtra(AIDL_START_NAME, startName); @@ -1681,6 +1688,7 @@ public class OsmandAidlApi { intent.putExtra(AIDL_SEARCH_LON, searchLon); intent.putExtra(AIDL_PROFILE, profile); intent.putExtra(AIDL_FORCE, force); + intent.putExtra(AIDL_LOCATION_PERMISSION, requestLocationPermission); app.sendBroadcast(intent); return true; } @@ -1720,12 +1728,13 @@ public class OsmandAidlApi { return true; } - boolean navigateGpx(String data, Uri uri, boolean force) { + boolean navigateGpx(String data, Uri uri, boolean force, boolean requestLocationPermission) { Intent intent = new Intent(); intent.setAction(AIDL_NAVIGATE_GPX); intent.putExtra(AIDL_DATA, data); intent.putExtra(AIDL_URI, uri); intent.putExtra(AIDL_FORCE, force); + intent.putExtra(AIDL_LOCATION_PERMISSION, requestLocationPermission); app.sendBroadcast(intent); return true; } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 99e888973f..2760dbe1d0 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -44,6 +44,7 @@ import net.osmand.aidl.gpx.RemoveGpxParams; import net.osmand.aidl.gpx.ShowGpxParams; import net.osmand.aidl.gpx.StartGpxRecordingParams; import net.osmand.aidl.gpx.StopGpxRecordingParams; +import net.osmand.aidl.lock.SetLockStateParams; import net.osmand.aidl.map.ALatLon; import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.maplayer.AddMapLayerParams; @@ -85,10 +86,9 @@ import net.osmand.aidl.quickaction.QuickActionParams; import net.osmand.aidl.search.SearchParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; -import net.osmand.aidl.lock.SetLockStateParams; import net.osmand.data.LatLon; -import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -736,7 +736,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { return params != null && api != null && api.navigate( params.getStartName(), params.getStartLat(), params.getStartLon(), params.getDestName(), params.getDestLat(), params.getDestLon(), - params.getProfile(), params.isForce()); + params.getProfile(), params.isForce(), params.isNeedLocationPermission()); } catch (Exception e) { handleException(e); return false; @@ -747,7 +747,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean navigateGpx(NavigateGpxParams params) { try { OsmandAidlApi api = getApi("navigateGpx"); - return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), params.isForce()); + return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), + params.isForce(), params.isNeedLocationPermission()); } catch (Exception e) { handleException(e); return false; @@ -857,7 +858,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { return params != null && api != null && api.navigateSearch( params.getStartName(), params.getStartLat(), params.getStartLon(), params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(), - params.getProfile(), params.isForce()); + params.getProfile(), params.isForce(), params.isNeedLocationPermission()); } catch (Exception e) { handleException(e); return false; @@ -1328,6 +1329,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { return false; } } + @Override public boolean setLockState(SetLockStateParams params) { try { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 9943257c03..1f681f5bb7 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -693,7 +693,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return params != null && api != null && api.navigate( params.getStartName(), params.getStartLat(), params.getStartLon(), params.getDestName(), params.getDestLat(), params.getDestLon(), - params.getProfile(), params.isForce()); + params.getProfile(), params.isForce(), params.isNeedLocationPermission()); } catch (Exception e) { handleException(e); return false; @@ -704,7 +704,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener public boolean navigateGpx(NavigateGpxParams params) { try { OsmandAidlApi api = getApi("navigateGpx"); - return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), params.isForce()); + return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), + params.isForce(), params.isNeedLocationPermission()); } catch (Exception e) { handleException(e); return false; @@ -814,7 +815,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return params != null && api != null && api.navigateSearch( params.getStartName(), params.getStartLat(), params.getStartLon(), params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(), - params.getProfile(), params.isForce()); + params.getProfile(), params.isForce(), params.isNeedLocationPermission()); } catch (Exception e) { handleException(e); return false; diff --git a/OsmAnd/src/net/osmand/aidl/navigation/NavigateGpxParams.java b/OsmAnd/src/net/osmand/aidl/navigation/NavigateGpxParams.java index 6e8fb8efe7..0944c1a5f9 100644 --- a/OsmAnd/src/net/osmand/aidl/navigation/NavigateGpxParams.java +++ b/OsmAnd/src/net/osmand/aidl/navigation/NavigateGpxParams.java @@ -9,15 +9,18 @@ public class NavigateGpxParams implements Parcelable { private String data; private Uri uri; private boolean force; + private boolean needLocationPermission; - public NavigateGpxParams(String data, boolean force) { + public NavigateGpxParams(String data, boolean force, boolean needLocationPermission) { this.data = data; this.force = force; + this.needLocationPermission = needLocationPermission; } - public NavigateGpxParams(Uri uri, boolean force) { + public NavigateGpxParams(Uri uri, boolean force, boolean needLocationPermission) { this.uri = uri; this.force = force; + this.needLocationPermission = needLocationPermission; } public NavigateGpxParams(Parcel in) { @@ -48,22 +51,27 @@ public class NavigateGpxParams implements Parcelable { return force; } + public boolean isNeedLocationPermission() { + return needLocationPermission; + } + @Override public void writeToParcel(Parcel out, int flags) { out.writeString(data); out.writeParcelable(uri, flags); out.writeByte((byte) (force ? 1 : 0)); + out.writeByte((byte) (needLocationPermission ? 1 : 0)); } private void readFromParcel(Parcel in) { data = in.readString(); uri = in.readParcelable(Uri.class.getClassLoader()); force = in.readByte() != 0; + needLocationPermission = in.readByte() != 0; } @Override public int describeContents() { return 0; } - } diff --git a/OsmAnd/src/net/osmand/aidl/navigation/NavigateParams.java b/OsmAnd/src/net/osmand/aidl/navigation/NavigateParams.java index 8b0bdeb1eb..ce3b7ae0e6 100644 --- a/OsmAnd/src/net/osmand/aidl/navigation/NavigateParams.java +++ b/OsmAnd/src/net/osmand/aidl/navigation/NavigateParams.java @@ -13,8 +13,10 @@ public class NavigateParams implements Parcelable { private double destLon; private String profile; private boolean force; + private boolean needLocationPermission; - public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat, double destLon, String profile, boolean force) { + public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat, + double destLon, String profile, boolean force, boolean needLocationPermission) { this.startName = startName; this.startLat = startLat; this.startLon = startLon; @@ -23,6 +25,7 @@ public class NavigateParams implements Parcelable { this.destLon = destLon; this.profile = profile; this.force = force; + this.needLocationPermission = needLocationPermission; } public NavigateParams(Parcel in) { @@ -73,6 +76,10 @@ public class NavigateParams implements Parcelable { return force; } + public boolean isNeedLocationPermission() { + return needLocationPermission; + } + @Override public void writeToParcel(Parcel out, int flags) { out.writeString(startName); @@ -83,6 +90,7 @@ public class NavigateParams implements Parcelable { out.writeDouble(destLon); out.writeString(profile); out.writeByte((byte) (force ? 1 : 0)); + out.writeByte((byte) (needLocationPermission ? 1 : 0)); } private void readFromParcel(Parcel in) { @@ -94,11 +102,11 @@ public class NavigateParams implements Parcelable { destLon = in.readDouble(); profile = in.readString(); force = in.readByte() != 0; + needLocationPermission = in.readByte() != 0; } @Override public int describeContents() { return 0; } - } diff --git a/OsmAnd/src/net/osmand/aidl/navigation/NavigateSearchParams.java b/OsmAnd/src/net/osmand/aidl/navigation/NavigateSearchParams.java index b092bcd4eb..8fc9ccea18 100644 --- a/OsmAnd/src/net/osmand/aidl/navigation/NavigateSearchParams.java +++ b/OsmAnd/src/net/osmand/aidl/navigation/NavigateSearchParams.java @@ -13,10 +13,11 @@ public class NavigateSearchParams implements Parcelable { private double searchLon; private String profile; private boolean force; + private boolean needLocationPermission; public NavigateSearchParams(String startName, double startLat, double startLon, String searchQuery, double searchLat, double searchLon, - String profile, boolean force) { + String profile, boolean force, boolean needLocationPermission) { this.startName = startName; this.startLat = startLat; this.startLon = startLon; @@ -25,6 +26,7 @@ public class NavigateSearchParams implements Parcelable { this.searchLon = searchLon; this.profile = profile; this.force = force; + this.needLocationPermission = needLocationPermission; } public NavigateSearchParams(Parcel in) { @@ -75,6 +77,10 @@ public class NavigateSearchParams implements Parcelable { return force; } + public boolean isNeedLocationPermission() { + return needLocationPermission; + } + @Override public void writeToParcel(Parcel out, int flags) { out.writeString(startName); @@ -85,6 +91,7 @@ public class NavigateSearchParams implements Parcelable { out.writeByte((byte) (force ? 1 : 0)); out.writeDouble(searchLat); out.writeDouble(searchLon); + out.writeByte((byte) (needLocationPermission ? 1 : 0)); } private void readFromParcel(Parcel in) { @@ -96,11 +103,11 @@ public class NavigateSearchParams implements Parcelable { force = in.readByte() != 0; searchLat = in.readDouble(); searchLon = in.readDouble(); + needLocationPermission = in.readByte() != 0; } @Override public int describeContents() { return 0; } - } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 57d6039145..5740f8fceb 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -30,6 +30,7 @@ import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -129,6 +130,7 @@ public class ExternalApiHelper { public static final String PARAM_URI = "uri"; public static final String PARAM_DATA = "data"; public static final String PARAM_FORCE = "force"; + public static final String PARAM_LOCATION_PERMISSION = "location_permission"; public static final String PARAM_START_NAME = "start_name"; public static final String PARAM_DEST_NAME = "dest_name"; @@ -237,7 +239,8 @@ public class ExternalApiHelper { if (gpx != null) { if (navigate) { boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); - saveAndNavigateGpx(mapActivity, gpx, force); + boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false); + saveAndNavigateGpx(mapActivity, gpx, force, locationPermission); } else { app.getSelectedGpxHelper().setGpxFileToDisplay(gpx); } @@ -289,6 +292,7 @@ public class ExternalApiHelper { final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName); boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); + final boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false); final RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode() && !force) { @@ -297,12 +301,12 @@ public class ExternalApiHelper { @Override public void onDismiss(DialogInterface dialog) { if (!routingHelper.isFollowingMode()) { - startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); + startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission); } } }); } else { - startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); + startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission); } } @@ -348,6 +352,7 @@ public class ExternalApiHelper { resultCode = RESULT_CODE_ERROR_SEARCH_LOCATION_UNDEFINED; } else { boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); + final boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false); final RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode() && !force) { @@ -356,12 +361,12 @@ public class ExternalApiHelper { @Override public void onDismiss(DialogInterface dialog) { if (!routingHelper.isFollowingMode()) { - searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults); + searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults, locationPermission); } } }); } else { - searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults); + searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults, locationPermission); } resultCode = Activity.RESULT_OK; } @@ -629,7 +634,8 @@ public class ExternalApiHelper { return null; } - public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, final boolean force) { + public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, + final boolean force, final boolean checkLocationPermission) { final WeakReference mapActivityRef = new WeakReference<>(mapActivity); if (Algorithms.isEmpty(gpxFile.path)) { @@ -670,12 +676,12 @@ public class ExternalApiHelper { public void onDismiss(DialogInterface dialog) { MapActivity mapActivity = mapActivityRef.get(); if (mapActivity != null && !routingHelper.isFollowingMode()) { - ExternalApiHelper.startNavigation(mapActivity, gpxFile); + ExternalApiHelper.startNavigation(mapActivity, gpxFile, checkLocationPermission); } } }); } else { - startNavigation(mapActivity, gpxFile); + startNavigation(mapActivity, gpxFile, checkLocationPermission); } } } @@ -705,23 +711,22 @@ public class ExternalApiHelper { mapContextMenu.show(new LatLon(lat, lon), pointDescription, object); } - static public void startNavigation(MapActivity mapActivity, - @NonNull GPXFile gpx) { - startNavigation(mapActivity, gpx, null, null, null, null, null); + static public void startNavigation(MapActivity mapActivity, @NonNull GPXFile gpx, boolean checkLocationPermission) { + startNavigation(mapActivity, gpx, null, null, null, null, null, checkLocationPermission); } static public void startNavigation(MapActivity mapActivity, @Nullable LatLon from, @Nullable PointDescription fromDesc, @Nullable LatLon to, @Nullable PointDescription toDesc, - @NonNull ApplicationMode mode) { - startNavigation(mapActivity, null, from, fromDesc, to, toDesc, mode); + @NonNull ApplicationMode mode, boolean checkLocationPermission) { + startNavigation(mapActivity, null, from, fromDesc, to, toDesc, mode, checkLocationPermission); } static private void startNavigation(MapActivity mapActivity, GPXFile gpx, LatLon from, PointDescription fromDesc, LatLon to, PointDescription toDesc, - ApplicationMode mode) { + ApplicationMode mode, boolean checkLocationPermission) { OsmandApplication app = mapActivity.getMyApplication(); RoutingHelper routingHelper = app.getRoutingHelper(); if (gpx == null) { @@ -745,12 +750,15 @@ public class ExternalApiHelper { app.getRoutingHelper().notifyIfRouteIsCalculated(); routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false); } + if (checkLocationPermission) { + OsmAndLocationProvider.requestFineLocationPermissionIfNeeded(mapActivity); + } } static public void searchAndNavigate(@NonNull MapActivity mapActivity, @NonNull final LatLon searchLocation, @Nullable final LatLon from, @Nullable final PointDescription fromDesc, @NonNull final ApplicationMode mode, @NonNull final String searchQuery, - final boolean showSearchResults) { + final boolean showSearchResults, final boolean checkLocationPermission) { final WeakReference mapActivityRef = new WeakReference<>(mapActivity); OsmandApplication app = mapActivity.getMyApplication(); @@ -791,7 +799,7 @@ public class ExternalApiHelper { LatLon to = new LatLon(res.getLatitude(), res.getLongitude()); PointDescription toDesc = new PointDescription( PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName()); - startNavigation(mapActivity, from, fromDesc, to, toDesc, mode); + startNavigation(mapActivity, from, fromDesc, to, toDesc, mode, checkLocationPermission); } else { mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found)); }