blob: 7f7d58cf0c04f40691377aeda3b07e6f5852149a [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
Santos Cordon7d4ddf62013-07-10 11:58:08 -070019import android.content.Intent;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070020import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.os.SystemProperties;
22import android.preference.Preference;
pkanward702e542017-02-08 15:44:54 -080023import android.preference.PreferenceFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.preference.PreferenceScreen;
25import android.provider.Settings;
Jonathan Basseri29386052015-04-23 17:35:28 -070026import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.text.TextUtils;
28
Susheel nyamala3d113762017-12-07 20:32:00 +053029import com.android.internal.annotations.VisibleForTesting;
Malcolm Chen3f2dd682017-07-24 16:44:32 -070030import com.android.internal.logging.MetricsLogger;
31import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import com.android.internal.telephony.Phone;
Susheel nyamala3d113762017-12-07 20:32:00 +053033import com.android.internal.telephony.PhoneConstants;
Alex Chaucfc19162018-02-27 09:44:27 +000034import com.android.settingslib.RestrictedLockUtils;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035
36/**
37 * List of Phone-specific settings screens.
38 */
39public class CdmaOptions {
40 private static final String LOG_TAG = "CdmaOptions";
41
42 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
43 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Alex Chaucfc19162018-02-27 09:44:27 +000044 private RestrictedPreference mButtonAPNExpand;
Malcolm Chen833d4ac2017-07-11 17:00:07 -070045 private Preference mCategoryAPNExpand;
46 private Preference mButtonCarrierSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047
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 Gutta91007152014-07-01 12:05:52 +053050 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Malcolm Chen833d4ac2017-07-11 17:00:07 -070051 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 Cordon7d4ddf62013-07-10 11:58:08 -070053
pkanward702e542017-02-08 15:44:54 -080054 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055 private PreferenceScreen mPrefScreen;
56 private Phone mPhone;
57
Susheel nyamala3d113762017-12-07 20:32:00 +053058 // Constructor for CdmaOptionsTest, since PreferenceScreen is final and cannot be mocked
59 @VisibleForTesting
60 public CdmaOptions(Phone phone) {
61 mPhone = phone;
62 }
63
pkanward702e542017-02-08 15:44:54 -080064 public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
65 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080067 mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068
Malcolm Chen833d4ac2017-07-11 17:00:07 -070069 // 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 Chaucfc19162018-02-27 09:44:27 +000075 mButtonAPNExpand = (RestrictedPreference) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070076 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 Basseri9504c6b2015-06-04 14:23:32 -070087 PersistableBundle carrierConfig =
88 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri29386052015-04-23 17:35:28 -070089 // Some CDMA carriers want the APN settings.
Susheel nyamala3d113762017-12-07 20:32:00 +053090 boolean addAPNExpand = shouldAddApnExpandPreference(carrierConfig);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070091 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 nyamala3d113762017-12-07 20:32:00 +0530104 log("update: addAPNExpand");
Alex Chaucfc19162018-02-27 09:44:27 +0000105 mButtonAPNExpand.setDisabledByAdmin(
106 MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
107 ? RestrictedLockUtils.getDeviceOwner(mButtonAPNExpand.getContext())
108 : null);
Jing Zhao43e95622014-08-25 13:49:19 -0500109 mButtonAPNExpand.setOnPreferenceClickListener(
110 new Preference.OnPreferenceClickListener() {
111 @Override
112 public boolean onPreferenceClick(Preference preference) {
Malcolm Chen3f2dd682017-07-24 16:44:32 -0700113 MetricsLogger.action(mButtonAPNExpand.getContext(),
114 MetricsEvent.ACTION_MOBILE_NETWORK_APN_SETTINGS);
Jing Zhao43e95622014-08-25 13:49:19 -0500115 // We need to build the Intent by hand as the Preference Framework
116 // does not allow to add an Intent with some extras into a Preference
117 // XML file
118 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
119 // This will setup the Home and Search affordance
120 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe9674ff22014-12-18 10:24:22 -0800121 intent.putExtra("sub_id", mPhone.getSubId());
pkanward702e542017-02-08 15:44:54 -0800122 mPrefFragment.startActivity(intent);
Jing Zhao43e95622014-08-25 13:49:19 -0500123 return true;
124 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700125 });
126 mPrefScreen.addPreference(mCategoryAPNExpand);
127 } else {
128 mPrefScreen.removePreference(mCategoryAPNExpand);
Jing Zhao43e95622014-08-25 13:49:19 -0500129 }
130
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700131 if (addCdmaSubscription) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132 log("Both NV and Ruim supported, ENABLE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700133 mPrefScreen.addPreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134 mButtonCdmaSubscription.setEnabled(true);
135 } else {
136 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700137 mPrefScreen.removePreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138 }
139
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700140 if (addCarrierSettings) {
141 mPrefScreen.addPreference(mButtonCarrierSettings);
142 } else {
143 mPrefScreen.removePreference(mButtonCarrierSettings);
Sandeep Gutta91007152014-07-01 12:05:52 +0530144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 }
146
Susheel nyamala3d113762017-12-07 20:32:00 +0530147 /**
148 * Return whether we should add the APN expandable preference based on the phone type and
149 * carrier config
150 */
151 @VisibleForTesting
152 public boolean shouldAddApnExpandPreference(PersistableBundle config) {
153 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
154 && config.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)) {
155 return true;
156 }
157 return false;
158 }
159
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 private boolean deviceSupportsNvAndRuim() {
161 // retrieve the list of subscription types supported by device.
162 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
163 boolean nvSupported = false;
164 boolean ruimSupported = false;
165
166 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
167 if (!TextUtils.isEmpty(subscriptionsSupported)) {
168 // Searches through the comma-separated list for a match for "NV"
169 // and "RUIM" to update nvSupported and ruimSupported.
170 for (String subscriptionType : subscriptionsSupported.split(",")) {
171 subscriptionType = subscriptionType.trim();
172 if (subscriptionType.equalsIgnoreCase("NV")) {
173 nvSupported = true;
174 }
175 if (subscriptionType.equalsIgnoreCase("RUIM")) {
176 ruimSupported = true;
177 }
178 }
179 }
180
181 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
182 " ruimSupported=" + ruimSupported);
183 return (nvSupported && ruimSupported);
184 }
185
186 public boolean preferenceTreeClick(Preference preference) {
187 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
188 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
189 return true;
190 }
191 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
192 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
193 return true;
194 }
195 return false;
196 }
197
198 public void showDialog(Preference preference) {
199 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
200 mButtonCdmaSystemSelect.showDialog(null);
201 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
202 mButtonCdmaSubscription.showDialog(null);
203 }
204 }
205
206 protected void log(String s) {
207 android.util.Log.d(LOG_TAG, s);
208 }
209}