summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2022-09-10 19:17:35 +0200
committerArne Schwabe <arne@rfc2549.org>2022-09-10 20:00:32 +0200
commit3127f73508d50cb85ab6789ad521accefe71ad33 (patch)
treee8b1ce366d685c4ce89c85880d3a2be3c42f86f3 /main
parent8142b5d5ed0a73d37e397a0b553571a3236d60a1 (diff)
Implement setting on pause on idle via app restrictions
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java16
-rw-r--r--main/src/main/res/values/untranslatable.xml1
-rw-r--r--main/src/main/res/xml/app_restrictions.xml5
3 files changed, 19 insertions, 3 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 175ecb70..c06b01b3 100644
--- a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java
+++ b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java
@@ -155,20 +155,30 @@ public class AppRestrictions {
pm.removeProfile(c, vp);
}
+ SharedPreferences defaultPrefs = Preferences.getDefaultSharedPreferences(c);
+
if (!TextUtils.isEmpty(defaultprofile)) {
if (!defaultprofileProvisioned) {
VpnStatus.logError("App restrictions: Setting a default profile UUID without providing a profile with that UUID");
} else {
- SharedPreferences prefs = Preferences.getDefaultSharedPreferences(c);
- String uuid = prefs.getString("alwaysOnVpn", null);
+ String uuid = defaultPrefs.getString("alwaysOnVpn", null);
if (!defaultprofile.equals(uuid))
{
- SharedPreferences.Editor editor = prefs.edit();
+ SharedPreferences.Editor editor = defaultPrefs.edit();
editor.putString("alwaysOnVpn", defaultprofile);
editor.apply();
+
}
}
}
+
+ if(restrictions.containsKey("screenoffpausevpn"))
+ {
+ boolean pauseVPN = restrictions.getBoolean("screenoffpausevpn");
+ SharedPreferences.Editor editor = defaultPrefs.edit();
+ editor.putBoolean("screenoff", pauseVPN);
+ editor.apply();
+ }
}
private String prepare(String config) {
diff --git a/main/src/main/res/values/untranslatable.xml b/main/src/main/res/values/untranslatable.xml
index 0260de8d..cde0d8a5 100644
--- a/main/src/main/res/values/untranslatable.xml
+++ b/main/src/main/res/values/untranslatable.xml
@@ -82,6 +82,7 @@
<string name="abi_mismatch">Preferred native ABI precedence of this device (%1$s) and ABI reported by native libraries (%2$s) mismatch</string>
<string name="faq_title_ncp">Failed to negotiate cipher with server</string>
<string name="import_from_URL">URL</string>
+ <string name="restriction_pausevpn">Pause VPN when screen is off and less than 64 kB transferred data in 60s</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 813e9bd3..167e48e8 100644
--- a/main/src/main/res/xml/app_restrictions.xml
+++ b/main/src/main/res/xml/app_restrictions.xml
@@ -66,4 +66,9 @@
android:restrictionType="string"
android:defaultValue=""
/>
+ <restriction
+ android:key="screenoffpausevpn"
+ android:title="@string/restriction_pausevpn"
+ android:restrictionType="bool"
+ />
</restrictions> \ No newline at end of file