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

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

[Relayout] Part 2: Plug in Activity

Activity's onPostResume should call into Autofill.
Add additional skeleton methods to be populated later.

Bug: 238252288
Flag: EXEMPT : DeviceConfig flags used: enable_relayout
exception granted in b/318391032
Test: m

Change-Id: I7d72740b8ec1214b943a1a8901b9e2cc581817ca
parent 16cdaf66
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2214,6 +2214,9 @@ public class Activity extends ContextThemeWrapper
        notifyVoiceInteractionManagerServiceActivityEvent(
                VoiceInteractionSession.VOICE_INTERACTION_ACTIVITY_EVENT_RESUME);

        // Notify autofill
        getAutofillClientController().onActivityPostResumed();

        mCalled = true;
    }

+70 −1
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ public final class AutofillClientController implements AutofillManager.AutofillC
    private AutofillPopupWindow mAutofillPopupWindow;
    private boolean mAutoFillResetNeeded;
    private boolean mAutoFillIgnoreFirstResumePause;
    private Boolean mRelayoutFix;

    /**
     * AutofillClientController constructor.
@@ -86,6 +87,18 @@ public final class AutofillClientController implements AutofillManager.AutofillC
        return mAutofillManager;
    }

    /**
     * Whether to apply relayout fixes.
     *
     * @hide
     */
    public boolean isRelayoutFixEnabled() {
        if (mRelayoutFix == null) {
            mRelayoutFix = getAutofillManager().isRelayoutFixEnabled();
        }
        return mRelayoutFix;
    }

    // ------------------ Called for Activity events ------------------

    /**
@@ -119,7 +132,54 @@ public final class AutofillClientController implements AutofillManager.AutofillC
     * Called when the {@link Activity#onResume()} is called.
     */
    public void onActivityResumed() {
        if (Helper.sVerbose) {
            Log.v(TAG, "onActivityResumed()");
        }
        if (isRelayoutFixEnabled()) {
            // Do nothing here. We'll handle it in onActivityPostResumed()
            return;
        }
        if (Helper.sVerbose) {
            Log.v(TAG, "onActivityResumed(): Relayout fix not enabled");
        }
        forResume();
    }

    /**
     * Called when the {@link Activity#onPostResume()} is called.
     */
    public void onActivityPostResumed() {
        if (Helper.sVerbose) {
            Log.v(TAG, "onActivityPostResumed()");
        }
        if (!isRelayoutFixEnabled()) {
            return;
        }
        if (Helper.sVerbose) {
            Log.v(TAG, "onActivityPostResumed(): Relayout fix enabled");
        }
        forResume();
    }

    /**
     * Code to execute when an app has resumed (or is about to resume)
     */
    private void forResume() {
        enableAutofillCompatibilityIfNeeded();
        boolean relayoutFix = isRelayoutFixEnabled();
        if (relayoutFix) {
            if (getAutofillManager().shouldRetryFill()) {
                if (Helper.sVerbose) {
                    Log.v(TAG, "forResume(): Autofill potential relayout. Retrying fill.");
                }
                getAutofillManager().attemptRefill();
            } else {
                if (Helper.sVerbose) {
                    Log.v(TAG, "forResume(): Not attempting refill.");
                }
            }
        }

        if (mAutoFillResetNeeded) {
            if (!mAutoFillIgnoreFirstResumePause) {
                View focus = mActivity.getCurrentFocus();
@@ -131,11 +191,20 @@ public final class AutofillClientController implements AutofillManager.AutofillC
                    // ViewRootImpl.performTraversals() changes window visibility to VISIBLE.
                    // So we cannot call View.notifyEnterOrExited() which will do nothing
                    // when View.isVisibleToUser() is false.
                    if (relayoutFix && getAutofillManager().isAuthenticationPending()) {
                        if (Helper.sVerbose) {
                            Log.v(TAG, "forResume(): ignoring focus due to auth pending");
                        }
                    } else {
                        if (Helper.sVerbose) {
                            Log.v(TAG, "forResume(): notifyViewEntered");
                        }
                        getAutofillManager().notifyViewEntered(focus);
                    }
                }
            }
        }
    }

    /**
     * Called when the Activity is performing resume.
+31 −0
Original line number Diff line number Diff line
@@ -1497,6 +1497,37 @@ public final class AutofillManager {
        notifyViewEntered(view, virtualId, absBounds, flags);
    }

    /**
     * Called to know whether authentication was pending.
     * @hide
     */
    public boolean isAuthenticationPending() {
        return mState == STATE_PENDING_AUTHENTICATION;
    }

    /**
     * Called to check if we should retry fill.
     * Useful for knowing whether to attempt refill after relayout.
     *
     * @hide
     */
    public boolean shouldRetryFill() {
        // TODO: Implement in follow-up cl
        return false;
    }

    /**
     * Called when a potential relayout may have occurred.
     *
     * @return whether refill was done. True if refill was done partially or fully.
     * @hide
     */
    public boolean attemptRefill() {
        Log.i(TAG, "Attempting refill");
        // TODO: Implement in follow-up cl
        return false;
    }

    /**
     * Called when a {@link View} that supports autofill is entered.
     *