Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/keepass2android-app/settings/SSIDManagerActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class SSIDManagerActivity : AppCompatActivity
SSIDAdapter adapter;

const string PrefsName = "SSIDPrefs";
const string KeySSIDs = "SSIDs";
const string KeySSIDs = "SSIDs"; // legacy: '|'-separated
const string KeySSIDsJson = "SSIDsJson";

protected override void OnCreate(Bundle savedInstanceState)
{
Expand Down Expand Up @@ -96,6 +97,21 @@ void LoadSSIDs()
public static List<string> LoadSSIDS(Context context)
{
var prefs = context.GetSharedPreferences(PrefsName, FileCreationMode.Private);
var json = prefs.GetString(KeySSIDsJson, null);
if (json != null)
{
try
{
return System.Text.Json.JsonSerializer.Deserialize<List<string>>(json) ?? new List<string>();
}
catch (System.Text.Json.JsonException)
{
return new List<string>();
}
}

// legacy format (before SSIDs containing '|' were supported): '|'-separated list.
// Didn't work with SSIDs containing '|'
var ssids = prefs.GetString(KeySSIDs, "");
if (!string.IsNullOrEmpty(ssids))
return ssids.Split('|').ToList();
Expand All @@ -112,7 +128,8 @@ public static void SaveSSIDs(List<string> ssidList, Context context)
{
var prefs = context.GetSharedPreferences(PrefsName, FileCreationMode.Private);
var prefsEditor = prefs.Edit();
prefsEditor.PutString(KeySSIDs, string.Join("|", ssidList));
prefsEditor.PutString(KeySSIDsJson, System.Text.Json.JsonSerializer.Serialize(ssidList));
prefsEditor.Remove(KeySSIDs); // legacy key, superseded by KeySSIDsJson
prefsEditor.Commit();

}
Expand Down
Loading