From: Tobias Brunner Date: Fri, 8 Jun 2018 11:54:46 +0000 (+0200) Subject: android: Store the ID of the most recently used profile as preference X-Git-Tag: 5.7.0dr5~20^2~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08c79d5112f346cfd98255430a916929343d2f2c;p=thirdparty%2Fstrongswan.git android: Store the ID of the most recently used profile as preference --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java index 1d2bed1a96..cb148521b8 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java @@ -27,6 +27,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.VpnService; import android.os.Build; @@ -34,6 +35,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.ParcelFileDescriptor; +import android.preference.PreferenceManager; import android.security.KeyChain; import android.security.KeyChainException; import android.support.v4.app.NotificationCompat; @@ -52,6 +54,7 @@ import org.strongswan.android.logic.imc.ImcState; import org.strongswan.android.logic.imc.RemediationInstruction; import org.strongswan.android.ui.MainActivity; import org.strongswan.android.ui.VpnProfileControlActivity; +import org.strongswan.android.utils.Constants; import org.strongswan.android.utils.IPRange; import org.strongswan.android.utils.IPRangeSet; import org.strongswan.android.utils.SettingsWriter; @@ -146,6 +149,10 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe { String password = bundle.getString(VpnProfileDataSource.KEY_PASSWORD); profile.setPassword(password); + + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); + pref.edit().putString(Constants.PREF_MRU_VPN_PROFILE, profile.getUUID().toString()) + .apply(); } } setNextProfile(profile); diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/utils/Constants.java b/src/frontends/android/app/src/main/java/org/strongswan/android/utils/Constants.java index 2e5de7fc36..52234933b7 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/utils/Constants.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/utils/Constants.java @@ -53,4 +53,9 @@ public final class Constants * Value used to signify that the most recently used profile should be used as default */ public static final String PREF_DEFAULT_VPN_PROFILE_MRU = "pref_default_vpn_profile_mru"; + + /** + * Preference key to store the most recently used VPN profile + */ + public static final String PREF_MRU_VPN_PROFILE = "pref_mru_vpn_profile"; }