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