]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Add a preference flag to ignore battery optimizations
authorTobias Brunner <tobias@strongswan.org>
Mon, 11 May 2020 13:49:22 +0000 (15:49 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 2 Jun 2020 12:07:06 +0000 (14:07 +0200)
This allows users to ignore whether the app is on the device's power
whitelist without a warning.  The flag is currently not set
automatically if the user denies the request.

src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java
src/frontends/android/app/src/main/java/org/strongswan/android/utils/Constants.java
src/frontends/android/app/src/main/res/values-de/strings.xml
src/frontends/android/app/src/main/res/values-pl/strings.xml
src/frontends/android/app/src/main/res/values-ru/strings.xml
src/frontends/android/app/src/main/res/values-ua/strings.xml
src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml
src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml
src/frontends/android/app/src/main/res/values/strings.xml
src/frontends/android/app/src/main/res/xml/settings.xml

index 896c9de94f316c2cf45fd983b47de3b1d00b5a1b..6cf91a5f6243f6a27cf202a816f2a25eaac4d3ff 100644 (file)
@@ -23,6 +23,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.ServiceConnection;
+import android.content.SharedPreferences;
 import android.net.Uri;
 import android.net.VpnService;
 import android.os.Build;
@@ -41,6 +42,7 @@ import org.strongswan.android.data.VpnProfileDataSource;
 import org.strongswan.android.data.VpnType.VpnTypeFeature;
 import org.strongswan.android.logic.VpnStateService;
 import org.strongswan.android.logic.VpnStateService.State;
+import org.strongswan.android.utils.Constants;
 
 import androidx.annotation.NonNull;
 import androidx.appcompat.app.AlertDialog;
@@ -49,6 +51,7 @@ import androidx.appcompat.app.AppCompatDialogFragment;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentTransaction;
+import androidx.preference.PreferenceManager;
 
 public class VpnProfileControlActivity extends AppCompatActivity
 {
@@ -198,7 +201,9 @@ public class VpnProfileControlActivity extends AppCompatActivity
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
                {
                        PowerManager pm = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
-                       if (!pm.isIgnoringBatteryOptimizations(this.getPackageName()))
+                       SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
+                       if (!pm.isIgnoringBatteryOptimizations(this.getPackageName()) &&
+                               !pref.getBoolean(Constants.PREF_IGNORE_POWER_WHITELIST, false))
                        {
                                PowerWhitelistRequired whitelist = new PowerWhitelistRequired();
                                mWaitingForResult = true;
index 52234933b70f87a6500c4ad35a923abcccce1649..71b6e0fceb2872d5a4392e15fd2452c63ba9f094 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2018 Tobias Brunner
+ * Copyright (C) 2016-2020 Tobias Brunner
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -58,4 +58,9 @@ public final class Constants
         * Preference key to store the most recently used VPN profile
         */
        public static final String PREF_MRU_VPN_PROFILE = "pref_mru_vpn_profile";
+
+       /**
+        * Preference key to store whether the user permanently dismissed our warning to add the app to the power whitelist
+        */
+       public static final String PREF_IGNORE_POWER_WHITELIST = "pref_ignore_power_whitelist";
 }
index 76652bc6318e4e009cd6b91142ce39d06d49f852..aaef5a6b9a9485268d73bc29d67fe391b9ab34a2 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012-2019 Tobias Brunner
+    Copyright (C) 2012-2020 Tobias Brunner
     Copyright (C) 2012 Giuliano Grassi
     Copyright (C) 2012 Ralf Sager
     HSR Hochschule fuer Technik Rapperswil
@@ -36,6 +36,8 @@
     <string name="pref_title">Einstellungen</string>
     <string name="pref_default_vpn_profile">Voreingestelltes VPN Profil</string>
     <string name="pref_default_vpn_profile_mru">Verbinden mit zuletzt verwendetem Profil</string>
+    <string name="pref_power_whitelist_title">Akku-Optimierung ignorieren</string>
+    <string name="pref_power_whitelist_summary">Keine Warnung anzeigen, falls die App nicht auf der weissen Liste für Akku-Optimierung ist</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
index 2e1df077ee31baa9b17b367d69b482937a726e44..16ae3fc7d581a15534e4a5eefb1b190e1d60c340 100644 (file)
@@ -36,6 +36,8 @@
     <string name="pref_title">Settings</string>
     <string name="pref_default_vpn_profile">Default VPN profile</string>
     <string name="pref_default_vpn_profile_mru">Connect to most recently used profile</string>
+    <string name="pref_power_whitelist_title">Ignore battery optimizations</string>
+    <string name="pref_power_whitelist_summary">Don\'t show a warning if the app is not on the device\'s power whitelist</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
index 23fa95d38371b4d0cab7542d13ec12338807d899..426084f22398ab0fcd91b32d4eb57d193f6e334e 100644 (file)
@@ -33,6 +33,8 @@
     <string name="pref_title">Settings</string>
     <string name="pref_default_vpn_profile">Default VPN profile</string>
     <string name="pref_default_vpn_profile_mru">Connect to most recently used profile</string>
+    <string name="pref_power_whitelist_title">Ignore battery optimizations</string>
+    <string name="pref_power_whitelist_summary">Don\'t show a warning if the app is not on the device\'s power whitelist</string>
 
     <!-- Log view -->
     <string name="log_title">Журнал</string>
index b4937364e15ef72134c19db953ed149a9864cdfc..7f414e524346d90232ca7928dfaadadaeb7df1a0 100644 (file)
@@ -34,6 +34,8 @@
     <string name="pref_title">Settings</string>
     <string name="pref_default_vpn_profile">Default VPN profile</string>
     <string name="pref_default_vpn_profile_mru">Connect to most recently used profile</string>
+    <string name="pref_power_whitelist_title">Ignore battery optimizations</string>
+    <string name="pref_power_whitelist_summary">Don\'t show a warning if the app is not on the device\'s power whitelist</string>
 
     <!-- Log view -->
     <string name="log_title">Журнал</string>
index c1dbefb665b1506d5e81159540e31fbf8b6f4f6d..75a3bef33d1f0b030dd822b6ff5e5ef3dfe6cfda 100644 (file)
@@ -33,6 +33,8 @@
     <string name="pref_title">Settings</string>
     <string name="pref_default_vpn_profile">Default VPN profile</string>
     <string name="pref_default_vpn_profile_mru">Connect to most recently used profile</string>
+    <string name="pref_power_whitelist_title">Ignore battery optimizations</string>
+    <string name="pref_power_whitelist_summary">Don\'t show a warning if the app is not on the device\'s power whitelist</string>
 
     <!-- Log view -->
     <string name="log_title">日志</string>
index 13e75a43b4364413492617a09955661ea0e2adc9..28e4e5ae113d275a160ad0bc419778f312bcb45e 100644 (file)
@@ -33,6 +33,8 @@
     <string name="pref_title">Settings</string>
     <string name="pref_default_vpn_profile">Default VPN profile</string>
     <string name="pref_default_vpn_profile_mru">Connect to most recently used profile</string>
+    <string name="pref_power_whitelist_title">Ignore battery optimizations</string>
+    <string name="pref_power_whitelist_summary">Don\'t show a warning if the app is not on the device\'s power whitelist</string>
 
     <!-- Log view -->
     <string name="log_title">日誌</string>
index fb74d3f8332300dafa59d8ad2c7258f96b1d82a2..b72aad9c610676bfb980c81d1829ba8314e204d2 100644 (file)
@@ -36,6 +36,8 @@
     <string name="pref_title">Settings</string>
     <string name="pref_default_vpn_profile">Default VPN profile</string>
     <string name="pref_default_vpn_profile_mru">Connect to most recently used profile</string>
+    <string name="pref_power_whitelist_title">Ignore battery optimizations</string>
+    <string name="pref_power_whitelist_summary">Don\'t show a warning if the app is not on the device\'s power whitelist</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
index 908a888d5c7269b4eb7ea4a5342031d86355c336..3eb7343e1bbd20a03f3e8bf24a5ec6034b243907 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2018 Tobias Brunner
+    Copyright (C) 2018-2020 Tobias Brunner
     HSR Hochschule fuer Technik Rapperswil
 
     This program is free software; you can redistribute it and/or modify it
@@ -20,4 +20,9 @@
         android:title="@string/pref_default_vpn_profile"
         android:summary="@string/pref_default_vpn_profile_mru" />
 
+    <SwitchPreference
+        android:key="pref_ignore_power_whitelist"
+        android:title="@string/pref_power_whitelist_title"
+        android:summary="@string/pref_power_whitelist_summary" />
+
 </PreferenceScreen>