diff options
author | Dave Tharp <dtharp@codeaurora.org> | 2015-05-28 12:38:15 -0700 |
---|---|---|
committer | WebTech Code Review <code-review@localhost> | 2015-05-29 17:08:57 -0700 |
commit | 880f6435f385c5eafed237e39d43de469619a5e6 (patch) | |
tree | 035aa8f17773e670353c1cfc54f51d8af2284a93 /src/com/android/browser/mdm | |
parent | 9295e45150be492c8c79a30bb5985ba09273d2f7 (diff) | |
download | android_packages_apps_Gello-880f6435f385c5eafed237e39d43de469619a5e6.tar.gz android_packages_apps_Gello-880f6435f385c5eafed237e39d43de469619a5e6.tar.bz2 android_packages_apps_Gello-880f6435f385c5eafed237e39d43de469619a5e6.zip |
MDM Third Party Cookies Restriction
Implemented Third Party Cookies (TPC) Restriction.
The control point is in the native code (cookie_settings.cc),
and we make use of the PrefServiceBridge to activate and
configure the restriction. To support this we've added two
new boolean preference keys (kMdmBlockThirdPartyCookiesManaged and
kMdmBlockThirdPartyCookies).
Note that when the restriction is in effect, it overrides the
'normal' preference setting (kBlockThirdPartyCookies), which
is present in SWE, but has no current UI element. If a UI is
eventually implemented to expose this setting, the MDM restriction
code will need to be updated to disable the UI feature when the
restriction is active.
Change-Id: I929c48b3a5f932daf63468baa7f327d3ce5c78be
Diffstat (limited to 'src/com/android/browser/mdm')
-rw-r--r-- | src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java | 79 | ||||
-rw-r--r-- | src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java | 122 |
2 files changed, 201 insertions, 0 deletions
diff --git a/src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java b/src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java new file mode 100644 index 00000000..d06bf424 --- /dev/null +++ b/src/com/android/browser/mdm/ThirdPartyCookiesRestriction.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package com.android.browser.mdm; + +import android.os.Bundle; + +import com.android.browser.PreferenceKeys; + +import org.chromium.chrome.browser.preferences.PrefServiceBridge; + +public class ThirdPartyCookiesRestriction extends Restriction implements PreferenceKeys { + + private final static String TAG = "TPC_Restriction"; + + public static final String TPC_ENABLED = "ThirdPartyCookiesRestrictionEnabled"; // boolean + public static final String TPC_VALUE = "ThirdPartyCookiesValue"; // boolean + + private static ThirdPartyCookiesRestriction sInstance; + private boolean mTpcValue; + + private ThirdPartyCookiesRestriction() { + super(); + } + + public static ThirdPartyCookiesRestriction getInstance() { + synchronized (ThirdPartyCookiesRestriction.class) { + if (sInstance == null) { + sInstance = new ThirdPartyCookiesRestriction(); + } + } + return sInstance; + } + + @Override + public void enforce(Bundle restrictions) { + enable(restrictions.getBoolean(TPC_ENABLED,false)); + mTpcValue = restrictions.getBoolean(TPC_VALUE, false); + + PrefServiceBridge psb = PrefServiceBridge.getInstance(); + + if(psb != null) { + psb.setMdmBlockThirdPartyCookiesManaged(isEnabled()); + psb.setMdmBlockThirdPartyCookiesEnabled(mTpcValue); + } + } + + public boolean getValue() { + return mTpcValue; + } + +} diff --git a/src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java b/src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java new file mode 100644 index 00000000..230eab87 --- /dev/null +++ b/src/com/android/browser/mdm/tests/ThirdPartyCookiesRestrictionsTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package com.android.browser.mdm.tests; + +import android.app.Instrumentation; +import android.os.Bundle; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import com.android.browser.BrowserActivity; +import com.android.browser.PreferenceKeys; +import com.android.browser.mdm.ManagedProfileManager; +import com.android.browser.mdm.ThirdPartyCookiesRestriction; + +public class ThirdPartyCookiesRestrictionsTest extends ActivityInstrumentationTestCase2<BrowserActivity> + implements PreferenceKeys { + + private final static String TAG = "TPCRestrictionsTest"; + + private Instrumentation mInstrumentation; + private BrowserActivity mActivity; + private ThirdPartyCookiesRestriction mTBCRestriction; + + public ThirdPartyCookiesRestrictionsTest() { + super(BrowserActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mInstrumentation = getInstrumentation(); + mActivity = getActivity(); + mTBCRestriction = ThirdPartyCookiesRestriction.getInstance(); + } + + public void test_DNT() throws Throwable { + Log.i(TAG,"!!! ******** Starting TPC Tests *************"); + + clearTPCRestrictions(); + assertFalse(mTBCRestriction.isEnabled()); + assertFalse(mTBCRestriction.getValue()); + + setTPCRestrictions(false, true); + assertFalse(mTBCRestriction.isEnabled()); + assertTrue(mTBCRestriction.getValue()); + + setTPCRestrictions(true, false); + assertTrue(mTBCRestriction.isEnabled()); + assertFalse(mTBCRestriction.getValue()); + + setTPCRestrictions(true, true); + assertTrue(mTBCRestriction.isEnabled()); + assertTrue(mTBCRestriction.getValue()); + } + + /** + * Activate ThirdPartyCookies restriction + * @param clear boolean. if true, clears the restriction by sending an empty bundle. In + * this case, the other args are ignored. + * + * @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. + * we still bundle it, but it should be ignored by the handler. + */ + private void setTPCRestrictions(boolean clear, boolean enable, boolean value) { + // Construct restriction bundle + final Bundle restrictions = new Bundle(); + + if(!clear) { + restrictions.putBoolean(ThirdPartyCookiesRestriction.TPC_ENABLED,enable); + restrictions.putBoolean(ThirdPartyCookiesRestriction.TPC_VALUE, value); + } + + // Deliver restriction on UI thread + mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + ManagedProfileManager.getInstance().setMdmRestrictions(restrictions); + } + }); + + // Wait to ensure restriction is set + mInstrumentation.waitForIdleSync(); + } + + private void setTPCRestrictions(boolean enable, boolean value) { + setTPCRestrictions(false, enable, value); + } + + private void clearTPCRestrictions() { + setTPCRestrictions(true, false, false); + } +} |