• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.domain.interactor.QSTileAvailabilityInteractor
23 import com.android.systemui.user.data.repository.UserRepository
24 import com.android.systemui.utils.coroutines.flow.flatMapLatestConflated
25 import javax.inject.Inject
26 import kotlinx.coroutines.flow.Flow
27 import kotlinx.coroutines.flow.combine
28 import kotlinx.coroutines.flow.flowOf
29 import kotlinx.coroutines.flow.map
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
47             .map { it.id }
48             .flatMapLatestConflated { userId ->
49                 if (availabilityInteractors.isEmpty()) {
50                     flowOf(emptyMap())
51                 } else {
52                     combine(
53                         availabilityInteractors.map { (spec, interactor) ->
54                             interactor.availability(UserHandle.of(userId)).map {
55                                 TileSpec.create(spec) to it
56                             }
57                         }
58                     ) {
59                         it.toMap()
60                     }
61                 }
62             }
63 }
64