Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c01a873c authored by Felipe Leme's avatar Felipe Leme
Browse files

Added sanitization for CompoundButton and RadioGroup.

Bug: 33269702
Bug: 33550221
Test: CtsAutoFillServiceTestCases (with new tests) pass

Change-Id: Ie2c8d2784227371588aa02973b8ef3ac1a6950aa
parent d09ccb8d
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -722,7 +722,14 @@ public class AssistStructure implements Parcelable {
            }

            pwriter.writeString(mClassName);
            out.writeInt(flags);

            int writtenFlags = flags;
            if ((flags&FLAGS_HAS_AUTO_FILL_DATA) != 0 && (mSanitized || !sanitizeOnWrite)) {
                // Remove 'checked' from sanitized auto-fill request.
                writtenFlags = flags & ~FLAGS_CHECKED;
            }

            out.writeInt(writtenFlags);
            if ((flags&FLAGS_HAS_ID) != 0) {
                out.writeInt(mId);
                if (mId != 0) {
+14 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.view.Gravity;
import android.view.SoundEffectConstants;
import android.view.ViewDebug;
import android.view.ViewHierarchyEncoder;
import android.view.ViewStructure;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.autofill.AutoFillManager;
@@ -68,6 +69,10 @@ public abstract class CompoundButton extends Button implements Checkable {
    private OnCheckedChangeListener mOnCheckedChangeListener;
    private OnCheckedChangeListener mOnCheckedChangeWidgetListener;

    // Indicates whether the toggle state was set from resources or dynamically, so it can be used
    // to sanitize auto-fill requests.
    private boolean mCheckedFromResource = false;

    private static final int[] CHECKED_STATE_SET = {
        R.attr.state_checked
    };
@@ -109,6 +114,7 @@ public abstract class CompoundButton extends Button implements Checkable {
        final boolean checked = a.getBoolean(
                com.android.internal.R.styleable.CompoundButton_checked, false);
        setChecked(checked);
        mCheckedFromResource = true;

        a.recycle();

@@ -148,6 +154,7 @@ public abstract class CompoundButton extends Button implements Checkable {
    @Override
    public void setChecked(boolean checked) {
        if (mChecked != checked) {
            mCheckedFromResource = false;
            mChecked = checked;
            refreshDrawableState();
            notifyViewAccessibilityStateChangedIfNeeded(
@@ -568,6 +575,13 @@ public abstract class CompoundButton extends Button implements Checkable {

    // TODO(b/33197203): add unit/CTS tests for auto-fill methods (and make sure they handle enable)

    @Override
    public void onProvideAutoFillStructure(ViewStructure structure, int flags) {
        super.onProvideAutoFillStructure(structure, flags);

        structure.setSanitized(mCheckedFromResource);
    }

    @Override
    public void autoFill(AutoFillValue value) {
        if (!isEnabled()) return;
+12 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStructure;
import android.view.autofill.AutoFillManager;
import android.view.autofill.AutoFillType;
import android.view.autofill.AutoFillValue;
@@ -66,6 +67,10 @@ public class RadioGroup extends LinearLayout {
    private OnCheckedChangeListener mOnCheckedChangeListener;
    private PassThroughHierarchyChangeListener mPassThroughListener;

    // Indicates whether the child was set from resources or dynamically, so it can be used
    // to sanitize auto-fill requests.
    private int mInitialCheckedId = View.NO_ID;

    /**
     * {@inheritDoc}
     */
@@ -89,8 +94,8 @@ public class RadioGroup extends LinearLayout {
        int value = attributes.getResourceId(R.styleable.RadioGroup_checkedButton, View.NO_ID);
        if (value != View.NO_ID) {
            mCheckedId = value;
            mInitialCheckedId = value;
        }

        final int index = attributes.getInt(com.android.internal.R.styleable.RadioGroup_orientation, VERTICAL);
        setOrientation(index);

@@ -410,6 +415,12 @@ public class RadioGroup extends LinearLayout {

    // TODO(b/33197203): add unit/CTS tests for auto-fill methods (and make sure they handle enable)

    @Override
    public void onProvideAutoFillStructure(ViewStructure structure, int flags) {
        super.onProvideAutoFillStructure(structure, flags);
        structure.setSanitized(mCheckedId == mInitialCheckedId);
    }

    @Override
    public void autoFill(AutoFillValue value) {
        if (!isEnabled()) return;
+1 −1
Original line number Diff line number Diff line
@@ -727,7 +727,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    private boolean mHasPresetAutoSizeValues = false;

    // Indicates whether the text was set from resources or dynamically, so it can be used to
    // sanitize auto-fill request.
    // sanitize auto-fill requests.
    private boolean mTextFromResource = false;

    /**