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 
30 enum class SatelliteConnectionState {
31     // State is unknown or undefined
32     Unknown,
33     // Radio is off
34     Off,
35     // Radio is on, but not yet connected
36     On,
37     // Radio is connected, aka satellite is available for use
38     Connected;
39 
40     companion object {
41         // TODO(b/316635648): validate these states. We don't need the level of granularity that
42         //  SatelliteManager gives us.
fromModemStatenull43         fun fromModemState(@SatelliteManager.SatelliteModemState modemState: Int) =
44             when (modemState) {
45                 // Transferring data is connected
46                 SATELLITE_MODEM_STATE_CONNECTED,
47                 SATELLITE_MODEM_STATE_DATAGRAM_TRANSFERRING,
48                 SATELLITE_MODEM_STATE_DATAGRAM_RETRYING -> Connected
49 
50                 // Modem is on but not connected
51                 SATELLITE_MODEM_STATE_IDLE,
52                 SATELLITE_MODEM_STATE_LISTENING,
53                 SATELLITE_MODEM_STATE_NOT_CONNECTED -> On
54 
55                 // Consider unavailable equivalent to Off
56                 SATELLITE_MODEM_STATE_UNAVAILABLE,
57                 SATELLITE_MODEM_STATE_OFF -> Off
58 
59                 // Else, we don't know what's up
60                 SATELLITE_MODEM_STATE_UNKNOWN -> Unknown
61                 else -> Unknown
62             }
63     }
64 }
65