diff options
author | Dave Tharp <dtharp@codeaurora.org> | 2015-06-26 13:54:32 -0700 |
---|---|---|
committer | jrizzoli <joey@cyanogenmoditalia.it> | 2015-08-28 13:15:45 +0200 |
commit | ce624d4eb0df16ebd5cfefda9aaf93d5f6a4ad99 (patch) | |
tree | 6e1b89ac509ec62ad2668308a2000b2aedb7e26f /src/com/android/browser/mdm | |
parent | cda155abb868b2bb54816f87258878db6b030b4a (diff) | |
download | android_packages_apps_Gello-ce624d4eb0df16ebd5cfefda9aaf93d5f6a4ad99.tar.gz android_packages_apps_Gello-ce624d4eb0df16ebd5cfefda9aaf93d5f6a4ad99.tar.bz2 android_packages_apps_Gello-ce624d4eb0df16ebd5cfefda9aaf93d5f6a4ad99.zip |
[MDM] Rework Third Party Cookie Restriction for new UI
Previous implementation of the Third Party Cookie (TPC)
Restriction was done before SWE had a UI element to
control this feature. The implementation included a
separate override for the MDM setting since it was
not clear how the TPC preference could/would be changed/set.
Note that the original implementation was functional after
the addition of the UI element because of the 'override'
design, but of course now that there is a UI element, we
need to manage it as well. Since we are now managing
the UI element, it makes sense to align the implementation
with other similar MDM implementations (e.g. Do-Not-Track)
which means we no longer need the 'override' design.
This patch removes the 'override' code, and re-implements
TPC Restrictions in the same manner as other UI bound
features.
Change-Id: I5898409d3f0aa4d5b254d00032feda1d6080bfd1
Diffstat (limited to 'src/com/android/browser/mdm')
-rw-r--r-- | src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java | 40 | ||||
-rw-r--r-- | src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java | 6 |
2 files changed, 37 insertions, 9 deletions
diff --git a/src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java b/src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java index 86e31034..43bf6bd1 100644 --- a/src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java +++ b/src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java @@ -31,6 +31,7 @@ package com.android.browser.mdm; import android.os.Bundle; +import android.preference.Preference; import android.util.Log; import org.codeaurora.swe.MdmManager; @@ -40,10 +41,11 @@ public class ThirdPartyCookiesRestriction extends Restriction { private final static String TAG = "TPC_Restriction"; public static final String TPC_ENABLED = "ThirdPartyCookiesRestrictionEnabled"; // boolean - public static final String TPC_VALUE = "ThirdPartyCookiesValue"; // boolean + public static final String TPC_ALLOWED = "AllowThirdPartyCookies"; // boolean private static ThirdPartyCookiesRestriction sInstance; - private boolean mTpcValue; + private boolean mAllowTpc; + private MdmCheckBoxPreference mPref = null; private ThirdPartyCookiesRestriction() { super(TAG); @@ -58,15 +60,41 @@ public class ThirdPartyCookiesRestriction extends Restriction { return sInstance; } + public void registerPreference (Preference pref) { + mPref = (MdmCheckBoxPreference) pref; + updatePref(); + } + + private void updatePref() { + if (null != mPref) { + if (isEnabled()) { + mPref.setChecked(getValue()); + mPref.disablePref(); + } + else { + mPref.enablePref(); + } + mPref.setMdmRestrictionState(isEnabled()); + } + } + @Override public void enforce(Bundle restrictions) { enable(restrictions.getBoolean(TPC_ENABLED,false)); - mTpcValue = restrictions.getBoolean(TPC_VALUE, false); - Log.i(TAG, "Enforcing. enabled[" + isEnabled() + "]. val[" + mTpcValue + "]"); - MdmManager.updateMdmThirdPartyCookies(isEnabled(), mTpcValue); + mAllowTpc = restrictions.getBoolean(TPC_ALLOWED, true); + Log.d(TAG, "Enforcing. enabled[" + isEnabled() + "]. tpc allowed[" + mAllowTpc + "]"); + + // Real time update of the Preference if it is registered + updatePref(); + + if (isEnabled()) { + // Logic in native is "should we block?", so we need to + // reverse the logic here. + MdmManager.updateMdmThirdPartyCookies(!mAllowTpc); + } } public boolean getValue() { - return mTpcValue; + return mAllowTpc; } } diff --git a/src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java b/src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java index 230eab87..a77e94ae 100644 --- a/src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java +++ b/src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java @@ -66,7 +66,7 @@ public class ThirdPartyCookiesRestrictionsTest extends ActivityInstrumentationTe clearTPCRestrictions(); assertFalse(mTBCRestriction.isEnabled()); - assertFalse(mTBCRestriction.getValue()); + assertTrue(mTBCRestriction.getValue()); // default is 'allowed' setTPCRestrictions(false, true); assertFalse(mTBCRestriction.isEnabled()); @@ -88,7 +88,7 @@ public class ThirdPartyCookiesRestrictionsTest extends ActivityInstrumentationTe * * @param enable boolean. Set the state of the restriction. * - * @param value boolean. Set the state of Do Not Track if enabled is set to true. + * @param value boolean. Set the state of TPC. true == allowed. If enabled is set to true. * we still bundle it, but it should be ignored by the handler. */ private void setTPCRestrictions(boolean clear, boolean enable, boolean value) { @@ -97,7 +97,7 @@ public class ThirdPartyCookiesRestrictionsTest extends ActivityInstrumentationTe if(!clear) { restrictions.putBoolean(ThirdPartyCookiesRestriction.TPC_ENABLED,enable); - restrictions.putBoolean(ThirdPartyCookiesRestriction.TPC_VALUE, value); + restrictions.putBoolean(ThirdPartyCookiesRestriction.TPC_ALLOWED, value); } // Deliver restriction on UI thread |