summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
}
}