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

Commit 11986e35 authored by amehfooz's avatar amehfooz
Browse files

[SB][ComposeIcons] Add OrderedIconSlotNamesRepository

Add a repository which will read config_statusBarIcons
and provide this as a StateFlow.

Bug: 418830269
Test: OrderedIconSlotNamesRepositoryTest
Flag: com.android.systemui.status_bar_system_status_icons_in_compose
Change-Id: I942da82618639d99f3cf6a3b984241c0718e19e6
parent 7560bbd4
Loading
Loading
Loading
Loading
+52 −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.statusbar.systemstatusicons.data.repository

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class OrderedIconSlotNamesRepositoryTest : SysuiTestCase() {

    private val kosmos = testKosmos().useUnconfinedTestDispatcher()

    @Test
    fun repository_orderPreserved() =
        kosmos.runTest {
            val iconSlotNames = arrayOf("A", "B", "C")
            kosmos.statusBarConfigIconSlotNames = iconSlotNames

            assertThat(orderedIconSlotNamesRepository.orderedIconSlotNames.value)
                .isEqualTo(iconSlotNames.toList())
        }

    @Test
    fun repository_usesEmptyList() =
        kosmos.runTest {
            kosmos.statusBarConfigIconSlotNames = emptyArray<String>()

            assertThat(orderedIconSlotNamesRepository.orderedIconSlotNames.value).isEmpty()
        }
}
+2 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ import com.android.systemui.statusbar.policy.SensitiveNotificationProtectionCont
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.statusbar.policy.dagger.SmartRepliesInflationModule;
import com.android.systemui.statusbar.policy.dagger.StatusBarPolicyModule;
import com.android.systemui.statusbar.systemstatusicons.SystemStatusIconsModule;
import com.android.systemui.statusbar.ui.binder.StatusBarViewBinderModule;
import com.android.systemui.statusbar.window.StatusBarWindowModule;
import com.android.systemui.telephony.data.repository.TelephonyRepositoryModule;
@@ -279,6 +280,7 @@ import javax.inject.Named;
        StatusBarViewBinderModule.class,
        StatusBarWindowModule.class,
        SystemPropertiesFlagsModule.class,
        SystemStatusIconsModule.class,
        SysUIConcurrencyModule.class,
        SysUICoroutinesModule.class,
        CommonSystemUIUnfoldModule.class,
+41 −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.statusbar.systemstatusicons

import android.content.Context
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import dagger.Module
import dagger.Provides
import javax.inject.Qualifier

@Qualifier @Retention(AnnotationRetention.BINARY) annotation class SystemStatusOrderedIconSlotNames

@Module
object SystemStatusIconsModule {

    /**
     * Provides the ordered list of status bar icon slot names read from the `config_statusBarIcons`
     * resource array.
     */
    @Provides
    @SysUISingleton
    @SystemStatusOrderedIconSlotNames
    fun provideSystemStatusOrderedIconSlotNames(@Application context: Context): Array<String> {
        return context.resources.getStringArray(com.android.internal.R.array.config_statusBarIcons)
    }
}
+38 −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.statusbar.systemstatusicons.data.repository

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.systemstatusicons.SystemStatusOrderedIconSlotNames
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

/**
 * Repository responsible for providing the ordered list of status bar icon slot names. It processes
 * the raw configuration array provided by [SystemStatusIconsModule].
 */
@SysUISingleton
class OrderedIconSlotNamesRepository
@Inject
constructor(@SystemStatusOrderedIconSlotNames configIconSlotNames: Array<String>) {
    private val _orderedIconSlotNames = MutableStateFlow(configIconSlotNames.toList())

    /** StateFlow emitting the ordered list of status bar icon slot names. */
    val orderedIconSlotNames: StateFlow<List<String>> = _orderedIconSlotNames.asStateFlow()
}
+30 −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.statusbar.systemstatusicons.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.systemstatusicons.data.repository.OrderedIconSlotNamesRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.StateFlow

/** Interactor for retrieving the ordered list of icon slot names. */
@SysUISingleton
class OrderedIconSlotNamesInteractor
@Inject
constructor(repository: OrderedIconSlotNamesRepository) {
    val orderedIconSlotNames: StateFlow<List<String>> = repository.orderedIconSlotNames
}
Loading