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

Commit c64742c0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "desktop-effects-tile" into main

* changes:
  Add tile states for DesktopEffectsTile
  Add SecureSettingsForUserRepository
parents e32edfa8 05fd89e0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -358,4 +358,14 @@
        <item>Off</item>
        <item>On</item>
    </string-array>

    <!-- State names for desktop effects tile: unavailable, off, on.
     This subtitle is shown when the tile is in that particular state but does not set its own
     subtitle, so some of these may never appear on screen. They should still be translated as
     if they could appear. [CHAR LIMIT=32] -->
    <string-array name="tile_states_desktopeffects">
        <item>Unavailable</item>
        <item>Off</item>
        <item>On</item>
    </string-array>
</resources>
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ object SubtitleArrayMapping {
        subtitleIdsMap["font_scaling"] = R.array.tile_states_font_scaling
        subtitleIdsMap["hearing_devices"] = R.array.tile_states_hearing_devices
        subtitleIdsMap["notes"] = R.array.tile_states_notes
        subtitleIdsMap["desktopeffects"] = R.array.tile_states_desktopeffects
    }

    /** Get the subtitle resource id of the given tile */
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.util.settings.repository

import android.provider.Settings
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.util.settings.SecureSettings
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineDispatcher

/** Repository observing values of a [Settings.Secure] for the specified user. */
@SysUISingleton
class SecureSettingsForUserRepository
@Inject
constructor(
    secureSettings: SecureSettings,
    @Background backgroundDispatcher: CoroutineDispatcher,
    @Background backgroundContext: CoroutineContext,
) : SettingsForUserRepository(secureSettings, backgroundDispatcher, backgroundContext)
+66 −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.util.settings.repository

import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import com.android.systemui.util.settings.UserSettingsProxy
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext

/**
 * Repository observing values of a [UserSettingsProxy] for the specified user. This repository
 * should be used for any system that tracks the desired user internally (e.g. the Quick Settings
 * tiles system). In other cases, use a [UserAwareSettingsRepository] instead.
 */
abstract class SettingsForUserRepository(
    private val userSettings: UserSettingsProxy,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    @Background private val backgroundContext: CoroutineContext,
) {
    fun boolSettingForUser(
        userId: Int,
        name: String,
        defaultValue: Boolean = false,
    ): Flow<Boolean> =
        settingObserver(name, userId) { userSettings.getBoolForUser(name, defaultValue, userId) }
            .distinctUntilChanged()
            .flowOn(backgroundDispatcher)

    fun <T> settingObserver(name: String, userId: Int, settingsReader: () -> T): Flow<T> {
        return userSettings
            .observerFlow(userId, name)
            .onStart { emit(Unit) }
            .map { settingsReader.invoke() }
    }

    suspend fun setBoolForUser(userId: Int, name: String, value: Boolean) {
        withContext(backgroundContext) { userSettings.putBoolForUser(name, value, userId) }
    }

    suspend fun getBoolForUser(userId: Int, name: String, defaultValue: Boolean = false): Boolean {
        return withContext(backgroundContext) {
            userSettings.getBoolForUser(name, defaultValue, userId)
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ import kotlinx.coroutines.withContext
/**
 * Repository for observing values of a [UserSettingsProxy], for the currently active user. That
 * means that when the user is switched and the new user has a different value, the flow will emit
 * the new value.
 * the new value. For any system that tracks the desired user internally (e.g. the Quick Settings
 * tiles system), use a [SettingsForUserRepository] instead.
 */
// TODO: b/377244768 - Make internal when UserAwareSecureSettingsRepository can be made internal.
abstract class UserAwareSettingsRepository(
Loading