summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Tharp <dtharp@codeaurora.org>2015-08-17 17:09:02 -0700
committerjrizzoli <joey@cyanogenmoditalia.it>2015-08-28 13:15:47 +0200
commit6014dad6acf443eb1b06ba064eb06ae8ea26229f (patch)
tree52a950447f142c3bf05474ff2b43fc7ac0a885b7
parenta4422f0b948fab4a23fd6a18755360c9051d6312 (diff)
downloadandroid_packages_apps_Gello-6014dad6acf443eb1b06ba064eb06ae8ea26229f.tar.gz
android_packages_apps_Gello-6014dad6acf443eb1b06ba064eb06ae8ea26229f.tar.bz2
android_packages_apps_Gello-6014dad6acf443eb1b06ba064eb06ae8ea26229f.zip
[MDM] Added restrictionEnable to AutoFill restriction
THe Chromium policy document had a single controlling key for Autofill, and I attempted to emulate it. Unfortunately, a side-effect was reported in the non-mdm browser. The Fix was to go ahead and implement a second key (as we do for other restrictions), restrictionEnable. As a bonus, the enable logic for the actual value is no longer reversed, therfore les confusing. Change-Id: Ib074bf3efa79bded3fca246bf63824d640c26954
-rw-r--r--src/com/android/browser/mdm/AutoFillRestriction.java37
-rw-r--r--src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java31
2 files changed, 40 insertions, 28 deletions
diff --git a/src/com/android/browser/mdm/AutoFillRestriction.java b/src/com/android/browser/mdm/AutoFillRestriction.java
index e0e516dc..6fe9bbc1 100644
--- a/src/com/android/browser/mdm/AutoFillRestriction.java
+++ b/src/com/android/browser/mdm/AutoFillRestriction.java
@@ -42,11 +42,14 @@ public class AutoFillRestriction extends Restriction implements PreferenceKeys {
private final static String TAG = "AutoFillRestriction";
- public static final String AUTO_FILL_RESTRICTION = "AutoFillEnabled";
+ public static final String AUTO_FILL_RESTRICTION_ENABLED = "AutoFillRestrictionEnabled";
+ public static final String AUTO_FILL_ALLOWED = "AutoFillAllowed";
private static AutoFillRestriction sInstance;
private MdmCheckBoxPreference mPref = null;
+ private boolean m_bAfAllowed;
+
private AutoFillRestriction() {
super(TAG);
}
@@ -73,36 +76,38 @@ public class AutoFillRestriction extends Restriction implements PreferenceKeys {
private void updatePref() {
if (null != mPref) {
if (isEnabled()) {
- mPref.setChecked(false);
+ mPref.setChecked(getValue());
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);
+ boolean restrictionEnabled = restrictions.getBoolean(AUTO_FILL_RESTRICTION_ENABLED, false);
+ enable(restrictionEnabled);
+
+ if(isEnabled()) {
+ m_bAfAllowed = true;
+ if (restrictions.containsKey(AUTO_FILL_ALLOWED)) {
+ m_bAfAllowed = restrictions.getBoolean(AUTO_FILL_ALLOWED);
+ }
- editor.putBoolean(PREF_AUTOFILL_ENABLED, !isEnabled());
- editor.apply();
+ Log.i(TAG, "Enforce [" + m_bAfAllowed + "]");
+ editor.putBoolean(PREF_AUTOFILL_ENABLED, m_bAfAllowed);
+ editor.apply();
+ }
updatePref();
}
+
+ public boolean getValue() {
+ return m_bAfAllowed;
+ }
}
diff --git a/src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java b/src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java
index 291f6fee..fc1f35a9 100644
--- a/src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java
+++ b/src/com/android/browser/mdm/tests/AutoFillRestrictionsTest.java
@@ -37,7 +37,6 @@ 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> {
@@ -65,27 +64,35 @@ public class AutoFillRestrictionsTest extends ActivityInstrumentationTestCase2<B
clearAutoFillRestrictions();
assertFalse(autoFillRestriction.isEnabled());
- setAutoFillRestrictions(true);
+ setAutoFillRestrictions(true, true);
assertTrue(autoFillRestriction.isEnabled());
+ assertTrue(autoFillRestriction.getValue());
- setAutoFillRestrictions(false);
+ setAutoFillRestrictions(true, false);
+ assertTrue(autoFillRestriction.isEnabled());
+ assertFalse(autoFillRestriction.getValue());
+
+ setAutoFillRestrictions(false, true);
+ assertFalse(autoFillRestriction.isEnabled());
+
+ setAutoFillRestrictions(false, 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)
+ * @param restrictionEnabled Enables the restriction
+ * @param allowed Required. true : allow editing
+ * or false : disallow editing
*
*/
- private void setAutoFillRestrictions(boolean clear, boolean enabled) {
+ private void setAutoFillRestrictions(boolean clear, boolean restrictionEnabled, boolean allowed) {
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);
+ restrictions.putBoolean(AutoFillRestriction.AUTO_FILL_RESTRICTION_ENABLED, restrictionEnabled);
+ restrictions.putBoolean(AutoFillRestriction.AUTO_FILL_ALLOWED, allowed);
}
// Deliver restriction on UI thread
@@ -101,10 +108,10 @@ public class AutoFillRestrictionsTest extends ActivityInstrumentationTestCase2<B
}
private void clearAutoFillRestrictions() {
- setAutoFillRestrictions(true, false);
+ setAutoFillRestrictions(true, false, false);
}
- private void setAutoFillRestrictions(boolean enabled) {
- setAutoFillRestrictions(false, enabled);
+ private void setAutoFillRestrictions(boolean enabled, boolean allowed) {
+ setAutoFillRestrictions(false, enabled, allowed);
}
}