]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Store the ID of the most recently used profile as preference
authorTobias Brunner <tobias@strongswan.org>
Fri, 8 Jun 2018 11:54:46 +0000 (13:54 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:35 +0000 (11:31 +0200)
src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java
src/frontends/android/app/src/main/java/org/strongswan/android/utils/Constants.java

index 1d2bed1a96f4c33aee4edb41d32b17e5176bc048..cb148521b82781f67b1805f02073c02d32775e4b 100644 (file)
@@ -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);
index 2e5de7fc3637fae766eb923757b1645a0124904b..52234933b70f87a6500c4ad35a923abcccce1649 100644 (file)
@@ -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";
 }