From 6052665277412bb874d8b3aa54e64965d7c05698 Mon Sep 17 00:00:00 2001 From: alexzatsepin Date: Wed, 2 Nov 2016 14:31:37 +0300 Subject: [PATCH] [android] Fixed the reading statistics problem while sending the gps coords through socket [android] Removed the redundant PlatformSocket interface for JNI performance reasons --- .../mapswithme/maps/location/PlatformSocket.java | 16 ---------------- .../mapswithme/maps/location/SocketWrapper.java | 11 ++++------- .../mapswithme/util/statistics/Statistics.java | 1 + tracking/reporter.cpp | 10 ---------- 4 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 android/src/com/mapswithme/maps/location/PlatformSocket.java diff --git a/android/src/com/mapswithme/maps/location/PlatformSocket.java b/android/src/com/mapswithme/maps/location/PlatformSocket.java deleted file mode 100644 index ffcee739a0..0000000000 --- a/android/src/com/mapswithme/maps/location/PlatformSocket.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mapswithme.maps.location; - -import android.support.annotation.NonNull; - -interface PlatformSocket -{ - boolean open(@NonNull String host, int port); - - void close(); - - void setTimeout(int millis); - - boolean read(@NonNull byte[] data, int count); - - boolean write(@NonNull byte[] data, int count); -} diff --git a/android/src/com/mapswithme/maps/location/SocketWrapper.java b/android/src/com/mapswithme/maps/location/SocketWrapper.java index 3d057a6c6f..fb1acc1236 100644 --- a/android/src/com/mapswithme/maps/location/SocketWrapper.java +++ b/android/src/com/mapswithme/maps/location/SocketWrapper.java @@ -19,7 +19,7 @@ import java.net.SocketException; import java.net.SocketTimeoutException; /** - * Implements {@link PlatformSocket} interface that will be used by the core for + * Implements interface that will be used by the core for * sending/receiving the raw data trough platform socket interface. *

* The instance of this class is supposed to be created in JNI layer @@ -28,7 +28,7 @@ import java.net.SocketTimeoutException; *

* All public methods are blocking and shouldn't be called from the main thread. */ -class SocketWrapper implements PlatformSocket +class SocketWrapper { private final static Logger sLogger = new DebugLogger(SocketWrapper.class.getSimpleName()); private final static int DEFAULT_TIMEOUT = 30 * 1000; @@ -39,7 +39,6 @@ class SocketWrapper implements PlatformSocket private int mPort; private int mTimeout = DEFAULT_TIMEOUT; - @Override public boolean open(@NonNull String host, int port) { if (mSocket != null) @@ -113,7 +112,6 @@ class SocketWrapper implements PlatformSocket return SSLSocketFactory.getDefault(); } - @Override public void close() { if (mSocket == null) @@ -125,6 +123,7 @@ class SocketWrapper implements PlatformSocket try { mSocket.close(); + sLogger.d("Socket has been closed: ", this); } catch (IOException e) { sLogger.e("Failed to close socket: ", this, e); @@ -134,7 +133,6 @@ class SocketWrapper implements PlatformSocket } } - @Override public boolean read(@NonNull byte[] data, int count) { if (!checkSocketAndArguments(data, count)) @@ -190,7 +188,6 @@ class SocketWrapper implements PlatformSocket return count == readBytes; } - @Override public boolean write(@NonNull byte[] data, int count) { if (!checkSocketAndArguments(data, count)) @@ -205,6 +202,7 @@ class SocketWrapper implements PlatformSocket OutputStream out = mSocket.getOutputStream(); out.write(data, 0, count); + sLogger.d(count + " bytes have been written"); return true; } catch (SocketTimeoutException e) { @@ -235,7 +233,6 @@ class SocketWrapper implements PlatformSocket return true; } - @Override public void setTimeout(int millis) { mTimeout = millis; diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java index 52958379e7..5e282b0dc7 100644 --- a/android/src/com/mapswithme/util/statistics/Statistics.java +++ b/android/src/com/mapswithme/util/statistics/Statistics.java @@ -230,6 +230,7 @@ public enum Statistics Statistics() { mEnabled = Config.isStatisticsEnabled(); + Config.setStatisticsEnabled(mEnabled); final Context context = MwmApplication.get(); // At the moment we need special handling for Alohalytics to enable/disable logging of events in core C++ code. if (mEnabled) diff --git a/tracking/reporter.cpp b/tracking/reporter.cpp index 35b59c65ae..626b7f4388 100644 --- a/tracking/reporter.cpp +++ b/tracking/reporter.cpp @@ -18,17 +18,7 @@ size_t constexpr kRealTimeBufferSize = 60; namespace tracking { -// static -// Apple and Android applications use different keys for settings.ini. -// Keys saved for existing users, so can' fix it easy, need migration. -// Use this hack until change to special traffic key. -#if defined(OMIM_OS_IPHONE) const char Reporter::kEnableTrackingKey[] = "StatisticsEnabled"; -#elif defined(OMIM_OS_ANDROID) -const char Reporter::kEnableTrackingKey[] = "AllowStat"; -#else -const char Reporter::kEnableTrackingKey[] = "AllowStat"; -#endif // static milliseconds const Reporter::kPushDelayMs = milliseconds(10000);