Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.phone; |
| 18 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 19 | import android.preference.Preference; |
| 20 | import android.preference.PreferenceActivity; |
| 21 | import android.preference.PreferenceScreen; |
| 22 | import android.content.res.Resources; |
| 23 | |
| 24 | import com.android.internal.telephony.Phone; |
| 25 | import com.android.internal.telephony.PhoneConstants; |
| 26 | import com.android.internal.telephony.PhoneFactory; |
| 27 | |
| 28 | /** |
| 29 | * List of Network-specific settings screens. |
| 30 | */ |
| 31 | public class GsmUmtsOptions { |
| 32 | private static final String LOG_TAG = "GsmUmtsOptions"; |
| 33 | |
| 34 | private PreferenceScreen mButtonAPNExpand; |
| 35 | private PreferenceScreen mButtonOperatorSelectionExpand; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | |
| 37 | private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key"; |
| 38 | private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key"; |
Sandeep Gutta | 9100715 | 2014-07-01 12:05:52 +0530 | [diff] [blame] | 39 | private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | private PreferenceActivity mPrefActivity; |
| 41 | private PreferenceScreen mPrefScreen; |
| 42 | |
| 43 | public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen) { |
| 44 | mPrefActivity = prefActivity; |
| 45 | mPrefScreen = prefScreen; |
| 46 | create(); |
| 47 | } |
| 48 | |
| 49 | protected void create() { |
| 50 | mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options); |
| 51 | mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY); |
| 52 | mButtonOperatorSelectionExpand = |
| 53 | (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) { |
| 55 | log("Not a GSM phone"); |
| 56 | mButtonAPNExpand.setEnabled(false); |
| 57 | mButtonOperatorSelectionExpand.setEnabled(false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | } else { |
| 59 | log("Not a CDMA phone"); |
| 60 | Resources res = mPrefActivity.getResources(); |
| 61 | |
| 62 | // Determine which options to display, for GSM these are defaulted |
| 63 | // are defaulted to true in Phone/res/values/config.xml. But for |
| 64 | // some operators like verizon they maybe overriden in operator |
| 65 | // specific resources or device specifc overlays. |
| 66 | if (!res.getBoolean(R.bool.config_apn_expand)) { |
| 67 | mPrefScreen.removePreference(mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY)); |
| 68 | } |
| 69 | if (!res.getBoolean(R.bool.config_operator_selection_expand)) { |
| 70 | mPrefScreen.removePreference(mPrefScreen |
| 71 | .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY)); |
| 72 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | |
| 74 | if (res.getBoolean(R.bool.csp_enabled)) { |
| 75 | if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) { |
| 76 | log("[CSP] Enabling Operator Selection menu."); |
| 77 | mButtonOperatorSelectionExpand.setEnabled(true); |
| 78 | } else { |
| 79 | log("[CSP] Disabling Operator Selection menu."); |
| 80 | mPrefScreen.removePreference(mPrefScreen |
| 81 | .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY)); |
| 82 | } |
| 83 | } |
Sandeep Gutta | 9100715 | 2014-07-01 12:05:52 +0530 | [diff] [blame] | 84 | |
| 85 | // Read platform settings for carrier settings |
| 86 | final boolean isCarrierSettingsEnabled = mPrefActivity.getResources().getBoolean( |
| 87 | R.bool.config_carrier_settings_enable); |
| 88 | if (!isCarrierSettingsEnabled) { |
| 89 | Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY); |
| 90 | if (pref != null) { |
| 91 | mPrefScreen.removePreference(pref); |
| 92 | } |
| 93 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
| 97 | public boolean preferenceTreeClick(Preference preference) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 98 | log("preferenceTreeClick: return false"); |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | protected void log(String s) { |
| 103 | android.util.Log.d(LOG_TAG, s); |
| 104 | } |
| 105 | } |