Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexzatsepin <az@mapswithme.com>2016-12-13 18:01:08 +0300
committeralexzatsepin <az@mapswithme.com>2016-12-13 18:16:52 +0300
commit189b170961c033bab0762354159a76a8c7e19f16 (patch)
tree5aa6999b8c8c56c1fed97c841f65165217ec0931 /android
parent7bf549cba13001ffe5416f535d3fd84f89568438 (diff)
[android] Added logging for Platform socket
Diffstat (limited to 'android')
-rw-r--r--android/src/com/mapswithme/maps/location/PlatformSocket.java89
-rw-r--r--android/src/com/mapswithme/util/log/FileLogger.java8
-rw-r--r--android/src/com/mapswithme/util/log/Logger.java3
3 files changed, 70 insertions, 30 deletions
diff --git a/android/src/com/mapswithme/maps/location/PlatformSocket.java b/android/src/com/mapswithme/maps/location/PlatformSocket.java
index 62852e6050..42e2b32d85 100644
--- a/android/src/com/mapswithme/maps/location/PlatformSocket.java
+++ b/android/src/com/mapswithme/maps/location/PlatformSocket.java
@@ -5,9 +5,13 @@ import android.net.SSLCertificateSocketFactory;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.text.TextUtils;
import com.mapswithme.maps.BuildConfig;
+import com.mapswithme.util.StorageUtils;
+import com.mapswithme.util.Utils;
import com.mapswithme.util.log.DebugLogger;
+import com.mapswithme.util.log.FileLogger;
import com.mapswithme.util.log.Logger;
import javax.net.SocketFactory;
@@ -31,8 +35,10 @@ import java.net.SocketTimeoutException;
*/
class PlatformSocket
{
- private final static Logger sLogger = new DebugLogger(PlatformSocket.class.getSimpleName());
private final static int DEFAULT_TIMEOUT = 30 * 1000;
+ @NonNull
+ private final static Logger LOGGER = createLogger();
+ private static volatile long sSslConnectionCounter;
@Nullable
private Socket mSocket;
@Nullable
@@ -40,17 +46,39 @@ class PlatformSocket
private int mPort;
private int mTimeout = DEFAULT_TIMEOUT;
+ PlatformSocket()
+ {
+ sSslConnectionCounter = 0;
+ LOGGER.d("***********************************************************************************");
+ LOGGER.d("Platform socket is created by core, ssl connection counter is discarded.");
+ LOGGER.d("Installation ID: ", Utils.getInstallationId());
+ LOGGER.d("App version: ", BuildConfig.VERSION_NAME);
+ LOGGER.d("App version code: ", BuildConfig.VERSION_CODE);
+ }
+
+ @NonNull
+ private static Logger createLogger()
+ {
+ if (BuildConfig.BUILD_TYPE.equals("beta"))
+ {
+ String externalDir = StorageUtils.getExternalFilesDir();
+ if (!TextUtils.isEmpty(externalDir))
+ return new FileLogger(externalDir + "/socket.log");
+ }
+ return new DebugLogger(PlatformSocket.class.getSimpleName());
+ }
+
public boolean open(@NonNull String host, int port)
{
if (mSocket != null)
{
- sLogger.e("Socket is already opened. Seems that it wasn't closed.");
+ LOGGER.e("Socket is already opened. Seems that it wasn't closed.");
return false;
}
if (!isPortAllowed(port))
{
- sLogger.e("A wrong port number, it must be within (0-65535) range", port);
+ LOGGER.e("A wrong port number, it must be within (0-65535) range", port);
return false;
}
@@ -75,28 +103,33 @@ class PlatformSocket
@Nullable
private static Socket createSocket(@NonNull String host, int port, boolean ssl)
{
+ Socket socket = null;
if (ssl)
{
try
{
SocketFactory sf = getSocketFactory();
- return sf.createSocket(host, port);
+ socket = sf.createSocket(host, port);
+ sSslConnectionCounter++;
+ LOGGER.d("###############################################################################");
+ LOGGER.d(sSslConnectionCounter + " ssl connection is established.");
} catch (IOException e)
{
- sLogger.e("Failed to create the ssl socket, mHost = ", host, " mPort = ", port, e);
+ LOGGER.e(e, "Failed to create the ssl socket, mHost = " + host + " mPort = " + port);
}
} else
{
try
{
- return new Socket(host, port);
+ socket = new Socket(host, port);
+ LOGGER.d("Ssl socket is created and ssl handshake is passed successfully");
} catch (IOException e)
{
- sLogger.e("Failed to create the socket, mHost = ", host, " mPort = ", port, e);
+ LOGGER.e(e, "Failed to create the socket, mHost = " + host + " mPort = " + port);
}
}
- return null;
+ return socket;
}
@@ -117,17 +150,17 @@ class PlatformSocket
{
if (mSocket == null)
{
- sLogger.d("Socket is already closed or it wasn't opened yet");
+ LOGGER.d("Socket is already closed or it wasn't opened yet\n");
return;
}
try
{
mSocket.close();
- sLogger.d("Socket has been closed: ", this);
+ LOGGER.d("Socket has been closed: ", this + "\n");
} catch (IOException e)
{
- sLogger.e("Failed to close socket: ", this, e);
+ LOGGER.e(e, "Failed to close socket: ", this + "\n");
} finally
{
mSocket = null;
@@ -139,7 +172,7 @@ class PlatformSocket
if (!checkSocketAndArguments(data, count))
return false;
- sLogger.d("Reading has started, data.length = " + data.length, ", count = " + count);
+ LOGGER.d("Reading method is started, data.length = " + data.length + ", count = " + count);
long startTime = SystemClock.elapsedRealtime();
int readBytes = 0;
try
@@ -152,38 +185,38 @@ class PlatformSocket
{
try
{
- sLogger.d("Attempting to read ", count, " bytes from offset = ", readBytes);
+ LOGGER.d("Attempting to read " + count + " bytes from offset = " + readBytes);
int read = in.read(data, readBytes, count - readBytes);
if (read == -1)
{
- sLogger.d("All data have been read from the stream, read bytes count = ", readBytes);
+ LOGGER.d("All data is read from the stream, read bytes count = " + readBytes + "\n");
break;
}
if (read == 0)
{
- sLogger.e("0 bytes have been obtained. It's considered as error");
+ LOGGER.e("0 bytes are obtained. It's considered as error\n");
break;
}
- sLogger.d("Read bytes count = ", read);
+ LOGGER.d("Read bytes count = " + read + "\n");
readBytes += read;
} catch (SocketTimeoutException e)
{
long readingTime = SystemClock.elapsedRealtime() - startTime;
- sLogger.e(e, "Socked timeout has occurred after ", readingTime, " (ms) ");
+ LOGGER.e(e, "Socked timeout has occurred after " + readingTime + " (ms)\n ");
if (readingTime > mTimeout)
{
- sLogger.e("Socket wrapper timeout has occurred, requested count = ",
- count - readBytes, ", " + "readBytes = ", readBytes);
+ LOGGER.e("Socket wrapper timeout has occurred, requested count = " +
+ (count - readBytes) + ", readBytes = " + readBytes + "\n");
break;
}
}
}
} catch (IOException e)
{
- sLogger.e(e, "Failed to read data from socket: ", this);
+ LOGGER.e(e, "Failed to read data from socket: ", this, "\n");
}
return count == readBytes;
@@ -194,7 +227,7 @@ class PlatformSocket
if (!checkSocketAndArguments(data, count))
return false;
- sLogger.d("Writing method has started, data.length = " + data.length, ", count = " + count);
+ LOGGER.d("Writing method is started, data.length = " + data.length + ", count = " + count);
long startTime = SystemClock.elapsedRealtime();
try
{
@@ -203,15 +236,15 @@ class PlatformSocket
OutputStream out = mSocket.getOutputStream();
out.write(data, 0, count);
- sLogger.d(count + " bytes have been written");
+ LOGGER.d(count + " bytes are written\n");
return true;
} catch (SocketTimeoutException e)
{
long writingTime = SystemClock.elapsedRealtime() - startTime;
- sLogger.e(e, "Socked timeout has occurred after ", writingTime, " (ms) ");
+ LOGGER.e(e, "Socked timeout has occurred after " + writingTime + " (ms)\n");
} catch (IOException e)
{
- sLogger.e(e, "Failed to write data to socket: ", this);
+ LOGGER.e(e, "Failed to write data to socket: " + this + "\n");
}
return false;
@@ -221,13 +254,13 @@ class PlatformSocket
{
if (mSocket == null)
{
- sLogger.e("Socket must be opened before reading/writing");
+ LOGGER.e("Socket must be opened before reading/writing\n");
return false;
}
if (data.length < 0 || count < 0 || count > data.length)
{
- sLogger.e("Illegal arguments, data.length = ", data.length, ", count = " + count);
+ LOGGER.e("Illegal arguments, data.length = " + data.length + ", count = " + count + "\n");
return false;
}
@@ -237,7 +270,7 @@ class PlatformSocket
public void setTimeout(int millis)
{
mTimeout = millis;
- sLogger.d("Setting the socket wrapper timeout = ", millis, " ms");
+ LOGGER.d("Setting the socket wrapper timeout = " + millis + " ms\n");
}
private void setReadSocketTimeout(@NonNull Socket socket, int millis)
@@ -247,7 +280,7 @@ class PlatformSocket
socket.setSoTimeout(millis);
} catch (SocketException e)
{
- sLogger.e("Failed to set system socket timeout: ", millis, "ms, ", this, e);
+ LOGGER.e(e, "Failed to set system socket timeout: " + millis + "ms, " + this + "\n");
}
}
diff --git a/android/src/com/mapswithme/util/log/FileLogger.java b/android/src/com/mapswithme/util/log/FileLogger.java
index c274d63e0b..c4bc1042a6 100644
--- a/android/src/com/mapswithme/util/log/FileLogger.java
+++ b/android/src/com/mapswithme/util/log/FileLogger.java
@@ -1,5 +1,7 @@
package com.mapswithme.util.log;
+import android.support.annotation.NonNull;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -62,8 +64,12 @@ public class FileLogger extends Logger
}
@Override
- public void e(Throwable throwable, String message, Object... args)
+ public void e(@NonNull Throwable throwable, String message, Object... args)
{
+ e(throwable.getMessage());
+ Throwable cause = throwable.getCause();
+ if (cause != null)
+ e(cause.getMessage());
e(message, args);
}
}
diff --git a/android/src/com/mapswithme/util/log/Logger.java b/android/src/com/mapswithme/util/log/Logger.java
index d07dfa88e6..fb9ee29e02 100644
--- a/android/src/com/mapswithme/util/log/Logger.java
+++ b/android/src/com/mapswithme/util/log/Logger.java
@@ -1,5 +1,6 @@
package com.mapswithme.util.log;
+import android.support.annotation.NonNull;
import android.text.TextUtils;
public abstract class Logger
@@ -26,5 +27,5 @@ public abstract class Logger
public abstract void e(String message, Object... args);
- public abstract void e(Throwable throwable, String message, Object... args);
+ public abstract void e(@NonNull Throwable throwable, String message, Object... args);
}