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

Commit 28afe0e1 authored by Felipe Leme's avatar Felipe Leme
Browse files

Batch autofill() calls to views with virtual children.

This is useful in the cases where the virtual children hierarchy is rendered
by a different process.

Test: VirtualContainerActivityTest pass
Bug: 36056207
Change-Id: Id9bf3a9e9366b616dc2a6e0a204e238a2bee3a20
parent 81f01d9e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -45089,7 +45089,7 @@ package android.view {
    method public android.view.ViewPropertyAnimator animate();
    method public void announceForAccessibility(java.lang.CharSequence);
    method public boolean autofill(android.view.autofill.AutofillValue);
    method public boolean autofill(int, android.view.autofill.AutofillValue);
    method public boolean autofill(android.util.SparseArray<android.view.autofill.AutofillValue>);
    method protected boolean awakenScrollBars();
    method protected boolean awakenScrollBars(int);
    method protected boolean awakenScrollBars(int, boolean);
+1 −1
Original line number Diff line number Diff line
@@ -48552,7 +48552,7 @@ package android.view {
    method public android.view.ViewPropertyAnimator animate();
    method public void announceForAccessibility(java.lang.CharSequence);
    method public boolean autofill(android.view.autofill.AutofillValue);
    method public boolean autofill(int, android.view.autofill.AutofillValue);
    method public boolean autofill(android.util.SparseArray<android.view.autofill.AutofillValue>);
    method protected boolean awakenScrollBars();
    method protected boolean awakenScrollBars(int);
    method protected boolean awakenScrollBars(int, boolean);
+1 −1
Original line number Diff line number Diff line
@@ -45449,7 +45449,7 @@ package android.view {
    method public android.view.ViewPropertyAnimator animate();
    method public void announceForAccessibility(java.lang.CharSequence);
    method public boolean autofill(android.view.autofill.AutofillValue);
    method public boolean autofill(int, android.view.autofill.AutofillValue);
    method public boolean autofill(android.util.SparseArray<android.view.autofill.AutofillValue>);
    method protected boolean awakenScrollBars();
    method protected boolean awakenScrollBars(int);
    method protected boolean awakenScrollBars(int, boolean);
+25 −6
Original line number Diff line number Diff line
@@ -7193,6 +7193,7 @@ public class Activity extends ContextThemeWrapper
        final View root = getWindow().getDecorView();
        final int itemCount = ids.size();
        int numApplied = 0;
        ArrayMap<View, SparseArray<AutofillValue>> virtualValues = null;

        for (int i = 0; i < itemCount; i++) {
            final AutofillId id = ids.get(i);
@@ -7203,19 +7204,37 @@ public class Activity extends ContextThemeWrapper
                Log.w(TAG, "autofill(): no View with id " + viewId);
                continue;
            }
            final boolean wasApplied;
            if (id.isVirtual()) {
                wasApplied = view.autofill(id.getVirtualChildId(), value);
                final int parentId = id.getViewId();
                if (virtualValues == null) {
                    // Most likely there will be just one view with virtual children.
                    virtualValues = new ArrayMap<>(1);
                }
                SparseArray<AutofillValue> valuesByParent = virtualValues.get(view);
                if (valuesByParent == null) {
                    // We don't know the size yet, but usually it will be just a few fields...
                    valuesByParent = new SparseArray<>(5);
                    virtualValues.put(view, valuesByParent);
                }
                valuesByParent.put(id.getVirtualChildId(), value);
            } else {
                wasApplied = view.autofill(value);
                if (view.autofill(value)) {
                    numApplied++;
                }
            }
        }

            if (wasApplied) {
                numApplied++;
        if (virtualValues != null) {
            for (int i = 0; i < virtualValues.size(); i++) {
                final View parent = virtualValues.keyAt(i);
                final SparseArray<AutofillValue> childrenValues = virtualValues.valueAt(i);
                if (parent.autofill(childrenValues)) {
                    numApplied += childrenValues.size();
                }
            }
        }

        LogMaker log = new LogMaker(MetricsProto.MetricsEvent.AUTOFILL_DATASET_APPLIED);
        final LogMaker log = new LogMaker(MetricsProto.MetricsEvent.AUTOFILL_DATASET_APPLIED);
        log.addTaggedData(MetricsProto.MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, itemCount);
        log.addTaggedData(MetricsProto.MetricsEvent.FIELD_AUTOFILL_NUM_VIEWS_FILLED, numApplied);
        mMetricsLogger.write(log);
+6 −7
Original line number Diff line number Diff line
@@ -7379,7 +7379,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * <p>When implementing this method, subclasses must follow the rules below:
     *
     * <ol>
     * <li>Also implement {@link #autofill(int, AutofillValue)} to autofill the virtual
     * <li>Also implement {@link #autofill(SparseArray)} to autofill the virtual
     * children.
     * <li>Call
     * {@link android.view.autofill.AutofillManager#notifyViewEntered} and
@@ -7448,24 +7448,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    }
    /**
     * Automatically fills the content of a virtual view with the {@code value}
     * Automatically fills the content of a virtual views.
     *
     * <p>See {@link #autofill(AutofillValue)} and
     * {@link #onProvideAutofillVirtualStructure(ViewStructure, int)} for more info.
     *
     * @param value value to be autofilled.
     * @param virtualId id identifying the virtual child inside the custom view.
     * @param values map of values to be autofilled, keyed by virtual child id.
     *
     * @return {@code true} if the view was successfully autofilled, {@code false} otherwise
     */
    public boolean autofill(@SuppressWarnings("unused") int virtualId,
            @SuppressWarnings("unused") AutofillValue value) {
    public boolean autofill(
            @NonNull @SuppressWarnings("unused") SparseArray<AutofillValue>values) {
        return false;
    }
    /**
     * Describes the autofill type that should be used on calls to
     * {@link #autofill(AutofillValue)} and {@link #autofill(int, AutofillValue)}.
     * {@link #autofill(AutofillValue)} and {@link #autofill(SparseArray)}.
     *
     * <p>By default returns {@link #AUTOFILL_TYPE_NONE}, but views should override it (and
     * {@link #autofill(AutofillValue)} to support the Autofill Framework.
Loading