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