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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 29 matching lines...) Expand all
40 40
41 public class MainPreferences extends PreferenceActivity implements 41 public class MainPreferences extends PreferenceActivity implements
42 EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceC hangeListener 42 EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceC hangeListener
43 { 43 {
44 private static final String TAG = MainPreferences.class.getSimpleName(); 44 private static final String TAG = MainPreferences.class.getSimpleName();
45 private static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; 45 private static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser";
46 private ProgressDialog progressDialog = null; 46 private ProgressDialog progressDialog = null;
47 private Engine engine = null; 47 private Engine engine = null;
48 private AlertDialog setupDialog = null; 48 private AlertDialog setupDialog = null;
49 49
50 private SharedPreferences getSharedPreferences()
51 {
52 return PreferenceManager.getDefaultSharedPreferences(this.getApplicationCont ext());
53 }
54
50 @Override 55 @Override
51 public void onCreate(Bundle savedInstanceState) 56 public void onCreate(Bundle savedInstanceState)
52 { 57 {
53 super.onCreate(savedInstanceState); 58 super.onCreate(savedInstanceState);
54 PreferenceManager.setDefaultValues(this, R.layout.preferences_main, false); 59 PreferenceManager.setDefaultValues(this, R.layout.preferences_main, false);
55 60
56 this.getFragmentManager() 61 this.getFragmentManager()
57 .beginTransaction() 62 .beginTransaction()
58 .replace(android.R.id.content, new Preferences()) 63 .replace(android.R.id.content, new Preferences())
59 .commit(); 64 .commit();
60 65
61 PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()) 66 // This try/catch block is a workaround for a preference mismatch
62 .registerOnSharedPreferenceChangeListener(this); 67 // issue. We check for a type mismatch in one particular key and,
68 // if there's a mismatch, clean sweep the preferences.
69 // See: https://issues.adblockplus.org/ticket/3931
70 try
Felix Dahlke 2016/04/26 17:39:10 What causes this issue? Did we change the type of
71 {
72 this.getSharedPreferences().getBoolean(
73 this.getString(R.string.key_application_activated),
74 false);
75 }
76 catch(final Throwable t)
77 {
78 this.getSharedPreferences()
79 .edit()
80 .clear()
81 .commit();
82 }
63 } 83 }
64 84
65 @Override 85 @Override
66 protected void onStart() 86 protected void onStart()
67 { 87 {
68 this.progressDialog = ProgressDialog.show(this, 88 this.progressDialog = ProgressDialog.show(this,
69 this.getString(R.string.initialization_title), 89 this.getString(R.string.initialization_title),
70 this.getString(R.string.initialization_message)); 90 this.getString(R.string.initialization_message));
71 super.onStart(); 91 super.onStart();
72 EngineService.startService(this, this); 92 this.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
93 EngineService.startService(this.getApplicationContext(), this);
73 } 94 }
74 95
75 @Override 96 @Override
76 protected void onStop() 97 protected void onStop()
77 { 98 {
78 super.onStop(); 99 super.onStop();
100 this.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this) ;
79 } 101 }
80 102
81 private void checkForCompatibleSBrowserAndProceed() 103 private void checkForCompatibleSBrowserAndProceed()
82 { 104 {
83 if (!Engine.hasCompatibleSBrowserInstalled(this.getApplicationContext())) 105 if (!Engine.hasCompatibleSBrowserInstalled(this.getApplicationContext()))
84 { 106 {
85 final AlertDialog d = new AlertDialog.Builder(this) 107 final AlertDialog d = new AlertDialog.Builder(this)
86 .setCancelable(false) 108 .setCancelable(false)
87 .setTitle(R.string.sbrowser_dialog_title) 109 .setTitle(R.string.sbrowser_dialog_title)
88 .setMessage(Html.fromHtml(this.readTextFile(R.raw.sbrowser_dialog))) 110 .setMessage(Html.fromHtml(this.readTextFile(R.raw.sbrowser_dialog)))
(...skipping 17 matching lines...) Expand all
106 d.show(); 128 d.show();
107 } 129 }
108 else 130 else
109 { 131 {
110 this.checkAAStatusAndProceed(); 132 this.checkAAStatusAndProceed();
111 } 133 }
112 } 134 }
113 135
114 private void checkAAStatusAndProceed() 136 private void checkAAStatusAndProceed()
115 { 137 {
116 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); 138 final SharedPreferences prefs = this.getSharedPreferences();
117 final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown); 139 final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown);
118 final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false); 140 final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false);
119 if (!aaInfoShown) 141 if (!aaInfoShown)
120 { 142 {
121 final AlertDialog d = new AlertDialog.Builder(this) 143 final AlertDialog d = new AlertDialog.Builder(this)
122 .setCancelable(false) 144 .setCancelable(false)
123 .setTitle(R.string.aa_dialog_title) 145 .setTitle(R.string.aa_dialog_title)
124 .setMessage(Html.fromHtml(this.readTextFile(R.raw.aa_dialog))) 146 .setMessage(Html.fromHtml(this.readTextFile(R.raw.aa_dialog)))
125 .setNeutralButton(R.string.aa_dialog_button, new OnClickListener() 147 .setNeutralButton(R.string.aa_dialog_button, new OnClickListener()
126 { 148 {
127 @Override 149 @Override
128 public void onClick(DialogInterface dialog, int which) 150 public void onClick(DialogInterface dialog, int which)
129 { 151 {
130 prefs.edit() 152 prefs.edit()
131 .putBoolean(keyAaInfoShown, true) 153 .putBoolean(keyAaInfoShown, true)
132 .commit(); 154 .commit();
133 MainPreferences.this.checkSetupStatus(); 155 MainPreferences.this.checkSetupStatus();
134 } 156 }
135 }).create(); 157 }).create();
136 d.show(); 158 d.show();
137 } 159 }
138 else 160 else
139 { 161 {
140 this.checkSetupStatus(); 162 this.checkSetupStatus();
141 } 163 }
142 } 164 }
143 165
144 private void checkSetupStatus() 166 private void checkSetupStatus()
145 { 167 {
146 final boolean applicationActivated = PreferenceManager.getDefaultSharedPrefe rences(this) 168 final boolean applicationActivated = this.getSharedPreferences()
147 .getBoolean(this.getString(R.string.key_application_activated), false); 169 .getBoolean(this.getString(R.string.key_application_activated), false);
148 170
149 if (!applicationActivated) 171 if (!applicationActivated)
150 { 172 {
151 Log.d(TAG, "Showing setup dialog"); 173 Log.d(TAG, "Showing setup dialog");
152 this.setupDialog = new AlertDialog.Builder(this) 174 this.setupDialog = new AlertDialog.Builder(this)
153 .setCancelable(false) 175 .setCancelable(false)
154 .setTitle(R.string.setup_dialog_title) 176 .setTitle(R.string.setup_dialog_title)
155 .setMessage(Html.fromHtml(this.readTextFile(R.raw.setup_dialog))) 177 .setMessage(Html.fromHtml(this.readTextFile(R.raw.setup_dialog)))
156 .setNeutralButton(R.string.setup_dialog_button, new OnClickListener() 178 .setNeutralButton(R.string.setup_dialog_button, new OnClickListener()
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 r.close(); 247 r.close();
226 } 248 }
227 } 249 }
228 catch (IOException e) 250 catch (IOException e)
229 { 251 {
230 Log.e(TAG, "Resource reading failed for: " + id, e); 252 Log.e(TAG, "Resource reading failed for: " + id, e);
231 return "..."; 253 return "...";
232 } 254 }
233 } 255 }
234 } 256 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld