From 17c3e48860c58d9e2b737cd1e2413f7e2684b02a Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 11 Jun 2018 13:07:06 +0200 Subject: Fix a few strict mode violations --- .../de/blinkt/openvpn/core/ICSOpenVPNApplication.java | 15 +++++++++++++++ .../main/java/de/blinkt/openvpn/core/LogFileHandler.java | 4 +++- .../main/java/de/blinkt/openvpn/core/ProfileManager.java | 12 +++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) (limited to 'main') 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(); + } + } } } } -- cgit v1.2.3