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;
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;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
+import androidx.preference.PreferenceManager;
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;
/*
- * 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
* 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";
}
<?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
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<?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
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>