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

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

Fixed Autofill SaveUI logic so it considers all optional savable ids.

Test: atest OptionalSaveActivityTest#testDontShowSaveUiWhenUserManuallyFilledSameValue_optionalsOnlyNoRequired
Test: CtsAutoFillServiceTestCases # to make sure it didn't break anything

Bug: 112195709

Change-Id: Ia2902904be7093ef521b30e924815321ef8bd719
parent 0034421d
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -1473,7 +1473,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState

        // Cache used to make sure changed fields do not belong to a dataset.
        final ArrayMap<AutofillId, AutofillValue> currentValues = new ArrayMap<>();
        final ArraySet<AutofillId> allIds = new ArraySet<>();
        // Savable (optional or required) ids that will be checked against the dataset ids.
        final ArraySet<AutofillId> savableIds = new ArraySet<>();

        final AutofillId[] requiredIds = saveInfo.getRequiredIds();
        boolean allRequiredAreNotEmpty = true;
@@ -1485,7 +1486,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                    Slog.w(TAG, "null autofill id on " + Arrays.toString(requiredIds));
                    continue;
                }
                allIds.add(id);
                savableIds.add(id);
                final ViewState viewState = mViewStates.get(id);
                if (viewState == null) {
                    Slog.w(TAG, "showSaveLocked(): no ViewState for required " + id);
@@ -1553,7 +1554,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                // No change on required ids yet, look for changes on optional ids.
                for (int i = 0; i < optionalIds.length; i++) {
                    final AutofillId id = optionalIds[i];
                    allIds.add(id);
                    savableIds.add(id);
                    final ViewState viewState = mViewStates.get(id);
                    if (viewState == null) {
                        Slog.w(TAG, "no ViewState for optional " + id);
@@ -1622,16 +1623,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                                Helper.getFields(dataset);
                        if (sVerbose) {
                            Slog.v(TAG, "Checking if saved fields match contents of dataset #" + i
                                    + ": " + dataset + "; allIds=" + allIds);
                                    + ": " + dataset + "; allSavableIds=" + savableIds);
                        }
                        for (int j = 0; j < allIds.size(); j++) {
                            final AutofillId id = allIds.valueAt(j);
                        savable_ids_loop: for (int j = 0; j < savableIds.size(); j++) {
                            final AutofillId id = savableIds.valueAt(j);
                            final AutofillValue currentValue = currentValues.get(id);
                            if (currentValue == null) {
                                if (sDebug) {
                                    Slog.d(TAG, "dataset has value for field that is null: " + id);
                                }
                                continue datasets_loop;
                                continue savable_ids_loop;
                            }
                            final AutofillValue datasetValue = datasetValues.get(id);
                            if (!currentValue.equals(datasetValue)) {
@@ -1657,8 +1658,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                }

                // Use handler so logContextCommitted() is logged first
                mHandler.sendMessage(obtainMessage(
                        Session::logSaveShown, this));
                mHandler.sendMessage(obtainMessage( Session::logSaveShown, this));

                final IAutoFillManagerClient client = getClient();
                mPendingSaveUi = new PendingUi(mActivityToken, id, client);