blob: 22f6fd28177af4d2ca986be5f2670fffb9f3cec3 [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;
John Reckf48314f2011-04-27 17:52:17 -070025import android.os.Build;
Ben Murdoch23da30e2010-10-26 15:18:44 +010026import android.os.Message;
Ben Murdoch0cb81892010-10-08 12:41:33 +010027import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010028import android.provider.Browser;
Mathew Inwood825fba72011-10-04 14:52:52 +010029import android.provider.Settings;
John Reck5ba3c762011-09-14 15:00:15 -070030import android.util.DisplayMetrics;
The Android Open Source Project0c908882009-03-03 19:32:16 -080031import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010032import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033import android.webkit.WebIconDatabase;
34import android.webkit.WebSettings;
John Reck35e9dd62011-04-25 09:01:54 -070035import android.webkit.WebSettings.LayoutAlgorithm;
36import android.webkit.WebSettings.PluginState;
37import android.webkit.WebSettings.TextSize;
38import android.webkit.WebSettings.ZoomDensity;
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +000039import android.webkit.WebSettingsClassic;
40import android.webkit.WebSettingsClassic.AutoFillProfile;
Nicolas Roard78a98e42009-05-11 13:34:17 +010041import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080042import android.webkit.WebView;
43import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044
John Reck46500332011-06-07 14:36:10 -070045import com.android.browser.homepages.HomeProvider;
46import com.android.browser.provider.BrowserProvider;
47import com.android.browser.search.SearchEngine;
48import com.android.browser.search.SearchEngines;
49
John Reck35e9dd62011-04-25 09:01:54 -070050import java.lang.ref.WeakReference;
51import java.util.Iterator;
52import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070053import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080054
John Reck35e9dd62011-04-25 09:01:54 -070055/**
56 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080057 */
John Reck35e9dd62011-04-25 09:01:54 -070058public class BrowserSettings implements OnSharedPreferenceChangeListener,
59 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010060
John Reck35e9dd62011-04-25 09:01:54 -070061 // TODO: Do something with this UserAgent stuff
John Reck7fd1e8f2011-04-27 18:22:57 -070062 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
63 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
64 "Chrome/11.0.696.34 Safari/534.24";
The Android Open Source Project0c908882009-03-03 19:32:16 -080065
66 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070067 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
68 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070069
70 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070071 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
72 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070073
74 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070075 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
76 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080077
John Reck7fd1e8f2011-04-27 18:22:57 -070078 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
79 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
80 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
81
John Reck35e9dd62011-04-25 09:01:54 -070082 private static final String USER_AGENTS[] = { null,
83 DESKTOP_USERAGENT,
84 IPHONE_USERAGENT,
85 IPAD_USERAGENT,
John Reck7fd1e8f2011-04-27 18:22:57 -070086 FROYO_USERAGENT,
87 HONEYCOMB_USERAGENT,
John Reck35e9dd62011-04-25 09:01:54 -070088 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080089
John Reck8fc22a12011-06-16 14:57:41 -070090 // The minimum min font size
91 // Aka, the lower bounds for the min font size range
92 // which is 1:5..24
93 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070094 // The initial value in the text zoom range
95 // This is what represents 100% in the SeekBarPreference range
96 private static final int TEXT_ZOOM_START_VAL = 10;
97 // The size of a single step in the text zoom range, in percent
98 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070099 // The initial value in the double tap zoom range
100 // This is what represents 100% in the SeekBarPreference range
101 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
102 // The size of a single step in the double tap zoom range, in percent
103 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -0700104
John Reck35e9dd62011-04-25 09:01:54 -0700105 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -0700106
John Reck35e9dd62011-04-25 09:01:54 -0700107 private Context mContext;
108 private SharedPreferences mPrefs;
109 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -0700110 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -0700111 private WebStorageSizeManager mWebStorageSizeManager;
112 private AutofillHandler mAutofillHandler;
John Reckb8b2af82011-05-20 15:58:33 -0700113 private WeakHashMap<WebSettings, String> mCustomUserAgents;
Ben Murdochaaa1f372011-07-25 15:40:58 +0100114 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -0700115 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -0700116 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -0700117
118 // Cached values
119 private int mPageCacheCapacity = 1;
120 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800121
John Reck35e9dd62011-04-25 09:01:54 -0700122 // Cached settings
123 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800124
Ben Murdochaaa1f372011-07-25 15:40:58 +0100125 private static String sFactoryResetUrl;
126
John Reck35e9dd62011-04-25 09:01:54 -0700127 public static void initialize(final Context context) {
128 sInstance = new BrowserSettings(context);
129 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800130
John Reck35e9dd62011-04-25 09:01:54 -0700131 public static BrowserSettings getInstance() {
132 return sInstance;
133 }
Ben Murdochef671652010-11-25 17:17:58 +0000134
John Reck35e9dd62011-04-25 09:01:54 -0700135 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100136 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700137 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
138 mAutofillHandler = new AutofillHandler(mContext);
139 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckb8b2af82011-05-20 15:58:33 -0700140 mCustomUserAgents = new WeakHashMap<WebSettings, String>();
John Reck35e9dd62011-04-25 09:01:54 -0700141 mAutofillHandler.asyncLoadFromDb();
John Reckcadae722011-07-25 11:36:17 -0700142 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700143 }
144
145 public void setController(Controller controller) {
146 mController = controller;
John Reckc477e712011-08-17 11:27:15 -0700147 if (sInitialized) {
148 syncSharedSettings();
149 }
Ben Murdochef671652010-11-25 17:17:58 +0000150 }
151
John Reck35e9dd62011-04-25 09:01:54 -0700152 public void startManagingSettings(WebSettings settings) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000153 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
John Reckc477e712011-08-17 11:27:15 -0700154 if (mNeedsSharedSync) {
155 syncSharedSettings();
156 }
John Reck35e9dd62011-04-25 09:01:54 -0700157 synchronized (mManagedSettings) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000158 syncStaticSettings(settingsClassic);
159 syncSetting(settingsClassic);
John Reck35e9dd62011-04-25 09:01:54 -0700160 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800161 }
162 }
163
John Reckd1d87312012-03-08 13:25:00 -0800164 public void stopManagingSettings(WebSettings settings) {
165 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
166 while (iter.hasNext()) {
167 WeakReference<WebSettings> ref = iter.next();
168 if (ref.get() == settings) {
169 iter.remove();
170 return;
171 }
172 }
173 }
174
John Reckcadae722011-07-25 11:36:17 -0700175 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700176
177 @Override
178 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700179 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
180 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700181 // the cost of one cached page is ~3M (measured using nytimes.com). For
182 // low end devices, we only cache one page. For high end devices, we try
183 // to cache more pages, currently choose 5.
184 if (ActivityManager.staticGetMemoryClass() > 16) {
185 mPageCacheCapacity = 5;
186 }
187 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
188 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
189 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700190 // Workaround b/5254577
191 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700192 if (Build.VERSION.CODENAME.equals("REL")) {
193 // This is a release build, always startup with debug disabled
194 setDebugEnabled(false);
195 }
196 if (mPrefs.contains(PREF_TEXT_SIZE)) {
197 /*
198 * Update from TextSize enum to zoom percent
199 * SMALLEST is 50%
200 * SMALLER is 75%
201 * NORMAL is 100%
202 * LARGER is 150%
203 * LARGEST is 200%
204 */
205 switch (getTextSize()) {
206 case SMALLEST:
207 setTextZoom(50);
208 break;
209 case SMALLER:
210 setTextZoom(75);
211 break;
212 case LARGER:
213 setTextZoom(150);
214 break;
215 case LARGEST:
216 setTextZoom(200);
217 break;
218 }
219 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
220 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100221
222 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
223 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
224 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
225 BrowserProvider.getClientId(mContext.getContentResolver()));
226 }
227
Ben Murdochaaa1f372011-07-25 15:40:58 +0100228 synchronized (BrowserSettings.class) {
229 sInitialized = true;
230 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700231 }
232 }
233 };
234
Ben Murdochaaa1f372011-07-25 15:40:58 +0100235 private static void requireInitialization() {
236 synchronized (BrowserSettings.class) {
237 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700238 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100239 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700240 } catch (InterruptedException e) {
241 }
242 }
243 }
244 }
245
The Android Open Source Project0c908882009-03-03 19:32:16 -0800246 /**
John Reck35e9dd62011-04-25 09:01:54 -0700247 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800248 */
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000249 private void syncSetting(WebSettingsClassic settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700250 settings.setGeolocationEnabled(enableGeolocation());
251 settings.setJavaScriptEnabled(enableJavascript());
252 settings.setLightTouchEnabled(enableLightTouch());
253 settings.setNavDump(enableNavDump());
Derek Sollenberger31adf672011-07-08 11:31:30 -0400254 settings.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
John Reck35e9dd62011-04-25 09:01:54 -0700255 settings.setShowVisualIndicator(enableVisualIndicator());
256 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
257 settings.setDefaultZoom(getDefaultZoom());
258 settings.setMinimumFontSize(getMinimumFontSize());
259 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck92f25f82011-04-26 16:57:10 -0700260 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700261 settings.setPluginState(getPluginState());
John Reck7dc444b2011-06-16 17:44:29 -0700262 settings.setTextZoom(getTextZoom());
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700263 settings.setDoubleTapZoom(getDoubleTapZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700264 settings.setAutoFillEnabled(isAutofillEnabled());
265 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100266 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700267 settings.setLoadsImagesAutomatically(loadImages());
268 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
269 settings.setSavePassword(rememberPasswords());
270 settings.setSaveFormData(saveFormdata());
271 settings.setUseWideViewPort(isWideViewport());
272 settings.setAutoFillProfile(getAutoFillProfile());
John Reckb8b2af82011-05-20 15:58:33 -0700273
274 String ua = mCustomUserAgents.get(settings);
John Reck46500332011-06-07 14:36:10 -0700275 if (ua != null) {
John Reckb8b2af82011-05-20 15:58:33 -0700276 settings.setUserAgentString(ua);
277 } else {
278 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
279 }
John Reck2fd9d0e2011-07-15 11:13:48 -0700280
John Reckea17e782011-10-27 17:15:59 -0700281 boolean useInverted = useInvertedRendering();
John Reckeabe5da2011-08-08 13:24:13 -0700282 settings.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700283 useInverted ? "true" : "false");
284 if (useInverted) {
285 settings.setProperty(WebViewProperties.gfxInvertedScreenContrast,
286 Float.toString(getInvertedContrast()));
287 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700288
John Reckea17e782011-10-27 17:15:59 -0700289 if (isDebugEnabled()) {
290 settings.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
291 enableCpuUploadPath() ? "true" : "false");
292 }
Ben Murdochef671652010-11-25 17:17:58 +0000293 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800294
John Reck35e9dd62011-04-25 09:01:54 -0700295 /**
296 * Syncs all the settings that have no UI
297 * These cannot change, so we only need to set them once per WebSettings
298 */
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000299 private void syncStaticSettings(WebSettingsClassic settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700300 settings.setDefaultFontSize(16);
301 settings.setDefaultFixedFontSize(13);
302 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000303
John Reck35e9dd62011-04-25 09:01:54 -0700304 // WebView inside Browser doesn't want initial focus to be set.
305 settings.setNeedInitialFocus(false);
306 // Browser supports multiple windows
307 settings.setSupportMultipleWindows(true);
308 // enable smooth transition for better performance during panning or
309 // zooming
310 settings.setEnableSmoothTransition(true);
Teng-Hui Zhu164f74e2011-11-07 12:54:43 -0800311 // WebView should be preserving the memory as much as possible.
312 // However, apps like browser wish to turn on the performance mode which
313 // would require more memory.
314 // TODO: We need to dynamically allocate/deallocate temporary memory for
315 // apps which are trying to use minimal memory. Currently, double
316 // buffering is always turned on, which is unnecessary.
317 settings.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
John Reck35e9dd62011-04-25 09:01:54 -0700318 // disable content url access
319 settings.setAllowContentAccess(false);
320
321 // HTML5 API flags
322 settings.setAppCacheEnabled(true);
323 settings.setDatabaseEnabled(true);
324 settings.setDomStorageEnabled(true);
325 settings.setWorkersEnabled(true); // This only affects V8.
326
327 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700328 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700329 settings.setAppCachePath(getAppCachePath());
330 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
331 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700332 // origin policy for file access
333 settings.setAllowUniversalAccessFromFileURLs(false);
334 settings.setAllowFileAccessFromFileURLs(false);
John Reck35e9dd62011-04-25 09:01:54 -0700335 }
336
337 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700338 mNeedsSharedSync = false;
John Reck35e9dd62011-04-25 09:01:54 -0700339 CookieManager.getInstance().setAcceptCookie(acceptCookies());
340 if (mController != null) {
341 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700342 }
John Reck35e9dd62011-04-25 09:01:54 -0700343 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700344
John Reck35e9dd62011-04-25 09:01:54 -0700345 private void syncManagedSettings() {
346 syncSharedSettings();
347 synchronized (mManagedSettings) {
348 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
349 while (iter.hasNext()) {
350 WeakReference<WebSettings> ref = iter.next();
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000351 WebSettingsClassic settings = (WebSettingsClassic)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700352 if (settings == null) {
353 iter.remove();
354 continue;
355 }
356 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000357 }
John Reck35e9dd62011-04-25 09:01:54 -0700358 }
359 }
Ben Murdochef671652010-11-25 17:17:58 +0000360
John Reck35e9dd62011-04-25 09:01:54 -0700361 @Override
362 public void onSharedPreferenceChanged(
363 SharedPreferences sharedPreferences, String key) {
364 syncManagedSettings();
365 if (PREF_SEARCH_ENGINE.equals(key)) {
366 updateSearchEngine(false);
367 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700368 if (PREF_FULLSCREEN.equals(key)) {
369 if (mController.getUi() != null) {
370 mController.getUi().setFullscreen(useFullscreen());
371 }
Michael Kolb0241e752011-07-07 14:58:50 -0700372 } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
373 if (mController.getUi() != null) {
374 mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
375 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700376 }
John Reck35e9dd62011-04-25 09:01:54 -0700377 }
378
John Reck961d35d2011-06-23 09:45:54 -0700379 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100380 requireInitialization();
381 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700382 }
383
384 public LayoutAlgorithm getLayoutAlgorithm() {
385 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
386 if (autofitPages()) {
387 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
388 }
389 if (isDebugEnabled()) {
390 if (isSmallScreen()) {
391 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000392 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700393 if (isNormalLayout()) {
394 layoutAlgorithm = LayoutAlgorithm.NORMAL;
395 } else {
396 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
397 }
Ben Murdochef671652010-11-25 17:17:58 +0000398 }
John Reck35e9dd62011-04-25 09:01:54 -0700399 }
400 return layoutAlgorithm;
401 }
Ben Murdochef671652010-11-25 17:17:58 +0000402
John Reck35e9dd62011-04-25 09:01:54 -0700403 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700404 requireInitialization();
405 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800406 }
407
John Reck35e9dd62011-04-25 09:01:54 -0700408 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700409 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700410 return mWebStorageSizeManager;
411 }
412
John Reck35e9dd62011-04-25 09:01:54 -0700413 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700414 if (mAppCachePath == null) {
415 mAppCachePath = mContext.getDir("appcache", 0).getPath();
416 }
417 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700418 }
419
420 private void updateSearchEngine(boolean force) {
421 String searchEngineName = getSearchEngineName();
422 if (force || mSearchEngine == null ||
423 !mSearchEngine.getName().equals(searchEngineName)) {
424 if (mSearchEngine != null) {
425 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000426 // One or more tabs could have been in voice search mode.
427 // Clear it, since the new SearchEngine may not support
428 // it, or may handle it differently.
429 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
430 mController.getTabControl().getTab(i).revertVoiceSearchMode();
431 }
432 }
John Reck35e9dd62011-04-25 09:01:54 -0700433 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000434 }
John Reck35e9dd62011-04-25 09:01:54 -0700435 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000436 }
437 }
438
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100439 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700440 if (mSearchEngine == null) {
441 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100442 }
John Reck35e9dd62011-04-25 09:01:54 -0700443 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100444 }
445
John Reck35e9dd62011-04-25 09:01:54 -0700446 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700447 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700448 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100449 }
450
John Reck35e9dd62011-04-25 09:01:54 -0700451 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700452 Editor edit = mPrefs.edit();
453 edit.putBoolean(PREF_DEBUG_MENU, value);
454 if (!value) {
455 // Reset to "safe" value
456 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
457 }
458 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100459 }
460
John Reck35e9dd62011-04-25 09:01:54 -0700461 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800462 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700463 if (mController != null) {
464 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800465 if (current != null) {
466 current.clearCache(true);
467 }
468 }
469 }
470
John Reck35e9dd62011-04-25 09:01:54 -0700471 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800472 CookieManager.getInstance().removeAllCookie();
473 }
474
John Reck35e9dd62011-04-25 09:01:54 -0700475 public void clearHistory() {
476 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800477 Browser.clearHistory(resolver);
478 Browser.clearSearches(resolver);
479 }
480
John Reck35e9dd62011-04-25 09:01:54 -0700481 public void clearFormData() {
482 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700483 if (mController!= null) {
484 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100485 if (currentTopView != null) {
486 currentTopView.clearFormData();
487 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800488 }
489 }
490
John Reck35e9dd62011-04-25 09:01:54 -0700491 public void clearPasswords() {
492 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800493 db.clearUsernamePassword();
494 db.clearHttpAuthUsernamePassword();
495 }
496
John Reck35e9dd62011-04-25 09:01:54 -0700497 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100498 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100499 }
500
John Reck35e9dd62011-04-25 09:01:54 -0700501 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100502 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100503 }
504
John Reck35e9dd62011-04-25 09:01:54 -0700505 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700506 // Preserve autologin setting
507 long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1);
508 mPrefs.edit()
509 .clear()
510 .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal)
511 .apply();
John Reck35e9dd62011-04-25 09:01:54 -0700512 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700513 }
514
John Reck35e9dd62011-04-25 09:01:54 -0700515 public AutoFillProfile getAutoFillProfile() {
516 mAutofillHandler.waitForLoad();
517 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800518 }
519
John Reck35e9dd62011-04-25 09:01:54 -0700520 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
521 mAutofillHandler.waitForLoad();
522 mAutofillHandler.setAutoFillProfile(profile, msg);
Ben Murdoch273330a2011-07-08 18:37:22 +0100523 // Auto-fill will reuse the same profile ID when making edits to the profile,
524 // so we need to force a settings sync (otherwise the SharedPreferences
525 // manager will optimise out the call to onSharedPreferenceChanged(), as
526 // it thinks nothing has changed).
527 syncManagedSettings();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800528 }
529
John Reck35e9dd62011-04-25 09:01:54 -0700530 public void toggleDebugSettings() {
531 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800532 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100533
John Reckb8b2af82011-05-20 15:58:33 -0700534 public boolean hasDesktopUseragent(WebView view) {
535 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
536 }
537
538 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700539 if (view == null) {
540 return;
541 }
John Reckb8b2af82011-05-20 15:58:33 -0700542 WebSettings settings = view.getSettings();
543 if (mCustomUserAgents.get(settings) != null) {
544 mCustomUserAgents.remove(settings);
545 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
546 } else {
547 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
548 settings.setUserAgentString(DESKTOP_USERAGENT);
549 }
550 }
551
John Reck7dc444b2011-06-16 17:44:29 -0700552 public static int getAdjustedMinimumFontSize(int rawValue) {
553 rawValue++; // Preference starts at 0, min font at 1
554 if (rawValue > 1) {
555 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
556 }
557 return rawValue;
558 }
559
John Reck5ba3c762011-09-14 15:00:15 -0700560 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700561 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700562 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700563 }
564
565 static int getRawTextZoom(int percent) {
566 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
567 }
568
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700569 public int getAdjustedDoubleTapZoom(int rawValue) {
570 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
571 return (int) ((rawValue + 100) * mFontSizeMult);
572 }
573
574 static int getRawDoubleTapZoom(int percent) {
575 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
576 }
577
John Reckcadae722011-07-25 11:36:17 -0700578 public SharedPreferences getPreferences() {
579 return mPrefs;
580 }
581
John Reck35e9dd62011-04-25 09:01:54 -0700582 // -----------------------------
583 // getter/setters for accessibility_preferences.xml
584 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100585
John Reck7dc444b2011-06-16 17:44:29 -0700586 @Deprecated
587 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700588 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
589 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100590 }
591
John Reck35e9dd62011-04-25 09:01:54 -0700592 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700593 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700594 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100595 }
596
John Reck92f25f82011-04-26 16:57:10 -0700597 public boolean forceEnableUserScalable() {
598 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
599 }
600
John Reck7dc444b2011-06-16 17:44:29 -0700601 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700602 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700603 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
604 return getAdjustedTextZoom(textZoom);
605 }
606
607 public void setTextZoom(int percent) {
608 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
609 }
610
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700611 public int getDoubleTapZoom() {
612 requireInitialization();
613 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
614 return getAdjustedDoubleTapZoom(doubleTapZoom);
615 }
616
617 public void setDoubleTapZoom(int percent) {
618 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
619 }
620
John Reck35e9dd62011-04-25 09:01:54 -0700621 // -----------------------------
622 // getter/setters for advanced_preferences.xml
623 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100624
John Reck35e9dd62011-04-25 09:01:54 -0700625 public String getSearchEngineName() {
626 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100627 }
John Reck63bb6872010-12-01 19:29:32 -0800628
John Reck35e9dd62011-04-25 09:01:54 -0700629 public boolean openInBackground() {
630 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800631 }
John Reck35e9dd62011-04-25 09:01:54 -0700632
633 public boolean enableJavascript() {
634 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
635 }
636
637 // TODO: Cache
638 public PluginState getPluginState() {
639 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
640 return PluginState.valueOf(state);
641 }
642
643 // TODO: Cache
644 public ZoomDensity getDefaultZoom() {
645 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
646 return ZoomDensity.valueOf(zoom);
647 }
648
649 public boolean loadPageInOverviewMode() {
650 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
651 }
652
653 public boolean autofitPages() {
654 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
655 }
656
657 public boolean blockPopupWindows() {
658 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
659 }
660
661 public boolean loadImages() {
662 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
663 }
664
665 public String getDefaultTextEncoding() {
666 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
667 }
668
669 // -----------------------------
670 // getter/setters for general_preferences.xml
671 // -----------------------------
672
673 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700674 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
675 }
676
677 public void setHomePage(String value) {
678 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
679 }
680
681 public boolean isAutofillEnabled() {
682 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
683 }
684
685 public void setAutofillEnabled(boolean value) {
686 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
687 }
688
689 // -----------------------------
690 // getter/setters for debug_preferences.xml
691 // -----------------------------
692
693 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700694 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700695 return true;
696 }
697 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
698 }
699
Derek Sollenberger31adf672011-07-08 11:31:30 -0400700 public boolean isSkiaHardwareAccelerated() {
701 if (!isDebugEnabled()) {
702 return false;
703 }
704 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
705 }
706
John Reck35e9dd62011-04-25 09:01:54 -0700707 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700708 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700709 return 0;
710 }
711 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
712 }
713
714 // -----------------------------
715 // getter/setters for hidden_debug_preferences.xml
716 // -----------------------------
717
718 public boolean enableVisualIndicator() {
719 if (!isDebugEnabled()) {
720 return false;
721 }
722 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
723 }
724
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700725 public boolean enableCpuUploadPath() {
726 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700727 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700728 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700729 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700730 }
731
John Reck35e9dd62011-04-25 09:01:54 -0700732 public boolean enableJavascriptConsole() {
733 if (!isDebugEnabled()) {
734 return false;
735 }
736 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
737 }
738
739 public boolean isSmallScreen() {
740 if (!isDebugEnabled()) {
741 return false;
742 }
743 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
744 }
745
746 public boolean isWideViewport() {
747 if (!isDebugEnabled()) {
748 return true;
749 }
750 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
751 }
752
753 public boolean isNormalLayout() {
754 if (!isDebugEnabled()) {
755 return false;
756 }
757 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
758 }
759
760 public boolean isTracing() {
761 if (!isDebugEnabled()) {
762 return false;
763 }
764 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
765 }
766
767 public boolean enableLightTouch() {
768 if (!isDebugEnabled()) {
769 return false;
770 }
771 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
772 }
773
774 public boolean enableNavDump() {
775 if (!isDebugEnabled()) {
776 return false;
777 }
778 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
779 }
780
781 public String getJsEngineFlags() {
782 if (!isDebugEnabled()) {
783 return "";
784 }
785 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
786 }
787
788 // -----------------------------
789 // getter/setters for lab_preferences.xml
790 // -----------------------------
791
792 public boolean useQuickControls() {
793 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
794 }
795
796 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700797 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700798 }
799
Michael Kolbc38c6042011-04-27 10:46:06 -0700800 public boolean useFullscreen() {
801 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
802 }
803
John Reck2fd9d0e2011-07-15 11:13:48 -0700804 public boolean useInvertedRendering() {
805 return mPrefs.getBoolean(PREF_INVERTED, false);
806 }
807
Nicolas Roard5d513102011-08-03 15:35:34 -0700808 public float getInvertedContrast() {
809 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
810 }
811
John Reck35e9dd62011-04-25 09:01:54 -0700812 // -----------------------------
813 // getter/setters for privacy_security_preferences.xml
814 // -----------------------------
815
816 public boolean showSecurityWarnings() {
817 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
818 }
819
820 public boolean acceptCookies() {
821 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
822 }
823
824 public boolean saveFormdata() {
825 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
826 }
827
828 public boolean enableGeolocation() {
829 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
830 }
831
832 public boolean rememberPasswords() {
833 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
834 }
835
Michael Kolb14612442011-06-24 13:06:29 -0700836 // -----------------------------
837 // getter/setters for bandwidth_preferences.xml
838 // -----------------------------
839
Mathew Inwood467813f2011-09-02 15:43:17 +0100840 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
841 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700842 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100843
844 public static String getPreloadAlwaysPreferenceString(Context context) {
845 return context.getResources().getString(R.string.pref_data_preload_value_always);
846 }
847
Mathew Inwood825fba72011-10-04 14:52:52 +0100848 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
849 "browser_default_preload_setting";
850
851 public String getDefaultPreloadSetting() {
852 String preload = Settings.Secure.getString(mContext.getContentResolver(),
853 DEAULT_PRELOAD_SECURE_SETTING_KEY);
854 if (preload == null) {
855 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
856 }
857 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100858 }
859
860 public String getPreloadEnabled() {
861 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
862 }
863
George Mount3636d0a2011-11-21 09:08:21 -0800864 // -----------------------------
865 // getter/setters for browser recovery
866 // -----------------------------
867 /**
868 * The last time browser was started.
869 * @return The last browser start time as System.currentTimeMillis. This
870 * can be 0 if this is the first time or the last tab was closed.
871 */
872 public long getLastRecovered() {
873 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
874 }
875
876 /**
877 * Sets the last browser start time.
878 * @param time The last time as System.currentTimeMillis that the browser
879 * was started. This should be set to 0 if the last tab is closed.
880 */
881 public void setLastRecovered(long time) {
882 mPrefs.edit()
883 .putLong(KEY_LAST_RECOVERED, time)
884 .apply();
885 }
886
887 /**
888 * Used to determine whether or not the previous browser run crashed. Once
889 * the previous state has been determined, the value will be set to false
890 * until a pause is received.
891 * @return true if the last browser run was paused or false if it crashed.
892 */
893 public boolean wasLastRunPaused() {
894 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
895 }
896
897 /**
898 * Sets whether or not the last run was a pause or crash.
899 * @param isPaused Set to true When a pause is received or false after
900 * resuming.
901 */
902 public void setLastRunPaused(boolean isPaused) {
903 mPrefs.edit()
904 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
905 .apply();
906 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800907}