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