blob: 4fe93d6ed969cfae498f5e5631fd0d4e340c1696 [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());
332 }
333
334 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700335 mNeedsSharedSync = false;
John Reck35e9dd62011-04-25 09:01:54 -0700336 CookieManager.getInstance().setAcceptCookie(acceptCookies());
337 if (mController != null) {
338 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700339 }
John Reck35e9dd62011-04-25 09:01:54 -0700340 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700341
John Reck35e9dd62011-04-25 09:01:54 -0700342 private void syncManagedSettings() {
343 syncSharedSettings();
344 synchronized (mManagedSettings) {
345 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
346 while (iter.hasNext()) {
347 WeakReference<WebSettings> ref = iter.next();
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000348 WebSettingsClassic settings = (WebSettingsClassic)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700349 if (settings == null) {
350 iter.remove();
351 continue;
352 }
353 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000354 }
John Reck35e9dd62011-04-25 09:01:54 -0700355 }
356 }
Ben Murdochef671652010-11-25 17:17:58 +0000357
John Reck35e9dd62011-04-25 09:01:54 -0700358 @Override
359 public void onSharedPreferenceChanged(
360 SharedPreferences sharedPreferences, String key) {
361 syncManagedSettings();
362 if (PREF_SEARCH_ENGINE.equals(key)) {
363 updateSearchEngine(false);
364 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700365 if (PREF_FULLSCREEN.equals(key)) {
366 if (mController.getUi() != null) {
367 mController.getUi().setFullscreen(useFullscreen());
368 }
Michael Kolb0241e752011-07-07 14:58:50 -0700369 } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
370 if (mController.getUi() != null) {
371 mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
372 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700373 }
John Reck35e9dd62011-04-25 09:01:54 -0700374 }
375
John Reck961d35d2011-06-23 09:45:54 -0700376 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100377 requireInitialization();
378 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700379 }
380
381 public LayoutAlgorithm getLayoutAlgorithm() {
382 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
383 if (autofitPages()) {
384 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
385 }
386 if (isDebugEnabled()) {
387 if (isSmallScreen()) {
388 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000389 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700390 if (isNormalLayout()) {
391 layoutAlgorithm = LayoutAlgorithm.NORMAL;
392 } else {
393 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
394 }
Ben Murdochef671652010-11-25 17:17:58 +0000395 }
John Reck35e9dd62011-04-25 09:01:54 -0700396 }
397 return layoutAlgorithm;
398 }
Ben Murdochef671652010-11-25 17:17:58 +0000399
John Reck35e9dd62011-04-25 09:01:54 -0700400 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700401 requireInitialization();
402 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800403 }
404
John Reck35e9dd62011-04-25 09:01:54 -0700405 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700406 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700407 return mWebStorageSizeManager;
408 }
409
John Reck35e9dd62011-04-25 09:01:54 -0700410 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700411 if (mAppCachePath == null) {
412 mAppCachePath = mContext.getDir("appcache", 0).getPath();
413 }
414 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700415 }
416
417 private void updateSearchEngine(boolean force) {
418 String searchEngineName = getSearchEngineName();
419 if (force || mSearchEngine == null ||
420 !mSearchEngine.getName().equals(searchEngineName)) {
421 if (mSearchEngine != null) {
422 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000423 // One or more tabs could have been in voice search mode.
424 // Clear it, since the new SearchEngine may not support
425 // it, or may handle it differently.
426 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
427 mController.getTabControl().getTab(i).revertVoiceSearchMode();
428 }
429 }
John Reck35e9dd62011-04-25 09:01:54 -0700430 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000431 }
John Reck35e9dd62011-04-25 09:01:54 -0700432 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000433 }
434 }
435
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100436 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700437 if (mSearchEngine == null) {
438 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100439 }
John Reck35e9dd62011-04-25 09:01:54 -0700440 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100441 }
442
John Reck35e9dd62011-04-25 09:01:54 -0700443 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700444 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700445 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100446 }
447
John Reck35e9dd62011-04-25 09:01:54 -0700448 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700449 Editor edit = mPrefs.edit();
450 edit.putBoolean(PREF_DEBUG_MENU, value);
451 if (!value) {
452 // Reset to "safe" value
453 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
454 }
455 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100456 }
457
John Reck35e9dd62011-04-25 09:01:54 -0700458 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800459 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 if (mController != null) {
461 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800462 if (current != null) {
463 current.clearCache(true);
464 }
465 }
466 }
467
John Reck35e9dd62011-04-25 09:01:54 -0700468 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800469 CookieManager.getInstance().removeAllCookie();
470 }
471
John Reck35e9dd62011-04-25 09:01:54 -0700472 public void clearHistory() {
473 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800474 Browser.clearHistory(resolver);
475 Browser.clearSearches(resolver);
476 }
477
John Reck35e9dd62011-04-25 09:01:54 -0700478 public void clearFormData() {
479 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700480 if (mController!= null) {
481 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100482 if (currentTopView != null) {
483 currentTopView.clearFormData();
484 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800485 }
486 }
487
John Reck35e9dd62011-04-25 09:01:54 -0700488 public void clearPasswords() {
489 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800490 db.clearUsernamePassword();
491 db.clearHttpAuthUsernamePassword();
492 }
493
John Reck35e9dd62011-04-25 09:01:54 -0700494 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100495 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100496 }
497
John Reck35e9dd62011-04-25 09:01:54 -0700498 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100499 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100500 }
501
John Reck35e9dd62011-04-25 09:01:54 -0700502 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700503 // Preserve autologin setting
504 long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1);
505 mPrefs.edit()
506 .clear()
507 .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal)
508 .apply();
John Reck35e9dd62011-04-25 09:01:54 -0700509 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700510 }
511
John Reck35e9dd62011-04-25 09:01:54 -0700512 public AutoFillProfile getAutoFillProfile() {
513 mAutofillHandler.waitForLoad();
514 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800515 }
516
John Reck35e9dd62011-04-25 09:01:54 -0700517 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
518 mAutofillHandler.waitForLoad();
519 mAutofillHandler.setAutoFillProfile(profile, msg);
Ben Murdoch273330a2011-07-08 18:37:22 +0100520 // Auto-fill will reuse the same profile ID when making edits to the profile,
521 // so we need to force a settings sync (otherwise the SharedPreferences
522 // manager will optimise out the call to onSharedPreferenceChanged(), as
523 // it thinks nothing has changed).
524 syncManagedSettings();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800525 }
526
John Reck35e9dd62011-04-25 09:01:54 -0700527 public void toggleDebugSettings() {
528 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800529 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100530
John Reckb8b2af82011-05-20 15:58:33 -0700531 public boolean hasDesktopUseragent(WebView view) {
532 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
533 }
534
535 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700536 if (view == null) {
537 return;
538 }
John Reckb8b2af82011-05-20 15:58:33 -0700539 WebSettings settings = view.getSettings();
540 if (mCustomUserAgents.get(settings) != null) {
541 mCustomUserAgents.remove(settings);
542 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
543 } else {
544 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
545 settings.setUserAgentString(DESKTOP_USERAGENT);
546 }
547 }
548
John Reck7dc444b2011-06-16 17:44:29 -0700549 public static int getAdjustedMinimumFontSize(int rawValue) {
550 rawValue++; // Preference starts at 0, min font at 1
551 if (rawValue > 1) {
552 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
553 }
554 return rawValue;
555 }
556
John Reck5ba3c762011-09-14 15:00:15 -0700557 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700558 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700559 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700560 }
561
562 static int getRawTextZoom(int percent) {
563 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
564 }
565
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700566 public int getAdjustedDoubleTapZoom(int rawValue) {
567 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
568 return (int) ((rawValue + 100) * mFontSizeMult);
569 }
570
571 static int getRawDoubleTapZoom(int percent) {
572 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
573 }
574
John Reckcadae722011-07-25 11:36:17 -0700575 public SharedPreferences getPreferences() {
576 return mPrefs;
577 }
578
John Reck35e9dd62011-04-25 09:01:54 -0700579 // -----------------------------
580 // getter/setters for accessibility_preferences.xml
581 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100582
John Reck7dc444b2011-06-16 17:44:29 -0700583 @Deprecated
584 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700585 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
586 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100587 }
588
John Reck35e9dd62011-04-25 09:01:54 -0700589 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700590 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700591 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100592 }
593
John Reck92f25f82011-04-26 16:57:10 -0700594 public boolean forceEnableUserScalable() {
595 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
596 }
597
John Reck7dc444b2011-06-16 17:44:29 -0700598 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700599 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700600 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
601 return getAdjustedTextZoom(textZoom);
602 }
603
604 public void setTextZoom(int percent) {
605 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
606 }
607
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700608 public int getDoubleTapZoom() {
609 requireInitialization();
610 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
611 return getAdjustedDoubleTapZoom(doubleTapZoom);
612 }
613
614 public void setDoubleTapZoom(int percent) {
615 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
616 }
617
John Reck35e9dd62011-04-25 09:01:54 -0700618 // -----------------------------
619 // getter/setters for advanced_preferences.xml
620 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100621
John Reck35e9dd62011-04-25 09:01:54 -0700622 public String getSearchEngineName() {
623 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100624 }
John Reck63bb6872010-12-01 19:29:32 -0800625
John Reck35e9dd62011-04-25 09:01:54 -0700626 public boolean openInBackground() {
627 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800628 }
John Reck35e9dd62011-04-25 09:01:54 -0700629
630 public boolean enableJavascript() {
631 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
632 }
633
634 // TODO: Cache
635 public PluginState getPluginState() {
636 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
637 return PluginState.valueOf(state);
638 }
639
640 // TODO: Cache
641 public ZoomDensity getDefaultZoom() {
642 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
643 return ZoomDensity.valueOf(zoom);
644 }
645
646 public boolean loadPageInOverviewMode() {
647 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
648 }
649
650 public boolean autofitPages() {
651 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
652 }
653
654 public boolean blockPopupWindows() {
655 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
656 }
657
658 public boolean loadImages() {
659 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
660 }
661
662 public String getDefaultTextEncoding() {
663 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
664 }
665
666 // -----------------------------
667 // getter/setters for general_preferences.xml
668 // -----------------------------
669
670 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700671 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
672 }
673
674 public void setHomePage(String value) {
675 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
676 }
677
678 public boolean isAutofillEnabled() {
679 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
680 }
681
682 public void setAutofillEnabled(boolean value) {
683 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
684 }
685
686 // -----------------------------
687 // getter/setters for debug_preferences.xml
688 // -----------------------------
689
690 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700691 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700692 return true;
693 }
694 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
695 }
696
Derek Sollenberger31adf672011-07-08 11:31:30 -0400697 public boolean isSkiaHardwareAccelerated() {
698 if (!isDebugEnabled()) {
699 return false;
700 }
701 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
702 }
703
John Reck35e9dd62011-04-25 09:01:54 -0700704 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700705 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700706 return 0;
707 }
708 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
709 }
710
711 // -----------------------------
712 // getter/setters for hidden_debug_preferences.xml
713 // -----------------------------
714
715 public boolean enableVisualIndicator() {
716 if (!isDebugEnabled()) {
717 return false;
718 }
719 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
720 }
721
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700722 public boolean enableCpuUploadPath() {
723 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700724 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700725 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700726 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700727 }
728
John Reck35e9dd62011-04-25 09:01:54 -0700729 public boolean enableJavascriptConsole() {
730 if (!isDebugEnabled()) {
731 return false;
732 }
733 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
734 }
735
736 public boolean isSmallScreen() {
737 if (!isDebugEnabled()) {
738 return false;
739 }
740 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
741 }
742
743 public boolean isWideViewport() {
744 if (!isDebugEnabled()) {
745 return true;
746 }
747 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
748 }
749
750 public boolean isNormalLayout() {
751 if (!isDebugEnabled()) {
752 return false;
753 }
754 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
755 }
756
757 public boolean isTracing() {
758 if (!isDebugEnabled()) {
759 return false;
760 }
761 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
762 }
763
764 public boolean enableLightTouch() {
765 if (!isDebugEnabled()) {
766 return false;
767 }
768 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
769 }
770
771 public boolean enableNavDump() {
772 if (!isDebugEnabled()) {
773 return false;
774 }
775 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
776 }
777
778 public String getJsEngineFlags() {
779 if (!isDebugEnabled()) {
780 return "";
781 }
782 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
783 }
784
785 // -----------------------------
786 // getter/setters for lab_preferences.xml
787 // -----------------------------
788
789 public boolean useQuickControls() {
790 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
791 }
792
793 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700794 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700795 }
796
Michael Kolbc38c6042011-04-27 10:46:06 -0700797 public boolean useFullscreen() {
798 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
799 }
800
John Reck2fd9d0e2011-07-15 11:13:48 -0700801 public boolean useInvertedRendering() {
802 return mPrefs.getBoolean(PREF_INVERTED, false);
803 }
804
Nicolas Roard5d513102011-08-03 15:35:34 -0700805 public float getInvertedContrast() {
806 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
807 }
808
John Reck35e9dd62011-04-25 09:01:54 -0700809 // -----------------------------
810 // getter/setters for privacy_security_preferences.xml
811 // -----------------------------
812
813 public boolean showSecurityWarnings() {
814 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
815 }
816
817 public boolean acceptCookies() {
818 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
819 }
820
821 public boolean saveFormdata() {
822 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
823 }
824
825 public boolean enableGeolocation() {
826 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
827 }
828
829 public boolean rememberPasswords() {
830 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
831 }
832
Michael Kolb14612442011-06-24 13:06:29 -0700833 // -----------------------------
834 // getter/setters for bandwidth_preferences.xml
835 // -----------------------------
836
Mathew Inwood467813f2011-09-02 15:43:17 +0100837 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
838 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700839 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100840
841 public static String getPreloadAlwaysPreferenceString(Context context) {
842 return context.getResources().getString(R.string.pref_data_preload_value_always);
843 }
844
Mathew Inwood825fba72011-10-04 14:52:52 +0100845 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
846 "browser_default_preload_setting";
847
848 public String getDefaultPreloadSetting() {
849 String preload = Settings.Secure.getString(mContext.getContentResolver(),
850 DEAULT_PRELOAD_SECURE_SETTING_KEY);
851 if (preload == null) {
852 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
853 }
854 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100855 }
856
857 public String getPreloadEnabled() {
858 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
859 }
860
George Mount3636d0a2011-11-21 09:08:21 -0800861 // -----------------------------
862 // getter/setters for browser recovery
863 // -----------------------------
864 /**
865 * The last time browser was started.
866 * @return The last browser start time as System.currentTimeMillis. This
867 * can be 0 if this is the first time or the last tab was closed.
868 */
869 public long getLastRecovered() {
870 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
871 }
872
873 /**
874 * Sets the last browser start time.
875 * @param time The last time as System.currentTimeMillis that the browser
876 * was started. This should be set to 0 if the last tab is closed.
877 */
878 public void setLastRecovered(long time) {
879 mPrefs.edit()
880 .putLong(KEY_LAST_RECOVERED, time)
881 .apply();
882 }
883
884 /**
885 * Used to determine whether or not the previous browser run crashed. Once
886 * the previous state has been determined, the value will be set to false
887 * until a pause is received.
888 * @return true if the last browser run was paused or false if it crashed.
889 */
890 public boolean wasLastRunPaused() {
891 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
892 }
893
894 /**
895 * Sets whether or not the last run was a pause or crash.
896 * @param isPaused Set to true When a pause is received or false after
897 * resuming.
898 */
899 public void setLastRunPaused(boolean isPaused) {
900 mPrefs.edit()
901 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
902 .apply();
903 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800904}