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.satellite.shared.model
18 
19 import android.telephony.satellite.SatelliteManager
20 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED
21 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_DATAGRAM_RETRYING
22 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_DATAGRAM_TRANSFERRING
23 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_IDLE
24 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_LISTENING
25 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_NOT_CONNECTED
26 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_OFF
27 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_UNAVAILABLE
28 import android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_UNKNOWN
29 import com.android.systemui.log.table.Diffable
30 import com.android.systemui.log.table.TableRowLogger
31 
32 enum class SatelliteConnectionState : Diffable<SatelliteConnectionState> {
33     // State is unknown or undefined
34     Unknown,
35     // Radio is off
36     Off,
37     // Radio is on, but not yet connected
38     On,
39     // Radio is connected, aka satellite is available for use
40     Connected;
41 
logDiffsnull42     override fun logDiffs(prevVal: SatelliteConnectionState, row: TableRowLogger) {
43         if (prevVal != this) {
44             row.logChange(COL_CONNECTION_STATE, name)
45         }
46     }
47 
48     companion object {
49         const val COL_CONNECTION_STATE = "connState"
50 
51         // TODO(b/316635648): validate these states. We don't need the level of granularity that
52         //  SatelliteManager gives us.
fromModemStatenull53         fun fromModemState(@SatelliteManager.SatelliteModemState modemState: Int) =
54             when (modemState) {
55                 // Transferring data is connected
56                 SATELLITE_MODEM_STATE_CONNECTED,
57                 SATELLITE_MODEM_STATE_DATAGRAM_TRANSFERRING,
58                 SATELLITE_MODEM_STATE_DATAGRAM_RETRYING -> Connected
59 
60                 // Modem is on but not connected
61                 SATELLITE_MODEM_STATE_IDLE,
62                 SATELLITE_MODEM_STATE_LISTENING,
63                 SATELLITE_MODEM_STATE_NOT_CONNECTED -> On
64 
65                 // Consider unavailable equivalent to Off
66                 SATELLITE_MODEM_STATE_UNAVAILABLE,
67                 SATELLITE_MODEM_STATE_OFF -> Off
68 
69                 // Else, we don't know what's up
70                 SATELLITE_MODEM_STATE_UNKNOWN -> Unknown
71                 else -> Unknown
72             }
73     }
74 }
75