From b0b22942d9205aae2fafe031e77c4db254d21a39 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 18 Jul 2017 16:37:03 +0300 Subject: [PATCH 1/6] Add time for logging --- .../plus/monitoring/LiveMonitoringHelper.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java index f2f09745ed..c3798b2c18 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java @@ -6,8 +6,12 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; +import java.text.DateFormat; import java.text.MessageFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; import javax.net.ssl.HostnameVerifier; @@ -112,6 +116,14 @@ public class LiveMonitoringHelper { } public void sendData(LiveMonitoringData data) { + Calendar c = Calendar.getInstance(); + int hours = c.get(Calendar.HOUR); + int minutes = c.get(Calendar.MINUTE); + int seconds = c.get(Calendar.SECOND); + Date date = new Date(data.time); + DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); + String dateFormatted = formatter.format(date); + log.info("Time at first: " + dateFormatted + " Current time at first: " + hours + ":" + minutes + ":" + seconds); String st = settings.LIVE_MONITORING_URL.get(); List prm = new ArrayList(); int maxLen = 0; @@ -191,6 +203,13 @@ public class LiveMonitoringHelper { is.close(); } log.info("Monitor response (" + urlConnection.getHeaderField("Content-Type") + "): " + responseBody.toString()); + c = Calendar.getInstance(); + hours = c.get(Calendar.HOUR); + minutes = c.get(Calendar.MINUTE); + seconds = c.get(Calendar.SECOND); + date = new Date(data.time); + dateFormatted = formatter.format(date); + log.info("Time after response: " + dateFormatted + " Current time after response: " + hours + ":" + minutes + ":" + seconds); } urlConnection.disconnect(); From 67c8fbb549fce4c8652392b64efd8d3a9d614f48 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 20 Jul 2017 16:18:54 +0300 Subject: [PATCH 2/6] Switch to asynctask with queue --- .../plus/monitoring/LiveMonitoringHelper.java | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java index c3798b2c18..db63549917 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java @@ -6,13 +6,10 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; -import java.text.DateFormat; import java.text.MessageFormat; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; @@ -37,17 +34,20 @@ public class LiveMonitoringHelper { private OsmandSettings settings; private long lastTimeUpdated; private LatLon lastPoint; - private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class); + private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class); + private ConcurrentLinkedQueue queue; + private boolean started = false; public LiveMonitoringHelper(Context ctx){ this.ctx = ctx; settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings(); + queue = new ConcurrentLinkedQueue<>(); } public boolean isLiveMonitoringEnabled(){ return settings.LIVE_MONITORING.get() && (settings.SAVE_TRACK_TO_GPX.get() || settings.SAVE_GLOBAL_TRACK_TO_GPX.get()); } - + public void updateLocation(net.osmand.Location location) { boolean record = false; long locationTime = System.currentTimeMillis(); @@ -71,10 +71,18 @@ public class LiveMonitoringHelper { record = false; } } + if (isLiveMonitoringEnabled()) { + if (!started) { + new LiveSender().execute(queue); + started = true; + } + } else { + started = false; + } if(record) { LiveMonitoringData data = new LiveMonitoringData((float)location.getLatitude(), (float)location.getLongitude(), (float)location.getAltitude(), location.getSpeed(), location.getAccuracy(), location.getBearing(), locationTime); - new LiveSender().execute(data); + queue.add(data); lastPoint = new LatLon(location.getLatitude(), location.getLongitude()); lastTimeUpdated = locationTime; } @@ -103,27 +111,23 @@ public class LiveMonitoringHelper { } - private class LiveSender extends AsyncTask { + private class LiveSender extends AsyncTask, Void, Void> { @Override - protected Void doInBackground(LiveMonitoringData... params) { - for(LiveMonitoringData d : params){ - sendData(d); + protected Void doInBackground(ConcurrentLinkedQueue... concurrentLinkedQueues) { + while (isLiveMonitoringEnabled()) { + for (ConcurrentLinkedQueue queue : concurrentLinkedQueues) { + if (!queue.isEmpty()) { + LiveMonitoringData data = (LiveMonitoringData) queue.poll(); + sendData(data); + } + } } return null; } - } public void sendData(LiveMonitoringData data) { - Calendar c = Calendar.getInstance(); - int hours = c.get(Calendar.HOUR); - int minutes = c.get(Calendar.MINUTE); - int seconds = c.get(Calendar.SECOND); - Date date = new Date(data.time); - DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); - String dateFormatted = formatter.format(date); - log.info("Time at first: " + dateFormatted + " Current time at first: " + hours + ":" + minutes + ":" + seconds); String st = settings.LIVE_MONITORING_URL.get(); List prm = new ArrayList(); int maxLen = 0; @@ -203,13 +207,6 @@ public class LiveMonitoringHelper { is.close(); } log.info("Monitor response (" + urlConnection.getHeaderField("Content-Type") + "): " + responseBody.toString()); - c = Calendar.getInstance(); - hours = c.get(Calendar.HOUR); - minutes = c.get(Calendar.MINUTE); - seconds = c.get(Calendar.SECOND); - date = new Date(data.time); - dateFormatted = formatter.format(date); - log.info("Time after response: " + dateFormatted + " Current time after response: " + hours + ":" + minutes + ":" + seconds); } urlConnection.disconnect(); From 7fad69288bd80d811f461150b48197cd68ba4252 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 20 Jul 2017 17:16:34 +0300 Subject: [PATCH 3/6] Add settings for maximum interval to send --- OsmAnd/res/values/strings.xml | 2 ++ OsmAnd/src/net/osmand/plus/OsmandSettings.java | 3 +++ .../src/net/osmand/plus/monitoring/LiveMonitoringHelper.java | 4 +++- .../net/osmand/plus/monitoring/OsmandMonitoringPlugin.java | 1 + .../osmand/plus/monitoring/SettingsMonitoringActivity.java | 3 +++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ece08960ca..a038f3c946 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1936,6 +1936,8 @@ Online tracking interval Specify the web address with parameter syntax: lat={0}, lon={1}, timestamp={2}, hdop={3}, altitude={4}, speed={5}, bearing={6} Online tracking web address + Maximum online tracking interval to send + Specify maximum online tracking interval to send Log track using GPX widget or via \'Trip recording\' settings. Show current track This free OsmAnd version is limited to %1$s downloads and does not support offline Wikipedia articles. diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 239d39b89d..9dd1a5d01a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1121,6 +1121,9 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public final CommonPreference LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeGlobal(); + // this value string is synchronized with settings_pref.xml preference name + public final CommonPreference LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 300000).makeGlobal(); + // this value string is synchronized with settings_pref.xml preference name public final CommonPreference LIVE_MONITORING_URL = new StringPreference("live_monitoring_url", "http://example.com?lat={0}&lon={1}×tamp={2}&hdop={3}&altitude={4}&speed={5}").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java index db63549917..55f6c35de4 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java @@ -119,7 +119,9 @@ public class LiveMonitoringHelper { for (ConcurrentLinkedQueue queue : concurrentLinkedQueues) { if (!queue.isEmpty()) { LiveMonitoringData data = (LiveMonitoringData) queue.poll(); - sendData(data); + if (!(System.currentTimeMillis() - data.time > settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND.get())) { + sendData(data); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 32b1ef0f89..29c7f00bb2 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -131,6 +131,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { public static final int[] SECONDS = new int[] {0, 1, 2, 3, 5, 10, 15, 30, 60, 90}; public static final int[] MINUTES = new int[] {2, 3, 5}; + public static final int[] MAX_INTERVAL_TO_SEND_MINUTES = new int[] {5, 10, 15}; @Override diff --git a/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java b/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java index 30f767f1c4..2ea999fcb5 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java @@ -25,6 +25,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity { public static final int[] BG_MINUTES = new int[]{2, 3, 5, 10, 15, 30, 60, 90}; private static final int[] SECONDS = OsmandMonitoringPlugin.SECONDS; private static final int[] MINUTES = OsmandMonitoringPlugin.MINUTES; + private static final int[] MAX_INTERVAL_TO_SEND_MINUTES = OsmandMonitoringPlugin.MAX_INTERVAL_TO_SEND_MINUTES; public SettingsMonitoringActivity() { super(true); @@ -136,6 +137,8 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity { cat.addPreference(liveMonitoring); cat.addPreference(createTimeListPreference(settings.LIVE_MONITORING_INTERVAL, SECONDS, MINUTES, 1000, R.string.live_monitoring_interval, R.string.live_monitoring_interval_descr)); + cat.addPreference(createTimeListPreference(settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND, null, + MAX_INTERVAL_TO_SEND_MINUTES, 1000, R.string.live_monitoring_max_interval_to_send, R.string.live_monitoring_max_interval_to_send_desrc)); } private void createNotificationSection(PreferenceScreen grp) { From e59c4d6600d2000c685e444e591aafdbced13cb2 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 21 Jul 2017 10:07:21 +0300 Subject: [PATCH 4/6] Make 15 min as default value for max interval to send --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 2aa1d11e26..3c92a9fdd3 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1124,7 +1124,7 @@ public class OsmandSettings { public final CommonPreference LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeGlobal(); // this value string is synchronized with settings_pref.xml preference name - public final CommonPreference LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 300000).makeGlobal(); + public final CommonPreference LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeGlobal(); // this value string is synchronized with settings_pref.xml preference name public final CommonPreference LIVE_MONITORING_URL = new StringPreference("live_monitoring_url", From a63575b54c910f01af21d5717c580ac700f9f31b Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 21 Jul 2017 09:59:37 +0200 Subject: [PATCH 5/6] Add more values --- .../net/osmand/plus/monitoring/OsmandMonitoringPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 29c7f00bb2..9b09af2ad0 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -131,7 +131,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { public static final int[] SECONDS = new int[] {0, 1, 2, 3, 5, 10, 15, 30, 60, 90}; public static final int[] MINUTES = new int[] {2, 3, 5}; - public static final int[] MAX_INTERVAL_TO_SEND_MINUTES = new int[] {5, 10, 15}; + public static final int[] MAX_INTERVAL_TO_SEND_MINUTES = new int[] {1, 2, 5, 10, 15, 20, 30, 60}; @Override @@ -514,4 +514,4 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { return DashTrackFragment.FRAGMENT_DATA; } -} \ No newline at end of file +} From 711cb09213a5bd1136365136fe95f28508a1ac26 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 21 Jul 2017 10:03:21 +0200 Subject: [PATCH 6/6] Update strings.xml --- OsmAnd/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 3ddb7b2509..b8ba789f1a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1936,8 +1936,8 @@ Online tracking interval Specify the web address with parameter syntax: lat={0}, lon={1}, timestamp={2}, hdop={3}, altitude={4}, speed={5}, bearing={6} Online tracking web address - Maximum online tracking interval to send - Specify maximum online tracking interval to send + Time buffer for online tracking + Specify a time buffer to keep locations to send without connection Log track using GPX widget or via \'Trip recording\' settings. Show current track This free OsmAnd version is limited to %1$s downloads and does not support offline Wikipedia articles.