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