summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/mdm
diff options
context:
space:
mode:
authorDave Tharp <dtharp@codeaurora.org>2015-06-24 13:32:46 -0700
committerjrizzoli <joey@cyanogenmoditalia.it>2015-08-28 13:15:45 +0200
commitc7ecda84fdab99a4a1b35463c4d934a9645789dc (patch)
tree71df23a89f366442473c18cdcf158c44eb0ad5a9 /src/com/android/browser/mdm
parentc9bc0b6d3b8042a02325d84513d155b9caf25d41 (diff)
downloadandroid_packages_apps_Gello-c7ecda84fdab99a4a1b35463c4d934a9645789dc.tar.gz
android_packages_apps_Gello-c7ecda84fdab99a4a1b35463c4d934a9645789dc.tar.bz2
android_packages_apps_Gello-c7ecda84fdab99a4a1b35463c4d934a9645789dc.zip
MDM Auto Fill Restriction
Implementation of MDM form auto fill restriction. When enforced, the auto-fill menu item is greyed and unchecked, and if clicked, results in the "Managed by your administrator" Toast message. Disabling the restriction checks the menu item checkbox and ungreys the menuitem, restoring full control of this feature to the user. This patch also includes minor refactoring of DoNotTrackRestriction. Change-Id: I2f36ea9263a70f0a9470900c3abc48d9376a4604
Diffstat (limited to 'src/com/android/browser/mdm')
-rw-r--r--src/com/android/browser/mdm/AutoFillRestriction.java108
-rw-r--r--src/com/android/browser/mdm/DoNotTrackRestriction.java10
-rw-r--r--src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java110
3 files changed, 222 insertions, 6 deletions
diff --git a/src/com/android/browser/mdm/AutoFillRestriction.java b/src/com/android/browser/mdm/AutoFillRestriction.java
new file mode 100644
index 00000000..e0e516dc
--- /dev/null
+++ b/src/com/android/browser/mdm/AutoFillRestriction.java
@@ -0,0 +1,108 @@
+/*
+ * 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.SharedPreferences;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.util.Log;
+
+import com.android.browser.BrowserSettings;
+import com.android.browser.PreferenceKeys;
+
+public class AutoFillRestriction extends Restriction implements PreferenceKeys {
+
+ private final static String TAG = "AutoFillRestriction";
+
+ public static final String AUTO_FILL_RESTRICTION = "AutoFillEnabled";
+
+ private static AutoFillRestriction sInstance;
+ private MdmCheckBoxPreference mPref = null;
+
+ private AutoFillRestriction() {
+ super(TAG);
+ }
+
+ public static AutoFillRestriction getInstance() {
+ synchronized (AutoFillRestriction.class) {
+ if (sInstance == null) {
+ sInstance = new AutoFillRestriction();
+ }
+ }
+ return sInstance;
+ }
+
+ @Override
+ protected void doCustomInit() {
+ }
+
+
+ public void registerPreference (Preference pref) {
+ mPref = (MdmCheckBoxPreference) pref;
+ updatePref();
+ }
+
+ private void updatePref() {
+ if (null != mPref) {
+ if (isEnabled()) {
+ mPref.setChecked(false);
+ mPref.disablePref();
+ }
+ else {
+ mPref.setChecked(true);
+ mPref.enablePref();
+ }
+ mPref.setMdmRestrictionState(isEnabled());
+ }
+ }
+
+ /*
+ * Note reversed logic:
+ * [x] 'Restrict' true = AutoFillEnabled : false => disable Auto fill in swe
+ * [ ] 'Restrict' false = AutoFillEnabled : true => enable Auto fill in swe
+ */
+ @Override
+ public void enforce(Bundle restrictions) {
+ SharedPreferences.Editor editor = BrowserSettings.getInstance().getPreferences().edit();
+
+ boolean bEnable = false;
+ if (restrictions.containsKey(AUTO_FILL_RESTRICTION)) {
+ bEnable = ! restrictions.getBoolean(AUTO_FILL_RESTRICTION);
+ }
+ Log.i(TAG, "Enforce [" + bEnable + "]");
+ enable(bEnable);
+
+ editor.putBoolean(PREF_AUTOFILL_ENABLED, !isEnabled());
+ editor.apply();
+
+ updatePref();
+ }
+}
diff --git a/src/com/android/browser/mdm/DoNotTrackRestriction.java b/src/com/android/browser/mdm/DoNotTrackRestriction.java
index 94db45f8..2f4a540f 100644
--- a/src/com/android/browser/mdm/DoNotTrackRestriction.java
+++ b/src/com/android/browser/mdm/DoNotTrackRestriction.java
@@ -31,11 +31,9 @@
package com.android.browser.mdm;
import android.os.Bundle;
-import android.util.Log;
+import android.preference.Preference;
-import com.android.browser.PreferenceKeys;
-
-public class DoNotTrackRestriction extends Restriction implements PreferenceKeys {
+public class DoNotTrackRestriction extends Restriction {
private final static String TAG = "DoNotTrackRestriction";
@@ -103,8 +101,8 @@ public class DoNotTrackRestriction extends Restriction implements PreferenceKeys
return mDntValue;
}
- public void registerPreference (MdmCheckBoxPreference pref) {
- mPref = pref;
+ public void registerPreference (Preference pref) {
+ mPref = (MdmCheckBoxPreference) pref;
updatePref();
}
}
diff --git a/src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java b/src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java
new file mode 100644
index 00000000..291f6fee
--- /dev/null
+++ b/src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.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.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.mdm.AutoFillRestriction;
+import com.android.browser.mdm.EditBookmarksRestriction;
+import com.android.browser.mdm.ManagedProfileManager;
+
+public class AutoFillRestrictionsTest extends ActivityInstrumentationTestCase2<BrowserActivity> {
+
+ private final static String TAG = "+++AutoFillRestTest";
+
+ private Instrumentation mInstrumentation;
+ private BrowserActivity mActivity;
+ private AutoFillRestriction autoFillRestriction;
+
+ public AutoFillRestrictionsTest() {
+ super(BrowserActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mInstrumentation = getInstrumentation();
+ mActivity = getActivity();
+ autoFillRestriction = AutoFillRestriction.getInstance();
+ }
+
+ public void test_EditBookmarksRestriction() throws Throwable {
+ Log.i(TAG, "*** Starting AutoFillTest ***");
+ clearAutoFillRestrictions();
+ assertFalse(autoFillRestriction.isEnabled());
+
+ setAutoFillRestrictions(true);
+ assertTrue(autoFillRestriction.isEnabled());
+
+ setAutoFillRestrictions(false);
+ assertFalse(autoFillRestriction.isEnabled());
+ }
+
+ /**
+ * Activate EditBookmarks restriction
+ * @param clear if true, sends an empty bundle (which is interpreted as "allow editing"
+ * @param enabled Required. true (disallow editing: restriction enforced)
+ * or false (allow editing: restriction lifted)
+ *
+ */
+ private void setAutoFillRestrictions(boolean clear, boolean enabled) {
+ final Bundle restrictions = new Bundle();
+
+ if (!clear) {
+ // note reversed logic. This is setting 'EditBookmarksEnabled'
+ // if enabled is true, we want it set to false and vice cersa
+ restrictions.putBoolean(AutoFillRestriction.AUTO_FILL_RESTRICTION, ! enabled);
+ }
+
+ // 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 clearAutoFillRestrictions() {
+ setAutoFillRestrictions(true, false);
+ }
+
+ private void setAutoFillRestrictions(boolean enabled) {
+ setAutoFillRestrictions(false, enabled);
+ }
+}