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

Commit 5429ade9 authored by Felipe Leme's avatar Felipe Leme
Browse files

Fixed findValueLocked() so it fetches values from previous sessions.

Test: atest MultiScreenLoginTest:testSaveBothFieldsCustomDescription_differentIds
Bug: 113593220

Change-Id: I662c526e1d885cc1cdbff113172a0b674dd0849c
parent 601622ab
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ public final class CharSequenceTransformation extends InternalTransformation imp
            int childViewId) throws Exception {
        final StringBuilder converted = new StringBuilder();
        final int size = mFields.size();
        if (sDebug) Log.d(TAG, size + " multiple fields on id " + childViewId);
        if (sDebug) Log.d(TAG, size + " fields on id " + childViewId);
        for (Entry<AutofillId, Pair<Pattern, String>> entry : mFields.entrySet()) {
            final AutofillId id = entry.getKey();
            final Pair<Pattern, String> field = entry.getValue();
+35 −8
Original line number Diff line number Diff line
@@ -395,16 +395,42 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     * or {@code null} when not found on either of them.
     */
    @GuardedBy("mLock")
    private AutofillValue findValueLocked(@NonNull AutofillId id) {
        final ViewState state = mViewStates.get(id);
    @Nullable
    private AutofillValue findValueLocked(@NonNull AutofillId autofillId) {
        final AutofillValue value = findValueFromThisSessionOnlyLocked(autofillId);
        if (value != null) return value;

        // TODO(b/113281366): rather than explicitly look for previous session, it might be better
        // to merge the sessions when created (see note on mergePreviousSessionLocked())
        final ArrayList<Session> previousSessions = mService.getPreviousSessionsLocked(this);
        if (previousSessions != null) {
            if (sDebug) {
                Slog.d(TAG, "findValueLocked(): looking on " + previousSessions.size()
                        + " previous sessions for autofillId " + autofillId);
            }
            for (int i = 0; i < previousSessions.size(); i++) {
                final Session previousSession = previousSessions.get(i);
                final AutofillValue previousValue = previousSession
                        .findValueFromThisSessionOnlyLocked(autofillId);
                if (previousValue != null) {
                    return previousValue;
                }
            }
        }
        return null;
    }

    @Nullable
    private AutofillValue findValueFromThisSessionOnlyLocked(@NonNull AutofillId autofillId) {
        final ViewState state = mViewStates.get(autofillId);
        if (state == null) {
            if (sDebug) Slog.d(TAG, "findValueLocked(): no view state for " + id);
            if (sDebug) Slog.d(TAG, "findValueLocked(): no view state for " + autofillId);
            return null;
        }
        AutofillValue value = state.getCurrentValue();
        if (value == null) {
            if (sDebug) Slog.d(TAG, "findValueLocked(): no current value for " + id);
            value = getValueFromContextsLocked(id);
            if (sDebug) Slog.d(TAG, "findValueLocked(): no current value for " + autofillId);
            value = getValueFromContextsLocked(autofillId);
        }
        return value;
    }
@@ -1769,15 +1795,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     */
    @GuardedBy("mLock")
    @Nullable
    private AutofillValue getValueFromContextsLocked(AutofillId id) {
    private AutofillValue getValueFromContextsLocked(@NonNull AutofillId autofillId) {
        final int numContexts = mContexts.size();
        for (int i = numContexts - 1; i >= 0; i--) {
            final FillContext context = mContexts.get(i);
            final ViewNode node = Helper.findViewNodeByAutofillId(context.getStructure(), id);
            final ViewNode node = Helper.findViewNodeByAutofillId(context.getStructure(),
                    autofillId);
            if (node != null) {
                final AutofillValue value = node.getAutofillValue();
                if (sDebug) {
                    Slog.d(TAG, "getValueFromContexts(" + id + ") at " + i + ": " + value);
                    Slog.d(TAG, "getValueFromContexts(" + autofillId + ") at " + i + ": " + value);
                }
                if (value != null && !value.isEmpty()) {
                    return value;
+5 −5
Original line number Diff line number Diff line
@@ -212,20 +212,20 @@ final class ViewState {
    public String toString() {
        final StringBuilder builder = new StringBuilder("ViewState: [id=").append(id);
        if (mDatasetId != null) {
            builder.append("datasetId:" ).append(mDatasetId);
            builder.append(", datasetId:" ).append(mDatasetId);
        }
        builder.append("state:" ).append(getStateAsString());
        if (mCurrentValue != null) {
            builder.append("currentValue:" ).append(mCurrentValue);
            builder.append(", currentValue:" ).append(mCurrentValue);
        }
        if (mAutofilledValue != null) {
            builder.append("autofilledValue:" ).append(mAutofilledValue);
            builder.append(", autofilledValue:" ).append(mAutofilledValue);
        }
        if (mSanitizedValue != null) {
            builder.append("sanitizedValue:" ).append(mSanitizedValue);
            builder.append(", sanitizedValue:" ).append(mSanitizedValue);
        }
        if (mVirtualBounds != null) {
            builder.append("virtualBounds:" ).append(mVirtualBounds);
            builder.append(", virtualBounds:" ).append(mVirtualBounds);
        }
        return builder.toString();
    }