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

Commit 0b472c23 authored by Bharat Singh's avatar Bharat Singh Committed by Android (Google) Code Review
Browse files

Merge "[SysUI][Floaty][TempFix] Remove window if invocation effect not playing" into main

parents 657f8547 0b9e9dbd
Loading
Loading
Loading
Loading
+36 −24
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ constructor(

    private var root: EffectsWindowRoot? = null

    // TODO(b/414267753): Make cleanup of window logic more robust
    private var isInvocationEffectHappening = false

    override fun start() {
        topLevelWindowEffectsScope.launch {
            squeezeEffectInteractor.isSqueezeEffectEnabled.collectLatest { enabled ->
@@ -80,6 +83,8 @@ constructor(
                                roundedCornerInfo.bottomResourceId,
                                roundedCornerInfo.physicalPixelDisplaySizeRatio,
                            )
                        } else if (root != null && !isInvocationEffectHappening) {
                            removeWindow()
                        }
                    }
                }
@@ -92,7 +97,14 @@ constructor(
        @DrawableRes bottomRoundedCornerId: Int,
        physicalPixelDisplaySizeRatio: Float,
    ) {
        if (root == null) {
        if (isInvocationEffectHappening) {
            return
        }

        if (root != null) {
            removeWindow()
        }

        root =
            EffectsWindowRoot(
                    context = context,
@@ -103,25 +115,25 @@ constructor(
                    onEffectFinished = ::removeWindow,
                    appZoomOutOptional = appZoomOutOptional,
                    interactionJankMonitor = interactionJankMonitor,
                    onEffectStarted = { isInvocationEffectHappening = true },
                )
                .apply { visibility = View.GONE }

        root?.let { rootView ->
                if (TopUiControllerRefactor.isEnabled) {
                    topUiController.setRequestTopUi(true, TAG)
                } else {
            runOnMainThread { notificationShadeWindowController.setRequestTopUi(true, TAG) }
                }
            windowManager.addView(rootView, getWindowManagerLayoutParams())
            rootView.post { rootView.visibility = View.VISIBLE }
        }
    }
    }

    private suspend fun removeWindow() {
        if (root?.isAttachedToWindow == true) {
            windowManager.removeView(root)
            root = null
        }

        root = null
        isInvocationEffectHappening = false

        if (TopUiControllerRefactor.isEnabled) {
            topUiController.setRequestTopUi(false, TAG)
        } else {
@@ -155,7 +167,7 @@ constructor(
        lp.layoutInDisplayCutoutMode =
            WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS

        lp.title = "TopLevelWindowEffects"
        lp.title = TAG
        lp.fitInsetsTypes = WindowInsets.Type.systemOverlays()
        lp.gravity = Gravity.TOP

+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import java.util.Optional
@SuppressLint("ViewConstructor")
class EffectsWindowRoot(
    context: Context,
    private val onEffectStarted: suspend () -> Unit,
    private val onEffectFinished: suspend () -> Unit,
    private val viewModelFactory: SqueezeEffectViewModel.Factory,
    @DrawableRes private val topRoundedCornerResourceId: Int,
@@ -53,6 +54,7 @@ class EffectsWindowRoot(
    override fun Content() {
        SqueezeEffect(
            viewModelFactory = viewModelFactory,
            onEffectStarted = onEffectStarted,
            onEffectFinished = onEffectFinished,
            topRoundedCornerResourceId = topRoundedCornerResourceId,
            bottomRoundedCornerResourceId = bottomRoundedCornerResourceId,
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ fun SqueezeEffect(
    @DrawableRes topRoundedCornerResourceId: Int,
    @DrawableRes bottomRoundedCornerResourceId: Int,
    physicalPixelDisplaySizeRatio: Float,
    onEffectStarted: suspend () -> Unit,
    onEffectFinished: suspend () -> Unit,
    appZoomOutOptional: Optional<AppZoomOut>,
    interactionJankMonitor: InteractionJankMonitor,
@@ -94,6 +95,8 @@ fun SqueezeEffect(
    // lifting the power button the animation shouldn't be interruptible either.
    var isAnimationInterruptible by remember { mutableStateOf(true) }

    LaunchedEffect(Unit) { onEffectStarted() }

    LaunchedEffect(longPressed) {
        if (longPressed) {
            isAnimationInterruptible = false