From d486768d6b0664d9032605897c8f1847ef4e3a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 20 Apr 2015 18:20:05 +0200 Subject: Remove textual status. I had a difficult moment trying to detect if the LogWindow had already been shown after an error. Finally, I implemented a LogWindowWrapper which contains a field for the reason it was shown, so that we can check if the previous error is the same than the current one leading to the avoidance of the second LogWindow. For this to work, we need to reset that reason each time we trigger a new vpn state (i.e. each time the user taps on the vpn icon). --- .../main/java/se/leap/bitmaskclient/eip/EipStatus.java | 15 +++++++++++---- .../java/se/leap/bitmaskclient/eip/VoidVpnService.java | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/eip') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java index b7f95277..356cf6b0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -137,18 +137,25 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { } public boolean errorInLast(int lines, Context context) { - boolean result = false; + return !lastError(lines, context).isEmpty(); + } + + public String lastError(int lines, Context context) { + String error = ""; + String[] error_keywords = {"error", "ERROR", "fatal", "FATAL"}; VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); String message = ""; for (int i = 1; i <= lines && log.length > i; i++) { - message = log[log.length - i].getString(context); + VpnStatus.LogItem log_item = log[log.length - i]; + message = log_item.getString(context); for (int j = 0; j < error_keywords.length; j++) if (message.contains(error_keywords[j])) - result = true; + error = message; } - return result; + + return error; } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index dac92fe2..cbf0fed2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -50,6 +50,10 @@ public class VoidVpnService extends VpnService { closeFd(); } + public static boolean isRunning() throws NullPointerException { + return thread.isAlive() && fd != null; + } + private static void closeFd() { try { if (fd != null) -- cgit v1.2.3