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

Commit b8eac375 authored by Behnam Heydarshahi's avatar Behnam Heydarshahi
Browse files

Add Flashlight Slider UiEvent

Flag: com.android.systemui.flashlight_strength
Bug: 419264460
Test: atest FlashlightSliderViewModelTest
Change-Id: Ia3a15efb4f14a73b418c7d167bdf1255add060f7
parent e48b88bc
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -20,10 +20,12 @@ import android.hardware.camera2.CameraManager.TorchCallback
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.logging.uiEventLoggerFake
import com.android.systemui.SysuiTestCase
import com.android.systemui.camera.cameraManager
import com.android.systemui.flashlight.data.repository.startFlashlightRepository
import com.android.systemui.flashlight.domain.interactor.flashlightInteractor
import com.android.systemui.flashlight.shared.logger.FlashlightUiEvent
import com.android.systemui.flashlight.shared.model.FlashlightModel
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
@@ -62,7 +64,7 @@ class FlashlightSliderViewModelTest : SysuiTestCase() {
        }

    @Test
    fun setLevel_updatesState() =
    fun setLevel_updatesStateAndLogsUiEvents() =
        kosmos.runTest {
            runCurrent()
            assertThat(underTest.currentFlashlightLevel!!.level).isEqualTo(DEFAULT_LEVEL)
@@ -73,10 +75,20 @@ class FlashlightSliderViewModelTest : SysuiTestCase() {
            assertThat(underTest.currentFlashlightLevel).isNotNull()
            assertThat(underTest.currentFlashlightLevel!!.level).isEqualTo(1)

            assertThat(uiEventLoggerFake.logs.size).isEqualTo(1)
            assertThat(uiEventLoggerFake.eventId(0))
                .isEqualTo(FlashlightUiEvent.FLASHLIGHT_SLIDER_SET_LEVEL.id)
            assertThat(uiEventLoggerFake.logs[0].position).isEqualTo(1) // value 1 logged

            underTest.setFlashlightLevel(2)
            runCurrent()

            assertThat(underTest.currentFlashlightLevel!!.level).isEqualTo(2)

            assertThat(uiEventLoggerFake.logs.size).isEqualTo(2)
            assertThat(uiEventLoggerFake.eventId(1))
                .isEqualTo(FlashlightUiEvent.FLASHLIGHT_SLIDER_SET_LEVEL.id)
            assertThat(uiEventLoggerFake.logs[1].position).isEqualTo(2)
        }

    @Test
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.flashlight.shared.logger

import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger.UiEventEnum

enum class FlashlightUiEvent(val eventId: Int) : UiEventEnum {
    @UiEvent(doc = "User sets flashlight level slider at a new position.")
    FLASHLIGHT_SLIDER_SET_LEVEL(2285);

    override fun getId(): Int = eventId
}
+5 −0
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.systemui.flashlight.ui.viewmodel

import androidx.compose.runtime.getValue
import com.android.internal.logging.UiEventLogger
import com.android.systemui.flashlight.domain.interactor.FlashlightInteractor
import com.android.systemui.flashlight.shared.logger.FlashlightLogger
import com.android.systemui.flashlight.shared.logger.FlashlightUiEvent
import com.android.systemui.flashlight.shared.model.FlashlightModel
import com.android.systemui.haptics.slider.compose.ui.SliderHapticsViewModel
import com.android.systemui.lifecycle.ExclusiveActivatable
@@ -35,6 +37,7 @@ constructor(
    val hapticsViewModelFactory: SliderHapticsViewModel.Factory,
    private val flashlightInteractor: FlashlightInteractor,
    private val logger: FlashlightLogger,
    private val uiEventLogger: UiEventLogger,
) : ExclusiveActivatable() {
    private val hydrator = Hydrator("FlashlightSliderViewModel.hydrator")

@@ -66,6 +69,8 @@ constructor(
            return
        }

        uiEventLogger.logWithPosition(FlashlightUiEvent.FLASHLIGHT_SLIDER_SET_LEVEL, 0, null, value)

        if (value == 0) {
            flashlightInteractor.setEnabled(false)
        } else {
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.flashlight.ui.viewmodel

import com.android.internal.logging.uiEventLogger
import com.android.systemui.flashlight.domain.interactor.flashlightInteractor
import com.android.systemui.flashlight.shared.logger.flashlightLogger
import com.android.systemui.haptics.slider.sliderHapticsViewModelFactory
@@ -34,5 +35,6 @@ private val Kosmos.flashlightSliderViewModel: FlashlightSliderViewModel by
            sliderHapticsViewModelFactory,
            flashlightInteractor,
            flashlightLogger,
            uiEventLogger,
        )
    }