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

Commit a0fb8e03 authored by Bryce Lee's avatar Bryce Lee
Browse files

Wait to pause activity if translucent activity is waiting.

A recent change moved an activity to paused if it was stopped and
became visible. However, there are situations where this is not
desired, such as when waiting for translucent activity to become
visible. The extra binder calls from pausing during this time
leads to visible jank. Therefore should avoid moving states until
after this operation has completed.

Change-Id: I7bbab002cbee479f436515e7cc5db6f3a1f10b16
Fixes: 73832787
Test: atest FrameworksServicesTests:com.android.server.am.ActivityRecordTests#testPausingWhenVisibleFromStopped
Test: atest CtsActivityManagerDeviceTestCases:ActivityLifecycleTests#testPausedWithTranslucentOnTop
Test: atest CtsActivityManagerDeviceTestCases:ActivityLifecycleTests#testPausedWhenReturningWithTranslucentOnTop
Test: atest CtsActivityManagerDeviceTestCases:ActivityLifecycleTests#testPausedWhenRecreatedFromInNonFocusedStack
Test: atest CtsActivityManagerDeviceTestCases:ActivityLifecycleTests#testPausedWhenRestartedFromInNonFocusedStack
parent c5ad6526
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -1712,8 +1712,12 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
            mStackSupervisor.mStoppingActivities.remove(this);
            mStackSupervisor.mGoingToSleepActivities.remove(this);

            // If the activity is stopped or stopping, cycle to the paused state.
            if (isState(STOPPED, STOPPING)) {
            // If the activity is stopped or stopping, cycle to the paused state. We avoid doing
            // this when there is an activity waiting to become translucent as the extra binder
            // calls will lead to noticeable jank. A later call to
            // ActivityStack#ensureActivitiesVisibleLocked will bring the activity to the proper
            // paused state.
            if (isState(STOPPED, STOPPING) && stack.mTranslucentActivityWaiting == null) {
                // Capture reason before state change
                final String reason = getLifecycleDescription("makeVisibleIfNeeded");

@@ -1727,7 +1731,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
            }
        } catch (Exception e) {
            // Just skip on any failure; we'll make it visible when it next restarts.
            Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e);
            Slog.w(TAG, "Exception thrown making visible: " + intent.getComponent(), e);
        }
        handleAlreadyVisible();
    }
+11 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
@@ -135,6 +136,16 @@ public class ActivityRecordTests extends ActivityTestsBase {
        mActivity.makeVisibleIfNeeded(null /* starting */);

        assertTrue(mActivity.isState(INITIALIZING));

        // Make sure the state does not change if we are not the current top activity.
        mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped behind");

        // Make sure that the state does not change when we have an activity becoming translucent
        final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build();
        mStack.mTranslucentActivityWaiting = topActivity;
        mActivity.makeVisibleIfNeeded(null /* starting */);

        assertTrue(mActivity.isState(STOPPED));
    }

    @Test