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

Commit 69ad8183 authored by Bryce Lee's avatar Bryce Lee
Browse files

Reduce synchronized lock scope.

The lock was introduced earlier to prevent race conditions between
setting the visibility and configuration. However, holding the lock
for the entire method leads to an increase in the frame time.

This changelist reduces the scope of the lock to cover the core
logic where this condition applies.

Change-Id: Ia97b3680f730264c10ff5067e4f21180cfb2202e
Fixes: 67010772
Test: go/wm-smoke
parent 9b120d5a
Loading
Loading
Loading
Loading
+118 −114
Original line number Diff line number Diff line
@@ -2246,14 +2246,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        try {
            // Protect against recursion.
            mStackSupervisor.inResumeTopActivity = true;
            // The contained logic must be synchronized, since we are both changing the visibility
            // and updating the {@link Configuration}. {@link ActivityRecord#setVisibility} will
            // ultimately cause the client code to schedule a layout. Since layouts retrieve the
            // current {@link Configuration}, we must ensure that the below code updates it before
            // the layout can occur.
            synchronized (mWindowManager.getWindowManagerLock()) {
            result = resumeTopActivityInnerLocked(prev, options);
            }
        } finally {
            mStackSupervisor.inResumeTopActivity = false;
        }
@@ -2564,6 +2557,12 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                    || (lastStack.mLastPausedActivity != null
                    && !lastStack.mLastPausedActivity.fullscreen));

            // The contained logic must be synchronized, since we are both changing the visibility
            // and updating the {@link Configuration}. {@link ActivityRecord#setVisibility} will
            // ultimately cause the client code to schedule a layout. Since layouts retrieve the
            // current {@link Configuration}, we must ensure that the below code updates it before
            // the layout can occur.
            synchronized(mWindowManager.getWindowManagerLock()) {
                // This activity is now becoming visible.
                if (!next.visible || next.stopped || lastActivityTranslucent) {
                    next.setVisibility(true);
@@ -2578,7 +2577,8 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

                mService.updateCpuStats();

            if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next + " (in existing)");
                if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next
                        + " (in existing)");

                setResumedActivityLocked(next, "resumeTopActivityInnerLocked");

@@ -2589,20 +2589,22 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                // Have the window manager re-evaluate the orientation of
                // the screen based on the new activity order.
                boolean notUpdated = true;

                if (mStackSupervisor.isFocusedStack(this)) {

                // We have special rotation behavior when Keyguard is locked. Make sure all activity
                // visibilities are set correctly as well as the transition is updated if needed to
                // get the correct rotation behavior.
                // TODO: Remove this once visibilities are set correctly immediately when starting
                // an activity.
                    // We have special rotation behavior when Keyguard is locked. Make sure all
                    // activity visibilities are set correctly as well as the transition is updated
                    // if needed to get the correct rotation behavior.
                    // TODO: Remove this once visibilities are set correctly immediately when
                    // starting an activity.
                    if (mStackSupervisor.mKeyguardController.isKeyguardLocked()) {
                        mStackSupervisor.ensureActivitiesVisibleLocked(null /* starting */,
                                0 /* configChanges */, false /* preserveWindows */);
                    }
                    final Configuration config = mWindowManager.updateOrientationFromAppTokens(
                            mStackSupervisor.getDisplayOverrideConfiguration(mDisplayId),
                        next.mayFreezeScreenLocked(next.app) ? next.appToken : null, mDisplayId);
                            next.mayFreezeScreenLocked(next.app) ? next.appToken : null,
                                    mDisplayId);
                    if (config != null) {
                        next.frozenBeforeDestroy = true;
                    }
@@ -2666,7 +2668,8 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                    next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState,
                            mService.isNextTransitionForward(), resumeAnimOptions);

                if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next);
                    if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed "
                            + next);
                } catch (Exception e) {
                    // Whoops, need to restart this activity!
                    if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to "
@@ -2687,6 +2690,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                    if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
                    return true;
                }
            }

            // From this point on, if something goes wrong there is no way
            // to recover the activity.