From c4c00813d713c7e431b01fb522087fbac22cdf56 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Tue, 16 Jun 2009 05:45:43 +0000 Subject: When corrupted settings are encountered, reset to default values git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@308 df292f66-193f-0410-a5fc-6d59da041ff2 --- src/org/connectbot/SettingsActivity.java | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/org/connectbot/SettingsActivity.java b/src/org/connectbot/SettingsActivity.java index 422e1df..1d4991f 100644 --- a/src/org/connectbot/SettingsActivity.java +++ b/src/org/connectbot/SettingsActivity.java @@ -18,15 +18,41 @@ package org.connectbot; +import org.connectbot.util.PreferenceConstants; + +import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; +import android.util.Log; public class SettingsActivity extends PreferenceActivity { + private static final String TAG = "ConnectBot.Settings"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.preferences); + try { + addPreferencesFromResource(R.xml.preferences); + } catch (ClassCastException e) { + Log.e(TAG, "Shared preferences are corrupt! Resetting to default values."); + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); + + // Blow away all the preferences + SharedPreferences.Editor editor = preferences.edit(); + editor.clear(); + editor.commit(); + + PreferenceManager.setDefaultValues(this, R.xml.preferences, true); + + // Since they were able to get to the Settings activity, they already agreed to the EULA + editor = preferences.edit(); + editor.putBoolean(PreferenceConstants.EULA, true); + editor.commit(); + + addPreferencesFromResource(R.xml.preferences); + } // TODO: add parse checking here to make sure we have integer value for scrollback -- cgit v1.2.3