• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.tiles.base.domain.interactor
18 
19 import android.os.UserHandle
20 import com.android.systemui.qs.tiles.base.domain.model.DataUpdateTrigger
21 import kotlinx.coroutines.CoroutineDispatcher
22 import kotlinx.coroutines.flow.Flow
23 import kotlinx.coroutines.flow.flowOf
24 
25 /**
26  * Provides data and availability for the tile. In most cases it would delegate data retrieval to
27  * repository, manager, controller or a combination of those. Avoid doing long running operations in
28  * these methods because there is no background thread guarantee. Use [Flow.flowOn] (typically
29  * with @Background [CoroutineDispatcher]) instead to move the calculations to another thread.
30  */
31 interface QSTileDataInteractor<DATA_TYPE> : QSTileAvailabilityInteractor {
32 
33     /**
34      * Returns a data flow scoped to the user. This means the subscription will live when the tile
35      * is listened for the [user]. It's cancelled when the tile is not listened or the user changes.
36      *
37      * You can use [Flow.onStart] on the returned to update the tile with the current state as soon
38      * as possible.
39      */
tileDatanull40     fun tileData(user: UserHandle, triggers: Flow<DataUpdateTrigger>): Flow<DATA_TYPE>
41 }
42 
43 interface QSTileAvailabilityInteractor {
44     /**
45      * Returns tile availability - whether this device currently supports this tile.
46      *
47      * You can use [Flow.onStart] on the returned to update the tile with the current state as soon
48      * as possible.
49      */
50     fun availability(user: UserHandle): Flow<Boolean>
51 
52     companion object {
53         val AlwaysAvailableInteractor =
54             object : QSTileAvailabilityInteractor {
55                 override fun availability(user: UserHandle): Flow<Boolean> {
56                     return flowOf(true)
57                 }
58             }
59     }
60 }
61