Enforce usage of https client. And some formatting.

This commit is contained in:
GaidamakUA 2016-03-12 17:39:05 +02:00
parent 47d4aa8dd9
commit 508f2893d4
4 changed files with 14 additions and 26 deletions

View file

@ -587,8 +587,6 @@
<string name="use_opengl_render_descr">Use hardware accelerated OpenGL rendering (may not work on some devices)</string>
<string name="error_avoid_specific_road">No bypass found</string>
<string name="home_button">Home</string>
<string name="osmo_use_https_descr">Use secure connection to server</string>
<string name="osmo_use_https">Use HTTPS</string>
<string name="map_update">Updates available for %1$s maps</string>
<string name="search_for">Search for</string>
<string name="coordinates">Coordinates</string>

View file

@ -1001,9 +1001,6 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> OSMO_AUTO_CONNECT = new BooleanPreference("osmo_automatically_connect", false).makeGlobal();
public final CommonPreference<Boolean> 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<Long> OSMO_LAST_PING = new LongPreference("osmo_last_ping", 0).makeGlobal().cache();
public final OsmandPreference<Boolean> OSMO_SEND_LOCATIONS_STATE = new BooleanPreference("osmo_send_locations", false).cache().makeGlobal();

View file

@ -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

View file

@ -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());