1 /*
2  * Copyright (C) 2022 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.data.model
18 
19 import android.telephony.TelephonyManager.DATA_CONNECTED
20 import android.telephony.TelephonyManager.DATA_CONNECTING
21 import android.telephony.TelephonyManager.DATA_DISCONNECTED
22 import android.telephony.TelephonyManager.DATA_DISCONNECTING
23 import android.telephony.TelephonyManager.DATA_HANDOVER_IN_PROGRESS
24 import android.telephony.TelephonyManager.DATA_SUSPENDED
25 import android.telephony.TelephonyManager.DATA_UNKNOWN
26 import android.telephony.TelephonyManager.DataState
27 import com.android.systemui.log.table.Diffable
28 import com.android.systemui.log.table.TableRowLogger
29 
30 /** Internal enum representation of the telephony data connection states */
31 enum class DataConnectionState : Diffable<DataConnectionState> {
32     Connected,
33     Connecting,
34     Disconnected,
35     Disconnecting,
36     Suspended,
37     HandoverInProgress,
38     Unknown,
39     Invalid;
40 
logDiffsnull41     override fun logDiffs(prevVal: DataConnectionState, row: TableRowLogger) {
42         if (prevVal != this) {
43             row.logChange(COL_CONNECTION_STATE, name)
44         }
45     }
46 
47     companion object {
48         private const val COL_CONNECTION_STATE = "connectionState"
49     }
50 }
51 
toDataConnectionTypenull52 fun @receiver:DataState Int.toDataConnectionType(): DataConnectionState =
53     when (this) {
54         DATA_CONNECTED -> DataConnectionState.Connected
55         DATA_CONNECTING -> DataConnectionState.Connecting
56         DATA_DISCONNECTED -> DataConnectionState.Disconnected
57         DATA_DISCONNECTING -> DataConnectionState.Disconnecting
58         DATA_SUSPENDED -> DataConnectionState.Suspended
59         DATA_HANDOVER_IN_PROGRESS -> DataConnectionState.HandoverInProgress
60         DATA_UNKNOWN -> DataConnectionState.Unknown
61         else -> DataConnectionState.Invalid
62     }
63