• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.settings.network.telephony
18 
19 import android.content.Context
20 import android.telephony.CarrierConfigManager
21 import android.telephony.SubscriptionManager
22 import android.telephony.TelephonyManager
23 import android.util.Log
24 
25 class NrRepository(private val context: Context) {
26     private val carrierConfigRepository = CarrierConfigRepository(context)
27 
isNrAvailablenull28     fun isNrAvailable(subId: Int): Boolean {
29         if (!SubscriptionManager.isValidSubscriptionId(subId) || !has5gCapability(subId)) {
30             return false
31         }
32         val carrierNrAvailabilities =
33             carrierConfigRepository.getIntArray(
34                 subId = subId,
35                 key = CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
36             )
37         return carrierNrAvailabilities?.isNotEmpty() ?: false
38     }
39 
has5gCapabilitynull40     private fun has5gCapability(subId: Int): Boolean {
41         val telephonyManager = context.telephonyManager(subId)
42         return (telephonyManager.supportedRadioAccessFamily and
43                 TelephonyManager.NETWORK_TYPE_BITMASK_NR > 0)
44             .also { Log.d(TAG, "[$subId] has5gCapability: $it") }
45     }
46 
47     private companion object {
48         private const val TAG = "NrRepository"
49     }
50 }
51