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 com.android.settings.R 23 import com.android.settings.core.BasePreferenceController 24 import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem 25 import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchResult 26 27 class CarrierSettingsVersionPreferenceController(context: Context, preferenceKey: String) : 28 BasePreferenceController(context, preferenceKey) { 29 30 private var subId: Int = SubscriptionManager.INVALID_SUBSCRIPTION_ID 31 private val searchItem = CarrierSettingsVersionSearchItem(context) 32 initnull33 fun init(subId: Int) { 34 this.subId = subId 35 } 36 getSummarynull37 override fun getSummary() = searchItem.getSummary(subId) 38 39 override fun getAvailabilityStatus() = 40 if (searchItem.isAvailable(subId)) AVAILABLE else CONDITIONALLY_UNAVAILABLE 41 42 companion object { 43 class CarrierSettingsVersionSearchItem(private val context: Context) : 44 MobileNetworkSettingsSearchItem { 45 private val carrierConfigRepository = CarrierConfigRepository(context) 46 47 fun getSummary(subId: Int): String? = 48 carrierConfigRepository.getString( 49 subId, CarrierConfigManager.KEY_CARRIER_CONFIG_VERSION_STRING) 50 51 fun isAvailable(subId: Int): Boolean = !getSummary(subId).isNullOrEmpty() 52 53 override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? { 54 if (!isAvailable(subId)) return null 55 return MobileNetworkSettingsSearchResult( 56 key = "carrier_settings_version_key", 57 title = context.getString(R.string.carrier_settings_version), 58 ) 59 } 60 } 61 } 62 } 63