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.content.Intent; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 20 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import android.os.SystemProperties; |
| 22 | import android.preference.Preference; |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 23 | import android.preference.PreferenceFragment; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.preference.PreferenceScreen; |
| 25 | import android.provider.Settings; |
Jonathan Basseri | 2938605 | 2015-04-23 17:35:28 -0700 | [diff] [blame] | 26 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.text.TextUtils; |
| 28 | |
| 29 | import com.android.internal.telephony.Phone; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * List of Phone-specific settings screens. |
| 33 | */ |
| 34 | public class CdmaOptions { |
| 35 | private static final String LOG_TAG = "CdmaOptions"; |
| 36 | |
| 37 | private CdmaSystemSelectListPreference mButtonCdmaSystemSelect; |
| 38 | private CdmaSubscriptionListPreference mButtonCdmaSubscription; |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 39 | private Preference mButtonAPNExpand; |
| 40 | private Preference mCategoryAPNExpand; |
| 41 | private Preference mButtonCarrierSettings; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | |
| 43 | private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key"; |
| 44 | private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key"; |
Sandeep Gutta | 9100715 | 2014-07-01 12:05:52 +0530 | [diff] [blame] | 45 | private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key"; |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 46 | private static final String BUTTON_APN_EXPAND_KEY = "button_cdma_apn_key"; |
| 47 | private static final String CATEGORY_APN_EXPAND_KEY = "category_cdma_apn_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 49 | private PreferenceFragment mPrefFragment; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | private PreferenceScreen mPrefScreen; |
| 51 | private Phone mPhone; |
| 52 | |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 53 | public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) { |
| 54 | mPrefFragment = prefFragment; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | mPrefScreen = prefScreen; |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 56 | mPrefFragment.addPreferencesFromResource(R.xml.cdma_options); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 58 | // Initialize preferences. |
| 59 | mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen |
| 60 | .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY); |
| 61 | mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen |
| 62 | .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY); |
| 63 | mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY); |
| 64 | mButtonAPNExpand = mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY); |
| 65 | mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY); |
| 66 | |
| 67 | update(phone); |
| 68 | } |
| 69 | |
| 70 | // Unlike mPrefFragment or mPrefScreen, mPhone may change during lifecycle of CdmaOptions. |
| 71 | // For example, a new sim card is inserted. When that happens, we update CdmaOptions with new |
| 72 | // phone. |
| 73 | protected void update(Phone phone) { |
| 74 | mPhone = phone; |
| 75 | |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 76 | PersistableBundle carrierConfig = |
| 77 | PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId()); |
Jonathan Basseri | 2938605 | 2015-04-23 17:35:28 -0700 | [diff] [blame] | 78 | // Some CDMA carriers want the APN settings. |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 79 | boolean addAPNExpand = |
| 80 | carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL); |
| 81 | boolean addCdmaSubscription = |
| 82 | deviceSupportsNvAndRuim(); |
| 83 | // Read platform settings for carrier settings |
| 84 | boolean addCarrierSettings = |
| 85 | carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL); |
| 86 | |
| 87 | mPrefScreen.addPreference(mButtonCdmaSystemSelect); |
| 88 | mButtonCdmaSystemSelect.setEnabled(true); |
| 89 | |
| 90 | // Making no assumptions of whether they are added or removed at this point. |
| 91 | // Calling add or remove explicitly to make sure they are updated. |
| 92 | |
| 93 | if (addAPNExpand) { |
Jing Zhao | 43e9562 | 2014-08-25 13:49:19 -0500 | [diff] [blame] | 94 | mButtonAPNExpand.setOnPreferenceClickListener( |
| 95 | new Preference.OnPreferenceClickListener() { |
| 96 | @Override |
| 97 | public boolean onPreferenceClick(Preference preference) { |
| 98 | // We need to build the Intent by hand as the Preference Framework |
| 99 | // does not allow to add an Intent with some extras into a Preference |
| 100 | // XML file |
| 101 | final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS); |
| 102 | // This will setup the Home and Search affordance |
| 103 | intent.putExtra(":settings:show_fragment_as_subsetting", true); |
Sanket Padawe | 9674ff2 | 2014-12-18 10:24:22 -0800 | [diff] [blame] | 104 | intent.putExtra("sub_id", mPhone.getSubId()); |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 105 | mPrefFragment.startActivity(intent); |
Jing Zhao | 43e9562 | 2014-08-25 13:49:19 -0500 | [diff] [blame] | 106 | return true; |
| 107 | } |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 108 | }); |
| 109 | mPrefScreen.addPreference(mCategoryAPNExpand); |
| 110 | } else { |
| 111 | mPrefScreen.removePreference(mCategoryAPNExpand); |
Jing Zhao | 43e9562 | 2014-08-25 13:49:19 -0500 | [diff] [blame] | 112 | } |
| 113 | |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 114 | if (addCdmaSubscription) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | log("Both NV and Ruim supported, ENABLE subscription type selection"); |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 116 | mPrefScreen.addPreference(mButtonCdmaSubscription); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | mButtonCdmaSubscription.setEnabled(true); |
| 118 | } else { |
| 119 | log("Both NV and Ruim NOT supported, REMOVE subscription type selection"); |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 120 | mPrefScreen.removePreference(mButtonCdmaSubscription); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Malcolm Chen | 833d4ac | 2017-07-11 17:00:07 -0700 | [diff] [blame] | 123 | if (addCarrierSettings) { |
| 124 | mPrefScreen.addPreference(mButtonCarrierSettings); |
| 125 | } else { |
| 126 | mPrefScreen.removePreference(mButtonCarrierSettings); |
Sandeep Gutta | 9100715 | 2014-07-01 12:05:52 +0530 | [diff] [blame] | 127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | private boolean deviceSupportsNvAndRuim() { |
| 131 | // retrieve the list of subscription types supported by device. |
| 132 | String subscriptionsSupported = SystemProperties.get("ril.subscription.types"); |
| 133 | boolean nvSupported = false; |
| 134 | boolean ruimSupported = false; |
| 135 | |
| 136 | log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported); |
| 137 | if (!TextUtils.isEmpty(subscriptionsSupported)) { |
| 138 | // Searches through the comma-separated list for a match for "NV" |
| 139 | // and "RUIM" to update nvSupported and ruimSupported. |
| 140 | for (String subscriptionType : subscriptionsSupported.split(",")) { |
| 141 | subscriptionType = subscriptionType.trim(); |
| 142 | if (subscriptionType.equalsIgnoreCase("NV")) { |
| 143 | nvSupported = true; |
| 144 | } |
| 145 | if (subscriptionType.equalsIgnoreCase("RUIM")) { |
| 146 | ruimSupported = true; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | log("deviceSupportsnvAnRum: nvSupported=" + nvSupported + |
| 152 | " ruimSupported=" + ruimSupported); |
| 153 | return (nvSupported && ruimSupported); |
| 154 | } |
| 155 | |
| 156 | public boolean preferenceTreeClick(Preference preference) { |
| 157 | if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) { |
| 158 | log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true"); |
| 159 | return true; |
| 160 | } |
| 161 | if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) { |
| 162 | log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true"); |
| 163 | return true; |
| 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | public void showDialog(Preference preference) { |
| 169 | if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) { |
| 170 | mButtonCdmaSystemSelect.showDialog(null); |
| 171 | } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) { |
| 172 | mButtonCdmaSubscription.showDialog(null); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | protected void log(String s) { |
| 177 | android.util.Log.d(LOG_TAG, s); |
| 178 | } |
| 179 | } |