blob: 762149ba7fd1008038c865535c25deff68963282 [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.app.Activity;
22import android.content.ContentResolver;
23import android.content.Context;
24import android.content.pm.ActivityInfo;
25import android.content.SharedPreferences;
26import android.content.SharedPreferences.Editor;
27import android.os.SystemProperties;
Nicolas Roard78a98e42009-05-11 13:34:17 +010028import android.preference.PreferenceActivity;
29import android.preference.PreferenceScreen;
30import android.util.Log;
The Android Open Source Project0c908882009-03-03 19:32:16 -080031import android.view.WindowManager;
32import android.webkit.CacheManager;
33import android.webkit.CookieManager;
34import android.webkit.WebView;
35import android.webkit.WebViewDatabase;
36import android.webkit.WebIconDatabase;
37import android.webkit.WebSettings;
Nicolas Roard78a98e42009-05-11 13:34:17 +010038import android.webkit.WebStorage;
The Android Open Source Project0c908882009-03-03 19:32:16 -080039import android.preference.PreferenceManager;
40import android.provider.Browser;
41
42import java.util.HashMap;
43import java.util.Observable;
44
45/*
46 * Package level class for storing various WebView and Browser settings. To use
47 * this class:
48 * BrowserSettings s = BrowserSettings.getInstance();
49 * s.addObserver(webView.getSettings());
50 * s.loadFromDb(context); // Only needed on app startup
51 * s.javaScriptEnabled = true;
52 * ... // set any other settings
53 * s.update(); // this will update all the observers
54 *
55 * To remove an observer:
56 * s.deleteObserver(webView.getSettings());
57 */
58class BrowserSettings extends Observable {
59
Leon Scroggins9ac587d2009-04-20 12:53:46 -040060 // Private variables for settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080061 // NOTE: these defaults need to be kept in sync with the XML
62 // until the performance of PreferenceManager.setDefaultValues()
63 // is improved.
64 private boolean loadsImagesAutomatically = true;
65 private boolean javaScriptEnabled = true;
66 private boolean pluginsEnabled = true;
67 private String pluginsPath; // default value set in loadFromDb().
68 private boolean javaScriptCanOpenWindowsAutomatically = false;
69 private boolean showSecurityWarnings = true;
70 private boolean rememberPasswords = true;
71 private boolean saveFormData = true;
72 private boolean openInBackground = false;
73 private String defaultTextEncodingName;
Grace Klobaf2c5c1b2009-05-26 10:48:31 -070074 private String homeUrl = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080075 private boolean loginInitialized = false;
76 private boolean autoFitPage = true;
Leon Scrogginsb0cd0722009-03-31 14:31:22 -070077 private boolean landscapeOnly = false;
The Android Open Source Project0c908882009-03-03 19:32:16 -080078 private boolean showDebugSettings = false;
Ben Murdoch092dd5d2009-04-22 12:34:12 +010079 private String databasePath; // default value set in loadFromDb()
80 private boolean databaseEnabled = true;
Nicolas Roard78a98e42009-05-11 13:34:17 +010081 private long webStorageDefaultQuota = 5 * 1024 * 1024;
Andrei Popescu5151ac12009-04-17 10:43:07 +010082 // The Browser always enables Application Caches.
83 private boolean appCacheEnabled = true;
84 private String appCachePath; // default value set in loadFromDb().
Ben Murdoch734a0662009-06-02 19:11:52 +010085 private boolean domStorageEnabled = true;
Feng Qianb3c02da2009-06-29 15:58:08 -070086 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080087
Nicolas Roard78a98e42009-05-11 13:34:17 +010088 private final static String TAG = "BrowserSettings";
89
The Android Open Source Project0c908882009-03-03 19:32:16 -080090 // Development settings
91 public WebSettings.LayoutAlgorithm layoutAlgorithm =
92 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
93 private boolean useWideViewPort = true;
94 private int userAgent = 0;
95 private boolean tracing = false;
96 private boolean lightTouch = false;
97 private boolean navDump = false;
Feng Qianb3c02da2009-06-29 15:58:08 -070098
The Android Open Source Project0c908882009-03-03 19:32:16 -080099 // Browser only settings
100 private boolean doFlick = false;
101
102 // Private preconfigured values
103 private static int minimumFontSize = 8;
104 private static int minimumLogicalFontSize = 8;
105 private static int defaultFontSize = 16;
106 private static int defaultFixedFontSize = 13;
107 private static WebSettings.TextSize textSize =
108 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700109 private static WebSettings.ZoomDensity zoomDensity =
110 WebSettings.ZoomDensity.MEDIUM;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800111
112 // Preference keys that are used outside this class
113 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
114 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
115 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
116 public final static String PREF_HOMEPAGE = "homepage";
117 public final static String PREF_CLEAR_FORM_DATA =
118 "privacy_clear_form_data";
119 public final static String PREF_CLEAR_PASSWORDS =
120 "privacy_clear_passwords";
Nicolas Roard78a98e42009-05-11 13:34:17 +0100121 public final static String PREF_DEFAULT_QUOTA =
122 "webstorage_default_quota";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800123 public final static String PREF_EXTRAS_RESET_DEFAULTS =
124 "reset_default_preferences";
125 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
126 public final static String PREF_GEARS_SETTINGS = "gears_settings";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100127 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800128 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700129 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800130 public final static String PREF_DEFAULT_TEXT_ENCODING =
131 "default_text_encoding";
132
133 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Grace Klobaa4fa6ee2009-06-26 00:34:46 -0700134 "U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, " +
135 "like Gecko) Version/4.0 Safari/530.17";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800136
137 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Grace Klobaa4fa6ee2009-06-26 00:34:46 -0700138 "CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 " +
139 "(KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800140
141 // Value to truncate strings when adding them to a TextView within
142 // a ListView
143 public final static int MAX_TEXTVIEW_LEN = 80;
144
145 private TabControl mTabControl;
146
147 // Single instance of the BrowserSettings for use in the Browser app.
148 private static BrowserSettings sSingleton;
149
150 // Private map of WebSettings to Observer objects used when deleting an
151 // observer.
152 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
153 new HashMap<WebSettings,Observer>();
154
155 /*
156 * An observer wrapper for updating a WebSettings object with the new
157 * settings after a call to BrowserSettings.update().
158 */
159 static class Observer implements java.util.Observer {
160 // Private WebSettings object that will be updated.
161 private WebSettings mSettings;
162
163 Observer(WebSettings w) {
164 mSettings = w;
165 }
166
167 public void update(Observable o, Object arg) {
168 BrowserSettings b = (BrowserSettings)o;
169 WebSettings s = mSettings;
170
171 s.setLayoutAlgorithm(b.layoutAlgorithm);
172 if (b.userAgent == 0) {
173 // use the default ua string
174 s.setUserAgentString(null);
175 } else if (b.userAgent == 1) {
176 s.setUserAgentString(DESKTOP_USERAGENT);
177 } else if (b.userAgent == 2) {
178 s.setUserAgentString(IPHONE_USERAGENT);
179 }
180 s.setUseWideViewPort(b.useWideViewPort);
181 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
182 s.setJavaScriptEnabled(b.javaScriptEnabled);
183 s.setPluginsEnabled(b.pluginsEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800184 s.setJavaScriptCanOpenWindowsAutomatically(
185 b.javaScriptCanOpenWindowsAutomatically);
186 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
187 s.setMinimumFontSize(b.minimumFontSize);
188 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
189 s.setDefaultFontSize(b.defaultFontSize);
190 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
191 s.setNavDump(b.navDump);
192 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700193 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800194 s.setLightTouchEnabled(b.lightTouch);
195 s.setSaveFormData(b.saveFormData);
196 s.setSavePassword(b.rememberPasswords);
197
198 // WebView inside Browser doesn't want initial focus to be set.
199 s.setNeedInitialFocus(false);
200 // Browser supports multiple windows
201 s.setSupportMultipleWindows(true);
202 // Turn off file access
203 s.setAllowFileAccess(false);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100204
205 s.setDatabasePath(b.databasePath);
206 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100207 s.setDomStorageEnabled(b.domStorageEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100208 s.setWebStorageDefaultQuota(b.webStorageDefaultQuota);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100209
Andrei Popescu5151ac12009-04-17 10:43:07 +0100210 // Turn on Application Caches.
211 s.setAppCachePath(b.appCachePath);
212 s.setAppCacheEnabled(b.appCacheEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800213 }
214 }
215
216 /**
217 * Load settings from the browser app's database.
218 * NOTE: Strings used for the preferences must match those specified
219 * in the browser_preferences.xml
220 * @param ctx A Context object used to query the browser's settings
221 * database. If the database exists, the saved settings will be
222 * stored in this BrowserSettings object. This will update all
223 * observers of this object.
224 */
225 public void loadFromDb(Context ctx) {
226 SharedPreferences p =
227 PreferenceManager.getDefaultSharedPreferences(ctx);
228
229 // Set the default value for the plugins path to the application's
230 // local directory.
231 pluginsPath = ctx.getDir("plugins", 0).getPath();
Andrei Popescu5151ac12009-04-17 10:43:07 +0100232 // Set the default value for the Application Caches path.
233 appCachePath = ctx.getDir("appcache", 0).getPath();
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100234 // Set the default value for the Database path.
235 databasePath = ctx.getDir("databases", 0).getPath();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800236
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700237 homeUrl = getFactoryResetHomeUrl(ctx);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700238
The Android Open Source Project0c908882009-03-03 19:32:16 -0800239 // Load the defaults from the xml
240 // This call is TOO SLOW, need to manually keep the defaults
241 // in sync
242 //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences);
243 syncSharedPreferences(p);
244 }
245
246 /* package */ void syncSharedPreferences(SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700247
The Android Open Source Project0c908882009-03-03 19:32:16 -0800248 homeUrl =
249 p.getString(PREF_HOMEPAGE, homeUrl);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700250
The Android Open Source Project0c908882009-03-03 19:32:16 -0800251 loadsImagesAutomatically = p.getBoolean("load_images",
252 loadsImagesAutomatically);
253 javaScriptEnabled = p.getBoolean("enable_javascript",
254 javaScriptEnabled);
255 pluginsEnabled = p.getBoolean("enable_plugins",
256 pluginsEnabled);
257 pluginsPath = p.getString("plugins_path", pluginsPath);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100258 databasePath = p.getString("database_path", databasePath);
259 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100260 webStorageDefaultQuota = Long.parseLong(p.getString(PREF_DEFAULT_QUOTA,
261 String.valueOf(webStorageDefaultQuota)));
Andrei Popescu5151ac12009-04-17 10:43:07 +0100262 appCacheEnabled = p.getBoolean("enable_appcache",
Ben Murdoch734a0662009-06-02 19:11:52 +0100263 appCacheEnabled);
264 domStorageEnabled = p.getBoolean("enable_domstorage",
265 domStorageEnabled);
Andrei Popescu5151ac12009-04-17 10:43:07 +0100266 appCachePath = p.getString("appcache_path", appCachePath);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800267 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
268 "block_popup_windows",
269 !javaScriptCanOpenWindowsAutomatically);
270 showSecurityWarnings = p.getBoolean("show_security_warnings",
271 showSecurityWarnings);
272 rememberPasswords = p.getBoolean("remember_passwords",
273 rememberPasswords);
274 saveFormData = p.getBoolean("save_formdata",
275 saveFormData);
276 boolean accept_cookies = p.getBoolean("accept_cookies",
277 CookieManager.getInstance().acceptCookie());
278 CookieManager.getInstance().setAcceptCookie(accept_cookies);
279 openInBackground = p.getBoolean("open_in_background", openInBackground);
280 loginInitialized = p.getBoolean("login_initialized", loginInitialized);
281 textSize = WebSettings.TextSize.valueOf(
282 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700283 zoomDensity = WebSettings.ZoomDensity.valueOf(
284 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800285 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Leon Scrogginsb0cd0722009-03-31 14:31:22 -0700286 boolean landscapeOnlyTemp =
287 p.getBoolean("landscape_only", landscapeOnly);
288 if (landscapeOnlyTemp != landscapeOnly) {
289 landscapeOnly = landscapeOnlyTemp;
290 mTabControl.getBrowserActivity().setRequestedOrientation(
291 landscapeOnly ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
292 : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
293 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800294 useWideViewPort = true; // use wide view port for either setting
295 if (autoFitPage) {
296 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
297 } else {
298 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
299 }
300 defaultTextEncodingName =
301 p.getString(PREF_DEFAULT_TEXT_ENCODING,
302 defaultTextEncodingName);
303
304 showDebugSettings =
305 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
306 // Debug menu items have precidence if the menu is visible
307 if (showDebugSettings) {
308 boolean small_screen = p.getBoolean("small_screen",
309 layoutAlgorithm ==
310 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
311 if (small_screen) {
312 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
313 } else {
314 boolean normal_layout = p.getBoolean("normal_layout",
315 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
316 if (normal_layout) {
317 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
318 } else {
319 layoutAlgorithm =
320 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
321 }
322 }
323 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
324 tracing = p.getBoolean("enable_tracing", tracing);
325 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
326 navDump = p.getBoolean("enable_nav_dump", navDump);
327 doFlick = p.getBoolean("enable_flick", doFlick);
328 userAgent = Integer.parseInt(p.getString("user_agent", "0"));
329 mTabControl.getBrowserActivity().setBaseSearchUrl(
330 p.getString("search_url", ""));
331 }
Feng Qianb3c02da2009-06-29 15:58:08 -0700332 // JS flags is loaded from DB even if showDebugSettings is false,
333 // so that it can be set once and be effective all the time.
334 jsFlags = p.getString("js_engine_flags", "");
The Android Open Source Project0c908882009-03-03 19:32:16 -0800335 }
336
337 public String getPluginsPath() {
338 return pluginsPath;
339 }
340
341 public String getHomePage() {
342 return homeUrl;
343 }
344
Feng Qianb3c02da2009-06-29 15:58:08 -0700345 public String getJsFlags() {
346 return jsFlags;
347 }
348
The Android Open Source Project0c908882009-03-03 19:32:16 -0800349 public void setHomePage(Context context, String url) {
350 Editor ed = PreferenceManager.
351 getDefaultSharedPreferences(context).edit();
352 ed.putString(PREF_HOMEPAGE, url);
353 ed.commit();
354 homeUrl = url;
355 }
356
357 public boolean isLoginInitialized() {
358 return loginInitialized;
359 }
360
361 public void setLoginInitialized(Context context) {
362 loginInitialized = true;
363 Editor ed = PreferenceManager.
364 getDefaultSharedPreferences(context).edit();
365 ed.putBoolean("login_initialized", loginInitialized);
366 ed.commit();
367 }
368
369 public WebSettings.TextSize getTextSize() {
370 return textSize;
371 }
372
Grace Kloba2f830682009-06-25 11:08:53 -0700373 public WebSettings.ZoomDensity getDefaultZoom() {
374 return zoomDensity;
375 }
376
The Android Open Source Project0c908882009-03-03 19:32:16 -0800377 public boolean openInBackground() {
378 return openInBackground;
379 }
380
381 public boolean showSecurityWarnings() {
382 return showSecurityWarnings;
383 }
384
385 public boolean isTracing() {
386 return tracing;
387 }
388
389 public boolean isLightTouch() {
390 return lightTouch;
391 }
392
393 public boolean isNavDump() {
394 return navDump;
395 }
396
397 public boolean doFlick() {
398 return doFlick;
399 }
400
401 public boolean showDebugSettings() {
402 return showDebugSettings;
403 }
404
405 public void toggleDebugSettings() {
406 showDebugSettings = !showDebugSettings;
407 navDump = showDebugSettings;
408 update();
409 }
410
411 /**
412 * Add a WebSettings object to the list of observers that will be updated
413 * when update() is called.
414 *
415 * @param s A WebSettings object that is strictly tied to the life of a
416 * WebView.
417 */
418 public Observer addObserver(WebSettings s) {
419 Observer old = mWebSettingsToObservers.get(s);
420 if (old != null) {
421 super.deleteObserver(old);
422 }
423 Observer o = new Observer(s);
424 mWebSettingsToObservers.put(s, o);
425 super.addObserver(o);
426 return o;
427 }
428
429 /**
430 * Delete the given WebSettings observer from the list of observers.
431 * @param s The WebSettings object to be deleted.
432 */
433 public void deleteObserver(WebSettings s) {
434 Observer o = mWebSettingsToObservers.get(s);
435 if (o != null) {
436 mWebSettingsToObservers.remove(s);
437 super.deleteObserver(o);
438 }
439 }
440
441 /*
442 * Package level method for obtaining a single app instance of the
443 * BrowserSettings.
444 */
445 /*package*/ static BrowserSettings getInstance() {
446 if (sSingleton == null ) {
447 sSingleton = new BrowserSettings();
448 }
449 return sSingleton;
450 }
451
452 /*
453 * Package level method for associating the BrowserSettings with TabControl
454 */
455 /* package */void setTabControl(TabControl tabControl) {
456 mTabControl = tabControl;
457 }
458
459 /*
460 * Update all the observers of the object.
461 */
462 /*package*/ void update() {
463 setChanged();
464 notifyObservers();
465 }
466
467 /*package*/ void clearCache(Context context) {
468 WebIconDatabase.getInstance().removeAllIcons();
469 if (mTabControl != null) {
470 WebView current = mTabControl.getCurrentWebView();
471 if (current != null) {
472 current.clearCache(true);
473 }
474 }
475 }
476
477 /*package*/ void clearCookies(Context context) {
478 CookieManager.getInstance().removeAllCookie();
479 }
480
481 /* package */void clearHistory(Context context) {
482 ContentResolver resolver = context.getContentResolver();
483 Browser.clearHistory(resolver);
484 Browser.clearSearches(resolver);
485 }
486
487 /* package */ void clearFormData(Context context) {
488 WebViewDatabase.getInstance(context).clearFormData();
489 if (mTabControl != null) {
490 mTabControl.getCurrentTopWebView().clearFormData();
491 }
492 }
493
494 /*package*/ void clearPasswords(Context context) {
495 WebViewDatabase db = WebViewDatabase.getInstance(context);
496 db.clearUsernamePassword();
497 db.clearHttpAuthUsernamePassword();
498 }
499
Nicolas Roard78a98e42009-05-11 13:34:17 +0100500 /*package*/ void clearDatabases(Context context) {
501 WebStorage.getInstance().deleteAllDatabases();
502 // Remove all listed databases from the preferences
503 PreferenceActivity activity = (PreferenceActivity) context;
504 PreferenceScreen screen = (PreferenceScreen)
Nicolas Roarde46990e2009-06-19 16:27:49 +0100505 activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100506 screen.removeAll();
Nicolas Roard6f480422009-05-12 16:31:33 +0100507 screen.setEnabled(false);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100508 }
509
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400510 /*package*/ void resetDefaultPreferences(Context ctx) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800511 SharedPreferences p =
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400512 PreferenceManager.getDefaultSharedPreferences(ctx);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800513 p.edit().clear().commit();
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400514 PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences,
The Android Open Source Project0c908882009-03-03 19:32:16 -0800515 true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700516 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700517 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700518 }
519
520 private String getFactoryResetHomeUrl(Context context) {
521 String url = context.getResources().getString(R.string.homepage_base);
522 if (url.indexOf("{CID}") != -1) {
523 url = url.replace("{CID}", Partner.getString(context
Ramanan Rajeswaran9768ac52009-06-03 19:34:58 -0700524 .getContentResolver(), Partner.CLIENT_ID, "android-google"));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700525 }
526 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800527 }
528
529 // Private constructor that does nothing.
530 private BrowserSettings() {
531 }
532}