1 /* 2 * Copyright (C) 2018 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.cdma; 18 19 import android.content.Context; 20 import android.provider.Settings; 21 import android.telephony.TelephonyManager; 22 23 import androidx.preference.ListPreference; 24 import androidx.preference.Preference; 25 26 import com.android.internal.telephony.Phone; 27 import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants; 28 29 /** 30 * Preference controller for "System Select" 31 */ 32 public class CdmaSystemSelectPreferenceController extends CdmaBasePreferenceController 33 implements ListPreference.OnPreferenceChangeListener { 34 CdmaSystemSelectPreferenceController(Context context, String key)35 public CdmaSystemSelectPreferenceController(Context context, String key) { 36 super(context, key); 37 } 38 39 @Override updateState(Preference preference)40 public void updateState(Preference preference) { 41 super.updateState(preference); 42 final ListPreference listPreference = (ListPreference) preference; 43 listPreference.setVisible(getAvailabilityStatus() == AVAILABLE); 44 final int mode = mTelephonyManager.getCdmaRoamingMode(); 45 if (mode != TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT) { 46 if (mode == TelephonyManager.CDMA_ROAMING_MODE_HOME 47 || mode == TelephonyManager.CDMA_ROAMING_MODE_ANY) { 48 listPreference.setValue(Integer.toString(mode)); 49 } else { 50 resetCdmaRoamingModeToDefault(); 51 } 52 } 53 final int settingsNetworkMode = Settings.Global.getInt( 54 mContext.getContentResolver(), 55 Settings.Global.PREFERRED_NETWORK_MODE + mSubId, 56 Phone.PREFERRED_NT_MODE); 57 listPreference.setEnabled( 58 settingsNetworkMode != TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA); 59 } 60 61 @Override onPreferenceChange(Preference preference, Object object)62 public boolean onPreferenceChange(Preference preference, Object object) { 63 int newMode = Integer.parseInt((String) object); 64 //TODO(b/117611981): only set it in one place 65 if (mTelephonyManager.setCdmaRoamingMode(newMode)) { 66 Settings.Global.putInt(mContext.getContentResolver(), 67 Settings.Global.CDMA_ROAMING_MODE, newMode); 68 return true; 69 } 70 71 return false; 72 } 73 resetCdmaRoamingModeToDefault()74 private void resetCdmaRoamingModeToDefault() { 75 final ListPreference listPreference = (ListPreference) mPreference; 76 //set the mButtonCdmaRoam 77 listPreference.setValue(Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY)); 78 //set the Settings.System 79 Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.CDMA_ROAMING_MODE, 80 TelephonyManager.CDMA_ROAMING_MODE_ANY); 81 //Set the Status 82 mTelephonyManager.setCdmaRoamingMode(TelephonyManager.CDMA_ROAMING_MODE_ANY); 83 } 84 } 85