From d34dd25f596d3eaa61df338ba62c19269ccf63ab Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Tue, 18 Nov 2025 12:08:43 +0100 Subject: Improve minimal UI, add reconnect and encryption to app restrictions --- .../de/blinkt/openvpn/api/AppRestrictions.java | 41 +++++++--------- .../java/de/blinkt/openvpn/core/VpnStatus.java | 7 +++ main/src/main/res/layout/minimalui.xml | 56 ---------------------- main/src/main/res/values/untranslatable.xml | 7 ++- main/src/main/res/xml/app_restrictions.xml | 22 +++++++-- .../java/de/blinkt/openvpn/fragments/MinimalUI.kt | 10 ++-- main/src/ui/res/layout/minimalui.xml | 56 ++++++++++++++++++++++ 7 files changed, 106 insertions(+), 93 deletions(-) delete mode 100644 main/src/main/res/layout/minimalui.xml create mode 100644 main/src/ui/res/layout/minimalui.xml (limited to 'main/src') 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 d6b0909e..e507adfc 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java +++ b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java @@ -95,8 +95,10 @@ public class AppRestrictions { public void parseRestrictionsBundle(Context c, Bundle restrictions) { - if (restrictions == null) + if (restrictions == null) { + GlobalPreferences.setInstance(false, false); return; + } String configVersion = restrictions.getString("version", "(not set)"); try { @@ -150,31 +152,15 @@ public class AppRestrictions { private static void setMiscSettings(Context c, Bundle restrictions) { SharedPreferences defaultPrefs = Preferences.getDefaultSharedPreferences(c); - if(restrictions.containsKey("screenoffpausevpn")) - { - boolean pauseVPN = restrictions.getBoolean("screenoffpausevpn"); - SharedPreferences.Editor editor = defaultPrefs.edit(); - editor.putBoolean("screenoff", pauseVPN); - editor.apply(); - } - if(restrictions.containsKey("ignorenetworkstate")) - { - boolean ignoreNetworkState = restrictions.getBoolean("ignorenetworkstate"); - SharedPreferences.Editor editor = defaultPrefs.edit(); - editor.putBoolean("ignorenetstate", ignoreNetworkState); - editor.apply(); - } - if (restrictions.containsKey("restartvpnonboot")) - { - boolean restartVPNonBoot = restrictions.getBoolean("restartvpnonboot"); - SharedPreferences.Editor editor = defaultPrefs.edit(); - editor.putBoolean("restartvpnonboot", restartVPNonBoot); - editor.apply(); - } - + applyBooleanDefaultPrefsRestriction(restrictions, "screenoffpausevpn", defaultPrefs, "screenoff"); + applyBooleanDefaultPrefsRestriction(restrictions, "ignorenetworkstate", defaultPrefs, "ignorenetstate"); + applyBooleanDefaultPrefsRestriction(restrictions, "restartvpnonboot", defaultPrefs, "restartvpnonboot"); + applyBooleanDefaultPrefsRestriction(restrictions,"preferencryption", defaultPrefs, "preferencryption" ); + applyBooleanDefaultPrefsRestriction(restrictions, "netchangereconnect", defaultPrefs, "netchangereconnect"); boolean minimalUi = restrictions.getBoolean("minimal_ui", false); if (minimalUi && defaultPrefs.getBoolean("showlogwindow", true)){ + /* always disable showing log window in minimal UI mode */ SharedPreferences.Editor editor = defaultPrefs.edit(); editor.putBoolean("showlogwindow", false); editor.apply(); @@ -184,6 +170,15 @@ public class AppRestrictions { GlobalPreferences.setInstance(minimalUi, forceConnected); } + private static void applyBooleanDefaultPrefsRestriction(Bundle restrictions, String restriction_name, SharedPreferences defaultPrefs, String prefs_name) { + if (restrictions.containsKey(restriction_name)) { + boolean pauseVPN = restrictions.getBoolean(restriction_name); + SharedPreferences.Editor editor = defaultPrefs.edit(); + editor.putBoolean(prefs_name, pauseVPN); + editor.apply(); + } + } + private void importVPNProfiles(Context c, Bundle restrictions, Parcelable[] profileList) { Set provisionedUuids = new HashSet<>(); 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 6117b3d0..9a3791b3 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -76,9 +76,16 @@ public class VpnStatus { } public static String getLastCleanLogMessage(Context c) { + return getLastCleanLogMessage(c, false); + } + + public static String getLastCleanLogMessage(Context c, boolean shortversion) { String message = mLaststatemsg; switch (mLastLevel) { case LEVEL_CONNECTED: + if (shortversion) + return c.getString(R.string.state_connected); + String[] parts = mLaststatemsg.split(","); /* (a) the integer unix date/time, diff --git a/main/src/main/res/layout/minimalui.xml b/main/src/main/res/layout/minimalui.xml deleted file mode 100644 index 3ff7da2b..00000000 --- a/main/src/main/res/layout/minimalui.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/main/src/main/res/values/untranslatable.xml b/main/src/main/res/values/untranslatable.xml index 80824ea1..bf5497bd 100644 --- a/main/src/main/res/values/untranslatable.xml +++ b/main/src/main/res/values/untranslatable.xml @@ -88,14 +88,17 @@ Enable the workaround to use an on boot receiver to start the VPN if the Always On VPN functionality is not available Apps using the VPN List of packages name (e.g. com.google.chrome) that are should be used with the VPN. Separated by comma, space or newlines - Keep the VPN connected even when no network is detected, e.g. when reverse tethering over USB using adb + Keep the VPN connected even when no network is detected, e.g. when reverse tethering over USB using adb List of apps that are allowed to use the remote AIDL. If this list is in the restrictions, the app will not allowed any changes to the list by the user. Package names of allowed apps separated by comma, space or newlines Remote API access Only present a restricted UI that only allow connecting/disconnecting the default VPN. Most other functionality is is disabled as well Minimal UI When in the minimal UI mode, try to keep the default VPN always connected. Do not allow disconnecting it. Restarting the VPN is still allowed. Disallow disconnecting default VPN - + Try to encrypt the profile on storage when supported by the Android OS + Encrypt profiles + Reconnect on network change + Trigger a reconnection of the OpenVPN connection if the change in the network connectivity is detected insecure diff --git a/main/src/main/res/xml/app_restrictions.xml b/main/src/main/res/xml/app_restrictions.xml index 3d2d1cc2..02e3fe06 100644 --- a/main/src/main/res/xml/app_restrictions.xml +++ b/main/src/main/res/xml/app_restrictions.xml @@ -48,10 +48,10 @@ android:restrictionType="string" android:title="@string/apprest_certalias" /> + android:key="allowed_apps" + android:restrictionType="string" + android:title="@string/apprest_vpn_applist" /> + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3