blob: 1f091e2151fa720d964a42d42470c368697f74d0 [file] [log] [blame]
Cary Clarkf2407c62009-09-04 12:25:10 -04001
The Android Open Source Project0c908882009-03-03 19:32:16 -08002/*
3 * Copyright (C) 2007 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.browser;
19
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010020import com.android.browser.search.SearchEngine;
21import com.android.browser.search.SearchEngines;
22
Grace Kloba9804c432009-12-02 11:07:40 -080023import android.app.ActivityManager;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010024import android.content.ComponentName;
The Android Open Source Project0c908882009-03-03 19:32:16 -080025import android.content.ContentResolver;
26import android.content.Context;
John Reck63bb6872010-12-01 19:29:32 -080027import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028import android.content.pm.ActivityInfo;
29import android.content.SharedPreferences;
30import android.content.SharedPreferences.Editor;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010031import android.database.ContentObserver;
Ben Murdoch0cb81892010-10-08 12:41:33 +010032import android.database.Cursor;
Jeff Davidson43610292010-07-16 16:03:58 -070033import android.net.Uri;
Ben Murdoch0cb81892010-10-08 12:41:33 +010034import android.os.AsyncTask;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010035import android.os.Handler;
Ben Murdoch23da30e2010-10-26 15:18:44 +010036import android.os.Message;
Nicolas Roard78a98e42009-05-11 13:34:17 +010037import android.preference.PreferenceActivity;
Ben Murdoch0cb81892010-10-08 12:41:33 +010038import android.preference.PreferenceManager;
Nicolas Roard78a98e42009-05-11 13:34:17 +010039import android.preference.PreferenceScreen;
Ben Murdoch0cb81892010-10-08 12:41:33 +010040import android.provider.Browser;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010041import android.provider.Settings;
42import android.util.Log;
The Android Open Source Project0c908882009-03-03 19:32:16 -080043import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010044import android.webkit.GeolocationPermissions;
Nicolas Roard99b3ae12009-09-22 15:17:52 +010045import android.webkit.ValueCallback;
The Android Open Source Project0c908882009-03-03 19:32:16 -080046import android.webkit.WebView;
47import android.webkit.WebViewDatabase;
48import android.webkit.WebIconDatabase;
49import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010050import android.webkit.WebSettings.AutoFillProfile;
Nicolas Roard78a98e42009-05-11 13:34:17 +010051import android.webkit.WebStorage;
Ben Murdoch0cb81892010-10-08 12:41:33 +010052import android.widget.Toast;
The Android Open Source Project0c908882009-03-03 19:32:16 -080053
54import java.util.HashMap;
Nicolas Roard99b3ae12009-09-22 15:17:52 +010055import java.util.Map;
56import java.util.Set;
The Android Open Source Project0c908882009-03-03 19:32:16 -080057import java.util.Observable;
58
59/*
60 * Package level class for storing various WebView and Browser settings. To use
61 * this class:
62 * BrowserSettings s = BrowserSettings.getInstance();
63 * s.addObserver(webView.getSettings());
64 * s.loadFromDb(context); // Only needed on app startup
65 * s.javaScriptEnabled = true;
66 * ... // set any other settings
67 * s.update(); // this will update all the observers
68 *
69 * To remove an observer:
70 * s.deleteObserver(webView.getSettings());
71 */
John Reck63bb6872010-12-01 19:29:32 -080072public class BrowserSettings extends Observable implements OnSharedPreferenceChangeListener {
Leon Scroggins9ac587d2009-04-20 12:53:46 -040073 // Private variables for settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080074 // NOTE: these defaults need to be kept in sync with the XML
75 // until the performance of PreferenceManager.setDefaultValues()
76 // is improved.
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080077 // Note: boolean variables are set inside reset function.
78 private boolean loadsImagesAutomatically;
79 private boolean javaScriptEnabled;
Patrick Scotte536b332010-03-22 10:19:32 -040080 private WebSettings.PluginState pluginState;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080081 private boolean javaScriptCanOpenWindowsAutomatically;
82 private boolean showSecurityWarnings;
83 private boolean rememberPasswords;
84 private boolean saveFormData;
Ben Murdochce549fc2010-09-09 10:28:08 +010085 private boolean autoFillEnabled;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080086 private boolean openInBackground;
The Android Open Source Project0c908882009-03-03 19:32:16 -080087 private String defaultTextEncodingName;
Grace Klobaf2c5c1b2009-05-26 10:48:31 -070088 private String homeUrl = "";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010089 private SearchEngine searchEngine;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080090 private boolean autoFitPage;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080091 private boolean loadsPageInOverviewMode;
92 private boolean showDebugSettings;
Andrei Popescu01068702009-08-03 16:03:24 +010093 // HTML5 API flags
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080094 private boolean appCacheEnabled;
95 private boolean databaseEnabled;
96 private boolean domStorageEnabled;
97 private boolean geolocationEnabled;
98 private boolean workersEnabled; // only affects V8. JSC does not have a similar setting
Andrei Popescu01068702009-08-03 16:03:24 +010099 // HTML5 API configuration params
100 private long appCacheMaxSize = Long.MAX_VALUE;
101 private String appCachePath; // default value set in loadFromDb().
102 private String databasePath; // default value set in loadFromDb()
Steve Block5029cf02009-08-21 13:16:58 +0100103 private String geolocationDatabasePath; // default value set in loadFromDb()
Andrei Popescu01068702009-08-03 16:03:24 +0100104 private WebStorageSizeManager webStorageSizeManager;
105
106 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800107
Nicolas Roard78a98e42009-05-11 13:34:17 +0100108 private final static String TAG = "BrowserSettings";
109
The Android Open Source Project0c908882009-03-03 19:32:16 -0800110 // Development settings
111 public WebSettings.LayoutAlgorithm layoutAlgorithm =
112 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
113 private boolean useWideViewPort = true;
114 private int userAgent = 0;
115 private boolean tracing = false;
116 private boolean lightTouch = false;
117 private boolean navDump = false;
Derek Sollenberger8de82852010-11-18 19:51:50 -0500118 private boolean hardwareAccelerated = true;
Feng Qianb3c02da2009-06-29 15:58:08 -0700119
Ben Murdochbff2d602009-07-01 20:19:05 +0100120 // By default the error console is shown once the user navigates to about:debug.
121 // The setting can be then toggled from the settings menu.
122 private boolean showConsole = true;
123
The Android Open Source Project0c908882009-03-03 19:32:16 -0800124 // Private preconfigured values
Shimeng (Simon) Wangb4fb25c2010-07-13 15:18:10 -0700125 private static int minimumFontSize = 1;
126 private static int minimumLogicalFontSize = 1;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800127 private static int defaultFontSize = 16;
128 private static int defaultFixedFontSize = 13;
129 private static WebSettings.TextSize textSize =
130 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700131 private static WebSettings.ZoomDensity zoomDensity =
132 WebSettings.ZoomDensity.MEDIUM;
Grace Kloba9804c432009-12-02 11:07:40 -0800133 private static int pageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800134
Ben Murdoch0cb81892010-10-08 12:41:33 +0100135
Ben Murdoch23da30e2010-10-26 15:18:44 +0100136 private AutoFillProfile autoFillProfile;
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100137 // Default to zero. In the case no profile is set up, the initial
138 // value will come from the AutoFillSettingsFragment when the user
139 // creates a profile. Otherwise, we'll read the ID of the last used
140 // profile from the prefs db.
141 private int autoFillActiveProfileId;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100142 private static final int NO_AUTOFILL_PROFILE_SET = 0;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100143
The Android Open Source Project0c908882009-03-03 19:32:16 -0800144 // Preference keys that are used outside this class
145 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
146 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
147 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
148 public final static String PREF_HOMEPAGE = "homepage";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100149 public final static String PREF_SEARCH_ENGINE = "search_engine";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800150 public final static String PREF_CLEAR_FORM_DATA =
151 "privacy_clear_form_data";
152 public final static String PREF_CLEAR_PASSWORDS =
153 "privacy_clear_passwords";
154 public final static String PREF_EXTRAS_RESET_DEFAULTS =
155 "reset_default_preferences";
156 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100157 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800158 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700159 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800160 public final static String PREF_DEFAULT_TEXT_ENCODING =
161 "default_text_encoding";
Steve Blockc6f577f2009-08-20 18:11:08 +0100162 public final static String PREF_CLEAR_GEOLOCATION_ACCESS =
163 "privacy_clear_geolocation_access";
Ben Murdochaf554522010-09-10 22:09:30 +0100164 public final static String PREF_AUTOFILL_ENABLED = "autofill_enabled";
165 public final static String PREF_AUTOFILL_PROFILE = "autofill_profile";
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100166 public final static String PREF_AUTOFILL_ACTIVE_PROFILE_ID = "autofill_active_profile_id";
John Reck63bb6872010-12-01 19:29:32 -0800167 public final static String PREF_HARDWARE_ACCEL = "enable_hardware_accel";
168 public final static String PREF_USER_AGENT = "user_agent";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800169
170 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700171 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
172 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800173
174 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700175 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
176 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
177
178 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
179 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
180 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
181
182 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
183 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
184 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800185
186 // Value to truncate strings when adding them to a TextView within
187 // a ListView
188 public final static int MAX_TEXTVIEW_LEN = 80;
189
Jeff Davidson43610292010-07-16 16:03:58 -0700190 public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider";
191
192 public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/");
193
John Reck63bb6872010-12-01 19:29:32 -0800194 // Set to true to enable some of the about:debug options
195 public static final boolean DEV_BUILD = true;
196
Michael Kolb8233fac2010-10-26 16:08:53 -0700197 private Controller mController;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800198
199 // Single instance of the BrowserSettings for use in the Browser app.
200 private static BrowserSettings sSingleton;
201
202 // Private map of WebSettings to Observer objects used when deleting an
203 // observer.
204 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
205 new HashMap<WebSettings,Observer>();
206
Ben Murdochef671652010-11-25 17:17:58 +0000207 private boolean mLoadFromDbComplete;
208
209 public void waitForLoadFromDbToComplete() {
210 synchronized (sSingleton) {
211 while (!mLoadFromDbComplete) {
212 try {
213 sSingleton.wait();
214 } catch (InterruptedException e) { }
215 }
216 }
217 }
218
The Android Open Source Project0c908882009-03-03 19:32:16 -0800219 /*
220 * An observer wrapper for updating a WebSettings object with the new
221 * settings after a call to BrowserSettings.update().
222 */
223 static class Observer implements java.util.Observer {
224 // Private WebSettings object that will be updated.
225 private WebSettings mSettings;
226
227 Observer(WebSettings w) {
228 mSettings = w;
229 }
230
231 public void update(Observable o, Object arg) {
232 BrowserSettings b = (BrowserSettings)o;
233 WebSettings s = mSettings;
234
235 s.setLayoutAlgorithm(b.layoutAlgorithm);
236 if (b.userAgent == 0) {
237 // use the default ua string
238 s.setUserAgentString(null);
239 } else if (b.userAgent == 1) {
240 s.setUserAgentString(DESKTOP_USERAGENT);
241 } else if (b.userAgent == 2) {
242 s.setUserAgentString(IPHONE_USERAGENT);
Bart Searsf6915fb2010-07-08 19:58:22 -0700243 } else if (b.userAgent == 3) {
244 s.setUserAgentString(IPAD_USERAGENT);
245 } else if (b.userAgent == 4) {
246 s.setUserAgentString(FROYO_USERAGENT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800247 }
248 s.setUseWideViewPort(b.useWideViewPort);
249 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
250 s.setJavaScriptEnabled(b.javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400251 s.setPluginState(b.pluginState);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800252 s.setJavaScriptCanOpenWindowsAutomatically(
253 b.javaScriptCanOpenWindowsAutomatically);
254 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
255 s.setMinimumFontSize(b.minimumFontSize);
256 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
257 s.setDefaultFontSize(b.defaultFontSize);
258 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
259 s.setNavDump(b.navDump);
260 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700261 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800262 s.setLightTouchEnabled(b.lightTouch);
263 s.setSaveFormData(b.saveFormData);
Ben Murdochce549fc2010-09-09 10:28:08 +0100264 s.setAutoFillEnabled(b.autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800265 s.setSavePassword(b.rememberPasswords);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700266 s.setLoadWithOverviewMode(b.loadsPageInOverviewMode);
Grace Kloba79565032009-11-24 14:23:39 -0800267 s.setPageCacheCapacity(pageCacheCapacity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800268
269 // WebView inside Browser doesn't want initial focus to be set.
270 s.setNeedInitialFocus(false);
271 // Browser supports multiple windows
272 s.setSupportMultipleWindows(true);
Grace Kloba61fc77c2010-06-22 09:57:33 -0700273 // enable smooth transition for better performance during panning or
274 // zooming
275 s.setEnableSmoothTransition(true);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100276
Andrei Popescu01068702009-08-03 16:03:24 +0100277 // HTML5 API flags
278 s.setAppCacheEnabled(b.appCacheEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100279 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100280 s.setDomStorageEnabled(b.domStorageEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100281 s.setWorkersEnabled(b.workersEnabled); // This only affects V8.
Steve Block97b08022009-08-21 10:26:25 +0100282 s.setGeolocationEnabled(b.geolocationEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100283
Andrei Popescu01068702009-08-03 16:03:24 +0100284 // HTML5 configuration parameters.
Andrei Popescu20634ce2009-07-22 16:46:55 +0100285 s.setAppCacheMaxSize(b.appCacheMaxSize);
Andrei Popescu01068702009-08-03 16:03:24 +0100286 s.setAppCachePath(b.appCachePath);
287 s.setDatabasePath(b.databasePath);
Steve Block5029cf02009-08-21 13:16:58 +0100288 s.setGeolocationDatabasePath(b.geolocationDatabasePath);
Ben Murdochbff2d602009-07-01 20:19:05 +0100289
Ben Murdoch0cb81892010-10-08 12:41:33 +0100290 // Active AutoFill profile data.
Ben Murdoch23da30e2010-10-26 15:18:44 +0100291 s.setAutoFillProfile(b.autoFillProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100292
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800293 b.updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800294 }
295 }
296
297 /**
Ben Murdochef671652010-11-25 17:17:58 +0000298 * Load settings from the browser app's database. It is performed in
299 * an AsyncTask as it involves plenty of slow disk IO.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800300 * NOTE: Strings used for the preferences must match those specified
Jeff Hamilton175ab302010-10-04 12:53:49 -0500301 * in the various preference XML files.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800302 * @param ctx A Context object used to query the browser's settings
303 * database. If the database exists, the saved settings will be
304 * stored in this BrowserSettings object. This will update all
305 * observers of this object.
306 */
Ben Murdochef671652010-11-25 17:17:58 +0000307 public void asyncLoadFromDb(final Context ctx) {
308 mLoadFromDbComplete = false;
309 // Run the initial settings load in an AsyncTask as it hits the
310 // disk multiple times through SharedPreferences and SQLite. We
311 // need to be certain though that this has completed before we start
312 // to load pages though, so in the worst case we will block waiting
313 // for it to finish in BrowserActivity.onCreate().
314 new LoadFromDbTask(ctx).execute();
315 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800316
Ben Murdochef671652010-11-25 17:17:58 +0000317 private class LoadFromDbTask extends AsyncTask<Void, Void, Void> {
318 private Context mContext;
319
320 public LoadFromDbTask(Context context) {
321 mContext = context;
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700322 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700323
Ben Murdochef671652010-11-25 17:17:58 +0000324 protected Void doInBackground(Void... unused) {
325 SharedPreferences p =
326 PreferenceManager.getDefaultSharedPreferences(mContext);
327 // Set the default value for the Application Caches path.
328 appCachePath = mContext.getDir("appcache", 0).getPath();
329 // Determine the maximum size of the application cache.
330 webStorageSizeManager = new WebStorageSizeManager(
331 mContext,
332 new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
333 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
334 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
335 // Set the default value for the Database path.
336 databasePath = mContext.getDir("databases", 0).getPath();
337 // Set the default value for the Geolocation database path.
338 geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath();
339
John Reckef074262010-12-02 16:09:14 -0800340 if (p.getString(PREF_HOMEPAGE, null) == null) {
Ben Murdochef671652010-11-25 17:17:58 +0000341 // No home page preferences is set, set it to default.
342 setHomePage(mContext, getFactoryResetHomeUrl(mContext));
343 }
344
345 // the cost of one cached page is ~3M (measured using nytimes.com). For
346 // low end devices, we only cache one page. For high end devices, we try
347 // to cache more pages, currently choose 5.
348 ActivityManager am = (ActivityManager) mContext
349 .getSystemService(Context.ACTIVITY_SERVICE);
350 if (am.getMemoryClass() > 16) {
351 pageCacheCapacity = 5;
352 } else {
353 pageCacheCapacity = 1;
354 }
355
356 // Read the last active AutoFill profile id.
357 autoFillActiveProfileId = p.getInt(
358 PREF_AUTOFILL_ACTIVE_PROFILE_ID, autoFillActiveProfileId);
359
360 // Load the autofill profile data from the database. We use a database separate
361 // to the browser preference DB to make it easier to support multiple profiles
362 // and switching between them.
363 AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(mContext);
364 Cursor c = autoFillDb.getProfile(autoFillActiveProfileId);
365
366 if (c.getCount() > 0) {
367 c.moveToFirst();
368
369 String fullName = c.getString(c.getColumnIndex(
370 AutoFillProfileDatabase.Profiles.FULL_NAME));
371 String email = c.getString(c.getColumnIndex(
372 AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS));
373 String company = c.getString(c.getColumnIndex(
374 AutoFillProfileDatabase.Profiles.COMPANY_NAME));
375 String addressLine1 = c.getString(c.getColumnIndex(
376 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1));
377 String addressLine2 = c.getString(c.getColumnIndex(
378 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2));
379 String city = c.getString(c.getColumnIndex(
380 AutoFillProfileDatabase.Profiles.CITY));
381 String state = c.getString(c.getColumnIndex(
382 AutoFillProfileDatabase.Profiles.STATE));
383 String zip = c.getString(c.getColumnIndex(
384 AutoFillProfileDatabase.Profiles.ZIP_CODE));
385 String country = c.getString(c.getColumnIndex(
386 AutoFillProfileDatabase.Profiles.COUNTRY));
387 String phone = c.getString(c.getColumnIndex(
388 AutoFillProfileDatabase.Profiles.PHONE_NUMBER));
389 autoFillProfile = new AutoFillProfile(autoFillActiveProfileId,
390 fullName, email, company, addressLine1, addressLine2, city,
391 state, zip, country, phone);
392 }
393 c.close();
394 autoFillDb.close();
395
396 // PreferenceManager.setDefaultValues is TOO SLOW, need to manually keep
397 // the defaults in sync
John Reck63bb6872010-12-01 19:29:32 -0800398 p.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
Ben Murdochef671652010-11-25 17:17:58 +0000399 syncSharedPreferences(mContext, p);
400
401 synchronized (sSingleton) {
402 mLoadFromDbComplete = true;
403 sSingleton.notify();
404 }
405 return null;
Grace Kloba9804c432009-12-02 11:07:40 -0800406 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800407 }
408
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100409 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700410
The Android Open Source Project0c908882009-03-03 19:32:16 -0800411 homeUrl =
412 p.getString(PREF_HOMEPAGE, homeUrl);
Leon Scroggins III31306602010-09-17 11:10:29 -0400413 String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
414 SearchEngine.GOOGLE);
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100415 if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) {
416 if (searchEngine != null) {
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400417 if (searchEngine.supportsVoiceSearch()) {
418 // One or more tabs could have been in voice search mode.
419 // Clear it, since the new SearchEngine may not support
420 // it, or may handle it differently.
Michael Kolb8233fac2010-10-26 16:08:53 -0700421 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
422 mController.getTabControl().getTab(i).revertVoiceSearchMode();
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400423 }
424 }
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100425 searchEngine.close();
426 }
427 searchEngine = SearchEngines.get(ctx, searchEngineName);
428 }
429 Log.i(TAG, "Selected search engine: " + searchEngine);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700430
The Android Open Source Project0c908882009-03-03 19:32:16 -0800431 loadsImagesAutomatically = p.getBoolean("load_images",
432 loadsImagesAutomatically);
433 javaScriptEnabled = p.getBoolean("enable_javascript",
434 javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400435 pluginState = WebSettings.PluginState.valueOf(
436 p.getString("plugin_state", pluginState.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800437 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
438 "block_popup_windows",
439 !javaScriptCanOpenWindowsAutomatically);
440 showSecurityWarnings = p.getBoolean("show_security_warnings",
441 showSecurityWarnings);
442 rememberPasswords = p.getBoolean("remember_passwords",
443 rememberPasswords);
444 saveFormData = p.getBoolean("save_formdata",
445 saveFormData);
Ben Murdochaf554522010-09-10 22:09:30 +0100446 autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800447 boolean accept_cookies = p.getBoolean("accept_cookies",
448 CookieManager.getInstance().acceptCookie());
449 CookieManager.getInstance().setAcceptCookie(accept_cookies);
450 openInBackground = p.getBoolean("open_in_background", openInBackground);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800451 textSize = WebSettings.TextSize.valueOf(
452 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700453 zoomDensity = WebSettings.ZoomDensity.valueOf(
454 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800455 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700456 loadsPageInOverviewMode = p.getBoolean("load_page",
457 loadsPageInOverviewMode);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800458 useWideViewPort = true; // use wide view port for either setting
459 if (autoFitPage) {
460 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
461 } else {
462 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
463 }
464 defaultTextEncodingName =
465 p.getString(PREF_DEFAULT_TEXT_ENCODING,
466 defaultTextEncodingName);
467
468 showDebugSettings =
469 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
470 // Debug menu items have precidence if the menu is visible
471 if (showDebugSettings) {
472 boolean small_screen = p.getBoolean("small_screen",
473 layoutAlgorithm ==
474 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
475 if (small_screen) {
476 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
477 } else {
478 boolean normal_layout = p.getBoolean("normal_layout",
479 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
480 if (normal_layout) {
481 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
482 } else {
483 layoutAlgorithm =
484 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
485 }
486 }
487 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
488 tracing = p.getBoolean("enable_tracing", tracing);
489 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
490 navDump = p.getBoolean("enable_nav_dump", navDump);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800491 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500492
John Reck63bb6872010-12-01 19:29:32 -0800493 // Only set these on startup if it is a dev build
494 if (DEV_BUILD) {
495 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
496 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
497 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500498
Feng Qianb3c02da2009-06-29 15:58:08 -0700499 // JS flags is loaded from DB even if showDebugSettings is false,
500 // so that it can be set once and be effective all the time.
501 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100502
503 // Read the setting for showing/hiding the JS Console always so that should the
504 // user enable debug settings, we already know if we should show the console.
505 // The user will never see the console unless they navigate to about:debug,
506 // regardless of the setting we read here. This setting is only used after debug
507 // is enabled.
508 showConsole = p.getBoolean("javascript_console", showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700509
Andrei Popescu01068702009-08-03 16:03:24 +0100510 // HTML5 API flags
511 appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled);
512 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
513 domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100514 geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100515 workersEnabled = p.getBoolean("enable_workers", workersEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100516
Grace Klobad9ee1392009-07-20 11:53:33 -0700517 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800518 }
519
The Android Open Source Project0c908882009-03-03 19:32:16 -0800520 public String getHomePage() {
521 return homeUrl;
522 }
523
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100524 public SearchEngine getSearchEngine() {
525 return searchEngine;
526 }
527
Feng Qianb3c02da2009-06-29 15:58:08 -0700528 public String getJsFlags() {
529 return jsFlags;
530 }
531
Andrei Popescu79e82b72009-07-27 12:01:59 +0100532 public WebStorageSizeManager getWebStorageSizeManager() {
533 return webStorageSizeManager;
534 }
535
The Android Open Source Project0c908882009-03-03 19:32:16 -0800536 public void setHomePage(Context context, String url) {
537 Editor ed = PreferenceManager.
538 getDefaultSharedPreferences(context).edit();
539 ed.putString(PREF_HOMEPAGE, url);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700540 ed.apply();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800541 homeUrl = url;
542 }
543
The Android Open Source Project0c908882009-03-03 19:32:16 -0800544 public WebSettings.TextSize getTextSize() {
545 return textSize;
546 }
547
Grace Kloba2f830682009-06-25 11:08:53 -0700548 public WebSettings.ZoomDensity getDefaultZoom() {
549 return zoomDensity;
550 }
551
The Android Open Source Project0c908882009-03-03 19:32:16 -0800552 public boolean openInBackground() {
553 return openInBackground;
554 }
555
556 public boolean showSecurityWarnings() {
557 return showSecurityWarnings;
558 }
559
560 public boolean isTracing() {
561 return tracing;
562 }
563
564 public boolean isLightTouch() {
565 return lightTouch;
566 }
567
568 public boolean isNavDump() {
569 return navDump;
570 }
571
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500572 public boolean isHardwareAccelerated() {
573 return hardwareAccelerated;
574 }
575
The Android Open Source Project0c908882009-03-03 19:32:16 -0800576 public boolean showDebugSettings() {
577 return showDebugSettings;
578 }
579
580 public void toggleDebugSettings() {
581 showDebugSettings = !showDebugSettings;
582 navDump = showDebugSettings;
583 update();
584 }
585
Ben Murdoch23da30e2010-10-26 15:18:44 +0100586 public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) {
587 if (profile != null) {
588 setActiveAutoFillProfileId(ctx, profile.getUniqueId());
589 // Update the AutoFill DB with the new profile.
590 new SaveProfileToDbTask(ctx, msg).execute(profile);
591 } else {
592 // Delete the current profile.
Ben Murdoche8a28332010-11-17 14:16:21 +0000593 if (autoFillProfile != null) {
594 new DeleteProfileFromDbTask(ctx, msg).execute(autoFillProfile.getUniqueId());
595 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
596 }
Ben Murdoch23da30e2010-10-26 15:18:44 +0100597 }
598 autoFillProfile = profile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100599 }
600
601 public AutoFillProfile getAutoFillProfile() {
Ben Murdoch23da30e2010-10-26 15:18:44 +0100602 return autoFillProfile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100603 }
604
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100605 private void setActiveAutoFillProfileId(Context context, int activeProfileId) {
606 autoFillActiveProfileId = activeProfileId;
607 Editor ed = PreferenceManager.
608 getDefaultSharedPreferences(context).edit();
609 ed.putInt(PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
610 ed.apply();
611 }
612
Ben Murdoch8029a772010-11-16 11:58:21 +0000613 /* package */ void disableAutoFill(Context ctx) {
614 autoFillEnabled = false;
615 Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
616 ed.putBoolean(PREF_AUTOFILL_ENABLED, false);
617 ed.apply();
618 }
619
The Android Open Source Project0c908882009-03-03 19:32:16 -0800620 /**
621 * Add a WebSettings object to the list of observers that will be updated
622 * when update() is called.
623 *
624 * @param s A WebSettings object that is strictly tied to the life of a
625 * WebView.
626 */
627 public Observer addObserver(WebSettings s) {
628 Observer old = mWebSettingsToObservers.get(s);
629 if (old != null) {
630 super.deleteObserver(old);
631 }
632 Observer o = new Observer(s);
633 mWebSettingsToObservers.put(s, o);
634 super.addObserver(o);
635 return o;
636 }
637
638 /**
639 * Delete the given WebSettings observer from the list of observers.
640 * @param s The WebSettings object to be deleted.
641 */
642 public void deleteObserver(WebSettings s) {
643 Observer o = mWebSettingsToObservers.get(s);
644 if (o != null) {
645 mWebSettingsToObservers.remove(s);
646 super.deleteObserver(o);
647 }
648 }
649
650 /*
John Reck63bb6872010-12-01 19:29:32 -0800651 * Application level method for obtaining a single app instance of the
The Android Open Source Project0c908882009-03-03 19:32:16 -0800652 * BrowserSettings.
653 */
John Reck63bb6872010-12-01 19:29:32 -0800654 public static BrowserSettings getInstance() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800655 if (sSingleton == null ) {
656 sSingleton = new BrowserSettings();
657 }
658 return sSingleton;
659 }
660
661 /*
662 * Package level method for associating the BrowserSettings with TabControl
663 */
Michael Kolb8233fac2010-10-26 16:08:53 -0700664 /* package */void setController(Controller ctrl) {
665 mController = ctrl;
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800666 updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800667 }
668
669 /*
670 * Update all the observers of the object.
671 */
672 /*package*/ void update() {
673 setChanged();
674 notifyObservers();
675 }
676
677 /*package*/ void clearCache(Context context) {
678 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700679 if (mController != null) {
680 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800681 if (current != null) {
682 current.clearCache(true);
683 }
684 }
685 }
686
687 /*package*/ void clearCookies(Context context) {
688 CookieManager.getInstance().removeAllCookie();
689 }
690
691 /* package */void clearHistory(Context context) {
692 ContentResolver resolver = context.getContentResolver();
693 Browser.clearHistory(resolver);
694 Browser.clearSearches(resolver);
695 }
696
697 /* package */ void clearFormData(Context context) {
698 WebViewDatabase.getInstance(context).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 if (mController!= null) {
700 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100701 if (currentTopView != null) {
702 currentTopView.clearFormData();
703 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800704 }
705 }
706
707 /*package*/ void clearPasswords(Context context) {
708 WebViewDatabase db = WebViewDatabase.getInstance(context);
709 db.clearUsernamePassword();
710 db.clearHttpAuthUsernamePassword();
711 }
712
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800713 private void updateTabControlSettings() {
714 // Enable/disable the error console.
Michael Kolb8233fac2010-10-26 16:08:53 -0700715 mController.setShouldShowErrorConsole(
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800716 showDebugSettings && showConsole);
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800717 }
718
Nicolas Roard78a98e42009-05-11 13:34:17 +0100719 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100720 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100721 }
722
723 /*package*/ void clearLocationAccess(Context context) {
724 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100725 }
726
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400727 /*package*/ void resetDefaultPreferences(Context ctx) {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800728 reset();
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500729 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700730 p.edit().clear().apply();
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500731 PreferenceManager.setDefaultValues(ctx, R.xml.page_content_preferences, true);
Jeff Hamiltona9bad832010-09-24 11:05:30 -0500732 PreferenceManager.setDefaultValues(ctx, R.xml.personal_preferences, true);
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500733 PreferenceManager.setDefaultValues(ctx, R.xml.privacy_preferences, true);
734 PreferenceManager.setDefaultValues(ctx, R.xml.security_preferences, true);
735 PreferenceManager.setDefaultValues(ctx, R.xml.advanced_preferences, true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700736 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700737 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100738 // reset appcache max size
739 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch23da30e2010-10-26 15:18:44 +0100740 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700741 }
742
John Reck33bbb802010-10-26 17:13:42 -0700743 /*package*/ static String getFactoryResetHomeUrl(Context context) {
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700744 String url = context.getResources().getString(R.string.homepage_base);
745 if (url.indexOf("{CID}") != -1) {
Patrick Scott43914692010-02-19 10:10:10 -0500746 url = url.replace("{CID}",
747 BrowserProvider.getClientId(context.getContentResolver()));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700748 }
749 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800750 }
751
The Android Open Source Project0c908882009-03-03 19:32:16 -0800752 // Private constructor that does nothing.
753 private BrowserSettings() {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800754 reset();
755 }
756
757 private void reset() {
758 // Private variables for settings
759 // NOTE: these defaults need to be kept in sync with the XML
760 // until the performance of PreferenceManager.setDefaultValues()
761 // is improved.
762 loadsImagesAutomatically = true;
763 javaScriptEnabled = true;
Patrick Scotte536b332010-03-22 10:19:32 -0400764 pluginState = WebSettings.PluginState.ON;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800765 javaScriptCanOpenWindowsAutomatically = false;
766 showSecurityWarnings = true;
767 rememberPasswords = true;
768 saveFormData = true;
Ben Murdochdc62cb92010-11-23 15:11:29 +0000769 autoFillEnabled = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800770 openInBackground = false;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800771 autoFitPage = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800772 loadsPageInOverviewMode = true;
773 showDebugSettings = false;
774 // HTML5 API flags
775 appCacheEnabled = true;
776 databaseEnabled = true;
777 domStorageEnabled = true;
778 geolocationEnabled = true;
779 workersEnabled = true; // only affects V8. JSC does not have a similar setting
The Android Open Source Project0c908882009-03-03 19:32:16 -0800780 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100781
Ben Murdoch23da30e2010-10-26 15:18:44 +0100782 private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100783 Context mContext;
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100784 AutoFillProfileDatabase mAutoFillProfileDb;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100785 Message mCompleteMessage;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100786
Ben Murdoch23da30e2010-10-26 15:18:44 +0100787 public AutoFillProfileDbTask(Context ctx, Message msg) {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100788 mContext = ctx;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100789 mCompleteMessage = msg;
790 }
791
792 protected void onPostExecute(Void result) {
793 if (mCompleteMessage != null) {
794 mCompleteMessage.sendToTarget();
795 }
796 mAutoFillProfileDb.close();
797 }
798
799 abstract protected Void doInBackground(T... values);
800 }
801
802
803 private class SaveProfileToDbTask extends AutoFillProfileDbTask<AutoFillProfile> {
804 public SaveProfileToDbTask(Context ctx, Message msg) {
805 super(ctx, msg);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100806 }
807
808 protected Void doInBackground(AutoFillProfile... values) {
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100809 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100810 assert autoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET;
811 AutoFillProfile newProfile = values[0];
812 mAutoFillProfileDb.addOrUpdateProfile(autoFillActiveProfileId, newProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100813 return null;
814 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100815 }
816
Ben Murdoch23da30e2010-10-26 15:18:44 +0100817 private class DeleteProfileFromDbTask extends AutoFillProfileDbTask<Integer> {
818 public DeleteProfileFromDbTask(Context ctx, Message msg) {
819 super(ctx, msg);
820 }
821
822 protected Void doInBackground(Integer... values) {
823 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
824 int id = values[0];
825 assert id > 0;
826 mAutoFillProfileDb.dropProfile(id);
827 return null;
828 }
829 }
John Reck63bb6872010-12-01 19:29:32 -0800830
831 @Override
832 public void onSharedPreferenceChanged(
833 SharedPreferences p, String key) {
834 if (PREF_HARDWARE_ACCEL.equals(key)) {
835 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
836 } else if (PREF_USER_AGENT.equals(key)) {
837 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
838 update();
839 }
840 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800841}