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