From a733aad2ec8ed8cdb8b6d9d584c172488eacfa8f Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 23 Jul 2018 13:10:58 +0200 Subject: Move app restriction initialisation to Application class --- .../java/de/blinkt/openvpn/activities/BaseActivity.java | 8 ++++---- .../main/java/de/blinkt/openvpn/api/AppRestrictions.java | 15 +++++++++++++-- .../de/blinkt/openvpn/core/ICSOpenVPNApplication.java | 4 ++++ main/src/main/res/values/untranslatable.xml | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) (limited to 'main') diff --git a/main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java b/main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java index 08f2787b..7258d8d6 100644 --- a/main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java +++ b/main/src/main/java/de/blinkt/openvpn/activities/BaseActivity.java @@ -34,10 +34,10 @@ public class BaseActivity extends Activity { @Override protected void onResume() { super.onResume(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - AppRestrictions.getInstance(this).checkRestrictions(this); - - } } + @Override + protected void onPause() { + super.onPause(); + } } diff --git a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java index 311b600d..1b2fc1b3 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java +++ b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java @@ -12,6 +12,7 @@ import android.os.Bundle; import android.os.Parcelable; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; +import de.blinkt.openvpn.core.Connection; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; @@ -30,6 +31,7 @@ public class AppRestrictions { static boolean alreadyChecked = false; private static AppRestrictions mInstance; private RestrictionsManager mRestrictionsMgr; + private BroadcastReceiver mRestrictionsReceiver; private AppRestrictions(Context c) { @@ -44,13 +46,17 @@ public class AppRestrictions { private void addChangesListener(Context c) { IntentFilter restrictionsFilter = new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED); - BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() { + mRestrictionsReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { applyRestrictions(context); } }; - c.registerReceiver(restrictionsReceiver, restrictionsFilter); + c.registerReceiver(mRestrictionsReceiver, restrictionsFilter); + } + + private void removeChangesListener(Context c) { + c.unregisterReceiver(mRestrictionsReceiver); } private String hashConfig(String config) { @@ -179,4 +185,9 @@ public class AppRestrictions { addChangesListener(c); applyRestrictions(c); } + + public void pauseCheckRestrictions(Context c) + { + removeChangesListener(c); + } } 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 3261d32b..181cca5f 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java @@ -22,6 +22,7 @@ import org.acra.annotation.ReportsCrashes; import android.os.StrictMode; import de.blinkt.openvpn.BuildConfig; import de.blinkt.openvpn.R; +import de.blinkt.openvpn.api.AppRestrictions; public class ICSOpenVPNApplication extends Application { private StatusListener mStatus; @@ -42,6 +43,9 @@ public class ICSOpenVPNApplication extends Application { if (BuildConfig.BUILD_TYPE.equals("debug")) enableStrictModes(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + AppRestrictions.getInstance(this).checkRestrictions(this); + } } private void enableStrictModes() { diff --git a/main/src/main/res/values/untranslatable.xml b/main/src/main/res/values/untranslatable.xml index d7113fa4..e71d79ab 100644 --- a/main/src/main/res/values/untranslatable.xml +++ b/main/src/main/res/values/untranslatable.xml @@ -64,7 +64,7 @@ 0E910C15–9A85-4DD9-AE0D-E6862392E638). Generate using uuidgen or similar tools UUID - Content of the OpenVPN configuration file + Content of the OpenVPN configuration file. These files are usually have the extension .ovpn (sometimes also .conf) and are plain text multi line configuration files. If your MDM does not support multiline configuration entries, you can also use a base64 encoded string here. A text file can be converted to base64 using openssl base64 -A -in Config Name of the VPN profile Name -- cgit v1.2.3