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

Commit 9efa7038 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11237490 from 662fe59a to 24Q2-release

Change-Id: I6ecfaf4e9a42d40043e1be819e7caf69a0ccd175
parents 765ba677 662fe59a
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.customization.picker.notifications.domain.interactor

import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor
import com.android.systemui.shared.notifications.shared.model.NotificationSettingsModel
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotStore
@@ -33,7 +32,7 @@ class NotificationsSnapshotRestorer(

    private var snapshotStore: SnapshotStore = SnapshotStore.NOOP

    private fun storeSnapshot(model: NotificationSettingsModel) {
    private fun storeSnapshot(model: NotificationSnapshotModel) {
        snapshotStore.store(snapshot(model))
    }

@@ -41,21 +40,25 @@ class NotificationsSnapshotRestorer(
        store: SnapshotStore,
    ): RestorableSnapshot {
        snapshotStore = store
        backgroundScope.launch { interactor.settings.collect { model -> storeSnapshot(model) } }
        return snapshot(interactor.getSettings())
        backgroundScope.launch {
            interactor.isShowNotificationsOnLockScreenEnabled.collect {
                storeSnapshot(
                    NotificationSnapshotModel(isShowNotificationsOnLockScreenEnabled = it)
                )
            }
        }
        return snapshot(
            NotificationSnapshotModel(interactor.isShowNotificationsOnLockScreenEnabled.value)
        )
    }

    override suspend fun restoreToSnapshot(snapshot: RestorableSnapshot) {
        val isShowNotificationsOnLockScreenEnabled =
            snapshot.args[KEY_IS_SHOW_NOTIFICATIONS_ON_LOCK_SCREEN_ENABLED]?.toBoolean() ?: false
        interactor.setSettings(
            NotificationSettingsModel(
                isShowNotificationsOnLockScreenEnabled = isShowNotificationsOnLockScreenEnabled,
            )
        )
        interactor.setShowNotificationsOnLockscreenEnabled(isShowNotificationsOnLockScreenEnabled)
    }

    private fun snapshot(model: NotificationSettingsModel): RestorableSnapshot {
    private fun snapshot(model: NotificationSnapshotModel): RestorableSnapshot {
        return RestorableSnapshot(
            mapOf(
                KEY_IS_SHOW_NOTIFICATIONS_ON_LOCK_SCREEN_ENABLED to
@@ -69,3 +72,9 @@ class NotificationsSnapshotRestorer(
            "is_show_notifications_on_lock_screen_enabled"
    }
}

/** Snapshot of notification settings relevant to the theme picker. */
private data class NotificationSnapshotModel(
    /** Whether notifications are shown on the lock screen. */
    val isShowNotificationsOnLockScreenEnabled: Boolean = false,
)
+3 −5
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import androidx.lifecycle.viewModelScope
import com.android.customization.module.logging.ThemesUserEventLogger
import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

/** Models UI state for a section that lets the user control the notification settings. */
@@ -36,15 +35,14 @@ constructor(
) : ViewModel() {

    /** Whether the switch should be on. */
    val isSwitchOn: Flow<Boolean> =
        interactor.settings.map { model -> model.isShowNotificationsOnLockScreenEnabled }
    val isSwitchOn: Flow<Boolean> = interactor.isShowNotificationsOnLockScreenEnabled

    /** Notifies that the section has been clicked. */
    fun onClicked() {
        viewModelScope.launch {
            interactor.toggleShowNotificationsOnLockScreenEnabled()
            interactor.toggleShowNotificationsOnLockscreenEnabled()
            logger.logLockScreenNotificationApplied(
                interactor.getSettings().isShowNotificationsOnLockScreenEnabled
                interactor.isShowNotificationsOnLockScreenEnabled.value
            )
        }
    }
+0 −92
Original line number Diff line number Diff line
/*
 * 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.
 * 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.customization.picker.repository

import android.provider.Settings
import androidx.test.filters.SmallTest
import com.android.systemui.shared.notifications.data.repository.NotificationSettingsRepository
import com.android.systemui.shared.notifications.shared.model.NotificationSettingsModel
import com.android.systemui.shared.settings.data.repository.FakeSecureSettingsRepository
import com.android.wallpaper.testing.collectLastValue
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@SmallTest
@RunWith(JUnit4::class)
class NotificationSettingsRepositoryTest {

    private lateinit var underTest: NotificationSettingsRepository

    private lateinit var testScope: TestScope
    private lateinit var secureSettingsRepository: FakeSecureSettingsRepository

    @Before
    fun setUp() {
        val testDispatcher = StandardTestDispatcher()
        testScope = TestScope(testDispatcher)
        secureSettingsRepository = FakeSecureSettingsRepository()

        underTest =
            NotificationSettingsRepository(
                scope = testScope.backgroundScope,
                backgroundDispatcher = testDispatcher,
                secureSettingsRepository = secureSettingsRepository,
            )
    }

    @Test
    fun settings() =
        testScope.runTest {
            val settings = collectLastValue(underTest.settings)

            secureSettingsRepository.set(
                name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                value = 1,
            )
            assertThat(settings())
                .isEqualTo(NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = true))

            secureSettingsRepository.set(
                name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                value = 0,
            )
            assertThat(settings())
                .isEqualTo(
                    NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = false)
                )
        }

    @Test
    fun setSettings() =
        testScope.runTest {
            val settings = collectLastValue(underTest.settings)

            val model1 = NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = true)
            underTest.setSettings(model1)
            assertThat(settings()).isEqualTo(model1)

            val model2 = NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = false)
            underTest.setSettings(model2)
            assertThat(settings()).isEqualTo(model2)
        }
}