diff options
| author | Arne Schwabe <arne@rfc2549.org> | 2025-11-18 12:08:43 +0100 |
|---|---|---|
| committer | Arne Schwabe <arne@rfc2549.org> | 2025-11-18 12:18:43 +0100 |
| commit | d34dd25f596d3eaa61df338ba62c19269ccf63ab (patch) | |
| tree | 279b913491a9f59c5381fd0a5608b2f0dd35b7f6 /main/src | |
| parent | 2c69da35a271ee4327ab51ec9cf7a1a5b93506bf (diff) | |
Improve minimal UI, add reconnect and encryption to app restrictions
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java | 41 | ||||
| -rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java | 7 | ||||
| -rw-r--r-- | main/src/main/res/values/untranslatable.xml | 7 | ||||
| -rw-r--r-- | main/src/main/res/xml/app_restrictions.xml | 22 | ||||
| -rw-r--r-- | main/src/ui/java/de/blinkt/openvpn/fragments/MinimalUI.kt | 10 | ||||
| -rw-r--r-- | main/src/ui/res/layout/minimalui.xml (renamed from main/src/main/res/layout/minimalui.xml) | 0 |
6 files changed, 50 insertions, 37 deletions
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<String> 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/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 @@ <string name="restriction_restartvpnonboot">Enable the workaround to use an on boot receiver to start the VPN if the Always On VPN functionality is not available</string> <string name="apprest_vpn_applist">Apps using the VPN</string> <string name="apprest_vpn_applist_desc">List of packages name (e.g. com.google.chrome) that are should be used with the VPN. Separated by comma, space or newlines</string> - <string name="restriction_ignorenetworkstate">Keep the VPN connected even when no network is detected, e.g. when reverse tethering over USB using adb</string> + <string name="apprest_ignorenetworkstate">Keep the VPN connected even when no network is detected, e.g. when reverse tethering over USB using adb</string> <string name="apprest_aidl_list">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</string> <string name="apprest_remoteaidl">Remote API access</string> <string name="apprest_minimal_ui">Only present a restricted UI that only allow connecting/disconnecting the default VPN. Most other functionality is is disabled as well</string> <string name="apprest_minimal_ui_title">Minimal UI</string> <string name="apprest_always_connected">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.</string> <string name="apprest_always_connected_title">Disallow disconnecting default VPN</string> - + <string name="apprest_encrypt_profiles">Try to encrypt the profile on storage when supported by the Android OS</string> + <string name="apprest_encrypt_profiles_title">Encrypt profiles</string> + <string name="apprest_netchangereconnect">Reconnect on network change</string> + <string name="apprest_netchangereconnect_title">Trigger a reconnection of the OpenVPN connection if the change in the network connectivity is detected</string> <string-array name="tls_profile_values" translatable="false"> <item>insecure</item> 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" /> <restriction - android:key="allowed_apps" - android:title="@string/apprest_vpn_applist" android:description="@string/apprest_vpn_applist_desc" - android:restrictionType="string" /> + android:key="allowed_apps" + android:restrictionType="string" + android:title="@string/apprest_vpn_applist" /> <!-- <restriction android:key="ovpn_list" @@ -68,7 +68,6 @@ </restriction> </restriction> <restriction - android:defaultValue="" android:key="defaultprofile" android:restrictionType="string" @@ -84,7 +83,7 @@ <restriction android:key="ignorenetworkstate" android:restrictionType="bool" - android:title="@string/restriction_ignorenetworkstate" /> + android:title="@string/apprest_ignorenetworkstate" /> <restriction android:description="@string/apprest_aidl_list" @@ -106,4 +105,17 @@ android:restrictionType="bool" android:title="@string/apprest_always_connected_title" /> + + <restriction + android:description="@string/apprest_encrypt_profiles" + android:key="preferencryption" + android:restrictionType="bool" + android:title="@string/apprest_encrypt_profiles_title" /> + + <restriction + android:description="@string/apprest_netchangereconnect" + android:key="netchangereconnect" + android:restrictionType="bool" + android:title="@string/apprest_netchangereconnect_title" /> + </restrictions>
\ No newline at end of file diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/MinimalUI.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/MinimalUI.kt index b57fdea7..dd9182cc 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/MinimalUI.kt +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/MinimalUI.kt @@ -32,11 +32,7 @@ import de.blinkt.openvpn.core.OpenVPNService import de.blinkt.openvpn.core.ProfileManager import de.blinkt.openvpn.core.VpnStatus -class MinimalUI: Fragment(), View.OnClickListener, VpnStatus.StateListener { - override fun onClick(v: View?) { - TODO("Not yet implemented") - } - +class MinimalUI: Fragment(), VpnStatus.StateListener { private var mPermReceiver: ActivityResultLauncher<String>? = null private lateinit var profileManger: ProfileManager private var mService: IOpenVPNServiceInternal? = null @@ -116,10 +112,10 @@ class MinimalUI: Fragment(), View.OnClickListener, VpnStatus.StateListener { level: ConnectionStatus?, Intent: Intent? ) { - val cleanLogMessage = VpnStatus.getLastCleanLogMessage(activity) + val cleanLogMessage = VpnStatus.getLastCleanLogMessage(activity, true) requireActivity().runOnUiThread { - vpnstatus.setText(localizedResId) + vpnstatus.setText(cleanLogMessage) val connected = level == ConnectionStatus.LEVEL_CONNECTED; vpntoggle.isChecked = connected } diff --git a/main/src/main/res/layout/minimalui.xml b/main/src/ui/res/layout/minimalui.xml index 3ff7da2b..3ff7da2b 100644 --- a/main/src/main/res/layout/minimalui.xml +++ b/main/src/ui/res/layout/minimalui.xml |
