Skip to content

Commit d34dd25

Browse files
committed
Improve minimal UI, add reconnect and encryption to app restrictions
1 parent 2c69da3 commit d34dd25

File tree

7 files changed

+51
-37
lines changed

7 files changed

+51
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ polaris.yml
3030
idir
3131

3232
test.local.conf
33+
.kotlin

main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ private void applyRestrictions(Context c) {
9595

9696
public void parseRestrictionsBundle(Context c, Bundle restrictions)
9797
{
98-
if (restrictions == null)
98+
if (restrictions == null) {
99+
GlobalPreferences.setInstance(false, false);
99100
return;
101+
}
100102

101103
String configVersion = restrictions.getString("version", "(not set)");
102104
try {
@@ -150,31 +152,15 @@ private void setAllowedRemoteControl(Context c, Bundle restrictions) {
150152
private static void setMiscSettings(Context c, Bundle restrictions) {
151153
SharedPreferences defaultPrefs = Preferences.getDefaultSharedPreferences(c);
152154

153-
if(restrictions.containsKey("screenoffpausevpn"))
154-
{
155-
boolean pauseVPN = restrictions.getBoolean("screenoffpausevpn");
156-
SharedPreferences.Editor editor = defaultPrefs.edit();
157-
editor.putBoolean("screenoff", pauseVPN);
158-
editor.apply();
159-
}
160-
if(restrictions.containsKey("ignorenetworkstate"))
161-
{
162-
boolean ignoreNetworkState = restrictions.getBoolean("ignorenetworkstate");
163-
SharedPreferences.Editor editor = defaultPrefs.edit();
164-
editor.putBoolean("ignorenetstate", ignoreNetworkState);
165-
editor.apply();
166-
}
167-
if (restrictions.containsKey("restartvpnonboot"))
168-
{
169-
boolean restartVPNonBoot = restrictions.getBoolean("restartvpnonboot");
170-
SharedPreferences.Editor editor = defaultPrefs.edit();
171-
editor.putBoolean("restartvpnonboot", restartVPNonBoot);
172-
editor.apply();
173-
}
174-
155+
applyBooleanDefaultPrefsRestriction(restrictions, "screenoffpausevpn", defaultPrefs, "screenoff");
156+
applyBooleanDefaultPrefsRestriction(restrictions, "ignorenetworkstate", defaultPrefs, "ignorenetstate");
157+
applyBooleanDefaultPrefsRestriction(restrictions, "restartvpnonboot", defaultPrefs, "restartvpnonboot");
158+
applyBooleanDefaultPrefsRestriction(restrictions,"preferencryption", defaultPrefs, "preferencryption" );
159+
applyBooleanDefaultPrefsRestriction(restrictions, "netchangereconnect", defaultPrefs, "netchangereconnect");
175160

176161
boolean minimalUi = restrictions.getBoolean("minimal_ui", false);
177162
if (minimalUi && defaultPrefs.getBoolean("showlogwindow", true)){
163+
/* always disable showing log window in minimal UI mode */
178164
SharedPreferences.Editor editor = defaultPrefs.edit();
179165
editor.putBoolean("showlogwindow", false);
180166
editor.apply();
@@ -184,6 +170,15 @@ private static void setMiscSettings(Context c, Bundle restrictions) {
184170
GlobalPreferences.setInstance(minimalUi, forceConnected);
185171
}
186172

173+
private static void applyBooleanDefaultPrefsRestriction(Bundle restrictions, String restriction_name, SharedPreferences defaultPrefs, String prefs_name) {
174+
if (restrictions.containsKey(restriction_name)) {
175+
boolean pauseVPN = restrictions.getBoolean(restriction_name);
176+
SharedPreferences.Editor editor = defaultPrefs.edit();
177+
editor.putBoolean(prefs_name, pauseVPN);
178+
editor.apply();
179+
}
180+
}
181+
187182
private void importVPNProfiles(Context c, Bundle restrictions, Parcelable[] profileList) {
188183
Set<String> provisionedUuids = new HashSet<>();
189184

main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,16 @@ public static boolean isVPNActive() {
7676
}
7777

7878
public static String getLastCleanLogMessage(Context c) {
79+
return getLastCleanLogMessage(c, false);
80+
}
81+
82+
public static String getLastCleanLogMessage(Context c, boolean shortversion) {
7983
String message = mLaststatemsg;
8084
switch (mLastLevel) {
8185
case LEVEL_CONNECTED:
86+
if (shortversion)
87+
return c.getString(R.string.state_connected);
88+
8289
String[] parts = mLaststatemsg.split(",");
8390
/*
8491
(a) the integer unix date/time,

main/src/main/res/values/untranslatable.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@
8888
<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>
8989
<string name="apprest_vpn_applist">Apps using the VPN</string>
9090
<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>
91-
<string name="restriction_ignorenetworkstate">Keep the VPN connected even when no network is detected, e.g. when reverse tethering over USB using adb</string>
91+
<string name="apprest_ignorenetworkstate">Keep the VPN connected even when no network is detected, e.g. when reverse tethering over USB using adb</string>
9292
<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>
9393
<string name="apprest_remoteaidl">Remote API access</string>
9494
<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>
9595
<string name="apprest_minimal_ui_title">Minimal UI</string>
9696
<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>
9797
<string name="apprest_always_connected_title">Disallow disconnecting default VPN</string>
98-
98+
<string name="apprest_encrypt_profiles">Try to encrypt the profile on storage when supported by the Android OS</string>
99+
<string name="apprest_encrypt_profiles_title">Encrypt profiles</string>
100+
<string name="apprest_netchangereconnect">Reconnect on network change</string>
101+
<string name="apprest_netchangereconnect_title">Trigger a reconnection of the OpenVPN connection if the change in the network connectivity is detected</string>
99102

100103
<string-array name="tls_profile_values" translatable="false">
101104
<item>insecure</item>

main/src/main/res/xml/app_restrictions.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
android:restrictionType="string"
4949
android:title="@string/apprest_certalias" />
5050
<restriction
51-
android:key="allowed_apps"
52-
android:title="@string/apprest_vpn_applist"
5351
android:description="@string/apprest_vpn_applist_desc"
54-
android:restrictionType="string" />
52+
android:key="allowed_apps"
53+
android:restrictionType="string"
54+
android:title="@string/apprest_vpn_applist" />
5555
<!--
5656
<restriction
5757
android:key="ovpn_list"
@@ -68,7 +68,6 @@
6868
</restriction>
6969
</restriction>
7070
<restriction
71-
7271
android:defaultValue=""
7372
android:key="defaultprofile"
7473
android:restrictionType="string"
@@ -84,7 +83,7 @@
8483
<restriction
8584
android:key="ignorenetworkstate"
8685
android:restrictionType="bool"
87-
android:title="@string/restriction_ignorenetworkstate" />
86+
android:title="@string/apprest_ignorenetworkstate" />
8887

8988
<restriction
9089
android:description="@string/apprest_aidl_list"
@@ -106,4 +105,17 @@
106105
android:restrictionType="bool"
107106
android:title="@string/apprest_always_connected_title" />
108107

108+
109+
<restriction
110+
android:description="@string/apprest_encrypt_profiles"
111+
android:key="preferencryption"
112+
android:restrictionType="bool"
113+
android:title="@string/apprest_encrypt_profiles_title" />
114+
115+
<restriction
116+
android:description="@string/apprest_netchangereconnect"
117+
android:key="netchangereconnect"
118+
android:restrictionType="bool"
119+
android:title="@string/apprest_netchangereconnect_title" />
120+
109121
</restrictions>

main/src/ui/java/de/blinkt/openvpn/fragments/MinimalUI.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ import de.blinkt.openvpn.core.OpenVPNService
3232
import de.blinkt.openvpn.core.ProfileManager
3333
import de.blinkt.openvpn.core.VpnStatus
3434

35-
class MinimalUI: Fragment(), View.OnClickListener, VpnStatus.StateListener {
36-
override fun onClick(v: View?) {
37-
TODO("Not yet implemented")
38-
}
39-
35+
class MinimalUI: Fragment(), VpnStatus.StateListener {
4036
private var mPermReceiver: ActivityResultLauncher<String>? = null
4137
private lateinit var profileManger: ProfileManager
4238
private var mService: IOpenVPNServiceInternal? = null
@@ -116,10 +112,10 @@ class MinimalUI: Fragment(), View.OnClickListener, VpnStatus.StateListener {
116112
level: ConnectionStatus?,
117113
Intent: Intent?
118114
) {
119-
val cleanLogMessage = VpnStatus.getLastCleanLogMessage(activity)
115+
val cleanLogMessage = VpnStatus.getLastCleanLogMessage(activity, true)
120116

121117
requireActivity().runOnUiThread {
122-
vpnstatus.setText(localizedResId)
118+
vpnstatus.setText(cleanLogMessage)
123119
val connected = level == ConnectionStatus.LEVEL_CONNECTED;
124120
vpntoggle.isChecked = connected
125121
}
File renamed without changes.

0 commit comments

Comments
 (0)