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

Commit 76ea19d9 authored by Simranjit Kohli's avatar Simranjit Kohli
Browse files

More logging for views filling

Add more log for views filling

1.  Add confirmed success. Confirmation is done via call by fetching
    autofillValue, or if app calls notifyValueChanged.
    If views aren't included in the success, it doesn't neccessarily
    mean that the autfilling failed. It could very well be that the app
    has implemented autofill functionality improperly.

2.  If for some reason, the autofill callback is for an autofill id that
    wasn't being tracked, we log count of such cases. We expect it to be
    0. This is only to catch such occurences, and investigate them, and
    fix tem later.

Bug: 332943845
Test: atest CtsAutoFillServiceTestCases
Change-Id: I69b9dcd7749b0b9d4ac7ea6cca910e8d0a8cd2da
parent 812805e8
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -1978,6 +1978,13 @@ public final class AutofillManager {

                    if (Objects.equals(mLastAutofilledData.get(id), value)) {
                        view.setAutofilled(true, hideHighlight);
                        try {
                            mService.setViewAutofilled(mSessionId, id, mContext.getUserId());
                        } catch (RemoteException e) {
                            // The failure could be a consequence of something going wrong on the
                            // server side. Do nothing here since it's just logging, but it's
                            // possible follow-up actions may fail.
                        }
                    } else {
                        view.setAutofilled(false, false);
                        mLastAutofilledData.remove(id);
@@ -2978,6 +2985,13 @@ public final class AutofillManager {
                mLastAutofilledData.put(view.getAutofillId(), targetValue);
            }
            view.setAutofilled(true, hideHighlight);
            try {
                mService.setViewAutofilled(mSessionId, view.getAutofillId(), mContext.getUserId());
            } catch (RemoteException e) {
                // The failure could be a consequence of something going wrong on the server side.
                // Do nothing here since it's just logging, but it's possible follow-up actions may
                // fail.
            }
        }
    }

+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ oneway interface IAutoFillManager {
    void updateSession(int sessionId, in AutofillId id, in Rect bounds,
        in AutofillValue value, int action, int flags, int userId);
    void setAutofillFailure(int sessionId, in List<AutofillId> ids, int userId);
    void setViewAutofilled(int sessionId, in AutofillId id, int userId);
    void finishSession(int sessionId, int userId, int commitReason);
    void cancelSession(int sessionId, int userId);
    void setAuthenticationResult(in Bundle data, int sessionId, int authenticationId, int userId);
+13 −0
Original line number Diff line number Diff line
@@ -1997,6 +1997,19 @@ public final class AutofillManagerService
            }
        }

        @Override
        public void setViewAutofilled(int sessionId, @NonNull AutofillId id, int userId) {
            synchronized (mLock) {
                final AutofillManagerServiceImpl service =
                        peekServiceForUserWithLocalBinderIdentityLocked(userId);
                if (service != null) {
                    service.setViewAutofilled(sessionId, getCallingUid(), id);
                } else if (sVerbose) {
                    Slog.v(TAG, "setAutofillFailure(): no service for " + userId);
                }
            }
        }

        @Override
        public void finishSession(int sessionId, int userId,
                @AutofillCommitReason int commitReason) {
+16 −0
Original line number Diff line number Diff line
@@ -466,6 +466,7 @@ final class AutofillManagerServiceImpl
    @GuardedBy("mLock")
    void setAutofillFailureLocked(int sessionId, int uid, @NonNull List<AutofillId> ids) {
        if (!isEnabledLocked()) {
            Slog.wtf(TAG, "Service not enabled");
            return;
        }
        final Session session = mSessions.get(sessionId);
@@ -476,9 +477,24 @@ final class AutofillManagerServiceImpl
        session.setAutofillFailureLocked(ids);
    }

    @GuardedBy("mLock")
    void setViewAutofilled(int sessionId, int uid, @NonNull AutofillId id) {
        if (!isEnabledLocked()) {
            Slog.wtf(TAG, "Service not enabled");
            return;
        }
        final Session session = mSessions.get(sessionId);
        if (session == null || uid != session.uid) {
            Slog.v(TAG, "setViewAutofilled(): no session for " + sessionId + "(" + uid + ")");
            return;
        }
        session.setViewAutofilled(id);
    }

    @GuardedBy("mLock")
    void finishSessionLocked(int sessionId, int uid, @AutofillCommitReason int commitReason) {
        if (!isEnabledLocked()) {
            Slog.wtf(TAG, "Service not enabled");
            return;
        }

+39 −4
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.content.pm.PackageManager;
import android.provider.Settings;
import android.service.autofill.Dataset;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Slog;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
@@ -548,9 +549,10 @@ public final class PresentationStatsEventLogger {
    /**
     * Set views_fillable_total_count as long as mEventInternal presents.
     */
    public void maybeSetViewFillableCounts(int totalFillableCount) {
    public void maybeSetViewFillablesAndCount(List<AutofillId> autofillIds) {
        mEventInternal.ifPresent(event -> {
            event.mViewFillableTotalCount = totalFillableCount;
            event.mAutofillIdsAttemptedAutofill = new ArraySet<>(autofillIds);
            event.mViewFillableTotalCount = event.mAutofillIdsAttemptedAutofill.size();
        });
    }

@@ -575,6 +577,29 @@ public final class PresentationStatsEventLogger {
            event.mFocusedId = id;
        });
    }
    /**
     * Set views_filled_failure_count using failure count as long as mEventInternal
     * presents.
     */
    public void maybeAddSuccessId(AutofillId autofillId) {
        mEventInternal.ifPresent(event -> {
            ArraySet<AutofillId> autofillIds = event.mAutofillIdsAttemptedAutofill;
            if (autofillIds == null) {
                Slog.w(TAG, "Attempted autofill ids is null, but received autofillId:" + autofillId
                        + " successfully filled");
                event.mViewFilledButUnexpectedCount++;
            } else if (autofillIds.contains(autofillId)) {
                if (sVerbose) {
                    Slog.v(TAG, "Logging autofill for id:" + autofillId);
                    event.mViewFillSuccessCount++;
                }
            } else {
                Slog.w(TAG, "Successfully filled autofillId:" + autofillId
                        + " not found in list of attempted autofill ids: " + autofillIds);
                event.mViewFilledButUnexpectedCount++;
            }
        });
    }

    public void logAndEndEvent() {
        if (!mEventInternal.isPresent()) {
@@ -621,7 +646,9 @@ public final class PresentationStatsEventLogger {
                    + " mWebviewRequestedCredential=" + event.mWebviewRequestedCredential
                    + " mViewFillableTotalCount=" + event.mViewFillableTotalCount
                    + " mViewFillFailureCount=" + event.mViewFillFailureCount
                    + " mFocusedId=" + event.mFocusedId);
                    + " mFocusedId=" + event.mFocusedId
                    + " mViewFillSuccessCount=" + event.mViewFillSuccessCount
                    + " mViewFilledButUnexpectedCount=" + event.mViewFilledButUnexpectedCount);
        }

        // TODO(b/234185326): Distinguish empty responses from other no presentation reasons.
@@ -665,7 +692,9 @@ public final class PresentationStatsEventLogger {
                event.mWebviewRequestedCredential,
                event.mViewFillableTotalCount,
                event.mViewFillFailureCount,
                event.mFocusedId);
                event.mFocusedId,
                event.mViewFillSuccessCount,
                event.mViewFilledButUnexpectedCount);
        mEventInternal = Optional.empty();
    }

@@ -705,6 +734,12 @@ public final class PresentationStatsEventLogger {
        int mViewFillFailureCount = -1;
        int mFocusedId = -1;

        // Default value for success count is set to 0 explicitly. Setting it to -1 for
        // uninitialized doesn't help much, as this would be non-zero only if callback is received.
        int mViewFillSuccessCount = 0;
        int mViewFilledButUnexpectedCount = 0;

        ArraySet<AutofillId> mAutofillIdsAttemptedAutofill;
        PresentationStatsEventInternal() {}
    }

Loading