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

Commit 0a07764d authored by Lucas Silva's avatar Lucas Silva
Browse files

Add keyguard indication area to glanceable hub

In order to make this work, we need to reset the indication area back to
the lockscreen when the hub is closed - as the view controller is a
singleton and maintains a reference to the active indication area view.
Instead of doing this directly, we simply update the binder to always
revert to the previous state when the view is disposed, which happens
when the view exits composition.

Bug: 340519071
Test: verified on device by opening and closing the hub and verifying
lockscreen indication area is still updated afterwards
Flag: com.android.systemui.communal_hub

Change-Id: Idd98cb5f81a1c985bbec3a9c304ce912fd67122e
parent e8c2428c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.communal.smartspace.SmartspaceInteractionHandler
import com.android.systemui.communal.ui.compose.section.AmbientStatusBarSection
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.keyguard.ui.composable.blueprint.BlueprintAlignmentLines
import com.android.systemui.keyguard.ui.composable.section.BottomAreaSection
import com.android.systemui.keyguard.ui.composable.section.LockSection
import com.android.systemui.statusbar.phone.SystemUIDialogFactory
import javax.inject.Inject
@@ -41,8 +42,10 @@ constructor(
    private val interactionHandler: SmartspaceInteractionHandler,
    private val dialogFactory: SystemUIDialogFactory,
    private val lockSection: LockSection,
    private val bottomAreaSection: BottomAreaSection,
    private val ambientStatusBarSection: AmbientStatusBarSection,
) {

    @Composable
    fun SceneScope.Content(modifier: Modifier = Modifier) {
        Layout(
@@ -65,10 +68,16 @@ constructor(
                        modifier = Modifier.element(Communal.Elements.LockIcon)
                    )
                }
                with(bottomAreaSection) {
                    IndicationArea(
                        Modifier.element(Communal.Elements.IndicationArea).fillMaxWidth()
                    )
                }
            }
        ) { measurables, constraints ->
            val communalGridMeasurable = measurables[0]
            val lockIconMeasurable = measurables[1]
            val bottomAreaMeasurable = measurables[2]

            val noMinConstraints =
                constraints.copy(
@@ -85,6 +94,13 @@ constructor(
                    bottom = lockIconPlaceable[BlueprintAlignmentLines.LockIcon.Bottom],
                )

            val bottomAreaPlaceable =
                bottomAreaMeasurable.measure(
                    noMinConstraints.copy(
                        maxHeight = (constraints.maxHeight - lockIconBounds.bottom).coerceAtLeast(0)
                    )
                )

            val communalGridPlaceable =
                communalGridMeasurable.measure(
                    noMinConstraints.copy(maxHeight = lockIconBounds.top)
@@ -99,6 +115,10 @@ constructor(
                    x = lockIconBounds.left,
                    y = lockIconBounds.top,
                )
                bottomAreaPlaceable.place(
                    x = 0,
                    y = constraints.maxHeight - bottomAreaPlaceable.height,
                )
            }
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.DpSize
@@ -183,7 +184,7 @@ constructor(
        indicationController: KeyguardIndicationController,
        modifier: Modifier = Modifier,
    ) {
        val (disposable, setDisposable) = mutableStateOf<DisposableHandle?>(null)
        val (disposable, setDisposable) = remember { mutableStateOf<DisposableHandle?>(null) }

        AndroidView(
            factory = { context ->
+12 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardIndicationAreaViewMode
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.res.R
import com.android.systemui.statusbar.KeyguardIndicationController
import com.android.systemui.util.kotlin.DisposableHandles
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
@@ -53,7 +54,15 @@ object KeyguardIndicationAreaBinder {
        viewModel: KeyguardIndicationAreaViewModel,
        indicationController: KeyguardIndicationController,
    ): DisposableHandle {
        indicationController.setIndicationArea(view)
        val disposables = DisposableHandles()

        // As the indication controller is a singleton, reset the view back to the previous view
        // once the current view is disposed.
        val previous = indicationController.indicationArea
        indicationController.indicationArea = view
        disposables += DisposableHandle {
            previous?.let { indicationController.indicationArea = it }
        }

        val indicationText: TextView = view.requireViewById(R.id.keyguard_indication_text)
        val indicationTextBottom: TextView =
@@ -63,7 +72,7 @@ object KeyguardIndicationAreaBinder {
        view.clipToPadding = false

        val configurationBasedDimensions = MutableStateFlow(loadFromResources(view))
        val disposableHandle =
        disposables +=
            view.repeatWhenAttached {
                repeatOnLifecycle(Lifecycle.State.STARTED) {
                    launch("$TAG#viewModel.alpha") {
@@ -126,7 +135,7 @@ object KeyguardIndicationAreaBinder {
                    }
                }
            }
        return disposableHandle
        return disposables
    }

    private fun loadFromResources(view: View): ConfigurationBasedDimensions {
+5 −0
Original line number Diff line number Diff line
@@ -386,6 +386,11 @@ public class KeyguardIndicationController {
        mStatusBarStateListener.onDozingChanged(mStatusBarStateController.isDozing());
    }

    @Nullable
    public ViewGroup getIndicationArea() {
        return mIndicationArea;
    }

    public void setIndicationArea(ViewGroup indicationArea) {
        mIndicationArea = indicationArea;
        mTopIndicationView = indicationArea.findViewById(R.id.keyguard_indication_text);