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

Commit 80e8df44 authored by Darrell Shi's avatar Darrell Shi
Browse files

(Reland) Show lock icon over hub

This is a temporary solution while the lock icon and indication area
aren't being persisted to the hub.

Original change: I4f5ea190589e52159d302c3a54bf1bdcaaf4ce86

Bug: 326060686
Test: verified the lock icon shows up, and properly updates depending on
lock state
Flag: ACONFIG com.android.systemui.communal_hub TEAMFOOD

Change-Id: Ie7e21329c255c4a9cc065b5dd74ca56cb64aee93
parent 5e3340b2
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
@@ -118,6 +119,7 @@ import com.android.systemui.communal.ui.compose.extensions.firstItemAtOffset
import com.android.systemui.communal.ui.compose.extensions.observeTapsWithoutConsuming
import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel
import com.android.systemui.communal.ui.viewmodel.CommunalEditModeViewModel
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.communal.widgets.WidgetConfigurator
import com.android.systemui.res.R
import kotlinx.coroutines.launch
@@ -218,6 +220,17 @@ fun CommunalHub(
            widgetConfigurator = widgetConfigurator,
        )

        // TODO(b/326060686): Remove this once keyguard indication area can persist over hub
        if (viewModel is CommunalViewModel) {
            val isUnlocked by viewModel.deviceUnlocked.collectAsState(initial = false)
            LockStateIcon(
                modifier =
                    Modifier.align(Alignment.BottomCenter)
                        .padding(bottom = Dimensions.LockIconBottomPadding),
                isUnlocked = isUnlocked,
            )
        }

        if (viewModel.isEditMode && onOpenWidgetPicker != null && onEditDone != null) {
            Toolbar(
                isDraggingToRemove = isDraggingToRemove,
@@ -364,6 +377,26 @@ private fun BoxScope.CommunalHubLazyGrid(
    }
}

@Composable
private fun LockStateIcon(
    isUnlocked: Boolean,
    modifier: Modifier = Modifier,
) {
    val colors = LocalAndroidColorScheme.current
    val resource =
        if (isUnlocked) {
            R.drawable.ic_unlocked
        } else {
            R.drawable.ic_lock
        }
    Icon(
        painter = painterResource(id = resource),
        contentDescription = null,
        tint = colors.onPrimaryContainer,
        modifier = modifier.size(Dimensions.LockIconSize),
    )
}

/**
 * Toolbar that contains action buttons to
 * 1) open the widget picker
@@ -923,6 +956,9 @@ object Dimensions {
            horizontal = ToolbarButtonPaddingHorizontal,
        )
    val IconSize = 48.dp

    val LockIconSize = 52.dp
    val LockIconBottomPadding = 70.dp
}

private object Colors {
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.communal.shared.model.CommunalWidgetContentModel
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel.Companion.POPUP_AUTO_HIDE_TIMEOUT_MS
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor
import com.android.systemui.flags.Flags.COMMUNAL_SERVICE_ENABLED
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
@@ -113,6 +114,7 @@ class CommunalViewModelTest : SysuiTestCase() {
                kosmos.communalInteractor,
                kosmos.communalTutorialInteractor,
                kosmos.shadeInteractor,
                kosmos.deviceEntryInteractor,
                mediaHost,
                logcatLogBuffer("CommunalViewModelTest"),
            )
+5 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import com.android.systemui.communal.domain.interactor.CommunalTutorialInteracto
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.Logger
import com.android.systemui.log.dagger.CommunalLog
@@ -46,6 +47,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch

/** The default view model used for showing the communal hub. */
@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
class CommunalViewModel
@Inject
@@ -54,6 +56,7 @@ constructor(
    private val communalInteractor: CommunalInteractor,
    tutorialInteractor: CommunalTutorialInteractor,
    shadeInteractor: ShadeInteractor,
    deviceEntryInteractor: DeviceEntryInteractor,
    @Named(MediaModule.COMMUNAL_HUB) mediaHost: MediaHost,
    @CommunalLog logBuffer: LogBuffer,
) : BaseCommunalViewModel(communalInteractor, mediaHost) {
@@ -87,6 +90,8 @@ constructor(
    /** Whether touches should be disabled in communal */
    val touchesAllowed: Flow<Boolean> = not(shadeInteractor.isAnyFullyExpanded)

    val deviceUnlocked: Flow<Boolean> = deviceEntryInteractor.isUnlocked

    init {
        // Initialize our media host for the UMO. This only needs to happen once and must be done
        // before the MediaHierarchyManager attempts to move the UMO to the hub.