From c5d0d27b5f567825e1e953f0f8879c4911bc97e4 Mon Sep 17 00:00:00 2001 From: Zahnstocher Date: Thu, 19 Jun 2014 16:07:15 +0200 Subject: [PATCH] Switch to TLS --- .../net/osmand/plus/NameFinderPoiFilter.java | 15 +++++++-- .../search/SearchAddressOnlineFragment.java | 15 ++++++++- .../plus/osmedit/EditingPOIActivity.java | 2 +- .../plus/osmedit/OpenstreetmapRemoteUtil.java | 33 ++++++++++++++----- .../net/osmand/plus/osmedit/OsmBugsLayer.java | 13 +++++++- .../plus/osmedit/OsmBugsRemoteUtil.java | 24 +++++++++++--- 6 files changed, 83 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/NameFinderPoiFilter.java b/OsmAnd/src/net/osmand/plus/NameFinderPoiFilter.java index 844fa6edd0..41aee81b34 100644 --- a/OsmAnd/src/net/osmand/plus/NameFinderPoiFilter.java +++ b/OsmAnd/src/net/osmand/plus/NameFinderPoiFilter.java @@ -27,7 +27,6 @@ public class NameFinderPoiFilter extends PoiFilter { List searchedAmenities = new ArrayList(); - private String query = ""; //$NON-NLS-1$ private String lastError = ""; //$NON-NLS-1$ @@ -55,12 +54,24 @@ public class NameFinderPoiFilter extends PoiFilter { @Override protected List searchAmenities(double lat, double lon, double topLatitude, double bottomLatitude, double leftLongitude, double rightLongitude, ResultMatcher matcher) { + + final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; + + String NOMINATIM_API; + + if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { + NOMINATIM_API = "https://nominatim.openstreetmap.org/search/"; + } + else { + NOMINATIM_API = "http://nominatim.openstreetmap.org/search/"; + } + searchedAmenities.clear(); String viewbox = "viewboxlbrt="+((float) leftLongitude)+","+((float) bottomLatitude)+","+((float) rightLongitude)+","+((float) topLatitude); try { lastError = ""; - String urlq = "http://nominatim.openstreetmap.org/search/"+URLEncoder.encode(query)+ "?format=xml&addressdetails=1&limit="+LIMIT+"&bounded=1&"+viewbox; + String urlq = NOMINATIM_API + URLEncoder.encode(query)+ "?format=xml&addressdetails=1&limit="+LIMIT+"&bounded=1&"+viewbox; log.info(urlq); URL url = new URL(urlq); //$NON-NLS-1$ InputStream stream = url.openStream(); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineFragment.java index 0c123e827d..1932866118 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineFragment.java @@ -142,6 +142,7 @@ public class SearchAddressOnlineFragment extends SherlockFragment implements Sea } protected void searchPlaces(final String search) { + if(Algorithms.isEmpty(search)){ return; } @@ -154,9 +155,21 @@ public class SearchAddressOnlineFragment extends SherlockFragment implements Sea @Override protected Void doInBackground(Void... params) { try { + + final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; + + String NOMINATIM_API; + + if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { + NOMINATIM_API = "https://nominatim.openstreetmap.org/search"; + } + else { + NOMINATIM_API = "http://nominatim.openstreetmap.org/search"; + } + final List places = new ArrayList(); StringBuilder b = new StringBuilder(); - b.append("http://nominatim.openstreetmap.org/search"); //$NON-NLS-1$ + b.append(NOMINATIM_API); //$NON-NLS-1$ b.append("?format=xml&addressdetails=0&accept-language=").append(Locale.getDefault().getLanguage()); //$NON-NLS-1$ b.append("&q=").append(URLEncoder.encode(search, "UTF-8")); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java index 1d906eb690..9ee0c1142f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java @@ -331,7 +331,7 @@ public class EditingPOIActivity implements DialogProvider { @Override public void onClick(View v) { - ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://wiki.openstreetmap.org/wiki/Map_Features"))); + ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features"))); } }); linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java index fa199e2f23..6314510e36 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java @@ -44,9 +44,6 @@ import android.view.View; import android.widget.Toast; public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { - -// private final static String SITE_API = "http://api06.dev.openstreetmap.org/"; - private final static String SITE_API = "http://api.openstreetmap.org/"; //$NON-NLS-1$ private static final long NO_CHANGESET_ID = -1; @@ -73,7 +70,25 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { return entityInfo; } - private final static String URL_TO_UPLOAD_GPX = " http://api.openstreetmap.org/api/0.6/gpx/create"; + private static String getSiteApi() + { + final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; + + String RETURN_API; + + if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { + RETURN_API = "https://api.openstreetmap.org/"; + } + else { + RETURN_API = "http://api.openstreetmap.org/"; + } + +// RETURN_API = "http://api06.dev.openstreetmap.org/"; + + return RETURN_API; + } + + private final static String URL_TO_UPLOAD_GPX = getSiteApi() + "api/0.6/gpx/create"; public String uploadGPXFile(String tagstring, String description, String visibility, File f) { String url = URL_TO_UPLOAD_GPX; @@ -178,7 +193,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { } catch (IOException e) { log.error("Unhandled exception", e); //$NON-NLS-1$ } - String response = sendRequest(SITE_API + "api/0.6/changeset/create/", "PUT", writer.getBuffer().toString(), ctx.getString(R.string.opening_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ + String response = sendRequest(getSiteApi() + "api/0.6/changeset/create/", "PUT", writer.getBuffer().toString(), ctx.getString(R.string.opening_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ if (response != null && response.length() > 0) { id = Long.parseLong(response); } @@ -256,7 +271,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { } catch (IOException e) { log.error("Unhandled exception", e); //$NON-NLS-1$ } - String res = sendRequest(SITE_API+"api/0.6/changeset/"+changeSetId + "/upload", "POST", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String res = sendRequest(getSiteApi() + "api/0.6/changeset/"+changeSetId + "/upload", "POST", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ writer.getBuffer().toString(), ctx.getString(R.string.commiting_node), true); log.debug(res+""); //$NON-NLS-1$ if (res != null) { @@ -286,7 +301,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { @Override public void closeChangeSet() { if (changeSetId != NO_CHANGESET_ID) { - String response = sendRequest(SITE_API+"api/0.6/changeset/"+changeSetId+"/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + String response = sendRequest(getSiteApi() + "api/0.6/changeset/"+changeSetId+"/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ log.info("Response : " + response); //$NON-NLS-1$ changeSetId = NO_CHANGESET_ID; } @@ -296,7 +311,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { public EntityInfo loadNode(Node n) { long nodeId = n.getId(); // >> 1; try { - String res = sendRequest(SITE_API + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$ + String res = sendRequest(getSiteApi() + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$ if(res != null){ OsmBaseStorage st = new OsmBaseStorage(); st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$ @@ -330,7 +345,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { } long nodeId = n.getId() >> 1; try { - String res = sendRequest(SITE_API+"api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$ + String res = sendRequest(getSiteApi() + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$ if(res != null){ OsmBaseStorage st = new OsmBaseStorage(); st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index e05e9290c5..9025983ed0 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -235,9 +235,20 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider protected List loadingBugs(double topLatitude, double leftLongitude, double bottomLatitude,double rightLongitude){ + final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; + + String SITE_API; + + if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { + SITE_API = "https://api.openstreetmap.org/"; + } + else { + SITE_API = "http://api.openstreetmap.org/"; + } + List bugs = new ArrayList(); StringBuilder b = new StringBuilder(); - b.append("http://api.openstreetmap.org/api/0.6/notes?bbox="); //$NON-NLS-1$ + b.append(SITE_API + "api/0.6/notes?bbox="); //$NON-NLS-1$ b.append(leftLongitude); //$NON-NLS-1$ b.append(",").append(bottomLatitude); //$NON-NLS-1$ b.append(",").append(rightLongitude); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java index bfd34b9b58..3d475e3639 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java @@ -21,8 +21,22 @@ import org.apache.commons.logging.Log; public class OsmBugsRemoteUtil implements OsmBugsUtil { private static final Log log = PlatformUtil.getLog(OsmBugsRemoteUtil.class); - - private final static String SITE_API = "http://api.openstreetmap.org/api/0.6/notes"; //$NON-NLS-1$ + + static String getNotesApi() + { + final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; + + String RETURN_API; + + if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { + RETURN_API = "https://api.openstreetmap.org/api/0.6/notes"; + } + else { + RETURN_API = "http://api.openstreetmap.org/api/0.6/notes"; + } + + return RETURN_API; + } private OsmandApplication app; private OsmandSettings settings; @@ -35,7 +49,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil { @Override public String createNewBug(double latitude, double longitude, String text){ StringBuilder b = new StringBuilder(); - b.append(SITE_API).append("?"); //$NON-NLS-1$ + b.append(getNotesApi()).append("?"); //$NON-NLS-1$ b.append("lat=").append(latitude); //$NON-NLS-1$ b.append("&lon=").append(longitude); //$NON-NLS-1$ b.append("&text=").append(URLEncoder.encode(text)); //$NON-NLS-1$ @@ -45,7 +59,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil { @Override public String addingComment(long id, String text){ StringBuilder b = new StringBuilder(); - b.append(SITE_API).append("/"); + b.append(getNotesApi()).append("/"); b.append(id); //$NON-NLS-1$ b.append("/comment?text=").append(URLEncoder.encode(text)); //$NON-NLS-1$ return editingPOI(b.toString(), "POST", "adding comment"); //$NON-NLS-1$ @@ -54,7 +68,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil { @Override public String closingBug(long id, String text){ StringBuilder b = new StringBuilder(); - b.append(SITE_API).append("/"); + b.append(getNotesApi()).append("/"); b.append(id); //$NON-NLS-1$ b.append("/close?text=").append(URLEncoder.encode(text)); //$NON-NLS-1$ return editingPOI(b.toString(), "POST", "close bug") ; //$NON-NLS-1$