1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 package com.android.settings.display; 15 16 import android.content.Context; 17 import android.os.PersistableBundle; 18 import android.provider.Settings; 19 import android.telephony.CarrierConfigManager; 20 import android.telephony.SubscriptionManager; 21 22 import androidx.preference.Preference; 23 import androidx.preference.TwoStatePreference; 24 25 import com.android.settings.core.PreferenceControllerMixin; 26 import com.android.settingslib.core.AbstractPreferenceController; 27 28 public class ShowOperatorNamePreferenceController extends AbstractPreferenceController 29 implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { 30 31 private static final String KEY_SHOW_OPERATOR_NAME = "show_operator_name"; 32 ShowOperatorNamePreferenceController(Context context)33 public ShowOperatorNamePreferenceController(Context context) { 34 super(context); 35 } 36 37 @Override isAvailable()38 public boolean isAvailable() { 39 final CarrierConfigManager configMgr = mContext 40 .getSystemService(CarrierConfigManager.class); 41 if (configMgr == null) { 42 return false; 43 } 44 final PersistableBundle b = configMgr.getConfigForSubId(SubscriptionManager 45 .getDefaultDataSubscriptionId()); 46 return b != null && b.getBoolean(CarrierConfigManager 47 .KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL, false); 48 } 49 50 @Override getPreferenceKey()51 public String getPreferenceKey() { 52 return KEY_SHOW_OPERATOR_NAME; 53 } 54 55 @Override onPreferenceChange(Preference preference, Object newValue)56 public boolean onPreferenceChange(Preference preference, Object newValue) { 57 boolean value = (Boolean) newValue; 58 Settings.Secure.putInt(mContext.getContentResolver(), 59 KEY_SHOW_OPERATOR_NAME, value ? 1 : 0); 60 return true; 61 } 62 63 @Override updateState(Preference preference)64 public void updateState(Preference preference) { 65 int value = Settings.Secure.getInt(mContext.getContentResolver(), 66 KEY_SHOW_OPERATOR_NAME, 1); 67 ((TwoStatePreference) preference).setChecked(value != 0); 68 } 69 } 70