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