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

Commit d8f6be77 authored by Simranjit Kohli's avatar Simranjit Kohli
Browse files

[Autofill PCC Metrics]: Populate PCC relevant metrics

Populate PCC relevant metrics..
Test: m
Bug: 265037574

Change-Id: Iebaf617e0a65104edfd2e4543ea65abf37388f7f
parent 4422472b
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.server.autofill;

import static android.service.autofill.Dataset.PICK_REASON_PCC_DETECTION_ONLY;
import static android.service.autofill.Dataset.PICK_REASON_PCC_DETECTION_PREFERRED_WITH_PROVIDER;

import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_FILL_RESPONSE_REPORTED;
import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_FILL_RESPONSE_REPORTED__AUTHENTICATION_RESULT__AUTHENTICATION_FAILURE;
import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_FILL_RESPONSE_REPORTED__AUTHENTICATION_RESULT__AUTHENTICATION_RESULT_UNKNOWN;
@@ -218,7 +221,16 @@ public final class FillResponseEventLogger {

  public void maybeSetAvailableCount(int val) {
    mEventInternal.ifPresent(event -> {
      // Don't reset if it's already populated.
      // This is just a technical limitation of not having complicated logic.
      // Autofill Provider may return some datasets which are applicable to data types.
      // In such a case, we set available count to the number of datasets provided.
      // However, it's possible that those data types aren't detected by PCC, so in effect, there
      // are 0 datasets. In the codebase, we treat it as null response, which may call this again
      // to set 0. But we don't want to overwrite this value.
      if (event.mAvailableCount == 0) {
        event.mAvailableCount = val;
      }
    });
  }

@@ -336,6 +348,32 @@ public final class FillResponseEventLogger {
    });
  }

  /**
   * Set available_pcc_count.
   */
  public void maybeSetAvailableDatasetsPccCount(@Nullable List<Dataset> datasetList) {
    mEventInternal.ifPresent(event -> {
      int pccOnlyCount = 0;
      int pccCount = 0;
      if (datasetList != null) {
        for (int i = 0; i < datasetList.size(); i++) {
          Dataset dataset = datasetList.get(i);
          if (dataset != null) {
            if (dataset.getEligibleReason() == PICK_REASON_PCC_DETECTION_ONLY) {
              pccOnlyCount++;
              pccCount++;
            } else if (dataset.getEligibleReason()
                    == PICK_REASON_PCC_DETECTION_PREFERRED_WITH_PROVIDER) {
              pccCount++;
            }
          }
        }
      }
      event.mAvailablePccOnlyCount = pccOnlyCount;
      event.mAvailablePccCount = pccCount;
    });
  }


  /**
   * Log an AUTOFILL_FILL_RESPONSE_REPORTED event.
+37 −10
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.autofill;

import static android.service.autofill.Dataset.PICK_REASON_PCC_DETECTION_ONLY;
import static android.service.autofill.Dataset.PICK_REASON_PCC_DETECTION_PREFERRED_WITH_PROVIDER;
import static android.service.autofill.FillEventHistory.Event.UI_TYPE_DIALOG;
import static android.service.autofill.FillEventHistory.Event.UI_TYPE_INLINE;
import static android.service.autofill.FillEventHistory.Event.UI_TYPE_MENU;
@@ -228,36 +230,61 @@ public final class PresentationStatsEventLogger {
    public void maybeSetAvailableCount(@Nullable List<Dataset> datasetList,
            AutofillId currentViewId) {
        mEventInternal.ifPresent(event -> {
            int availableCount = getDatasetCountForAutofillId(datasetList, currentViewId);
            event.mAvailableCount = availableCount;
            event.mIsDatasetAvailable = availableCount > 0;
            CountContainer container = getDatasetCountForAutofillId(datasetList, currentViewId);
            event.mAvailableCount = container.mAvailableCount;
            event.mAvailablePccCount = container.mAvailablePccCount;
            event.mAvailablePccOnlyCount = container.mAvailablePccOnlyCount;
            event.mIsDatasetAvailable = container.mAvailableCount > 0;
        });
    }

    public void maybeSetCountShown(@Nullable List<Dataset> datasetList,
            AutofillId currentViewId) {
        mEventInternal.ifPresent(event -> {
            int countShown = getDatasetCountForAutofillId(datasetList, currentViewId);
            event.mCountShown = countShown;
            if (countShown > 0) {
            CountContainer container = getDatasetCountForAutofillId(datasetList, currentViewId);
            event.mCountShown = container.mAvailableCount;
            if (container.mAvailableCount > 0) {
                event.mNoPresentationReason = NOT_SHOWN_REASON_ANY_SHOWN;
            }
        });
    }

    private static int getDatasetCountForAutofillId(@Nullable List<Dataset> datasetList,
    private static CountContainer getDatasetCountForAutofillId(@Nullable List<Dataset> datasetList,
            AutofillId currentViewId) {
        int availableCount = 0;

        CountContainer container = new CountContainer();
        if (datasetList != null) {
            for (int i = 0; i < datasetList.size(); i++) {
                Dataset data = datasetList.get(i);
                if (data != null && data.getFieldIds() != null
                        && data.getFieldIds().contains(currentViewId)) {
                    availableCount += 1;
                    container.mAvailableCount += 1;
                    if (data.getEligibleReason() == PICK_REASON_PCC_DETECTION_ONLY) {
                        container.mAvailablePccOnlyCount++;
                        container.mAvailablePccCount++;
                    } else if (data.getEligibleReason()
                            == PICK_REASON_PCC_DETECTION_PREFERRED_WITH_PROVIDER) {
                        container.mAvailablePccCount++;
                    }
                }
            }
        }
        return container;
    }

    private static class CountContainer{
        int mAvailableCount = 0;
        int mAvailablePccCount = 0;
        int mAvailablePccOnlyCount = 0;

        CountContainer() {}

        CountContainer(int availableCount, int availablePccCount,
                int availablePccOnlyCount) {
            mAvailableCount = availableCount;
            mAvailablePccCount = availablePccCount;
            mAvailablePccOnlyCount = availablePccOnlyCount;
        }
        return availableCount;
    }

    public void maybeSetCountFilteredUserTyping(int countFilteredUserTyping) {
+13 −9
Original line number Diff line number Diff line
@@ -1561,9 +1561,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                Slog.d(TAG, message.toString());
            }
        }

        if (((response.getDatasets() == null || response.getDatasets().isEmpty())
                        && response.getAuthentication() == null)
        List<Dataset> datasetList = response.getDatasets();
        if (((datasetList == null || datasetList.isEmpty()) && response.getAuthentication() == null)
                || autofillDisabled) {
            // Response is "empty" from a UI point of view, need to notify client.
            notifyUnavailableToClient(
@@ -1585,6 +1584,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            }
        }

        mFillResponseEventLogger.maybeSetAvailableCount(
                datasetList == null ? 0 : datasetList.size());

        // TODO(b/266379948): Ideally wait for PCC request to finish for a while more
        // (say 100ms) before proceeding further on.

@@ -1735,6 +1737,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            }
            if (ids.isEmpty()) return saveInfo;
            AutofillId[] autofillIds = new AutofillId[ids.size()];
            mSaveEventLogger.maybeSetIsFrameworkCreatedSaveInfo(true);
            ids.toArray(autofillIds);
            return SaveInfo.copy(saveInfo, autofillIds);
        }
@@ -4040,8 +4043,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                    mPresentationStatsEventLogger.maybeSetRequestId(response.getRequestId());
                    mPresentationStatsEventLogger.maybeSetAvailableCount(
                            response.getDatasets(), mCurrentViewId);
                    mFillResponseEventLogger.maybeSetAvailableCount(
                        response.getDatasets(), mCurrentViewId);
                }

                if (isSameViewEntered) {
@@ -4732,6 +4733,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            autofillableIds = null;
        }
        // Log the existing FillResponse event.
        mFillResponseEventLogger.maybeSetAvailableCount(0);
        mFillResponseEventLogger.logAndEndEvent();
        mService.resetLastResponse();

@@ -4960,10 +4962,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        mResponses.put(requestId, newResponse);
        mClientState = newClientState != null ? newClientState : newResponse.getClientState();

        mPresentationStatsEventLogger.maybeSetAvailableCount(
                newResponse.getDatasets(), mCurrentViewId);
        mFillResponseEventLogger.maybeSetAvailableCount(
            newResponse.getDatasets(), mCurrentViewId);
        List<Dataset> datasetList = newResponse.getDatasets();

        mPresentationStatsEventLogger.maybeSetAvailableCount(datasetList, mCurrentViewId);
        mFillResponseEventLogger.maybeSetAvailableDatasetsPccCount(datasetList);

        setViewStatesLocked(newResponse, ViewState.STATE_FILLABLE, false);
        updateFillDialogTriggerIdsLocked();
@@ -5088,6 +5090,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                if (generateEvent) {
                    mService.logDatasetSelected(dataset.getId(), id, mClientState, uiType);
                    mPresentationStatsEventLogger.maybeSetSelectedDatasetId(datasetIndex);
                    mPresentationStatsEventLogger.maybeSetSelectedDatasetPickReason(
                            dataset.getEligibleReason());
                }
                if (mCurrentViewId != null) {
                    mInlineSessionController.hideInlineSuggestionsUiLocked(mCurrentViewId);