summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Tharp <dtharp@codeaurora.org>2015-05-15 15:54:08 -0700
committerDave Tharp <dtharp@codeaurora.org>2015-05-15 15:54:08 -0700
commitb487d5d9ab5ddec76efb5c9dc48fa69259e3c06a (patch)
tree51f075f221e57a3e7da991bfc02d1a69fdc58c2e
parent6bdf645d7d3b1339b539efae3a743e1cbcd528f7 (diff)
downloadandroid_packages_apps_Gello-b487d5d9ab5ddec76efb5c9dc48fa69259e3c06a.tar.gz
android_packages_apps_Gello-b487d5d9ab5ddec76efb5c9dc48fa69259e3c06a.tar.bz2
android_packages_apps_Gello-b487d5d9ab5ddec76efb5c9dc48fa69259e3c06a.zip
MDM Do-Not-Track Restriction
Implements handling of MDM enforced restriction preventing the user from updating the 'Do Not Track' checkbox in the Privacy & Security menu. When enforced by MDM, the 'Do Not Track' menu entry is greyed out, and if tapped, presents a toast message informing the user that the setting is managed by the administrator. The checkbox reflects the value set by MDM. Included in this commit is the basic unit tests and a new 'MdmCheckBoxPreference' class that manages the display of the toast message and makes it possible to update the state of the entry immediately (instead of having to restart the menu to have a new MDM setting take effect. Change-Id: I931d80ccf80474120dba2d768a7a257e337bece2
-rw-r--r--res/xml/general_preferences.xml2
-rw-r--r--src/com/android/browser/BrowserSettings.java10
-rw-r--r--src/com/android/browser/mdm/DoNotTrackRestriction.java110
-rw-r--r--src/com/android/browser/mdm/MdmCheckBoxPreference.java128
-rw-r--r--src/com/android/browser/mdm/tests/DNTRestrictionsTest.java127
-rw-r--r--src/com/android/browser/preferences/GeneralPreferencesFragment.java16
6 files changed, 391 insertions, 2 deletions
diff --git a/res/xml/general_preferences.xml b/res/xml/general_preferences.xml
index d0bf5334..8f5817f1 100644
--- a/res/xml/general_preferences.xml
+++ b/res/xml/general_preferences.xml
@@ -113,7 +113,7 @@
android:summary="@string/pref_security_show_security_warning_summary"
android:title="@string/pref_security_show_security_warning" />
- <CheckBoxPreference
+ <com.android.browser.mdm.MdmCheckBoxPreference
android:defaultValue="true"
android:key="do_not_track"
android:summary="@string/pref_do_not_track_summary"
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 864315a2..8cd2a088 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -32,6 +32,7 @@ import android.webkit.WebStorage;
import com.android.browser.R;
import com.android.browser.homepages.HomeProvider;
+import com.android.browser.mdm.DoNotTrackRestriction;
import com.android.browser.mdm.ProxyRestriction;
import com.android.browser.mdm.SearchEngineRestriction;
import com.android.browser.platformsupport.Browser;
@@ -896,7 +897,14 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
}
public boolean doNotTrack() {
- return mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
+ boolean dntVal;
+ if (DoNotTrackRestriction.getInstance().isEnabled()) {
+ dntVal = DoNotTrackRestriction.getInstance().getValue();
+ }
+ else {
+ dntVal = mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
+ }
+ return dntVal;
}
public boolean acceptCookies() {
diff --git a/src/com/android/browser/mdm/DoNotTrackRestriction.java b/src/com/android/browser/mdm/DoNotTrackRestriction.java
new file mode 100644
index 00000000..e69fe16a
--- /dev/null
+++ b/src/com/android/browser/mdm/DoNotTrackRestriction.java
@@ -0,0 +1,110 @@
+/*
+ * 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 android.util.Log;
+
+import com.android.browser.PreferenceKeys;
+
+public class DoNotTrackRestriction extends Restriction implements PreferenceKeys {
+
+ private final static String TAG = "DoNotTrackRestriction";
+
+ public static final String DO_NOT_TRACK_ENABLED = "DoNotTrackEnabled"; // boolean
+ public static final String DO_NOT_TRACK_VALUE = "DoNotTrackValue"; // boolean
+
+ private static DoNotTrackRestriction sInstance;
+ private boolean mDntValue;
+
+ private MdmCheckBoxPreference mPref = null;
+
+ private DoNotTrackRestriction() {
+ super();
+ }
+
+ public static DoNotTrackRestriction getInstance() {
+ synchronized (DoNotTrackRestriction.class) {
+ if (sInstance == null) {
+ sInstance = new DoNotTrackRestriction();
+ }
+ }
+ return sInstance;
+ }
+
+ @Override
+ public void enforce(Bundle restrictions) {
+ // Possible states
+ // DNT_enabled DNT_value | menu-item-enabled check-box-value
+ // -----------------------------------------------------------------
+ // not set x | Yes curr-sys-value
+ // 0 x | Yes curr-sys-value
+ // 1 0 | No 0
+ // 1 1 | No 1
+
+ boolean dntEnabled = restrictions.getBoolean(DO_NOT_TRACK_ENABLED,false);
+ if (dntEnabled) {
+ mDntValue = restrictions.getBoolean(DO_NOT_TRACK_VALUE, true); // default to true
+
+ // enable the restriction : controls enable of the menu item
+ // Log.i(TAG, "DNT Restriction enabled. new val [" + mDntValue + "]");
+ enable(true);
+ }
+ else {
+ enable(false);
+ }
+
+ // Real time update of the Preference if it is registered
+ updatePref();
+ }
+
+ private void updatePref() {
+ if (null != mPref) {
+ if (isEnabled()) {
+ mPref.setChecked(getValue());
+ mPref.disablePref();
+ }
+ else {
+ mPref.enablePref();
+ }
+ mPref.setMdmRestrictionState(isEnabled());
+ }
+ }
+
+ public boolean getValue() {
+ return mDntValue;
+ }
+
+ public void registerPreference (MdmCheckBoxPreference pref) {
+ mPref = pref;
+ updatePref();
+ }
+}
diff --git a/src/com/android/browser/mdm/MdmCheckBoxPreference.java b/src/com/android/browser/mdm/MdmCheckBoxPreference.java
new file mode 100644
index 00000000..c235d522
--- /dev/null
+++ b/src/com/android/browser/mdm/MdmCheckBoxPreference.java
@@ -0,0 +1,128 @@
+/*
+ * 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.content.Context;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.util.AttributeSet;
+//import android.util.Log;
+import android.view.View;
+import android.widget.Toast;
+
+import com.android.browser.R;
+
+public class MdmCheckBoxPreference extends CheckBoxPreference {
+
+ View mView = null;
+ OnPreferenceClickListener mOrigClickListener = null;
+ boolean mMdmRestrictionState;
+ private boolean mPrefEnabled = true;
+
+ public MdmCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public MdmCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public MdmCheckBoxPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public MdmCheckBoxPreference(Context context) {
+ super(context);
+ }
+
+ public void setMdmRestrictionState(boolean val) {
+ // Log.i("+++", "setMdmRestrictionState(" + val + ")");
+ mMdmRestrictionState = val;
+ }
+
+ public void disablePref() {
+ // Log.i("+++", "disablePref(): mView[" +
+ // (mView != null ? "OK" : "Null") +
+ // "] mPrefEnabled[" + mPrefEnabled + "]");
+
+ if (null != mView && mPrefEnabled == true) {
+ // Set the onClick listener that will present the toast message to the user
+ mOrigClickListener = getOnPreferenceClickListener();
+
+ // Log.i("+++", "Setting toast");
+ setOnPreferenceClickListener( new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Toast.makeText(getContext(), R.string.mdm_managed_alert, Toast.LENGTH_SHORT).show();
+ return true;
+ }
+ });
+
+ // Prevent clicks from registering. We can't use setEnable() because
+ // we need the click to trigger the toast message.
+ setOnPreferenceChangeListener( new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ return false; // Do Not update
+ }
+ });
+
+ // Dim the view. setEnable usually does this for us, but we can't
+ // use it here.
+ mView.setAlpha((float) 0.5);
+ mPrefEnabled = false;
+
+ }
+ }
+
+ public void enablePref () {
+ // Log.i("+++", "enablePref(): mView[" +
+ // (mView != null ? "OK" : "Null") +
+ // "] mPrefEnabled[" + mPrefEnabled + "]");
+
+ if (null != mView && mPrefEnabled == false) {
+ setOnPreferenceClickListener(mOrigClickListener);
+ setOnPreferenceChangeListener(null);
+ mView.setAlpha((float) 1.0);
+ mPrefEnabled = true;
+ }
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ // Log.i("+++", "onBindView() : rs[" + mMdmRestrictionState + "]");
+ super.onBindView(view);
+
+ mView = view;
+ if (mMdmRestrictionState) {
+ disablePref();
+ }
+ }
+}
diff --git a/src/com/android/browser/mdm/tests/DNTRestrictionsTest.java b/src/com/android/browser/mdm/tests/DNTRestrictionsTest.java
new file mode 100644
index 00000000..5778fe38
--- /dev/null
+++ b/src/com/android/browser/mdm/tests/DNTRestrictionsTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.DoNotTrackRestriction;
+import com.android.browser.mdm.ManagedProfileManager;
+
+public class DNTRestrictionsTest extends ActivityInstrumentationTestCase2<BrowserActivity>
+ implements PreferenceKeys {
+
+ private final static String TAG = "DNTRestrictionsTest";
+
+ private Instrumentation mInstrumentation;
+ private BrowserActivity mActivity;
+ private DoNotTrackRestriction mDNTRestriction;
+
+ public DNTRestrictionsTest() {
+ super(BrowserActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mInstrumentation = getInstrumentation();
+ mActivity = getActivity();
+ mDNTRestriction = DoNotTrackRestriction.getInstance();
+ }
+
+ // Possible states
+ // DNT_enabled DNT_value | menu-item-enabled check-box-value
+ // -----------------------------------------------------------------
+ // not set x | Yes curr-sys-value
+ // 0 x | Yes curr-sys-value
+ // 1 0 | No 0
+ // 1 1 | No 1
+ public void test_DNT() throws Throwable {
+ Log.i(TAG,"!!! ******** Starting DNT Tests *************");
+
+ clearDNTRestrictions();
+ assertFalse(mDNTRestriction.isEnabled());
+
+ setDNTRestrictions(false, true);
+ assertFalse(mDNTRestriction.isEnabled());
+
+ setDNTRestrictions(true, false);
+ assertTrue(mDNTRestriction.isEnabled());
+ assertFalse(mDNTRestriction.getValue());
+
+ setDNTRestrictions(true, true);
+ assertTrue(mDNTRestriction.isEnabled());
+ assertTrue(mDNTRestriction.getValue());
+ }
+
+ /**
+ * Activate DoNotTrack 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 setDNTRestrictions(boolean clear, boolean enable, boolean value) {
+ // Construct restriction bundle
+ final Bundle restrictions = new Bundle();
+
+ if(!clear) {
+ restrictions.putBoolean(DoNotTrackRestriction.DO_NOT_TRACK_ENABLED,enable);
+ restrictions.putBoolean(DoNotTrackRestriction.DO_NOT_TRACK_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 setDNTRestrictions (boolean enable, boolean value) {
+ setDNTRestrictions(false, enable, value);
+ }
+
+ private void clearDNTRestrictions() {
+ setDNTRestrictions(true, false, false);
+ }
+}
diff --git a/src/com/android/browser/preferences/GeneralPreferencesFragment.java b/src/com/android/browser/preferences/GeneralPreferencesFragment.java
index 8ab79a3b..0629115d 100644
--- a/src/com/android/browser/preferences/GeneralPreferencesFragment.java
+++ b/src/com/android/browser/preferences/GeneralPreferencesFragment.java
@@ -48,6 +48,8 @@ import com.android.browser.PreferenceKeys;
import com.android.browser.R;
import com.android.browser.UrlUtils;
import com.android.browser.homepages.HomeProvider;
+import com.android.browser.mdm.DoNotTrackRestriction;
+import com.android.browser.mdm.MdmCheckBoxPreference;
import com.android.browser.mdm.SearchEngineRestriction;
public class GeneralPreferencesFragment extends PreferenceFragment
@@ -104,11 +106,25 @@ public class GeneralPreferencesFragment extends PreferenceFragment
findPreference("search_engine").setEnabled(false);
}
+ // Register Do-Not-Track Preference with it's MDM restriction handler
+ // Log.i("+++", "\n===== REGISTERING =====");
+ MdmCheckBoxPreference dntPref = (MdmCheckBoxPreference) findPreference(PreferenceKeys.PREF_DO_NOT_TRACK);
+ DoNotTrackRestriction.getInstance().registerPreference(dntPref);
+
mAdvFrag = new AdvancedPreferencesFragment(this);
mPrivFrag = new PrivacySecurityPreferencesFragment(this);
}
@Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ // Log.i("+++", "===== DESTROYING =====\n");
+ // Un-register Do-Not-Track Preference from it's MDM restriction handler
+ DoNotTrackRestriction.getInstance().registerPreference(null);
+ }
+
+ @Override
public boolean onPreferenceChange(Preference pref, Object objValue) {
if (getActivity() == null) {
// We aren't attached, so don't accept preferences changes from the