From 508f2893d4efad29301b880cb00d310edd6a071e Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Sat, 12 Mar 2016 17:39:05 +0200 Subject: [PATCH] Enforce usage of https client. And some formatting. --- OsmAnd/res/values/strings.xml | 2 -- .../src/net/osmand/plus/OsmandSettings.java | 3 --- .../src/net/osmand/plus/osmo/OsMoPlugin.java | 24 +++++++------------ .../plus/osmo/SettingsOsMoActivity.java | 11 ++++----- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ccabbb82dd..ab2249ce00 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -587,8 +587,6 @@ Use hardware accelerated OpenGL rendering (may not work on some devices) No bypass found Home - Use secure connection to server - Use HTTPS Updates available for %1$s maps Search for Coordinates diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 15eaaf7c2a..64c39e07e5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1001,9 +1001,6 @@ public class OsmandSettings { public final OsmandPreference OSMO_AUTO_CONNECT = new BooleanPreference("osmo_automatically_connect", false).makeGlobal(); - public final CommonPreference OSMO_USE_HTTPS = new BooleanPreference("osmo_use_https", - Build.VERSION.SDK_INT < 14/*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ ? false : true).makeGlobal(); - public final OsmandPreference OSMO_LAST_PING = new LongPreference("osmo_last_ping", 0).makeGlobal().cache(); public final OsmandPreference OSMO_SEND_LOCATIONS_STATE = new BooleanPreference("osmo_send_locations", false).cache().makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java index c94683e6a6..9e15a4e823 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java @@ -3,6 +3,7 @@ package net.osmand.plus.osmo; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; +import android.os.Build; import android.view.View; import android.widget.ArrayAdapter; @@ -34,7 +35,6 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -53,7 +53,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { protected Activity groupsActivity; protected OsMoControlDevice deviceControl; - private final static Log log = PlatformUtil.getLog(OsMoPlugin.class); + private final static Log LOG = PlatformUtil.getLog(OsMoPlugin.class); public OsMoPlugin(final OsmandApplication app) { @@ -398,6 +398,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { try { color = Algorithms.parseColor(obj.getString("color")); } catch (RuntimeException e) { + LOG.warn("", e); } } boolean visible = obj.has("visible"); @@ -406,12 +407,10 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { long len = !f.exists() ? -1 : f.length(); boolean sizeEqual = obj.has("size") && obj.getLong("size") == len; boolean modifySupported = f.setLastModified(timestamp - 1); - if (sizeEqual && !modifySupported) { - // false alarm - } else { + if (!sizeEqual || modifySupported) { changed = true; String url = obj.getString("url"); - log.info("Download gpx " + url); + LOG.info("Download gpx " + url); DownloadFileHelper df = new DownloadFileHelper(app); InputStream is = df.getInputStreamToDownload(new URL(url), false); int av = is.available(); @@ -431,10 +430,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { } app.getSelectedGpxHelper().setGpxFileToDisplay(selectGPXFile); } - } catch (JSONException e) { - e.printStackTrace(); - errors += e.getMessage() + "\n"; - } catch (IOException e) { + } catch (JSONException | IOException e) { e.printStackTrace(); errors += e.getMessage() + "\n"; } @@ -443,7 +439,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { } private void redownloadFile(File f, long timestamp, int color, InputStream is) - throws FileNotFoundException, IOException { + throws IOException { FileOutputStream fout = new FileOutputStream(f); byte[] buf = new byte[1024]; int k; @@ -453,7 +449,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { fout.close(); is.close(); if (!f.setLastModified(timestamp)) { - log.error("Timestamp updates are not supported"); + LOG.error("Timestamp updates are not supported"); } } @@ -468,8 +464,6 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { } } - ; - @Override protected void onPostExecute(String result) { if (result.length() > 0) { @@ -512,7 +506,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { } public boolean useHttps() { - return app.getSettings().OSMO_USE_HTTPS.get(); + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java b/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java index 5e7108dda4..6195eb4d19 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java @@ -70,11 +70,6 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { showGroupNotifiations.setSummary(R.string.osmo_show_group_notifications_descr); grp.addPreference(showGroupNotifiations); - CheckBoxPreference useHttps = createCheckBoxPreference(settings.OSMO_USE_HTTPS); - useHttps.setTitle(R.string.osmo_use_https); - useHttps.setSummary(R.string.osmo_use_https_descr); - grp.addPreference(useHttps); - // if (OsmandPlugin.isDevelopment()) { debugPref = new Preference(this); debugPref.setTitle(R.string.osmo_settings_debug); @@ -86,6 +81,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { private void updateDebugPref() { final OsMoPlugin plugin = OsMoPlugin.getEnabledPlugin(OsMoPlugin.class); + assert plugin != null; OsMoService service = plugin.getService(); OsMoTracker tracker = plugin.getTracker(); StringBuilder s = new StringBuilder(); @@ -103,7 +99,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { if(err == null) { err = "..."; } - s.append(getString(R.string.osmo_io_error) + err).append("\n"); + s.append(getString(R.string.osmo_io_error)).append(err).append("\n"); } s.append(getString(R.string.osmo_locations_sent, tracker.getLocationsSent(), @@ -116,6 +112,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { @Override public boolean onPreferenceClick(Preference preference) { final OsMoPlugin plugin = OsMoPlugin.getEnabledPlugin(OsMoPlugin.class); + assert plugin != null; if (preference == debugPref) { updateDebugPref(); AlertDialog.Builder bld = new AlertDialog.Builder(this); @@ -179,6 +176,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { @Override public void onClick(DialogInterface dialog, int which) { final OsMoPlugin plugin = OsMoPlugin.getEnabledPlugin(OsMoPlugin.class); + assert plugin != null; plugin.getService().pushCommand(OsMoService.REGENERATE_CMD); } }); @@ -195,6 +193,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { if (id.equals(settings.OSMO_AUTO_CONNECT.getId())) { if ((Boolean) newValue) { final OsMoPlugin plugin = OsMoPlugin.getEnabledPlugin(OsMoPlugin.class); + assert plugin != null; plugin.getService().connect(false); } // sendLocationsref.setEnabled(settings.OSMO_AUTO_CONNECT.get());