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

Commit 29d4d73f authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Resolve the flicker and visibility issues by AodBurnInLayer

Use refreshBlueprint to apply constraints to clock and smartspace

Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint DEVELOPMENT

Bug: 315994433
Bug: 317966991
Test: manual

Change-Id: I81e6d855ce1ddaa90d11e6bcd946876709cf909c
parent fa4a9b44
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.android.keyguard;
import static com.android.keyguard.KeyguardStatusAreaView.TRANSLATE_X_CLOCK_DESIGN;
import static com.android.keyguard.KeyguardStatusAreaView.TRANSLATE_Y_CLOCK_DESIGN;
import static com.android.keyguard.KeyguardStatusAreaView.TRANSLATE_Y_CLOCK_SIZE;
import static com.android.systemui.Flags.migrateClocksToBlueprint;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -191,11 +192,11 @@ public class KeyguardClockSwitch extends RelativeLayout {
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        if (!migrateClocksToBlueprint()) {
            mSmallClockFrame = findViewById(R.id.lockscreen_clock_view);
            mLargeClockFrame = findViewById(R.id.lockscreen_clock_view_large);
            mStatusArea = findViewById(R.id.keyguard_status_area);

        }
        onConfigChanged();
    }

+1 −1
Original line number Diff line number Diff line
@@ -494,7 +494,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
            boolean shouldBeCentered,
            boolean animate) {
        if (migrateClocksToBlueprint()) {
            mKeyguardInteractor.setClockShouldBeCentered(mSplitShadeEnabled && shouldBeCentered);
            mKeyguardInteractor.setClockShouldBeCentered(shouldBeCentered);
        } else {
            mKeyguardClockSwitchController.setSplitShadeCentered(
                    splitShadeEnabled && shouldBeCentered);
+34 −0
Original line number Diff line number Diff line
@@ -14,36 +14,21 @@
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.view.layout.sections
package com.android.systemui.keyguard.data.repository

import android.content.Context
import androidx.constraintlayout.widget.ConstraintSet
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
import com.android.systemui.res.R
import com.android.systemui.statusbar.policy.SplitShadeStateController
import android.view.View
import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

class SplitShadeClockSection
@Inject
constructor(
    clockInteractor: KeyguardClockInteractor,
    keyguardClockViewModel: KeyguardClockViewModel,
    context: Context,
    splitShadeStateController: SplitShadeStateController,
) : ClockSection(clockInteractor, keyguardClockViewModel, context, splitShadeStateController) {
    override fun applyDefaultConstraints(constraints: ConstraintSet) {
        super.applyDefaultConstraints(constraints)
        val largeClockEndGuideline =
            if (keyguardClockViewModel.clockShouldBeCentered.value) ConstraintSet.PARENT_ID
            else R.id.split_shade_guideline
        constraints.apply {
            connect(
                R.id.lockscreen_clock_view_large,
                ConstraintSet.END,
                largeClockEndGuideline,
                ConstraintSet.END
            )
        }
@SysUISingleton
class KeyguardSmartspaceRepository @Inject constructor() {
    private val _bcSmartspaceVisibility: MutableStateFlow<Int> = MutableStateFlow(View.GONE)
    val bcSmartspaceVisibility: StateFlow<Int> = _bcSmartspaceVisibility.asStateFlow()

    fun setBcSmartspaceVisibility(visibility: Int) {
        _bcSmartspaceVisibility.value = visibility
    }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -14,32 +14,20 @@
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.view.layout.sections
package com.android.systemui.keyguard.domain.interactor

import android.content.Context
import com.android.systemui.keyguard.KeyguardUnlockAnimationController
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.data.repository.KeyguardSmartspaceRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.StateFlow

/*
 * We need this class for the splitShadeBlueprint so `addViews` and `removeViews` will be called
 * when switching to and from splitShade.
 */
class SplitShadeSmartspaceSection
@SysUISingleton
class KeyguardSmartspaceInteractor
@Inject
constructor(
    keyguardClockViewModel: KeyguardClockViewModel,
    keyguardSmartspaceViewModel: KeyguardSmartspaceViewModel,
    context: Context,
    smartspaceController: LockscreenSmartspaceController,
    keyguardUnlockAnimationController: KeyguardUnlockAnimationController,
) :
    SmartspaceSection(
        keyguardClockViewModel,
        keyguardSmartspaceViewModel,
        context,
        smartspaceController,
        keyguardUnlockAnimationController,
    )
constructor(private val keyguardSmartspaceRepository: KeyguardSmartspaceRepository) {
    var bcSmartspaceVisibility: StateFlow<Int> = keyguardSmartspaceRepository.bcSmartspaceVisibility

    fun setBcSmartspaceVisibility(visibility: Int) {
        keyguardSmartspaceRepository.setBcSmartspaceVisibility(visibility)
    }
}
+34 −17
Original line number Diff line number Diff line
@@ -30,7 +30,10 @@ import androidx.constraintlayout.widget.ConstraintSet
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.app.animation.Interpolators
import com.android.keyguard.KeyguardClockSwitch.LARGE
import com.android.keyguard.KeyguardClockSwitch.SMALL
import com.android.systemui.Flags.migrateClocksToBlueprint
import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.ui.view.layout.sections.ClockSection
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
@@ -48,6 +51,7 @@ object KeyguardClockViewBinder {
        keyguardRootView: ConstraintLayout,
        viewModel: KeyguardClockViewModel,
        keyguardClockInteractor: KeyguardClockInteractor,
        blueprintInteractor: KeyguardBlueprintInteractor,
    ) {
        keyguardRootView.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.CREATED) {
@@ -61,18 +65,16 @@ object KeyguardClockViewBinder {
                    viewModel.currentClock.collect { currentClock ->
                        cleanupClockViews(viewModel.clock, keyguardRootView, viewModel.burnInLayer)
                        viewModel.clock = currentClock
                        addClockViews(currentClock, keyguardRootView, viewModel.burnInLayer)
                        viewModel.burnInLayer?.updatePostLayout(keyguardRootView)
                        applyConstraints(clockSection, keyguardRootView, true)
                        addClockViews(currentClock, keyguardRootView)
                        updateBurnInLayer(keyguardRootView, viewModel)
                        blueprintInteractor.refreshBlueprint()
                    }
                }
                // TODO: Weather clock dozing animation
                // will trigger both shouldBeCentered and clockSize change
                // we should avoid this
                launch {
                    if (!migrateClocksToBlueprint()) return@launch
                    viewModel.clockSize.collect {
                        applyConstraints(clockSection, keyguardRootView, true)
                        updateBurnInLayer(keyguardRootView, viewModel)
                        blueprintInteractor.refreshBlueprint()
                    }
                }
                launch {
@@ -82,13 +84,36 @@ object KeyguardClockViewBinder {
                            if (it.largeClock.config.hasCustomPositionUpdatedAnimation) {
                                playClockCenteringAnimation(clockSection, keyguardRootView, it)
                            } else {
                                applyConstraints(clockSection, keyguardRootView, true)
                                blueprintInteractor.refreshBlueprint()
                            }
                        }
                    }
                }
            }
        }
    }
    @VisibleForTesting
    fun updateBurnInLayer(
        keyguardRootView: ConstraintLayout,
        viewModel: KeyguardClockViewModel,
    ) {
        val burnInLayer = viewModel.burnInLayer
        val clockController = viewModel.currentClock.value
        clockController?.let { clock ->
            when (viewModel.clockSize.value) {
                LARGE -> {
                    clock.smallClock.layout.views.forEach { burnInLayer?.removeView(it) }
                    if (clock.config.useAlternateSmartspaceAODTransition) {
                        clock.largeClock.layout.views.forEach { burnInLayer?.addView(it) }
                    }
                }
                SMALL -> {
                    clock.smallClock.layout.views.forEach { burnInLayer?.addView(it) }
                    clock.largeClock.layout.views.forEach { burnInLayer?.removeView(it) }
                }
            }
        }
        viewModel.burnInLayer?.updatePostLayout(keyguardRootView)
    }

    private fun cleanupClockViews(
@@ -116,7 +141,6 @@ object KeyguardClockViewBinder {
    fun addClockViews(
        clockController: ClockController?,
        rootView: ConstraintLayout,
        burnInLayer: Layer?
    ) {
        clockController?.let { clock ->
            clock.smallClock.layout.views[0].id = R.id.lockscreen_clock_view
@@ -125,17 +149,10 @@ object KeyguardClockViewBinder {
            }
            // small clock should either be a single view or container with id
            // `lockscreen_clock_view`
            clock.smallClock.layout.views.forEach {
                rootView.addView(it)
                burnInLayer?.addView(it)
            }
            clock.smallClock.layout.views.forEach { rootView.addView(it) }
            clock.largeClock.layout.views.forEach { rootView.addView(it) }
            if (clock.config.useAlternateSmartspaceAODTransition) {
                clock.largeClock.layout.views.forEach { burnInLayer?.addView(it) }
        }
    }
    }

    fun applyConstraints(
        clockSection: ClockSection,
        rootView: ConstraintLayout,
Loading