blob: cddeda64a0974417ae7213d6651cefd5fd9ae966 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
John Reck35e9dd62011-04-25 09:01:54 -07002 * Copyright (C) 2011 The Android Open Source Project
The Android Open Source Project0c908882009-03-03 19:32:16 -08003 *
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
Grace Kloba9804c432009-12-02 11:07:40 -080019import android.app.ActivityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080020import android.content.ContentResolver;
21import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080022import android.content.SharedPreferences;
John Reck1da81882011-10-04 17:21:10 -070023import android.content.SharedPreferences.Editor;
John Reck812d2d62011-01-18 14:16:15 -080024import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Victoria Lease96497832012-03-23 14:19:56 -070025import android.net.ConnectivityManager;
26import android.net.NetworkInfo;
John Reckf48314f2011-04-27 17:52:17 -070027import android.os.Build;
Ben Murdoch23da30e2010-10-26 15:18:44 +010028import android.os.Message;
Ben Murdoch0cb81892010-10-08 12:41:33 +010029import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010030import android.provider.Browser;
Mathew Inwood825fba72011-10-04 14:52:52 +010031import android.provider.Settings;
John Reck5ba3c762011-09-14 15:00:15 -070032import android.util.DisplayMetrics;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010034import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080035import android.webkit.WebIconDatabase;
36import android.webkit.WebSettings;
John Reck35e9dd62011-04-25 09:01:54 -070037import android.webkit.WebSettings.LayoutAlgorithm;
38import android.webkit.WebSettings.PluginState;
39import android.webkit.WebSettings.TextSize;
40import android.webkit.WebSettings.ZoomDensity;
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +000041import android.webkit.WebSettingsClassic;
42import android.webkit.WebSettingsClassic.AutoFillProfile;
Nicolas Roard78a98e42009-05-11 13:34:17 +010043import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080044import android.webkit.WebView;
45import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080046
John Reck46500332011-06-07 14:36:10 -070047import com.android.browser.homepages.HomeProvider;
48import com.android.browser.provider.BrowserProvider;
49import com.android.browser.search.SearchEngine;
50import com.android.browser.search.SearchEngines;
51
John Reck35e9dd62011-04-25 09:01:54 -070052import java.lang.ref.WeakReference;
53import java.util.Iterator;
54import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070055import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080056
John Reck35e9dd62011-04-25 09:01:54 -070057/**
58 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080059 */
John Reck35e9dd62011-04-25 09:01:54 -070060public class BrowserSettings implements OnSharedPreferenceChangeListener,
61 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010062
John Reck35e9dd62011-04-25 09:01:54 -070063 // TODO: Do something with this UserAgent stuff
John Reck7fd1e8f2011-04-27 18:22:57 -070064 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
65 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
66 "Chrome/11.0.696.34 Safari/534.24";
The Android Open Source Project0c908882009-03-03 19:32:16 -080067
68 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070069 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
70 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070071
72 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070073 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
74 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070075
76 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070077 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
78 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080079
John Reck7fd1e8f2011-04-27 18:22:57 -070080 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
81 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
82 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
83
John Reck35e9dd62011-04-25 09:01:54 -070084 private static final String USER_AGENTS[] = { null,
85 DESKTOP_USERAGENT,
86 IPHONE_USERAGENT,
87 IPAD_USERAGENT,
John Reck7fd1e8f2011-04-27 18:22:57 -070088 FROYO_USERAGENT,
89 HONEYCOMB_USERAGENT,
John Reck35e9dd62011-04-25 09:01:54 -070090 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080091
John Reck8fc22a12011-06-16 14:57:41 -070092 // The minimum min font size
93 // Aka, the lower bounds for the min font size range
94 // which is 1:5..24
95 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070096 // The initial value in the text zoom range
97 // This is what represents 100% in the SeekBarPreference range
98 private static final int TEXT_ZOOM_START_VAL = 10;
99 // The size of a single step in the text zoom range, in percent
100 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700101 // The initial value in the double tap zoom range
102 // This is what represents 100% in the SeekBarPreference range
103 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
104 // The size of a single step in the double tap zoom range, in percent
105 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -0700106
John Reck35e9dd62011-04-25 09:01:54 -0700107 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -0700108
John Reck35e9dd62011-04-25 09:01:54 -0700109 private Context mContext;
110 private SharedPreferences mPrefs;
111 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -0700113 private WebStorageSizeManager mWebStorageSizeManager;
114 private AutofillHandler mAutofillHandler;
John Reckb8b2af82011-05-20 15:58:33 -0700115 private WeakHashMap<WebSettings, String> mCustomUserAgents;
Ben Murdochaaa1f372011-07-25 15:40:58 +0100116 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -0700117 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -0700118 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -0700119
Victoria Lease96497832012-03-23 14:19:56 -0700120 // Current state of network-dependent settings
121 private boolean mLinkPrefetchAllowed = true;
122
John Reck78a6a1d2011-07-21 13:54:03 -0700123 // Cached values
124 private int mPageCacheCapacity = 1;
125 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800126
John Reck35e9dd62011-04-25 09:01:54 -0700127 // Cached settings
128 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129
Ben Murdochaaa1f372011-07-25 15:40:58 +0100130 private static String sFactoryResetUrl;
131
John Reck35e9dd62011-04-25 09:01:54 -0700132 public static void initialize(final Context context) {
133 sInstance = new BrowserSettings(context);
134 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135
John Reck35e9dd62011-04-25 09:01:54 -0700136 public static BrowserSettings getInstance() {
137 return sInstance;
138 }
Ben Murdochef671652010-11-25 17:17:58 +0000139
John Reck35e9dd62011-04-25 09:01:54 -0700140 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100141 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700142 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
143 mAutofillHandler = new AutofillHandler(mContext);
144 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckb8b2af82011-05-20 15:58:33 -0700145 mCustomUserAgents = new WeakHashMap<WebSettings, String>();
John Reck35e9dd62011-04-25 09:01:54 -0700146 mAutofillHandler.asyncLoadFromDb();
John Reckcadae722011-07-25 11:36:17 -0700147 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700148 }
149
150 public void setController(Controller controller) {
151 mController = controller;
John Reckc477e712011-08-17 11:27:15 -0700152 if (sInitialized) {
153 syncSharedSettings();
154 }
Ben Murdochef671652010-11-25 17:17:58 +0000155 }
156
John Reck35e9dd62011-04-25 09:01:54 -0700157 public void startManagingSettings(WebSettings settings) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000158 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
John Reckc477e712011-08-17 11:27:15 -0700159 if (mNeedsSharedSync) {
160 syncSharedSettings();
161 }
John Reck35e9dd62011-04-25 09:01:54 -0700162 synchronized (mManagedSettings) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000163 syncStaticSettings(settingsClassic);
164 syncSetting(settingsClassic);
John Reck35e9dd62011-04-25 09:01:54 -0700165 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800166 }
167 }
168
John Reckd1d87312012-03-08 13:25:00 -0800169 public void stopManagingSettings(WebSettings settings) {
170 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
171 while (iter.hasNext()) {
172 WeakReference<WebSettings> ref = iter.next();
173 if (ref.get() == settings) {
174 iter.remove();
175 return;
176 }
177 }
178 }
179
John Reckcadae722011-07-25 11:36:17 -0700180 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700181
182 @Override
183 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700184 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
185 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700186 // the cost of one cached page is ~3M (measured using nytimes.com). For
187 // low end devices, we only cache one page. For high end devices, we try
188 // to cache more pages, currently choose 5.
189 if (ActivityManager.staticGetMemoryClass() > 16) {
190 mPageCacheCapacity = 5;
191 }
192 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
193 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
194 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700195 // Workaround b/5254577
196 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700197 if (Build.VERSION.CODENAME.equals("REL")) {
198 // This is a release build, always startup with debug disabled
199 setDebugEnabled(false);
200 }
201 if (mPrefs.contains(PREF_TEXT_SIZE)) {
202 /*
203 * Update from TextSize enum to zoom percent
204 * SMALLEST is 50%
205 * SMALLER is 75%
206 * NORMAL is 100%
207 * LARGER is 150%
208 * LARGEST is 200%
209 */
210 switch (getTextSize()) {
211 case SMALLEST:
212 setTextZoom(50);
213 break;
214 case SMALLER:
215 setTextZoom(75);
216 break;
217 case LARGER:
218 setTextZoom(150);
219 break;
220 case LARGEST:
221 setTextZoom(200);
222 break;
223 }
224 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
225 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100226
227 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
228 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
229 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
230 BrowserProvider.getClientId(mContext.getContentResolver()));
231 }
232
Ben Murdochaaa1f372011-07-25 15:40:58 +0100233 synchronized (BrowserSettings.class) {
234 sInitialized = true;
235 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700236 }
237 }
238 };
239
Ben Murdochaaa1f372011-07-25 15:40:58 +0100240 private static void requireInitialization() {
241 synchronized (BrowserSettings.class) {
242 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700243 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100244 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700245 } catch (InterruptedException e) {
246 }
247 }
248 }
249 }
250
The Android Open Source Project0c908882009-03-03 19:32:16 -0800251 /**
John Reck35e9dd62011-04-25 09:01:54 -0700252 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800253 */
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000254 private void syncSetting(WebSettingsClassic settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700255 settings.setGeolocationEnabled(enableGeolocation());
256 settings.setJavaScriptEnabled(enableJavascript());
257 settings.setLightTouchEnabled(enableLightTouch());
258 settings.setNavDump(enableNavDump());
Derek Sollenberger31adf672011-07-08 11:31:30 -0400259 settings.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
John Reck35e9dd62011-04-25 09:01:54 -0700260 settings.setShowVisualIndicator(enableVisualIndicator());
261 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
262 settings.setDefaultZoom(getDefaultZoom());
263 settings.setMinimumFontSize(getMinimumFontSize());
264 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck92f25f82011-04-26 16:57:10 -0700265 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700266 settings.setPluginState(getPluginState());
John Reck7dc444b2011-06-16 17:44:29 -0700267 settings.setTextZoom(getTextZoom());
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700268 settings.setDoubleTapZoom(getDoubleTapZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700269 settings.setAutoFillEnabled(isAutofillEnabled());
270 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100271 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700272 settings.setLoadsImagesAutomatically(loadImages());
273 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
274 settings.setSavePassword(rememberPasswords());
275 settings.setSaveFormData(saveFormdata());
276 settings.setUseWideViewPort(isWideViewport());
277 settings.setAutoFillProfile(getAutoFillProfile());
John Reckb8b2af82011-05-20 15:58:33 -0700278
279 String ua = mCustomUserAgents.get(settings);
John Reck46500332011-06-07 14:36:10 -0700280 if (ua != null) {
John Reckb8b2af82011-05-20 15:58:33 -0700281 settings.setUserAgentString(ua);
282 } else {
283 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
284 }
John Reck2fd9d0e2011-07-15 11:13:48 -0700285
John Reckea17e782011-10-27 17:15:59 -0700286 boolean useInverted = useInvertedRendering();
John Reckeabe5da2011-08-08 13:24:13 -0700287 settings.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700288 useInverted ? "true" : "false");
289 if (useInverted) {
290 settings.setProperty(WebViewProperties.gfxInvertedScreenContrast,
291 Float.toString(getInvertedContrast()));
292 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700293
John Reckea17e782011-10-27 17:15:59 -0700294 if (isDebugEnabled()) {
295 settings.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
296 enableCpuUploadPath() ? "true" : "false");
297 }
Victoria Lease96497832012-03-23 14:19:56 -0700298
299 settings.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000300 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800301
John Reck35e9dd62011-04-25 09:01:54 -0700302 /**
303 * Syncs all the settings that have no UI
304 * These cannot change, so we only need to set them once per WebSettings
305 */
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000306 private void syncStaticSettings(WebSettingsClassic settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700307 settings.setDefaultFontSize(16);
308 settings.setDefaultFixedFontSize(13);
309 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000310
John Reck35e9dd62011-04-25 09:01:54 -0700311 // WebView inside Browser doesn't want initial focus to be set.
312 settings.setNeedInitialFocus(false);
313 // Browser supports multiple windows
314 settings.setSupportMultipleWindows(true);
315 // enable smooth transition for better performance during panning or
316 // zooming
317 settings.setEnableSmoothTransition(true);
Teng-Hui Zhu164f74e2011-11-07 12:54:43 -0800318 // WebView should be preserving the memory as much as possible.
319 // However, apps like browser wish to turn on the performance mode which
320 // would require more memory.
321 // TODO: We need to dynamically allocate/deallocate temporary memory for
322 // apps which are trying to use minimal memory. Currently, double
323 // buffering is always turned on, which is unnecessary.
324 settings.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
John Reck35e9dd62011-04-25 09:01:54 -0700325 // disable content url access
326 settings.setAllowContentAccess(false);
327
328 // HTML5 API flags
329 settings.setAppCacheEnabled(true);
330 settings.setDatabaseEnabled(true);
331 settings.setDomStorageEnabled(true);
332 settings.setWorkersEnabled(true); // This only affects V8.
333
334 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700335 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700336 settings.setAppCachePath(getAppCachePath());
337 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
338 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700339 // origin policy for file access
340 settings.setAllowUniversalAccessFromFileURLs(false);
341 settings.setAllowFileAccessFromFileURLs(false);
John Reck35e9dd62011-04-25 09:01:54 -0700342 }
343
344 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700345 mNeedsSharedSync = false;
John Reck35e9dd62011-04-25 09:01:54 -0700346 CookieManager.getInstance().setAcceptCookie(acceptCookies());
347 if (mController != null) {
348 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700349 }
John Reck35e9dd62011-04-25 09:01:54 -0700350 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700351
John Reck35e9dd62011-04-25 09:01:54 -0700352 private void syncManagedSettings() {
353 syncSharedSettings();
354 synchronized (mManagedSettings) {
355 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
356 while (iter.hasNext()) {
357 WeakReference<WebSettings> ref = iter.next();
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000358 WebSettingsClassic settings = (WebSettingsClassic)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700359 if (settings == null) {
360 iter.remove();
361 continue;
362 }
363 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000364 }
John Reck35e9dd62011-04-25 09:01:54 -0700365 }
366 }
Ben Murdochef671652010-11-25 17:17:58 +0000367
John Reck35e9dd62011-04-25 09:01:54 -0700368 @Override
369 public void onSharedPreferenceChanged(
370 SharedPreferences sharedPreferences, String key) {
371 syncManagedSettings();
372 if (PREF_SEARCH_ENGINE.equals(key)) {
373 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700374 } else if (PREF_FULLSCREEN.equals(key)) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700375 if (mController.getUi() != null) {
376 mController.getUi().setFullscreen(useFullscreen());
377 }
Michael Kolb0241e752011-07-07 14:58:50 -0700378 } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
379 if (mController.getUi() != null) {
380 mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
381 }
Victoria Lease96497832012-03-23 14:19:56 -0700382 } else if (PREF_LINK_PREFETCH.equals(key)) {
383 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700384 }
John Reck35e9dd62011-04-25 09:01:54 -0700385 }
386
John Reck961d35d2011-06-23 09:45:54 -0700387 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100388 requireInitialization();
389 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700390 }
391
392 public LayoutAlgorithm getLayoutAlgorithm() {
393 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
394 if (autofitPages()) {
395 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
396 }
397 if (isDebugEnabled()) {
398 if (isSmallScreen()) {
399 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000400 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700401 if (isNormalLayout()) {
402 layoutAlgorithm = LayoutAlgorithm.NORMAL;
403 } else {
404 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
405 }
Ben Murdochef671652010-11-25 17:17:58 +0000406 }
John Reck35e9dd62011-04-25 09:01:54 -0700407 }
408 return layoutAlgorithm;
409 }
Ben Murdochef671652010-11-25 17:17:58 +0000410
John Reck35e9dd62011-04-25 09:01:54 -0700411 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700412 requireInitialization();
413 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800414 }
415
John Reck35e9dd62011-04-25 09:01:54 -0700416 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700417 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700418 return mWebStorageSizeManager;
419 }
420
John Reck35e9dd62011-04-25 09:01:54 -0700421 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700422 if (mAppCachePath == null) {
423 mAppCachePath = mContext.getDir("appcache", 0).getPath();
424 }
425 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700426 }
427
428 private void updateSearchEngine(boolean force) {
429 String searchEngineName = getSearchEngineName();
430 if (force || mSearchEngine == null ||
431 !mSearchEngine.getName().equals(searchEngineName)) {
432 if (mSearchEngine != null) {
433 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000434 // One or more tabs could have been in voice search mode.
435 // Clear it, since the new SearchEngine may not support
436 // it, or may handle it differently.
437 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
438 mController.getTabControl().getTab(i).revertVoiceSearchMode();
439 }
440 }
John Reck35e9dd62011-04-25 09:01:54 -0700441 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000442 }
John Reck35e9dd62011-04-25 09:01:54 -0700443 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000444 }
445 }
446
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100447 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700448 if (mSearchEngine == null) {
449 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100450 }
John Reck35e9dd62011-04-25 09:01:54 -0700451 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100452 }
453
John Reck35e9dd62011-04-25 09:01:54 -0700454 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700455 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700456 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100457 }
458
John Reck35e9dd62011-04-25 09:01:54 -0700459 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700460 Editor edit = mPrefs.edit();
461 edit.putBoolean(PREF_DEBUG_MENU, value);
462 if (!value) {
463 // Reset to "safe" value
464 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
465 }
466 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100467 }
468
John Reck35e9dd62011-04-25 09:01:54 -0700469 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800470 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700471 if (mController != null) {
472 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800473 if (current != null) {
474 current.clearCache(true);
475 }
476 }
477 }
478
John Reck35e9dd62011-04-25 09:01:54 -0700479 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800480 CookieManager.getInstance().removeAllCookie();
481 }
482
John Reck35e9dd62011-04-25 09:01:54 -0700483 public void clearHistory() {
484 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800485 Browser.clearHistory(resolver);
486 Browser.clearSearches(resolver);
487 }
488
John Reck35e9dd62011-04-25 09:01:54 -0700489 public void clearFormData() {
490 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700491 if (mController!= null) {
492 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100493 if (currentTopView != null) {
494 currentTopView.clearFormData();
495 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800496 }
497 }
498
John Reck35e9dd62011-04-25 09:01:54 -0700499 public void clearPasswords() {
500 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800501 db.clearUsernamePassword();
502 db.clearHttpAuthUsernamePassword();
503 }
504
John Reck35e9dd62011-04-25 09:01:54 -0700505 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100506 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100507 }
508
John Reck35e9dd62011-04-25 09:01:54 -0700509 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100510 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100511 }
512
John Reck35e9dd62011-04-25 09:01:54 -0700513 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700514 // Preserve autologin setting
515 long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1);
516 mPrefs.edit()
517 .clear()
518 .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal)
519 .apply();
John Reck35e9dd62011-04-25 09:01:54 -0700520 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700521 }
522
John Reck35e9dd62011-04-25 09:01:54 -0700523 public AutoFillProfile getAutoFillProfile() {
524 mAutofillHandler.waitForLoad();
525 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800526 }
527
John Reck35e9dd62011-04-25 09:01:54 -0700528 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
529 mAutofillHandler.waitForLoad();
530 mAutofillHandler.setAutoFillProfile(profile, msg);
Ben Murdoch273330a2011-07-08 18:37:22 +0100531 // Auto-fill will reuse the same profile ID when making edits to the profile,
532 // so we need to force a settings sync (otherwise the SharedPreferences
533 // manager will optimise out the call to onSharedPreferenceChanged(), as
534 // it thinks nothing has changed).
535 syncManagedSettings();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800536 }
537
John Reck35e9dd62011-04-25 09:01:54 -0700538 public void toggleDebugSettings() {
539 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800540 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100541
John Reckb8b2af82011-05-20 15:58:33 -0700542 public boolean hasDesktopUseragent(WebView view) {
543 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
544 }
545
546 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700547 if (view == null) {
548 return;
549 }
John Reckb8b2af82011-05-20 15:58:33 -0700550 WebSettings settings = view.getSettings();
551 if (mCustomUserAgents.get(settings) != null) {
552 mCustomUserAgents.remove(settings);
553 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
554 } else {
555 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
556 settings.setUserAgentString(DESKTOP_USERAGENT);
557 }
558 }
559
John Reck7dc444b2011-06-16 17:44:29 -0700560 public static int getAdjustedMinimumFontSize(int rawValue) {
561 rawValue++; // Preference starts at 0, min font at 1
562 if (rawValue > 1) {
563 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
564 }
565 return rawValue;
566 }
567
John Reck5ba3c762011-09-14 15:00:15 -0700568 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700569 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700570 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700571 }
572
573 static int getRawTextZoom(int percent) {
574 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
575 }
576
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700577 public int getAdjustedDoubleTapZoom(int rawValue) {
578 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
579 return (int) ((rawValue + 100) * mFontSizeMult);
580 }
581
582 static int getRawDoubleTapZoom(int percent) {
583 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
584 }
585
John Reckcadae722011-07-25 11:36:17 -0700586 public SharedPreferences getPreferences() {
587 return mPrefs;
588 }
589
Victoria Lease96497832012-03-23 14:19:56 -0700590 // update connectivity-dependent options
591 public void updateConnectionType() {
592 ConnectivityManager cm = (ConnectivityManager)
593 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
594 String linkPrefetchPreference = getLinkPrefetchEnabled();
595 boolean linkPrefetchAllowed = linkPrefetchPreference.
596 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
597 NetworkInfo ni = cm.getActiveNetworkInfo();
598 if (ni != null) {
599 switch (ni.getType()) {
600 case ConnectivityManager.TYPE_WIFI:
601 case ConnectivityManager.TYPE_ETHERNET:
602 case ConnectivityManager.TYPE_BLUETOOTH:
603 linkPrefetchAllowed |= linkPrefetchPreference.
604 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
605 break;
606 case ConnectivityManager.TYPE_MOBILE:
607 case ConnectivityManager.TYPE_MOBILE_DUN:
608 case ConnectivityManager.TYPE_MOBILE_MMS:
609 case ConnectivityManager.TYPE_MOBILE_SUPL:
610 case ConnectivityManager.TYPE_WIMAX:
611 default:
612 break;
613 }
614 }
615 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
616 mLinkPrefetchAllowed = linkPrefetchAllowed;
617 syncManagedSettings();
618 }
619 }
620
John Reck35e9dd62011-04-25 09:01:54 -0700621 // -----------------------------
622 // getter/setters for accessibility_preferences.xml
623 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100624
John Reck7dc444b2011-06-16 17:44:29 -0700625 @Deprecated
626 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700627 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
628 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100629 }
630
John Reck35e9dd62011-04-25 09:01:54 -0700631 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700632 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700633 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100634 }
635
John Reck92f25f82011-04-26 16:57:10 -0700636 public boolean forceEnableUserScalable() {
637 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
638 }
639
John Reck7dc444b2011-06-16 17:44:29 -0700640 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700641 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700642 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
643 return getAdjustedTextZoom(textZoom);
644 }
645
646 public void setTextZoom(int percent) {
647 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
648 }
649
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700650 public int getDoubleTapZoom() {
651 requireInitialization();
652 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
653 return getAdjustedDoubleTapZoom(doubleTapZoom);
654 }
655
656 public void setDoubleTapZoom(int percent) {
657 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
658 }
659
John Reck35e9dd62011-04-25 09:01:54 -0700660 // -----------------------------
661 // getter/setters for advanced_preferences.xml
662 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100663
John Reck35e9dd62011-04-25 09:01:54 -0700664 public String getSearchEngineName() {
665 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100666 }
John Reck63bb6872010-12-01 19:29:32 -0800667
John Reck35e9dd62011-04-25 09:01:54 -0700668 public boolean openInBackground() {
669 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800670 }
John Reck35e9dd62011-04-25 09:01:54 -0700671
672 public boolean enableJavascript() {
673 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
674 }
675
676 // TODO: Cache
677 public PluginState getPluginState() {
678 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
679 return PluginState.valueOf(state);
680 }
681
682 // TODO: Cache
683 public ZoomDensity getDefaultZoom() {
684 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
685 return ZoomDensity.valueOf(zoom);
686 }
687
688 public boolean loadPageInOverviewMode() {
689 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
690 }
691
692 public boolean autofitPages() {
693 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
694 }
695
696 public boolean blockPopupWindows() {
697 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
698 }
699
700 public boolean loadImages() {
701 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
702 }
703
704 public String getDefaultTextEncoding() {
705 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
706 }
707
708 // -----------------------------
709 // getter/setters for general_preferences.xml
710 // -----------------------------
711
712 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700713 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
714 }
715
716 public void setHomePage(String value) {
717 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
718 }
719
720 public boolean isAutofillEnabled() {
721 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
722 }
723
724 public void setAutofillEnabled(boolean value) {
725 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
726 }
727
728 // -----------------------------
729 // getter/setters for debug_preferences.xml
730 // -----------------------------
731
732 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700733 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700734 return true;
735 }
736 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
737 }
738
Derek Sollenberger31adf672011-07-08 11:31:30 -0400739 public boolean isSkiaHardwareAccelerated() {
740 if (!isDebugEnabled()) {
741 return false;
742 }
743 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
744 }
745
John Reck35e9dd62011-04-25 09:01:54 -0700746 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700747 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700748 return 0;
749 }
750 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
751 }
752
753 // -----------------------------
754 // getter/setters for hidden_debug_preferences.xml
755 // -----------------------------
756
757 public boolean enableVisualIndicator() {
758 if (!isDebugEnabled()) {
759 return false;
760 }
761 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
762 }
763
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700764 public boolean enableCpuUploadPath() {
765 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700766 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700767 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700768 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700769 }
770
John Reck35e9dd62011-04-25 09:01:54 -0700771 public boolean enableJavascriptConsole() {
772 if (!isDebugEnabled()) {
773 return false;
774 }
775 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
776 }
777
778 public boolean isSmallScreen() {
779 if (!isDebugEnabled()) {
780 return false;
781 }
782 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
783 }
784
785 public boolean isWideViewport() {
786 if (!isDebugEnabled()) {
787 return true;
788 }
789 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
790 }
791
792 public boolean isNormalLayout() {
793 if (!isDebugEnabled()) {
794 return false;
795 }
796 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
797 }
798
799 public boolean isTracing() {
800 if (!isDebugEnabled()) {
801 return false;
802 }
803 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
804 }
805
806 public boolean enableLightTouch() {
807 if (!isDebugEnabled()) {
808 return false;
809 }
810 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
811 }
812
813 public boolean enableNavDump() {
814 if (!isDebugEnabled()) {
815 return false;
816 }
817 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
818 }
819
820 public String getJsEngineFlags() {
821 if (!isDebugEnabled()) {
822 return "";
823 }
824 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
825 }
826
827 // -----------------------------
828 // getter/setters for lab_preferences.xml
829 // -----------------------------
830
831 public boolean useQuickControls() {
832 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
833 }
834
835 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700836 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700837 }
838
Michael Kolbc38c6042011-04-27 10:46:06 -0700839 public boolean useFullscreen() {
840 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
841 }
842
John Reck2fd9d0e2011-07-15 11:13:48 -0700843 public boolean useInvertedRendering() {
844 return mPrefs.getBoolean(PREF_INVERTED, false);
845 }
846
Nicolas Roard5d513102011-08-03 15:35:34 -0700847 public float getInvertedContrast() {
848 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
849 }
850
John Reck35e9dd62011-04-25 09:01:54 -0700851 // -----------------------------
852 // getter/setters for privacy_security_preferences.xml
853 // -----------------------------
854
855 public boolean showSecurityWarnings() {
856 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
857 }
858
859 public boolean acceptCookies() {
860 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
861 }
862
863 public boolean saveFormdata() {
864 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
865 }
866
867 public boolean enableGeolocation() {
868 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
869 }
870
871 public boolean rememberPasswords() {
872 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
873 }
874
Michael Kolb14612442011-06-24 13:06:29 -0700875 // -----------------------------
876 // getter/setters for bandwidth_preferences.xml
877 // -----------------------------
878
Mathew Inwood467813f2011-09-02 15:43:17 +0100879 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
880 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700881 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100882
883 public static String getPreloadAlwaysPreferenceString(Context context) {
884 return context.getResources().getString(R.string.pref_data_preload_value_always);
885 }
886
Mathew Inwood825fba72011-10-04 14:52:52 +0100887 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
888 "browser_default_preload_setting";
889
890 public String getDefaultPreloadSetting() {
891 String preload = Settings.Secure.getString(mContext.getContentResolver(),
892 DEAULT_PRELOAD_SECURE_SETTING_KEY);
893 if (preload == null) {
894 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
895 }
896 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100897 }
898
899 public String getPreloadEnabled() {
900 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
901 }
902
Victoria Lease96497832012-03-23 14:19:56 -0700903 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
904 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
905 }
906
907 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
908 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
909 }
910
911 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
912 "browser_default_link_prefetch_setting";
913
914 public String getDefaultLinkPrefetchSetting() {
915 String preload = Settings.Secure.getString(mContext.getContentResolver(),
916 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
917 if (preload == null) {
918 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
919 }
920 return preload;
921 }
922
923 public String getLinkPrefetchEnabled() {
924 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
925 }
926
George Mount3636d0a2011-11-21 09:08:21 -0800927 // -----------------------------
928 // getter/setters for browser recovery
929 // -----------------------------
930 /**
931 * The last time browser was started.
932 * @return The last browser start time as System.currentTimeMillis. This
933 * can be 0 if this is the first time or the last tab was closed.
934 */
935 public long getLastRecovered() {
936 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
937 }
938
939 /**
940 * Sets the last browser start time.
941 * @param time The last time as System.currentTimeMillis that the browser
942 * was started. This should be set to 0 if the last tab is closed.
943 */
944 public void setLastRecovered(long time) {
945 mPrefs.edit()
946 .putLong(KEY_LAST_RECOVERED, time)
947 .apply();
948 }
949
950 /**
951 * Used to determine whether or not the previous browser run crashed. Once
952 * the previous state has been determined, the value will be set to false
953 * until a pause is received.
954 * @return true if the last browser run was paused or false if it crashed.
955 */
956 public boolean wasLastRunPaused() {
957 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
958 }
959
960 /**
961 * Sets whether or not the last run was a pause or crash.
962 * @param isPaused Set to true When a pause is received or false after
963 * resuming.
964 */
965 public void setLastRunPaused(boolean isPaused) {
966 mPrefs.edit()
967 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
968 .apply();
969 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800970}