summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2018-06-11 13:07:06 +0200
committerArne Schwabe <arne@rfc2549.org>2018-06-11 13:07:06 +0200
commit17c3e48860c58d9e2b737cd1e2413f7e2684b02a (patch)
treeddc2813dad2a939cbfb325ed8b9b28ee02141c15 /main
parent591b868040f4cd537e2b85c41817b7a0eeb4c97d (diff)
Fix a few strict mode violations
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java15
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java4
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java12
3 files changed, 29 insertions, 2 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 1cbd99ef..3261d32b 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java
@@ -19,6 +19,8 @@ import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
*/
+import android.os.StrictMode;
+import de.blinkt.openvpn.BuildConfig;
import de.blinkt.openvpn.R;
public class ICSOpenVPNApplication extends Application {
@@ -37,6 +39,19 @@ public class ICSOpenVPNApplication extends Application {
mStatus = new StatusListener();
mStatus.init(getApplicationContext());
+ if (BuildConfig.BUILD_TYPE.equals("debug"))
+ enableStrictModes();
+
+ }
+
+ private void enableStrictModes() {
+ StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder()
+ .detectAll()
+ .penaltyLog()
+ .penaltyDeath()
+ .build();
+ StrictMode.setVmPolicy(policy);
+
}
@TargetApi(Build.VERSION_CODES.O)
diff --git a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
index 459333fb..c77e1c2f 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
@@ -134,7 +134,9 @@ class LogFileHandler extends Handler {
if (!logfile.exists() || !logfile.canRead())
return;
- readCacheContents(new FileInputStream(logfile));
+ FileInputStream log = new FileInputStream(logfile);
+ readCacheContents(log);
+ log.close();
} catch (java.io.IOException | java.lang.RuntimeException e) {
VpnStatus.logError("Reading cached logfile failed");
diff --git a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
index f776fc2e..aa4a50ff 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
@@ -174,8 +174,9 @@ public class ProfileManager {
vlist.add(TEMPORARY_PROFILE_FILENAME);
for (String vpnentry : vlist) {
+ ObjectInputStream vpnfile=null;
try {
- ObjectInputStream vpnfile = new ObjectInputStream(context.openFileInput(vpnentry + ".vp"));
+ vpnfile = new ObjectInputStream(context.openFileInput(vpnentry + ".vp"));
VpnProfile vp = ((VpnProfile) vpnfile.readObject());
// Sanity check
@@ -189,9 +190,18 @@ public class ProfileManager {
profiles.put(vp.getUUID().toString(), vp);
}
+
} catch (IOException | ClassNotFoundException e) {
if (!vpnentry.equals(TEMPORARY_PROFILE_FILENAME))
VpnStatus.logException("Loading VPN List", e);
+ } finally {
+ if (vpnfile!=null) {
+ try {
+ vpnfile.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
}
}