1 /* <lambda>null2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.qs.panels.domain.interactor 18 19 import android.os.UserHandle 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.qs.pipeline.shared.TileSpec 22 import com.android.systemui.qs.tiles.base.interactor.QSTileAvailabilityInteractor 23 import com.android.systemui.user.data.repository.UserRepository 24 import com.android.systemui.utils.coroutines.flow.flatMapLatestConflated 25 import kotlinx.coroutines.flow.Flow 26 import kotlinx.coroutines.flow.combine 27 import kotlinx.coroutines.flow.flowOf 28 import kotlinx.coroutines.flow.map 29 import javax.inject.Inject 30 31 /** 32 * Uses the [QSTileAvailabilityInteractor] from the new tiles to provide a map of availability, for 33 * the current user. 34 * 35 * This map contains every platform tile that can be constructed in the new tile infrastructure. 36 */ 37 @SysUISingleton 38 class NewTilesAvailabilityInteractor 39 @Inject 40 constructor( 41 private val availabilityInteractors: 42 Map<String, @JvmSuppressWildcards QSTileAvailabilityInteractor>, 43 userRepository: UserRepository, 44 ) { 45 val newTilesAvailable: Flow<Map<TileSpec, Boolean>> = 46 userRepository.selectedUserInfo.map { it.id } 47 .flatMapLatestConflated { userId -> 48 if (availabilityInteractors.isEmpty()) { 49 flowOf(emptyMap()) 50 } else { 51 combine(availabilityInteractors.map { (spec, interactor) -> 52 interactor.availability(UserHandle.of(userId)).map { 53 TileSpec.create(spec) to it 54 } 55 }) { 56 it.toMap() 57 } 58 } 59 } 60 } 61