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 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Jing Zhao | 43e9562 | 2014-08-25 13:49:19 -0500 | [diff] [blame] | 21 | import android.content.res.Resources; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
| 23 | import android.os.SystemProperties; |
| 24 | import android.preference.Preference; |
| 25 | import android.preference.PreferenceActivity; |
| 26 | import android.preference.PreferenceScreen; |
| 27 | import android.provider.Settings; |
| 28 | import android.telephony.TelephonyManager; |
| 29 | import android.text.TextUtils; |
| 30 | |
| 31 | import com.android.internal.telephony.Phone; |
| 32 | import com.android.internal.telephony.PhoneConstants; |
| 33 | import com.android.internal.telephony.TelephonyProperties; |
| 34 | |
| 35 | /** |
| 36 | * List of Phone-specific settings screens. |
| 37 | */ |
| 38 | public class CdmaOptions { |
| 39 | private static final String LOG_TAG = "CdmaOptions"; |
| 40 | |
| 41 | private CdmaSystemSelectListPreference mButtonCdmaSystemSelect; |
| 42 | private CdmaSubscriptionListPreference mButtonCdmaSubscription; |
Jing Zhao | 43e9562 | 2014-08-25 13:49:19 -0500 | [diff] [blame] | 43 | private PreferenceScreen mButtonAPNExpand; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | |
| 45 | private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key"; |
| 46 | private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key"; |
| 47 | private static final String BUTTON_CDMA_ACTIVATE_DEVICE_KEY = "cdma_activate_device_key"; |
Sandeep Gutta | 9100715 | 2014-07-01 12:05:52 +0530 | [diff] [blame] | 48 | private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key"; |
Sanket Padawe | a564e9b | 2015-01-07 11:24:49 -0800 | [diff] [blame] | 49 | private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key_cdma"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | |
| 51 | private PreferenceActivity mPrefActivity; |
| 52 | private PreferenceScreen mPrefScreen; |
| 53 | private Phone mPhone; |
| 54 | |
| 55 | public CdmaOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen, Phone phone) { |
| 56 | mPrefActivity = prefActivity; |
| 57 | mPrefScreen = prefScreen; |
| 58 | mPhone = phone; |
| 59 | create(); |
| 60 | } |
| 61 | |
| 62 | protected void create() { |
| 63 | mPrefActivity.addPreferencesFromResource(R.xml.cdma_options); |
| 64 | |
Jing Zhao | 43e9562 | 2014-08-25 13:49:19 -0500 | [diff] [blame] | 65 | mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY); |
| 66 | boolean removedAPNExpand = false; |
| 67 | Resources res = mPrefActivity.getResources(); |
| 68 | // Some CDMA carriers want the APN settings |
| 69 | if (!res.getBoolean(R.bool.config_show_apn_setting_cdma) && mButtonAPNExpand != null) { |
| 70 | mPrefScreen.removePreference(mButtonAPNExpand); |
| 71 | removedAPNExpand = true; |
| 72 | } |
| 73 | if (!removedAPNExpand) { |
| 74 | mButtonAPNExpand.setOnPreferenceClickListener( |
| 75 | new Preference.OnPreferenceClickListener() { |
| 76 | @Override |
| 77 | public boolean onPreferenceClick(Preference preference) { |
| 78 | // We need to build the Intent by hand as the Preference Framework |
| 79 | // does not allow to add an Intent with some extras into a Preference |
| 80 | // XML file |
| 81 | final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS); |
| 82 | // This will setup the Home and Search affordance |
| 83 | intent.putExtra(":settings:show_fragment_as_subsetting", true); |
Sanket Padawe | 9674ff2 | 2014-12-18 10:24:22 -0800 | [diff] [blame] | 84 | intent.putExtra("sub_id", mPhone.getSubId()); |
Jing Zhao | 43e9562 | 2014-08-25 13:49:19 -0500 | [diff] [blame] | 85 | mPrefActivity.startActivity(intent); |
| 86 | return true; |
| 87 | } |
| 88 | }); |
| 89 | } |
| 90 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen |
| 92 | .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY); |
| 93 | |
| 94 | mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen |
| 95 | .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY); |
| 96 | |
| 97 | mButtonCdmaSystemSelect.setEnabled(true); |
| 98 | if(deviceSupportsNvAndRuim()) { |
| 99 | log("Both NV and Ruim supported, ENABLE subscription type selection"); |
| 100 | mButtonCdmaSubscription.setEnabled(true); |
| 101 | } else { |
| 102 | log("Both NV and Ruim NOT supported, REMOVE subscription type selection"); |
| 103 | mPrefScreen.removePreference(mPrefScreen |
| 104 | .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)); |
| 105 | } |
| 106 | |
| 107 | final boolean voiceCapable = mPrefActivity.getResources().getBoolean( |
| 108 | com.android.internal.R.bool.config_voice_capable); |
| 109 | final boolean isLTE = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE; |
| 110 | if (voiceCapable || isLTE) { |
| 111 | // This option should not be available on voice-capable devices (i.e. regular phones) |
| 112 | // and is replaced by the LTE data service item on LTE devices |
| 113 | mPrefScreen.removePreference( |
| 114 | mPrefScreen.findPreference(BUTTON_CDMA_ACTIVATE_DEVICE_KEY)); |
| 115 | } |
Sandeep Gutta | 9100715 | 2014-07-01 12:05:52 +0530 | [diff] [blame] | 116 | |
| 117 | // Read platform settings for carrier settings |
| 118 | final boolean isCarrierSettingsEnabled = mPrefActivity.getResources().getBoolean( |
| 119 | R.bool.config_carrier_settings_enable); |
| 120 | if (!isCarrierSettingsEnabled) { |
| 121 | Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY); |
| 122 | if (pref != null) { |
| 123 | mPrefScreen.removePreference(pref); |
| 124 | } |
| 125 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | private boolean deviceSupportsNvAndRuim() { |
| 129 | // retrieve the list of subscription types supported by device. |
| 130 | String subscriptionsSupported = SystemProperties.get("ril.subscription.types"); |
| 131 | boolean nvSupported = false; |
| 132 | boolean ruimSupported = false; |
| 133 | |
| 134 | log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported); |
| 135 | if (!TextUtils.isEmpty(subscriptionsSupported)) { |
| 136 | // Searches through the comma-separated list for a match for "NV" |
| 137 | // and "RUIM" to update nvSupported and ruimSupported. |
| 138 | for (String subscriptionType : subscriptionsSupported.split(",")) { |
| 139 | subscriptionType = subscriptionType.trim(); |
| 140 | if (subscriptionType.equalsIgnoreCase("NV")) { |
| 141 | nvSupported = true; |
| 142 | } |
| 143 | if (subscriptionType.equalsIgnoreCase("RUIM")) { |
| 144 | ruimSupported = true; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | log("deviceSupportsnvAnRum: nvSupported=" + nvSupported + |
| 150 | " ruimSupported=" + ruimSupported); |
| 151 | return (nvSupported && ruimSupported); |
| 152 | } |
| 153 | |
| 154 | public boolean preferenceTreeClick(Preference preference) { |
| 155 | if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) { |
| 156 | log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true"); |
| 157 | return true; |
| 158 | } |
| 159 | if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) { |
| 160 | log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true"); |
| 161 | return true; |
| 162 | } |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | public void showDialog(Preference preference) { |
| 167 | if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) { |
| 168 | mButtonCdmaSystemSelect.showDialog(null); |
| 169 | } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) { |
| 170 | mButtonCdmaSubscription.showDialog(null); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | protected void log(String s) { |
| 175 | android.util.Log.d(LOG_TAG, s); |
| 176 | } |
| 177 | } |