summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-10-04 16:55:14 +0200
committerArne Schwabe <arne@rfc2549.org>2021-10-04 16:55:14 +0200
commitcf093699bdccb3975566f3e157e1c2ed3eb7f951 (patch)
treeb8e8830c5854727658802b0a4e13dc31cb6a1eb6
parent609fd8e2921a6c6a8238b7d469980d801bbcc79b (diff)
Add logging of StrictMode violations to app internal log
Also disable penaltyDeath by default as thjere is some Android internal leak that I am unable to track down.
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java42
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java6
2 files changed, 39 insertions, 9 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
index 6c5e3f10..92bfb61f 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
@@ -14,6 +14,12 @@ import android.graphics.Color;
import android.os.Build;
import android.os.StrictMode;
+import android.os.strictmode.Violation;
+
+import androidx.annotation.RequiresApi;
+
+import java.util.concurrent.Executors;
+
import de.blinkt.openvpn.BuildConfig;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.api.AppRestrictions;
@@ -23,6 +29,9 @@ public class ICSOpenVPNApplication extends Application {
@Override
public void onCreate() {
+ if (BuildConfig.BUILD_TYPE.equals("debug"))
+ enableStrictModes();
+
if("robolectric".equals(Build.FINGERPRINT))
return;
@@ -34,8 +43,7 @@ public class ICSOpenVPNApplication extends Application {
mStatus = new StatusListener();
mStatus.init(getApplicationContext());
- if (BuildConfig.BUILD_TYPE.equals("debug"))
- enableStrictModes();
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AppRestrictions.getInstance(this).checkRestrictions(this);
@@ -43,15 +51,36 @@ public class ICSOpenVPNApplication extends Application {
}
private void enableStrictModes() {
- StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder()
+ StrictMode.ThreadPolicy.Builder tpbuilder = new StrictMode.ThreadPolicy.Builder()
+ .detectAll()
+ .penaltyLog();
+
+
+
+ StrictMode.VmPolicy.Builder vpbuilder = new StrictMode.VmPolicy.Builder()
.detectAll()
- .penaltyLog()
- .penaltyDeath()
- .build();
+ .penaltyLog();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ tpbuilder.penaltyListener(Executors.newSingleThreadExecutor(), this::logViolation);
+ vpbuilder.penaltyListener(Executors.newSingleThreadExecutor(), this::logViolation);
+
+ }
+ //tpbuilder.penaltyDeath();
+ //vpbuilder.penaltyDeath();
+
+ StrictMode.VmPolicy policy = vpbuilder.build();
StrictMode.setVmPolicy(policy);
}
+ @RequiresApi(api = Build.VERSION_CODES.P)
+ public void logViolation(Violation v) {
+ String name = Application.getProcessName();
+ System.err.println("------------------------- Violation detected in " + name + " ------" + v.getCause() + "---------------------------");
+ VpnStatus.logException(VpnStatus.LogLevel.DEBUG, null, v);
+ }
+
@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannels() {
NotificationManager mNotificationManager =
@@ -90,4 +119,5 @@ public class ICSOpenVPNApplication extends Application {
mChannel.setLightColor(Color.CYAN);
mNotificationManager.createNotificationChannel(mChannel);
}
+
}
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 5b88f1a9..ef39540a 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
@@ -47,7 +47,7 @@ public class VpnStatus {
public static TrafficHistory trafficHistory;
- public static void logException(LogLevel ll, String context, Exception e) {
+ public static void logException(LogLevel ll, String context, Throwable e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
LogItem li;
@@ -59,11 +59,11 @@ public class VpnStatus {
newLogItem(li);
}
- public static void logException(Exception e) {
+ public static void logException(Throwable e) {
logException(LogLevel.ERROR, null, e);
}
- public static void logException(String context, Exception e) {
+ public static void logException(String context, Throwable e) {
logException(LogLevel.ERROR, context, e);
}