diff --git a/res/layout/privacy_settings.xml b/res/layout/privacy_settings.xml index 0d2a8d5..c498791 100644 --- a/res/layout/privacy_settings.xml +++ b/res/layout/privacy_settings.xml @@ -45,6 +45,41 @@ android:layout_centerVertical="true" /> + + + + + + + + + Details about version, author and license. Close tab Close all tabs + Block 3rd Party Cookies + This feature is only available on Android 5.0+ diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index 7ce2785..57610ca 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/src/acr/browser/lightning/BrowserActivity.java @@ -31,6 +31,7 @@ import android.graphics.drawable.Drawable; import android.media.MediaPlayer; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -1429,10 +1430,15 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl Utils.trimCache(this); } + @SuppressWarnings("deprecation") public void clearCookies() { CookieManager c = CookieManager.getInstance(); - CookieSyncManager.createInstance(this); - c.removeAllCookie(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + c.removeAllCookies(null); + } else { + CookieSyncManager.createInstance(this); + c.removeAllCookie(); + } } @Override diff --git a/src/acr/browser/lightning/IncognitoActivity.java b/src/acr/browser/lightning/IncognitoActivity.java index 33bac29..6c707d9 100644 --- a/src/acr/browser/lightning/IncognitoActivity.java +++ b/src/acr/browser/lightning/IncognitoActivity.java @@ -2,6 +2,7 @@ package acr.browser.lightning; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.webkit.CookieManager; @@ -19,13 +20,16 @@ public class IncognitoActivity extends BrowserActivity { mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); } + @SuppressWarnings("deprecation") @Override public void updateCookiePreference() { if (mPreferences == null) { mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); } mCookieManager = CookieManager.getInstance(); - CookieSyncManager.createInstance(this); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + CookieSyncManager.createInstance(this); + } mCookieManager.setAcceptCookie(mPreferences.getBoolean( PreferenceConstants.INCOGNITO_COOKIES, false)); super.updateCookiePreference(); @@ -73,7 +77,7 @@ public class IncognitoActivity extends BrowserActivity { closeDrawers(); finish(); } - + @Override public int getMenu() { return R.menu.incognito; diff --git a/src/acr/browser/lightning/LightningView.java b/src/acr/browser/lightning/LightningView.java index c8b1a41..3b5ee36 100644 --- a/src/acr/browser/lightning/LightningView.java +++ b/src/acr/browser/lightning/LightningView.java @@ -28,6 +28,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.webkit.*; +import android.webkit.CookieManager; import android.webkit.WebSettings.LayoutAlgorithm; import android.webkit.WebSettings.PluginState; import android.widget.EditText; @@ -361,6 +362,10 @@ public class LightningView { mSettings.setTextZoom(50); break; } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, + !mPreferences.getBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, false)); + } } @SuppressWarnings("deprecation") diff --git a/src/acr/browser/lightning/MainActivity.java b/src/acr/browser/lightning/MainActivity.java index 7a56789..8ad4cb3 100644 --- a/src/acr/browser/lightning/MainActivity.java +++ b/src/acr/browser/lightning/MainActivity.java @@ -2,6 +2,7 @@ package acr.browser.lightning; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.webkit.CookieManager; @@ -19,13 +20,16 @@ public class MainActivity extends BrowserActivity { mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); } + @SuppressWarnings("deprecation") @Override public void updateCookiePreference() { if (mPreferences == null) { mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); } mCookieManager = CookieManager.getInstance(); - CookieSyncManager.createInstance(this); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + CookieSyncManager.createInstance(this); + } mCookieManager.setAcceptCookie(mPreferences.getBoolean(PreferenceConstants.COOKIES, true)); super.updateCookiePreference(); } diff --git a/src/acr/browser/lightning/PreferenceConstants.java b/src/acr/browser/lightning/PreferenceConstants.java index 3cfcb0b..5eb713b 100644 --- a/src/acr/browser/lightning/PreferenceConstants.java +++ b/src/acr/browser/lightning/PreferenceConstants.java @@ -40,6 +40,7 @@ public final class PreferenceConstants { public static final String SAVE_URL = "saveUrl"; public static final String RENDERING_MODE = "renderMode"; public static final String SYNC_HISTORY = "syncHistory"; + public static final String BLOCK_THIRD_PARTY = "thirdParty"; public static final String USE_PROXY = "useProxy"; public static final String USE_PROXY_HOST = "useProxyHost"; diff --git a/src/acr/browser/lightning/PrivacySettingsActivity.java b/src/acr/browser/lightning/PrivacySettingsActivity.java index 7700ef4..07a8469 100644 --- a/src/acr/browser/lightning/PrivacySettingsActivity.java +++ b/src/acr/browser/lightning/PrivacySettingsActivity.java @@ -7,6 +7,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -30,7 +31,8 @@ public class PrivacySettingsActivity extends ActionBarActivity { private static final int API = android.os.Build.VERSION.SDK_INT; private SharedPreferences mPreferences; private SharedPreferences.Editor mEditPrefs; - private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit, cbClearCookiesExit; + private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit, + cbClearCookiesExit, cbThirdParty; private Context mContext; private boolean mSystemBrowser; private Handler messageHandler; @@ -41,10 +43,10 @@ public class PrivacySettingsActivity extends ActionBarActivity { setContentView(R.layout.privacy_settings); // set up ActionBar - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { @@ -69,7 +71,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { private void initialize() { - RelativeLayout rLocation, rSavePasswords, rClearCacheExit, rClearHistoryExit, rClearCookiesExit, rClearCache, rClearHistory, rClearCookies; + RelativeLayout rLocation, rSavePasswords, rClearCacheExit, rClearHistoryExit, rClearCookiesExit, rClearCache, rClearHistory, rClearCookies, rThirdParty; rLocation = (RelativeLayout) findViewById(R.id.rLocation); rSavePasswords = (RelativeLayout) findViewById(R.id.rSavePasswords); @@ -79,20 +81,28 @@ public class PrivacySettingsActivity extends ActionBarActivity { rClearCache = (RelativeLayout) findViewById(R.id.rClearCache); rClearHistory = (RelativeLayout) findViewById(R.id.rClearHistory); rClearCookies = (RelativeLayout) findViewById(R.id.rClearCookies); + rThirdParty = (RelativeLayout) findViewById(R.id.rThirdParty); cbLocation = (CheckBox) findViewById(R.id.cbLocation); cbSavePasswords = (CheckBox) findViewById(R.id.cbSavePasswords); cbClearCacheExit = (CheckBox) findViewById(R.id.cbClearCacheExit); cbClearHistoryExit = (CheckBox) findViewById(R.id.cbClearHistoryExit); cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit); + cbThirdParty = (CheckBox) findViewById(R.id.cbThirdParty); cbLocation.setChecked(mPreferences.getBoolean(PreferenceConstants.LOCATION, false)); - cbSavePasswords.setChecked(mPreferences.getBoolean(PreferenceConstants.SAVE_PASSWORDS, true)); - cbClearCacheExit.setChecked(mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false)); + cbSavePasswords.setChecked(mPreferences + .getBoolean(PreferenceConstants.SAVE_PASSWORDS, true)); + cbClearCacheExit.setChecked(mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, + false)); cbClearHistoryExit.setChecked(mPreferences.getBoolean( PreferenceConstants.CLEAR_HISTORY_EXIT, false)); cbClearCookiesExit.setChecked(mPreferences.getBoolean( PreferenceConstants.CLEAR_COOKIES_EXIT, false)); + cbThirdParty.setChecked(mPreferences.getBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, + false)); + + cbThirdParty.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); rLocation(rLocation); rSavePasswords(rSavePasswords); @@ -102,11 +112,13 @@ public class PrivacySettingsActivity extends ActionBarActivity { rClearCache(rClearCache); rClearHistory(rClearHistory); rClearCookies(rClearCookies); + rThirdParty(rThirdParty); cbLocation(cbLocation); cbSavePasswords(cbSavePasswords); cbClearCacheExit(cbClearCacheExit); cbClearHistoryExit(cbClearHistoryExit); cbClearCookiesExit(cbClearCookiesExit); + cbThirdParty(cbThirdParty); TextView syncHistory = (TextView) findViewById(R.id.isBrowserAvailable); @@ -218,6 +230,18 @@ public class PrivacySettingsActivity extends ActionBarActivity { }); } + private void cbThirdParty(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mEditPrefs.putBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, isChecked); + mEditPrefs.commit(); + } + + }); + } + private void cbClearCookiesExit(CheckBox view) { view.setOnCheckedChangeListener(new OnCheckedChangeListener() { @@ -266,6 +290,22 @@ public class PrivacySettingsActivity extends ActionBarActivity { }); } + private void rThirdParty(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + cbThirdParty.setChecked(!cbThirdParty.isChecked()); + } else { + Utils.showToast(mContext, mContext.getString(R.string.available_lollipop)); + } + } + + }); + } + private void rClearHistoryExit(RelativeLayout view) { view.setOnClickListener(new OnClickListener() { @@ -409,10 +449,16 @@ public class PrivacySettingsActivity extends ActionBarActivity { messageHandler.sendEmptyMessage(1); } + @SuppressWarnings("deprecation") public void clearCookies() { CookieManager c = CookieManager.getInstance(); - CookieSyncManager.createInstance(this); - c.removeAllCookie(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + c.removeAllCookies(null); + } else { + CookieSyncManager.createInstance(this); + c.removeAllCookie(); + } messageHandler.sendEmptyMessage(2); } }