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

Commit 59326673 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Group window relayout requests

Various places in sysui might call into
NotificationShadeWindowController. Some of these calls can lead to
relayoutWindow(), which is quite expensive.

We should group these calls, and execute them in batch.

Test: manual
Test: perfetto trace
Test: atest NotificationPanelViewControllerTest
Test: atest NotificationShadeWindowControllerImplTest
Fixes: 190382751
Bug: 210432290
Change-Id: Ib08f7ba66048eb023ee2d5e9c09461381c390f0d
parent c5900ec5
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.phone.BiometricUnlockController;
import com.android.systemui.statusbar.phone.DozeParameters;
@@ -318,6 +319,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
    // the properties of the keyguard

    private final KeyguardUpdateMonitor mUpdateMonitor;
    private final Lazy<NotificationShadeWindowController> mNotificationShadeWindowControllerLazy;

    /**
     * Last SIM state reported by the telephony system.
@@ -833,7 +835,8 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
            ScreenOffAnimationController screenOffAnimationController,
            Lazy<NotificationShadeDepthController> notificationShadeDepthController,
            ScreenOnCoordinator screenOnCoordinator,
            InteractionJankMonitor interactionJankMonitor) {
            InteractionJankMonitor interactionJankMonitor,
            Lazy<NotificationShadeWindowController> notificationShadeWindowControllerLazy) {
        super(context);
        mFalsingCollector = falsingCollector;
        mLockPatternUtils = lockPatternUtils;
@@ -850,6 +853,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
        dumpManager.registerDumpable(getClass().getName(), this);
        mDeviceConfig = deviceConfig;
        mScreenOnCoordinator = screenOnCoordinator;
        mNotificationShadeWindowControllerLazy = notificationShadeWindowControllerLazy;
        mShowHomeOverLockscreen = mDeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                NAV_BAR_HANDLE_SHOW_OVER_LOCKSCREEN,
@@ -1837,10 +1841,14 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
                    Trace.beginSection(
                            "KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
                    StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
                    handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration,
                    mNotificationShadeWindowControllerLazy.get().batchApplyWindowLayoutParams(
                            () -> {
                                handleStartKeyguardExitAnimation(params.startTime,
                                        params.fadeoutDuration,
                                        params.mApps, params.mWallpapers, params.mNonApps,
                                        params.mFinishedCallback);
                                mFalsingCollector.onSuccessfulUnlock();
                            });
                    Trace.endSection();
                    break;
                case CANCEL_KEYGUARD_EXIT_ANIM:
@@ -2139,10 +2147,12 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
                mKeyguardGoingAwayRunnable.run();
            } else {
                // TODO(bc-unlock): Fill parameters
                mNotificationShadeWindowControllerLazy.get().batchApplyWindowLayoutParams(() -> {
                    handleStartKeyguardExitAnimation(
                            SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
                            mHideAnimation.getDuration(), null /* apps */, null /* wallpapers */,
                            null /* nonApps */, null /* finishedCallback */);
                });
            }
        }
        Trace.endSection();
+5 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.KeyguardLiftController;
@@ -98,7 +99,8 @@ public class KeyguardModule {
            ScreenOffAnimationController screenOffAnimationController,
            Lazy<NotificationShadeDepthController> notificationShadeDepthController,
            ScreenOnCoordinator screenOnCoordinator,
            InteractionJankMonitor interactionJankMonitor) {
            InteractionJankMonitor interactionJankMonitor,
            Lazy<NotificationShadeWindowController> notificationShadeWindowController) {
        return new KeyguardViewMediator(
                context,
                falsingCollector,
@@ -122,7 +124,8 @@ public class KeyguardModule {
                screenOffAnimationController,
                notificationShadeDepthController,
                screenOnCoordinator,
                interactionJankMonitor
                interactionJankMonitor,
                notificationShadeWindowController
        );
    }

+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar;
import android.graphics.Region;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.systemui.statusbar.phone.StatusBarWindowCallback;
@@ -191,6 +192,14 @@ public interface NotificationShadeWindowController extends RemoteInputController
     */
    default void setLightRevealScrimOpaque(boolean opaque) {}

    /**
     * Defer any application of window {@link WindowManager.LayoutParams} until {@code scope} is
     * fully applied.
     */
    default void batchApplyWindowLayoutParams(@NonNull Runnable scope) {
        scope.run();
    }

    /**
     * Custom listener to pipe data back to plugins about whether or not the status bar would be
     * collapsed if not for the plugin.
+3 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@ import com.android.systemui.statusbar.LockscreenShadeTransitionController;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.NotificationShelfController;
import com.android.systemui.statusbar.PulseExpansionHandler;
import com.android.systemui.statusbar.QsFrameTranslateController;
@@ -741,6 +742,7 @@ public class NotificationPanelViewController extends PanelViewController {
            KeyguardStateController keyguardStateController,
            StatusBarStateController statusBarStateController,
            StatusBarWindowStateController statusBarWindowStateController,
            NotificationShadeWindowController notificationShadeWindowController,
            DozeLog dozeLog,
            DozeParameters dozeParameters, CommandQueue commandQueue, VibratorHelper vibratorHelper,
            LatencyTracker latencyTracker, PowerManager powerManager,
@@ -800,6 +802,7 @@ public class NotificationPanelViewController extends PanelViewController {
                dozeLog,
                keyguardStateController,
                (SysuiStatusBarStateController) statusBarStateController,
                notificationShadeWindowController,
                vibratorHelper,
                statusBarKeyguardViewManager,
                latencyTracker,
+23 −3
Original line number Diff line number Diff line
@@ -111,6 +111,12 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
    private final SysuiColorExtractor mColorExtractor;
    private final ScreenOffAnimationController mScreenOffAnimationController;
    private float mFaceAuthDisplayBrightness = LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
    /**
     * Layout params would be aggregated and dispatched all at once if this is > 0.
     *
     * @see #batchApplyWindowLayoutParams(Runnable)
     */
    private int mDeferWindowLayoutParams;

    @Inject
    public NotificationShadeWindowControllerImpl(Context context, WindowManager windowManager,
@@ -437,6 +443,20 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        }
    }

    private void applyWindowLayoutParams() {
        if (mDeferWindowLayoutParams == 0 && mLp != null && mLp.copyFrom(mLpChanged) != 0) {
            mWindowManager.updateViewLayout(mNotificationShadeView, mLp);
        }
    }

    @Override
    public void batchApplyWindowLayoutParams(Runnable scope) {
        mDeferWindowLayoutParams++;
        scope.run();
        mDeferWindowLayoutParams--;
        applyWindowLayoutParams();
    }

    private void apply(State state) {
        applyKeyguardFlags(state);
        applyFocusableFlag(state);
@@ -451,9 +471,8 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        applyHasTopUi(state);
        applyNotTouchable(state);
        applyStatusBarColorSpaceAgnosticFlag(state);
        if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {
            mWindowManager.updateViewLayout(mNotificationShadeView, mLp);
        }
        applyWindowLayoutParams();

        if (mHasTopUi != mHasTopUiChanged) {
            whitelistIpcs(() -> {
                try {
@@ -739,6 +758,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        pw.println(TAG + ":");
        pw.println("  mKeyguardMaxRefreshRate=" + mKeyguardMaxRefreshRate);
        pw.println("  mKeyguardPreferredRefreshRate=" + mKeyguardPreferredRefreshRate);
        pw.println("  mDeferWindowLayoutParams=" + mDeferWindowLayoutParams);
        pw.println(mCurrentState);
        if (mNotificationShadeView != null && mNotificationShadeView.getViewRootImpl() != null) {
            mNotificationShadeView.getViewRootImpl().dump("  ", pw);
Loading