blob: aa7e103325846c2a0122b4dd58d509c62e9f11c1 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -070019import com.google.android.providers.GoogleSettings.Partner;
20
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.ContentResolver;
22import android.content.Context;
23import android.content.pm.ActivityInfo;
24import android.content.SharedPreferences;
25import android.content.SharedPreferences.Editor;
Nicolas Roard78a98e42009-05-11 13:34:17 +010026import android.preference.PreferenceActivity;
27import android.preference.PreferenceScreen;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028import android.webkit.CookieManager;
29import android.webkit.WebView;
30import android.webkit.WebViewDatabase;
31import android.webkit.WebIconDatabase;
32import android.webkit.WebSettings;
Nicolas Roard78a98e42009-05-11 13:34:17 +010033import android.webkit.WebStorage;
The Android Open Source Project0c908882009-03-03 19:32:16 -080034import android.preference.PreferenceManager;
35import android.provider.Browser;
36
37import java.util.HashMap;
38import java.util.Observable;
39
40/*
41 * Package level class for storing various WebView and Browser settings. To use
42 * this class:
43 * BrowserSettings s = BrowserSettings.getInstance();
44 * s.addObserver(webView.getSettings());
45 * s.loadFromDb(context); // Only needed on app startup
46 * s.javaScriptEnabled = true;
47 * ... // set any other settings
48 * s.update(); // this will update all the observers
49 *
50 * To remove an observer:
51 * s.deleteObserver(webView.getSettings());
52 */
53class BrowserSettings extends Observable {
54
Leon Scroggins9ac587d2009-04-20 12:53:46 -040055 // Private variables for settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080056 // NOTE: these defaults need to be kept in sync with the XML
57 // until the performance of PreferenceManager.setDefaultValues()
58 // is improved.
59 private boolean loadsImagesAutomatically = true;
60 private boolean javaScriptEnabled = true;
61 private boolean pluginsEnabled = true;
62 private String pluginsPath; // default value set in loadFromDb().
63 private boolean javaScriptCanOpenWindowsAutomatically = false;
64 private boolean showSecurityWarnings = true;
65 private boolean rememberPasswords = true;
66 private boolean saveFormData = true;
67 private boolean openInBackground = false;
68 private String defaultTextEncodingName;
Grace Klobaf2c5c1b2009-05-26 10:48:31 -070069 private String homeUrl = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080070 private boolean loginInitialized = false;
71 private boolean autoFitPage = true;
Leon Scrogginsb0cd0722009-03-31 14:31:22 -070072 private boolean landscapeOnly = false;
The Android Open Source Project0c908882009-03-03 19:32:16 -080073 private boolean showDebugSettings = false;
Ben Murdoch092dd5d2009-04-22 12:34:12 +010074 private String databasePath; // default value set in loadFromDb()
75 private boolean databaseEnabled = true;
Nicolas Roard78a98e42009-05-11 13:34:17 +010076 private long webStorageDefaultQuota = 5 * 1024 * 1024;
Andrei Popescu5151ac12009-04-17 10:43:07 +010077 // The Browser always enables Application Caches.
78 private boolean appCacheEnabled = true;
79 private String appCachePath; // default value set in loadFromDb().
Ben Murdoch734a0662009-06-02 19:11:52 +010080 private boolean domStorageEnabled = true;
Feng Qianb3c02da2009-06-29 15:58:08 -070081 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080082
Nicolas Roard78a98e42009-05-11 13:34:17 +010083 private final static String TAG = "BrowserSettings";
84
The Android Open Source Project0c908882009-03-03 19:32:16 -080085 // Development settings
86 public WebSettings.LayoutAlgorithm layoutAlgorithm =
87 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
88 private boolean useWideViewPort = true;
89 private int userAgent = 0;
90 private boolean tracing = false;
91 private boolean lightTouch = false;
92 private boolean navDump = false;
Feng Qianb3c02da2009-06-29 15:58:08 -070093
The Android Open Source Project0c908882009-03-03 19:32:16 -080094 // Browser only settings
95 private boolean doFlick = false;
96
97 // Private preconfigured values
98 private static int minimumFontSize = 8;
99 private static int minimumLogicalFontSize = 8;
100 private static int defaultFontSize = 16;
101 private static int defaultFixedFontSize = 13;
102 private static WebSettings.TextSize textSize =
103 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700104 private static WebSettings.ZoomDensity zoomDensity =
105 WebSettings.ZoomDensity.MEDIUM;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800106
107 // Preference keys that are used outside this class
108 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
109 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
110 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
111 public final static String PREF_HOMEPAGE = "homepage";
112 public final static String PREF_CLEAR_FORM_DATA =
113 "privacy_clear_form_data";
114 public final static String PREF_CLEAR_PASSWORDS =
115 "privacy_clear_passwords";
Nicolas Roard78a98e42009-05-11 13:34:17 +0100116 public final static String PREF_DEFAULT_QUOTA =
117 "webstorage_default_quota";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800118 public final static String PREF_EXTRAS_RESET_DEFAULTS =
119 "reset_default_preferences";
120 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
121 public final static String PREF_GEARS_SETTINGS = "gears_settings";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100122 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800123 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700124 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800125 public final static String PREF_DEFAULT_TEXT_ENCODING =
126 "default_text_encoding";
127
128 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Grace Klobaa4fa6ee2009-06-26 00:34:46 -0700129 "U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, " +
130 "like Gecko) Version/4.0 Safari/530.17";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800131
132 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Grace Klobaa4fa6ee2009-06-26 00:34:46 -0700133 "CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 " +
134 "(KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135
136 // Value to truncate strings when adding them to a TextView within
137 // a ListView
138 public final static int MAX_TEXTVIEW_LEN = 80;
139
140 private TabControl mTabControl;
141
142 // Single instance of the BrowserSettings for use in the Browser app.
143 private static BrowserSettings sSingleton;
144
145 // Private map of WebSettings to Observer objects used when deleting an
146 // observer.
147 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
148 new HashMap<WebSettings,Observer>();
149
150 /*
151 * An observer wrapper for updating a WebSettings object with the new
152 * settings after a call to BrowserSettings.update().
153 */
154 static class Observer implements java.util.Observer {
155 // Private WebSettings object that will be updated.
156 private WebSettings mSettings;
157
158 Observer(WebSettings w) {
159 mSettings = w;
160 }
161
162 public void update(Observable o, Object arg) {
163 BrowserSettings b = (BrowserSettings)o;
164 WebSettings s = mSettings;
165
166 s.setLayoutAlgorithm(b.layoutAlgorithm);
167 if (b.userAgent == 0) {
168 // use the default ua string
169 s.setUserAgentString(null);
170 } else if (b.userAgent == 1) {
171 s.setUserAgentString(DESKTOP_USERAGENT);
172 } else if (b.userAgent == 2) {
173 s.setUserAgentString(IPHONE_USERAGENT);
174 }
175 s.setUseWideViewPort(b.useWideViewPort);
176 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
177 s.setJavaScriptEnabled(b.javaScriptEnabled);
178 s.setPluginsEnabled(b.pluginsEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800179 s.setJavaScriptCanOpenWindowsAutomatically(
180 b.javaScriptCanOpenWindowsAutomatically);
181 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
182 s.setMinimumFontSize(b.minimumFontSize);
183 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
184 s.setDefaultFontSize(b.defaultFontSize);
185 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
186 s.setNavDump(b.navDump);
187 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700188 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800189 s.setLightTouchEnabled(b.lightTouch);
190 s.setSaveFormData(b.saveFormData);
191 s.setSavePassword(b.rememberPasswords);
192
193 // WebView inside Browser doesn't want initial focus to be set.
194 s.setNeedInitialFocus(false);
195 // Browser supports multiple windows
196 s.setSupportMultipleWindows(true);
197 // Turn off file access
198 s.setAllowFileAccess(false);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100199
200 s.setDatabasePath(b.databasePath);
201 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100202 s.setDomStorageEnabled(b.domStorageEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100203 s.setWebStorageDefaultQuota(b.webStorageDefaultQuota);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100204
Andrei Popescu5151ac12009-04-17 10:43:07 +0100205 // Turn on Application Caches.
206 s.setAppCachePath(b.appCachePath);
207 s.setAppCacheEnabled(b.appCacheEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800208 }
209 }
210
211 /**
212 * Load settings from the browser app's database.
213 * NOTE: Strings used for the preferences must match those specified
214 * in the browser_preferences.xml
215 * @param ctx A Context object used to query the browser's settings
216 * database. If the database exists, the saved settings will be
217 * stored in this BrowserSettings object. This will update all
218 * observers of this object.
219 */
220 public void loadFromDb(Context ctx) {
221 SharedPreferences p =
222 PreferenceManager.getDefaultSharedPreferences(ctx);
223
224 // Set the default value for the plugins path to the application's
225 // local directory.
226 pluginsPath = ctx.getDir("plugins", 0).getPath();
Andrei Popescu5151ac12009-04-17 10:43:07 +0100227 // Set the default value for the Application Caches path.
228 appCachePath = ctx.getDir("appcache", 0).getPath();
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100229 // Set the default value for the Database path.
230 databasePath = ctx.getDir("databases", 0).getPath();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800231
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700232 homeUrl = getFactoryResetHomeUrl(ctx);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700233
The Android Open Source Project0c908882009-03-03 19:32:16 -0800234 // Load the defaults from the xml
235 // This call is TOO SLOW, need to manually keep the defaults
236 // in sync
237 //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences);
238 syncSharedPreferences(p);
239 }
240
241 /* package */ void syncSharedPreferences(SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700242
The Android Open Source Project0c908882009-03-03 19:32:16 -0800243 homeUrl =
244 p.getString(PREF_HOMEPAGE, homeUrl);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700245
The Android Open Source Project0c908882009-03-03 19:32:16 -0800246 loadsImagesAutomatically = p.getBoolean("load_images",
247 loadsImagesAutomatically);
248 javaScriptEnabled = p.getBoolean("enable_javascript",
249 javaScriptEnabled);
250 pluginsEnabled = p.getBoolean("enable_plugins",
251 pluginsEnabled);
252 pluginsPath = p.getString("plugins_path", pluginsPath);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100253 databasePath = p.getString("database_path", databasePath);
254 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100255 webStorageDefaultQuota = Long.parseLong(p.getString(PREF_DEFAULT_QUOTA,
256 String.valueOf(webStorageDefaultQuota)));
Andrei Popescu5151ac12009-04-17 10:43:07 +0100257 appCacheEnabled = p.getBoolean("enable_appcache",
Ben Murdoch734a0662009-06-02 19:11:52 +0100258 appCacheEnabled);
259 domStorageEnabled = p.getBoolean("enable_domstorage",
260 domStorageEnabled);
Andrei Popescu5151ac12009-04-17 10:43:07 +0100261 appCachePath = p.getString("appcache_path", appCachePath);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800262 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
263 "block_popup_windows",
264 !javaScriptCanOpenWindowsAutomatically);
265 showSecurityWarnings = p.getBoolean("show_security_warnings",
266 showSecurityWarnings);
267 rememberPasswords = p.getBoolean("remember_passwords",
268 rememberPasswords);
269 saveFormData = p.getBoolean("save_formdata",
270 saveFormData);
271 boolean accept_cookies = p.getBoolean("accept_cookies",
272 CookieManager.getInstance().acceptCookie());
273 CookieManager.getInstance().setAcceptCookie(accept_cookies);
274 openInBackground = p.getBoolean("open_in_background", openInBackground);
275 loginInitialized = p.getBoolean("login_initialized", loginInitialized);
276 textSize = WebSettings.TextSize.valueOf(
277 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700278 zoomDensity = WebSettings.ZoomDensity.valueOf(
279 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800280 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Leon Scrogginsb0cd0722009-03-31 14:31:22 -0700281 boolean landscapeOnlyTemp =
282 p.getBoolean("landscape_only", landscapeOnly);
283 if (landscapeOnlyTemp != landscapeOnly) {
284 landscapeOnly = landscapeOnlyTemp;
285 mTabControl.getBrowserActivity().setRequestedOrientation(
286 landscapeOnly ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
287 : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
288 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800289 useWideViewPort = true; // use wide view port for either setting
290 if (autoFitPage) {
291 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
292 } else {
293 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
294 }
295 defaultTextEncodingName =
296 p.getString(PREF_DEFAULT_TEXT_ENCODING,
297 defaultTextEncodingName);
298
299 showDebugSettings =
300 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
301 // Debug menu items have precidence if the menu is visible
302 if (showDebugSettings) {
303 boolean small_screen = p.getBoolean("small_screen",
304 layoutAlgorithm ==
305 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
306 if (small_screen) {
307 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
308 } else {
309 boolean normal_layout = p.getBoolean("normal_layout",
310 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
311 if (normal_layout) {
312 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
313 } else {
314 layoutAlgorithm =
315 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
316 }
317 }
318 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
319 tracing = p.getBoolean("enable_tracing", tracing);
320 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
321 navDump = p.getBoolean("enable_nav_dump", navDump);
322 doFlick = p.getBoolean("enable_flick", doFlick);
323 userAgent = Integer.parseInt(p.getString("user_agent", "0"));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800324 }
Feng Qianb3c02da2009-06-29 15:58:08 -0700325 // JS flags is loaded from DB even if showDebugSettings is false,
326 // so that it can be set once and be effective all the time.
327 jsFlags = p.getString("js_engine_flags", "");
The Android Open Source Project0c908882009-03-03 19:32:16 -0800328 }
329
330 public String getPluginsPath() {
331 return pluginsPath;
332 }
333
334 public String getHomePage() {
335 return homeUrl;
336 }
337
Feng Qianb3c02da2009-06-29 15:58:08 -0700338 public String getJsFlags() {
339 return jsFlags;
340 }
341
The Android Open Source Project0c908882009-03-03 19:32:16 -0800342 public void setHomePage(Context context, String url) {
343 Editor ed = PreferenceManager.
344 getDefaultSharedPreferences(context).edit();
345 ed.putString(PREF_HOMEPAGE, url);
346 ed.commit();
347 homeUrl = url;
348 }
349
350 public boolean isLoginInitialized() {
351 return loginInitialized;
352 }
353
354 public void setLoginInitialized(Context context) {
355 loginInitialized = true;
356 Editor ed = PreferenceManager.
357 getDefaultSharedPreferences(context).edit();
358 ed.putBoolean("login_initialized", loginInitialized);
359 ed.commit();
360 }
361
362 public WebSettings.TextSize getTextSize() {
363 return textSize;
364 }
365
Grace Kloba2f830682009-06-25 11:08:53 -0700366 public WebSettings.ZoomDensity getDefaultZoom() {
367 return zoomDensity;
368 }
369
The Android Open Source Project0c908882009-03-03 19:32:16 -0800370 public boolean openInBackground() {
371 return openInBackground;
372 }
373
374 public boolean showSecurityWarnings() {
375 return showSecurityWarnings;
376 }
377
378 public boolean isTracing() {
379 return tracing;
380 }
381
382 public boolean isLightTouch() {
383 return lightTouch;
384 }
385
386 public boolean isNavDump() {
387 return navDump;
388 }
389
390 public boolean doFlick() {
391 return doFlick;
392 }
393
394 public boolean showDebugSettings() {
395 return showDebugSettings;
396 }
397
398 public void toggleDebugSettings() {
399 showDebugSettings = !showDebugSettings;
400 navDump = showDebugSettings;
401 update();
402 }
403
404 /**
405 * Add a WebSettings object to the list of observers that will be updated
406 * when update() is called.
407 *
408 * @param s A WebSettings object that is strictly tied to the life of a
409 * WebView.
410 */
411 public Observer addObserver(WebSettings s) {
412 Observer old = mWebSettingsToObservers.get(s);
413 if (old != null) {
414 super.deleteObserver(old);
415 }
416 Observer o = new Observer(s);
417 mWebSettingsToObservers.put(s, o);
418 super.addObserver(o);
419 return o;
420 }
421
422 /**
423 * Delete the given WebSettings observer from the list of observers.
424 * @param s The WebSettings object to be deleted.
425 */
426 public void deleteObserver(WebSettings s) {
427 Observer o = mWebSettingsToObservers.get(s);
428 if (o != null) {
429 mWebSettingsToObservers.remove(s);
430 super.deleteObserver(o);
431 }
432 }
433
434 /*
435 * Package level method for obtaining a single app instance of the
436 * BrowserSettings.
437 */
438 /*package*/ static BrowserSettings getInstance() {
439 if (sSingleton == null ) {
440 sSingleton = new BrowserSettings();
441 }
442 return sSingleton;
443 }
444
445 /*
446 * Package level method for associating the BrowserSettings with TabControl
447 */
448 /* package */void setTabControl(TabControl tabControl) {
449 mTabControl = tabControl;
450 }
451
452 /*
453 * Update all the observers of the object.
454 */
455 /*package*/ void update() {
456 setChanged();
457 notifyObservers();
458 }
459
460 /*package*/ void clearCache(Context context) {
461 WebIconDatabase.getInstance().removeAllIcons();
462 if (mTabControl != null) {
463 WebView current = mTabControl.getCurrentWebView();
464 if (current != null) {
465 current.clearCache(true);
466 }
467 }
468 }
469
470 /*package*/ void clearCookies(Context context) {
471 CookieManager.getInstance().removeAllCookie();
472 }
473
474 /* package */void clearHistory(Context context) {
475 ContentResolver resolver = context.getContentResolver();
476 Browser.clearHistory(resolver);
477 Browser.clearSearches(resolver);
478 }
479
480 /* package */ void clearFormData(Context context) {
481 WebViewDatabase.getInstance(context).clearFormData();
482 if (mTabControl != null) {
483 mTabControl.getCurrentTopWebView().clearFormData();
484 }
485 }
486
487 /*package*/ void clearPasswords(Context context) {
488 WebViewDatabase db = WebViewDatabase.getInstance(context);
489 db.clearUsernamePassword();
490 db.clearHttpAuthUsernamePassword();
491 }
492
Nicolas Roard78a98e42009-05-11 13:34:17 +0100493 /*package*/ void clearDatabases(Context context) {
494 WebStorage.getInstance().deleteAllDatabases();
495 // Remove all listed databases from the preferences
496 PreferenceActivity activity = (PreferenceActivity) context;
497 PreferenceScreen screen = (PreferenceScreen)
Nicolas Roarde46990e2009-06-19 16:27:49 +0100498 activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100499 screen.removeAll();
Nicolas Roard6f480422009-05-12 16:31:33 +0100500 screen.setEnabled(false);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100501 }
502
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400503 /*package*/ void resetDefaultPreferences(Context ctx) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800504 SharedPreferences p =
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400505 PreferenceManager.getDefaultSharedPreferences(ctx);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800506 p.edit().clear().commit();
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400507 PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences,
The Android Open Source Project0c908882009-03-03 19:32:16 -0800508 true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700509 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700510 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700511 }
512
513 private String getFactoryResetHomeUrl(Context context) {
514 String url = context.getResources().getString(R.string.homepage_base);
515 if (url.indexOf("{CID}") != -1) {
516 url = url.replace("{CID}", Partner.getString(context
Ramanan Rajeswaran9768ac52009-06-03 19:34:58 -0700517 .getContentResolver(), Partner.CLIENT_ID, "android-google"));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700518 }
519 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800520 }
521
522 // Private constructor that does nothing.
523 private BrowserSettings() {
524 }
525}