1 /* 2 * Copyright (C) 2019 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.os.PersistableBundle; 21 import android.telephony.CarrierConfigManager; 22 import android.telephony.SubscriptionManager; 23 import android.text.TextUtils; 24 25 import com.android.settings.core.BasePreferenceController; 26 import com.android.settings.network.CarrierConfigCache; 27 28 public class CarrierSettingsVersionPreferenceController extends BasePreferenceController { 29 30 private int mSubscriptionId; 31 private CarrierConfigCache mCarrierConfigCache; 32 CarrierSettingsVersionPreferenceController(Context context, String preferenceKey)33 public CarrierSettingsVersionPreferenceController(Context context, String preferenceKey) { 34 super(context, preferenceKey); 35 mCarrierConfigCache = CarrierConfigCache.getInstance(context); 36 mSubscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 37 } 38 init(int subscriptionId)39 public void init(int subscriptionId) { 40 mSubscriptionId = subscriptionId; 41 } 42 43 @Override getSummary()44 public CharSequence getSummary() { 45 final PersistableBundle config = mCarrierConfigCache.getConfigForSubId(mSubscriptionId); 46 if (config == null) { 47 return null; 48 } 49 return config.getString(CarrierConfigManager.KEY_CARRIER_CONFIG_VERSION_STRING); 50 } 51 52 @Override getAvailabilityStatus()53 public int getAvailabilityStatus() { 54 return TextUtils.isEmpty(getSummary()) ? UNSUPPORTED_ON_DEVICE : AVAILABLE; 55 } 56 } 57