Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java

Issue 29340827: Issue 3931 - Crash on filter list request/delivery (Closed)
Patch Set: Created April 26, 2016, 9:34 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
diff --git a/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java b/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
index 5d6f381a90305f4965f749bea126be1d934a9e48..f4a5bc6f9be34577611b7ccbe64295425a76c9c7 100644
--- a/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
+++ b/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
@@ -47,6 +47,11 @@ public class MainPreferences extends PreferenceActivity implements
private Engine engine = null;
private AlertDialog setupDialog = null;
+ private SharedPreferences getSharedPreferences()
+ {
+ return PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
+ }
+
@Override
public void onCreate(Bundle savedInstanceState)
{
@@ -58,8 +63,23 @@ public class MainPreferences extends PreferenceActivity implements
.replace(android.R.id.content, new Preferences())
.commit();
- PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext())
- .registerOnSharedPreferenceChangeListener(this);
+ // This try/catch block is a workaround for a preference mismatch
+ // issue. We check for a type mismatch in one particular key and,
+ // if there's a mismatch, clean sweep the preferences.
+ // See: https://issues.adblockplus.org/ticket/3931
+ try
Felix Dahlke 2016/04/26 17:39:10 What causes this issue? Did we change the type of
+ {
+ this.getSharedPreferences().getBoolean(
+ this.getString(R.string.key_application_activated),
+ false);
+ }
+ catch(final Throwable t)
+ {
+ this.getSharedPreferences()
+ .edit()
+ .clear()
+ .commit();
+ }
}
@Override
@@ -69,13 +89,15 @@ public class MainPreferences extends PreferenceActivity implements
this.getString(R.string.initialization_title),
this.getString(R.string.initialization_message));
super.onStart();
- EngineService.startService(this, this);
+ this.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+ EngineService.startService(this.getApplicationContext(), this);
}
@Override
protected void onStop()
{
super.onStop();
+ this.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}
private void checkForCompatibleSBrowserAndProceed()
@@ -113,7 +135,7 @@ public class MainPreferences extends PreferenceActivity implements
private void checkAAStatusAndProceed()
{
- final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ final SharedPreferences prefs = this.getSharedPreferences();
final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown);
final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false);
if (!aaInfoShown)
@@ -143,7 +165,7 @@ public class MainPreferences extends PreferenceActivity implements
private void checkSetupStatus()
{
- final boolean applicationActivated = PreferenceManager.getDefaultSharedPreferences(this)
+ final boolean applicationActivated = this.getSharedPreferences()
.getBoolean(this.getString(R.string.key_application_activated), false);
if (!applicationActivated)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld