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

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

[Relayout] Implement Logging

Add logs for relayout and related fixes.

Bug: 238252288
Flag: EXEMPT : DeviceConfig flags used: enable_relayout
exception granted in b/318391032
Test: m; and verified manually.

Change-Id: I5f492a5fe97db193c907bacd8ff1b8ac69ed578b
parent 30da6cff
Loading
Loading
Loading
Loading
+43 −3
Original line number Diff line number Diff line
@@ -1374,6 +1374,14 @@ public final class AutofillManager {
                if (mRelayoutFix && isAuthenticationPending()) {
                    Log.i(TAG, "onInvisibleForAutofill(): Ignoring expiringResponse due to pending"
                            + " authentication");
                    try {
                        mService.notifyNotExpiringResponseDuringAuth(
                                mSessionId, 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.
                    }
                    return;
                }
                Log.i(TAG, "onInvisibleForAutofill(): expiringResponse");
@@ -1532,6 +1540,20 @@ public final class AutofillManager {
        return mState == STATE_PENDING_AUTHENTICATION;
    }

    /**
     * Called to log notify view entered was ignored due to pending auth
     * @hide
     */
    public void notifyViewEnteredIgnoredDuringAuthCount() {
        try {
            mService.notifyViewEnteredIgnoredDuringAuthCount(mSessionId, 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.
        }
    }

    /**
     * Called to check if we should retry fill.
     * Useful for knowing whether to attempt refill after relayout.
@@ -3250,7 +3272,7 @@ public final class AutofillManager {
                    failedIds, failedAutofillValues, hideHighlight);
        }
        try {
            mService.setAutofillFailure(mSessionId, failedIds, mContext.getUserId());
            mService.setAutofillFailure(mSessionId, failedIds, isRefill, mContext.getUserId());
        } catch (RemoteException e) {
            // In theory, we could ignore this error since it's not a big deal, but
            // in reality, we rather crash the app anyways, as the failure could be
@@ -3273,6 +3295,7 @@ public final class AutofillManager {
                    //  if there was auth previously.
                    Log.i(TAG, "handleFailedIdsLocked(): Attempting refill");
                    attemptRefill();
                    mFillReAttemptNeeded = false;
                }
            }
        }
@@ -3308,6 +3331,22 @@ public final class AutofillManager {
                return;
            }

            if (ids == null) {
                Log.i(TAG, "autofill(): No id's to fill");
                return;
            }

            if (mRelayoutFix && isRefill) {
                try {
                    mService.setAutofillIdsAttemptedForRefill(
                            mSessionId, ids, 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.
                }
            }

            final int itemCount = ids.size();
            int numApplied = 0;
            ArrayMap<View, SparseArray<AutofillValue>> virtualValues = null;
@@ -3361,7 +3400,8 @@ public final class AutofillManager {
                }
            }

            handleFailedIdsLocked(failedIds, failedAutofillValues, hideHighlight, isRefill);
            handleFailedIdsLocked(
                    failedIds, failedAutofillValues, hideHighlight, isRefill);

            if (virtualValues != null) {
                for (int i = 0; i < virtualValues.size(); i++) {
@@ -3415,7 +3455,7 @@ public final class AutofillManager {
    private void reportAutofillContentFailure(AutofillId id) {
        try {
            mService.setAutofillFailure(mSessionId, Collections.singletonList(id),
                    mContext.getUserId());
                    false /* isRefill */, mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+4 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ oneway interface IAutoFillManager {
        in IResultReceiver result);
    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 setAutofillFailure(int sessionId, in List<AutofillId> ids, boolean isRefill, 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);
@@ -67,4 +67,7 @@ oneway interface IAutoFillManager {
    void getDefaultFieldClassificationAlgorithm(in IResultReceiver result);
    void setAugmentedAutofillWhitelist(in List<String> packages, in List<ComponentName> activities,
        in IResultReceiver result);
    void notifyNotExpiringResponseDuringAuth(int sessionId, int userId);
    void notifyViewEnteredIgnoredDuringAuthCount(int sessionId, int userId);
    void setAutofillIdsAttemptedForRefill(int sessionId, in List<AutofillId> ids, int userId);
}
+43 −2
Original line number Diff line number Diff line
@@ -1985,12 +1985,13 @@ public final class AutofillManagerService
        }

        @Override
        public void setAutofillFailure(int sessionId, @NonNull List<AutofillId> ids, int userId) {
        public void setAutofillFailure(
                int sessionId, @NonNull List<AutofillId> ids, boolean isRefill, int userId) {
            synchronized (mLock) {
                final AutofillManagerServiceImpl service =
                        peekServiceForUserWithLocalBinderIdentityLocked(userId);
                if (service != null) {
                    service.setAutofillFailureLocked(sessionId, getCallingUid(), ids);
                    service.setAutofillFailureLocked(sessionId, getCallingUid(), ids, isRefill);
                } else if (sVerbose) {
                    Slog.v(TAG, "setAutofillFailure(): no service for " + userId);
                }
@@ -2010,6 +2011,46 @@ public final class AutofillManagerService
            }
        }

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

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

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

        @Override
        public void finishSession(int sessionId, int userId,
                @AutofillCommitReason int commitReason) {
+49 −2
Original line number Diff line number Diff line
@@ -464,7 +464,8 @@ final class AutofillManagerServiceImpl
    }

    @GuardedBy("mLock")
    void setAutofillFailureLocked(int sessionId, int uid, @NonNull List<AutofillId> ids) {
    void setAutofillFailureLocked(
            int sessionId, int uid, @NonNull List<AutofillId> ids, boolean isRefill) {
        if (!isEnabledLocked()) {
            Slog.wtf(TAG, "Service not enabled");
            return;
@@ -474,7 +475,7 @@ final class AutofillManagerServiceImpl
            Slog.v(TAG, "setAutofillFailure(): no session for " + sessionId + "(" + uid + ")");
            return;
        }
        session.setAutofillFailureLocked(ids);
        session.setAutofillFailureLocked(ids, isRefill);
    }

    @GuardedBy("mLock")
@@ -491,6 +492,52 @@ final class AutofillManagerServiceImpl
        session.setViewAutofilledLocked(id);
    }

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

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

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

    @GuardedBy("mLock")
    void finishSessionLocked(int sessionId, int uid, @AutofillCommitReason int commitReason) {
        if (!isEnabledLocked()) {
+56 −5
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_PRESENTATION_
import static com.android.server.autofill.Helper.sVerbose;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
@@ -684,6 +685,19 @@ public final class PresentationStatsEventLogger {
        });
    }

    /**
     * Set views_fillable_total_count as long as mEventInternal presents.
     */
    public void maybeUpdateViewFillablesForRefillAttempt(List<AutofillId> autofillIds) {
        mEventInternal.ifPresent(event -> {
            // These autofill ids would be the ones being re-attempted.
            event.mAutofillIdsAttemptedAutofill = new ArraySet<>(autofillIds);
            // These autofill id's are being refilled, so they had failed previously.
            // Note that these autofillIds correspond to the new autofill ids after relayout.
            event.mFailedAutofillIds = new ArraySet<>(autofillIds);
        });
    }

    /**
     * Set how many views are filtered from fill because they are not in current session
     */
@@ -697,9 +711,16 @@ public final class PresentationStatsEventLogger {
     * Set views_filled_failure_count using failure count as long as mEventInternal
     * presents.
     */
    public void maybeSetViewFillFailureCounts(int failureCount) {
    public void maybeSetViewFillFailureCounts(@NonNull List<AutofillId> ids, boolean isRefill) {
        mEventInternal.ifPresent(event -> {
            int failureCount = ids.size();
            if (isRefill) {
                event.mViewFailedOnRefillCount = failureCount;
            } else {
                event.mViewFillFailureCount = failureCount;
                event.mViewFailedPriorToRefillCount = failureCount;
                event.mFailedAutofillIds = new ArraySet<>(ids);
            }
        });
    }

@@ -719,7 +740,7 @@ public final class PresentationStatsEventLogger {
     * Set views_filled_failure_count using failure count as long as mEventInternal
     * presents.
     */
    public void maybeAddSuccessId(AutofillId autofillId) {
    public synchronized void maybeAddSuccessId(AutofillId autofillId) {
        mEventInternal.ifPresent(event -> {
            ArraySet<AutofillId> autofillIds = event.mAutofillIdsAttemptedAutofill;
            if (autofillIds == null) {
@@ -727,9 +748,21 @@ public final class PresentationStatsEventLogger {
                        + " successfully filled");
                event.mViewFilledButUnexpectedCount++;
            } else if (autofillIds.contains(autofillId)) {
                ArraySet<AutofillId> failedIds = event.mFailedAutofillIds;
                if (failedIds.contains(autofillId)) {
                    if (sVerbose) {
                        Slog.v(TAG, "Logging autofill refill of id:" + autofillId);
                    }
                    // This indicates the success after refill attempt
                    event.mViewFilledSuccessfullyOnRefillCount++;
                    // Remove so if we don't reprocess duplicate requests
                    failedIds.remove(autofillId);
                } else {
                    if (sVerbose) {
                        Slog.v(TAG, "Logging autofill for id:" + autofillId);
                    }
                }
                // Common actions to take irrespective of being filled by refill attempt or not.
                event.mViewFillSuccessCount++;
                autofillIds.remove(autofillId);
                event.mAlreadyFilledAutofillIds.add(autofillId);
@@ -746,6 +779,23 @@ public final class PresentationStatsEventLogger {
        });
    }

    /**
     * Set how many views are filtered from fill because they are not in current session
     */
    public void maybeSetNotifyNotExpiringResponseDuringAuth() {
        mEventInternal.ifPresent(event -> {
            event.mFixExpireResponseDuringAuthCount++;
        });
    }
    /**
     * Set how many views are filtered from fill because they are not in current session
     */
    public void notifyViewEnteredIgnoredDuringAuthCount() {
        mEventInternal.ifPresent(event -> {
            event.mNotifyViewEnteredIgnoredDuringAuthCount++;
        });
    }

    public void logAndEndEvent() {
        if (!mEventInternal.isPresent()) {
            Slog.w(TAG, "Shouldn't be logging AutofillPresentationEventReported again for same "
@@ -933,6 +983,7 @@ public final class PresentationStatsEventLogger {
        int mNotifyViewEnteredIgnoredDuringAuthCount = 0;

        ArraySet<AutofillId> mAutofillIdsAttemptedAutofill;
        ArraySet<AutofillId> mFailedAutofillIds = new ArraySet<>();
        ArraySet<AutofillId> mAlreadyFilledAutofillIds = new ArraySet<>();

        // Not logged - used for internal logic
Loading