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

Commit e579033d authored by Ben Lin's avatar Ben Lin
Browse files

Notify AutofillManager in onResume() IFF activity was not recreated.

In Activity#onResume(), AutofillManager is notified when there is a
current focus, in cases where user backgrounds and then foregrounds the
app, etc. However, onResume() is also called when screen rotation
occurs, but because both the window and the layout is torn down,
Activity#getCurrentFocus() returns null, thus AutofillManager is not
notified because there is no current focus. This is true on phones.

However, in some devices, such as Chromebooks, window is preserved on
rotation. The API is supported in Window Management's task resize
capabilities. Because the window is not torn down,
Activity#getCurrentFocus() now returns true, even if an upcoming layout
pass is bound to happen. Thus, AutofillManager gets notified twice: once
on screen rotation (onResume()), and another during the subsequent
layout pass.

This changes the logic to explicitly check for the case where activity
is recreated from a previous saved instance. If it is, then skip
notifying AutofillManager, as the subsequent layout pass will do the
job.

Bug: 111619119
Test: atest android.autofillservice.cts.SessionLifecycleTest#testDatasetVisibleWhileAutofilledAppIsLifecycled
atest android.autofillservice.cts.DuplicateIdActivityTest#testDoNotRestoreDuplicateAutofillIds

Change-Id: I1816abfa23d39d6f3370c9f32c6de7fc5ae0398e
(cherry picked from commit af5a24eea08975990c7487be8b64657bf61641b7)
parent 2f91645c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -1387,7 +1387,15 @@ public class Activity extends ContextThemeWrapper
        if (mAutoFillResetNeeded) {
            if (!mAutoFillIgnoreFirstResumePause) {
                View focus = getCurrentFocus();
                if (focus != null && focus.canNotifyAutofillEnterExitEvent()) {
                // On Activity rotation situation (mRestoredFromBundle is true),
                // we should not call on AutofillManager in onResume()
                // since the next Layout pass will do that.
                // However, there are both cases where Activity#getCurrentFocus()
                // will return null (window not preserved) and not null (window IS
                // preserved), so we need to explicitly check for mRestoredFromBundle
                // here.
                if (!mRestoredFromBundle && focus != null
                        && focus.canNotifyAutofillEnterExitEvent()) {
                    // TODO: in Activity killed/recreated case, i.e. SessionLifecycleTest#
                    // testDatasetVisibleWhileAutofilledAppIsLifecycled: the View's initial
                    // window visibility after recreation is INVISIBLE in onResume() and next frame