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.viewmodel 18 19 import android.content.res.Resources 20 import androidx.annotation.DrawableRes 21 import androidx.annotation.StringRes 22 import com.android.internal.logging.InstanceId 23 import com.android.systemui.qs.pipeline.shared.TileSpec 24 25 data class QSTileConfig( 26 val tileSpec: TileSpec, 27 val uiConfig: QSTileUIConfig, 28 val instanceId: InstanceId, 29 val metricsSpec: String = tileSpec.spec, 30 val policy: QSTilePolicy = QSTilePolicy.NoRestrictions, 31 ) 32 33 /** 34 * Static tile icon and label to be used when the fully operational tile isn't needed (ex. in edit 35 * mode). Icon and label are resources to better support config/locale changes. 36 */ 37 sealed interface QSTileUIConfig { 38 39 val iconRes: Int 40 @DrawableRes get 41 val labelRes: Int 42 @StringRes get 43 44 /** 45 * Represents the absence of static UI state. This should be avoided by platform tiles in favour 46 * of [Resource]. Returns [Resources.ID_NULL] for each field. 47 */ 48 data object Empty : QSTileUIConfig { 49 override val iconRes: Int 50 get() = Resources.ID_NULL 51 override val labelRes: Int 52 get() = Resources.ID_NULL 53 } 54 55 /** Config containing actual icon and label resources. */ 56 data class Resource( 57 @DrawableRes override val iconRes: Int, 58 @StringRes override val labelRes: Int, 59 ) : QSTileUIConfig 60 } 61 62 /** Represents policy restrictions that may be imposed on the tile. */ 63 sealed interface QSTilePolicy { 64 /** Tile has no policy restrictions */ 65 data object NoRestrictions : QSTilePolicy 66 67 /** 68 * Tile might be disabled by policy. Each item in [userRestrictions] is usually a constant from 69 * [android.os.UserManager] like [android.os.UserManager.DISALLOW_AIRPLANE_MODE]. 70 * [com.android.systemui.qs.tiles.base.interactor.DisabledByPolicyInteractor] is commonly used 71 * to resolve this and show user a message when needed. 72 */ 73 data class Restricted(val userRestrictions: List<String>) : QSTilePolicy 74 } 75