summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2019-08-13 13:13:47 +0200
committerArne Schwabe <arne@rfc2549.org>2019-08-13 13:13:47 +0200
commit590e04eb8d87ee20c167cbbafef3f002feb3e5f9 (patch)
tree38b14b7e7c6b6708ba8e72285a2a279f220a7b93 /main
parent01af60a3d85c64ba4a800fe4ac4da6bf0dc421ce (diff)
Implement proper logging to Logcat
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java13
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/StatusListener.java84
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java6
3 files changed, 64 insertions, 39 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java b/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java
index 6be24995..ecf27ef5 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java
@@ -42,15 +42,14 @@ public class NativeUtils {
System.loadLibrary("opvpnutil");
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN)
System.loadLibrary("jbcrypto");
- }
- if (!BuildConfig.FLAVOR.equals("skeleton")) {
- System.loadLibrary("osslspeedtest");
+
+ if (!BuildConfig.FLAVOR.equals("skeleton")) {
+ System.loadLibrary("osslspeedtest");
+ }
}
}
public static boolean isRoboUnitTest() {
- return "robolectric".equals(Build.FINGERPRINT);
- }
-
+ return "robolectric".equals(Build.FINGERPRINT); }
-}
+} \ No newline at end of file
diff --git a/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java b/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
index 5d0b7037..bb8572c9 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
@@ -12,6 +12,9 @@ import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
+import android.util.Log;
+import de.blinkt.openvpn.BuildConfig;
+import de.blinkt.openvpn.core.VpnStatus.LogLevel;
import java.io.DataInputStream;
import java.io.File;
@@ -21,8 +24,31 @@ import java.io.IOException;
* Created by arne on 09.11.16.
*/
-public class StatusListener {
+public class StatusListener implements VpnStatus.LogListener {
private File mCacheDir;
+ private Context mContext;
+ private IStatusCallbacks mCallback = new IStatusCallbacks.Stub() {
+ @Override
+ public void newLogItem(LogItem item) throws RemoteException {
+ VpnStatus.newLogItem(item);
+ }
+
+ @Override
+ public void updateStateString(String state, String msg, int resid, ConnectionStatus
+ level) throws RemoteException {
+ VpnStatus.updateStateString(state, msg, resid, level);
+ }
+
+ @Override
+ public void updateByteCount(long inBytes, long outBytes) throws RemoteException {
+ VpnStatus.updateByteCount(inBytes, outBytes);
+ }
+
+ @Override
+ public void connectedVPN(String uuid) throws RemoteException {
+ VpnStatus.setConnectedVPNProfile(uuid);
+ }
+ };
private ServiceConnection mConnection = new ServiceConnection() {
@@ -51,9 +77,15 @@ public class StatusListener {
fd.close();
-
} else {
VpnStatus.initLogCache(mCacheDir);
+ /* Set up logging to Logcat with a context) */
+
+ if (BuildConfig.DEBUG || BuildConfig.FLAVOR.equals("skeleton")) {
+ VpnStatus.addLogListener(StatusListener.this);
+ }
+
+
}
} catch (RemoteException | IOException e) {
@@ -64,7 +96,7 @@ public class StatusListener {
@Override
public void onServiceDisconnected(ComponentName arg0) {
-
+ VpnStatus.removeLogListener(StatusListener.this);
}
};
@@ -76,34 +108,30 @@ public class StatusListener {
mCacheDir = c.getCacheDir();
c.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
-
+ this.mContext = c;
}
-
- private IStatusCallbacks mCallback = new IStatusCallbacks.Stub()
-
- {
- @Override
- public void newLogItem(LogItem item) throws RemoteException {
- VpnStatus.newLogItem(item);
- }
-
- @Override
- public void updateStateString(String state, String msg, int resid, ConnectionStatus
- level) throws RemoteException {
- VpnStatus.updateStateString(state, msg, resid, level);
+ @Override
+ public void newLog(LogItem logItem) {
+ switch (logItem.getLogLevel()) {
+ case INFO:
+ Log.i("OpenVPN", logItem.getString(mContext));
+ break;
+ case DEBUG:
+ Log.d("OpenVPN", logItem.getString(mContext));
+ break;
+ case ERROR:
+ Log.e("OpenVPN", logItem.getString(mContext));
+ break;
+ case VERBOSE:
+ Log.v("OpenVPN", logItem.getString(mContext));
+ break;
+ case WARNING:
+ default:
+ Log.w("OpenVPN", logItem.getString(mContext));
+ break;
}
- @Override
- public void updateByteCount(long inBytes, long outBytes) throws RemoteException {
- VpnStatus.updateByteCount(inBytes, outBytes);
- }
-
- @Override
- public void connectedVPN(String uuid) throws RemoteException {
- VpnStatus.setConnectedVPNProfile(uuid);
- }
- };
-
+ }
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
index b87c8864..c8e98b6d 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
@@ -19,6 +19,8 @@ import java.util.Queue;
import java.util.Vector;
import java.util.concurrent.ConcurrentLinkedQueue;
+import android.util.Log;
+import de.blinkt.openvpn.BuildConfig;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
@@ -429,10 +431,6 @@ public class VpnStatus {
mLogFileHandler.sendMessage(mLogFileHandler.obtainMessage(LogFileHandler.TRIM_LOG_FILE));
}
- //if (BuildConfig.DEBUG && !cachedLine && !BuildConfig.FLAVOR.equals("test"))
- // Log.d("OpenVPN", logItem.getString(null));
-
-
for (LogListener ll : logListener) {
ll.newLog(logItem);
}