|
|
|
@ -12,19 +12,13 @@ import android.os.Message;
@@ -12,19 +12,13 @@ import android.os.Message;
|
|
|
|
|
import android.preference.CheckBoxPreference; |
|
|
|
|
import android.preference.Preference; |
|
|
|
|
import android.preference.PreferenceFragment; |
|
|
|
|
import android.provider.Browser; |
|
|
|
|
import android.support.v7.app.AlertDialog; |
|
|
|
|
import android.webkit.CookieManager; |
|
|
|
|
import android.webkit.CookieSyncManager; |
|
|
|
|
import android.webkit.WebIconDatabase; |
|
|
|
|
import android.webkit.WebStorage; |
|
|
|
|
import android.webkit.WebView; |
|
|
|
|
import android.webkit.WebViewDatabase; |
|
|
|
|
|
|
|
|
|
import acr.browser.lightning.R; |
|
|
|
|
import acr.browser.lightning.database.HistoryDatabase; |
|
|
|
|
import acr.browser.lightning.preference.PreferenceManager; |
|
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
|
import acr.browser.lightning.utils.WebUtils; |
|
|
|
|
|
|
|
|
|
public class PrivacySettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { |
|
|
|
|
|
|
|
|
@ -38,12 +32,14 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -38,12 +32,14 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
private static final String SETTINGS_CLEARCACHE = "clear_cache"; |
|
|
|
|
private static final String SETTINGS_CLEARHISTORY = "clear_history"; |
|
|
|
|
private static final String SETTINGS_CLEARCOOKIES = "clear_cookies"; |
|
|
|
|
private static final String SETTINGS_CLEARWEBSTORAGE = "clear_webstorage"; |
|
|
|
|
private static final String SETTINGS_WEBSTORAGEEXIT = "clear_webstorage_exit"; |
|
|
|
|
|
|
|
|
|
private static final int API = android.os.Build.VERSION.SDK_INT; |
|
|
|
|
private Activity mActivity; |
|
|
|
|
private PreferenceManager mPreferences; |
|
|
|
|
private CheckBoxPreference cblocation, cb3cookies, cbsavepasswords, cbcacheexit, cbhistoryexit, |
|
|
|
|
cbcookiesexit, cbsynchistory; |
|
|
|
|
cbcookiesexit, cbsynchistory, cbwebstorageexit; |
|
|
|
|
private boolean mSystemBrowser; |
|
|
|
|
private Handler messageHandler; |
|
|
|
|
|
|
|
|
@ -66,6 +62,8 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -66,6 +62,8 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
Preference clearcache = findPreference(SETTINGS_CLEARCACHE); |
|
|
|
|
Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY); |
|
|
|
|
Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES); |
|
|
|
|
Preference clearwebstorage = findPreference(SETTINGS_CLEARWEBSTORAGE); |
|
|
|
|
|
|
|
|
|
cblocation = (CheckBoxPreference) findPreference(SETTINGS_LOCATION); |
|
|
|
|
cb3cookies = (CheckBoxPreference) findPreference(SETTINGS_THIRDPCOOKIES); |
|
|
|
|
cbsavepasswords = (CheckBoxPreference) findPreference(SETTINGS_SAVEPASSWORD); |
|
|
|
@ -73,10 +71,13 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -73,10 +71,13 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
cbhistoryexit = (CheckBoxPreference) findPreference(SETTINGS_HISTORYEXIT); |
|
|
|
|
cbcookiesexit = (CheckBoxPreference) findPreference(SETTINGS_COOKIEEXIT); |
|
|
|
|
cbsynchistory = (CheckBoxPreference) findPreference(SETTINGS_SYNCHISTORY); |
|
|
|
|
cbwebstorageexit = (CheckBoxPreference) findPreference(SETTINGS_WEBSTORAGEEXIT); |
|
|
|
|
|
|
|
|
|
clearcache.setOnPreferenceClickListener(this); |
|
|
|
|
clearhistory.setOnPreferenceClickListener(this); |
|
|
|
|
clearcookies.setOnPreferenceClickListener(this); |
|
|
|
|
clearwebstorage.setOnPreferenceClickListener(this); |
|
|
|
|
|
|
|
|
|
cblocation.setOnPreferenceChangeListener(this); |
|
|
|
|
cb3cookies.setOnPreferenceChangeListener(this); |
|
|
|
|
cbsavepasswords.setOnPreferenceChangeListener(this); |
|
|
|
@ -84,6 +85,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -84,6 +85,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
cbhistoryexit.setOnPreferenceChangeListener(this); |
|
|
|
|
cbcookiesexit.setOnPreferenceChangeListener(this); |
|
|
|
|
cbsynchistory.setOnPreferenceChangeListener(this); |
|
|
|
|
cbwebstorageexit.setOnPreferenceChangeListener(this); |
|
|
|
|
|
|
|
|
|
cblocation.setChecked(mPreferences.getLocationEnabled()); |
|
|
|
|
cbsavepasswords.setChecked(mPreferences.getSavePasswordsEnabled()); |
|
|
|
@ -91,6 +93,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -91,6 +93,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
cbhistoryexit.setChecked(mPreferences.getClearHistoryExitEnabled()); |
|
|
|
|
cbcookiesexit.setChecked(mPreferences.getClearCookiesExitEnabled()); |
|
|
|
|
cb3cookies.setChecked(mPreferences.getBlockThirdPartyCookiesEnabled()); |
|
|
|
|
cbwebstorageexit.setChecked(mPreferences.getClearWebStorageExitEnabled()); |
|
|
|
|
|
|
|
|
|
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); |
|
|
|
|
|
|
|
|
@ -141,6 +144,9 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -141,6 +144,9 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
case SETTINGS_CLEARCOOKIES: |
|
|
|
|
clearCookiesDialog(); |
|
|
|
|
return true; |
|
|
|
|
case SETTINGS_CLEARWEBSTORAGE: |
|
|
|
|
clearWebStorage(); |
|
|
|
|
return true; |
|
|
|
|
default: |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -203,43 +209,21 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -203,43 +209,21 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
Utils.showSnackbar(mActivity, R.string.message_cache_cleared); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
|
private void clearHistory() { |
|
|
|
|
mActivity.deleteDatabase(HistoryDatabase.DATABASE_NAME); |
|
|
|
|
WebViewDatabase m = WebViewDatabase.getInstance(mActivity); |
|
|
|
|
m.clearFormData(); |
|
|
|
|
m.clearHttpAuthUsernamePassword(); |
|
|
|
|
if (API < 18) { |
|
|
|
|
m.clearUsernamePassword(); |
|
|
|
|
WebIconDatabase.getInstance().removeAllIcons(); |
|
|
|
|
} |
|
|
|
|
if (mSystemBrowser) { |
|
|
|
|
try { |
|
|
|
|
Browser.clearHistory(mActivity.getContentResolver()); |
|
|
|
|
} catch (Exception ignored) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Utils.trimCache(mActivity); |
|
|
|
|
WebUtils.clearHistory(getActivity(), mSystemBrowser); |
|
|
|
|
messageHandler.sendEmptyMessage(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
|
private void clearCookies() { |
|
|
|
|
// TODO Break out web storage deletion into its own option/action
|
|
|
|
|
// TODO clear web storage for all sites that are visited in Incognito mode
|
|
|
|
|
WebStorage storage = WebStorage.getInstance(); |
|
|
|
|
storage.deleteAllData(); |
|
|
|
|
CookieManager c = CookieManager.getInstance(); |
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
|
c.removeAllCookies(null); |
|
|
|
|
} else { |
|
|
|
|
CookieSyncManager.createInstance(mActivity); |
|
|
|
|
c.removeAllCookie(); |
|
|
|
|
} |
|
|
|
|
WebUtils.clearCookies(getActivity()); |
|
|
|
|
messageHandler.sendEmptyMessage(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void clearWebStorage() { |
|
|
|
|
WebUtils.clearWebStorage(); |
|
|
|
|
Utils.showSnackbar(getActivity(), R.string.message_web_storage_cleared); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) { |
|
|
|
|
// switch preferences
|
|
|
|
@ -268,6 +252,10 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
@@ -268,6 +252,10 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|
|
|
|
mPreferences.setClearCookiesExitEnabled((Boolean) newValue); |
|
|
|
|
cbcookiesexit.setChecked((Boolean) newValue); |
|
|
|
|
return true; |
|
|
|
|
case SETTINGS_WEBSTORAGEEXIT: |
|
|
|
|
mPreferences.setClearWebStorageExitEnabled((Boolean) newValue); |
|
|
|
|
cbwebstorageexit.setChecked((Boolean) newValue); |
|
|
|
|
return true; |
|
|
|
|
case SETTINGS_SYNCHISTORY: |
|
|
|
|
mPreferences.setSyncHistoryEnabled((Boolean) newValue); |
|
|
|
|
cbsynchistory.setChecked((Boolean) newValue); |
|
|
|
|