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.statusbar.pipeline.mobile.domain.model
18 
19 import com.android.settingslib.SignalIcon.MobileIconGroup
20 import com.android.systemui.log.table.Diffable
21 import com.android.systemui.log.table.TableRowLogger
22 
23 /**
24  * A data wrapper class for [MobileIconGroup]. One lingering nuance of this pipeline is its
25  * dependency on MobileMappings for its lookup from NetworkType -> NetworkTypeIcon. And because
26  * MobileMappings is a static map of (netType, icon) that knows nothing of `carrierId`, we need the
27  * concept of a "default" or "overridden" icon type.
28  *
29  * Until we can remove that dependency on MobileMappings, we should just allow for the composition
30  * of overriding an icon id using the lookup defined in [MobileIconCarrierIdOverrides]. By using the
31  * [overrideIcon] method defined below, we can create any arbitrarily overridden network type icon.
32  */
33 sealed interface NetworkTypeIconModel : Diffable<NetworkTypeIconModel> {
34     val contentDescription: Int
35     val iconId: Int
36     val name: String
37 
38     data class DefaultIcon(
39         val iconGroup: MobileIconGroup,
40     ) : NetworkTypeIconModel {
41         override val contentDescription = iconGroup.dataContentDescription
42         override val iconId = iconGroup.dataType
43         override val name = iconGroup.name
44 
logDiffsnull45         override fun logDiffs(prevVal: NetworkTypeIconModel, row: TableRowLogger) {
46             if (prevVal !is DefaultIcon || prevVal.name != name) {
47                 row.logChange(COL_NETWORK_ICON, name)
48             }
49         }
50     }
51 
52     data class OverriddenIcon(
53         val iconGroup: MobileIconGroup,
54         override val iconId: Int,
55     ) : NetworkTypeIconModel {
56         override val contentDescription = iconGroup.dataContentDescription
57         override val name = iconGroup.name
58 
logDiffsnull59         override fun logDiffs(prevVal: NetworkTypeIconModel, row: TableRowLogger) {
60             if (prevVal !is OverriddenIcon || prevVal.name != name || prevVal.iconId != iconId) {
61                 row.logChange(COL_NETWORK_ICON, "Ovrd($name)")
62             }
63         }
64     }
65 
66     companion object {
67         const val COL_NETWORK_ICON = "networkTypeIcon"
68     }
69 }
70