blob: 1dc4a09114ecb8087ab8560f5d221ccbaf670850 [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;
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070027import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.text.TextUtils;
29
Susheel nyamala3d113762017-12-07 20:32:00 +053030import com.android.internal.annotations.VisibleForTesting;
Malcolm Chen3f2dd682017-07-24 16:44:32 -070031import com.android.internal.logging.MetricsLogger;
32import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Susheel nyamala3d113762017-12-07 20:32:00 +053033import com.android.internal.telephony.PhoneConstants;
Philip P. Moltmann2edd49b2018-08-28 15:03:31 -070034import com.android.settingslib.RestrictedLockUtilsInternal;
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
jackqdyuleiebf28412018-09-21 13:47:39 -070042 private CarrierConfigManager mCarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
44 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Alex Chaucfc19162018-02-27 09:44:27 +000045 private RestrictedPreference mButtonAPNExpand;
Malcolm Chen833d4ac2017-07-11 17:00:07 -070046 private Preference mCategoryAPNExpand;
47 private Preference mButtonCarrierSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048
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 Gutta91007152014-07-01 12:05:52 +053051 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Malcolm Chen833d4ac2017-07-11 17:00:07 -070052 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 Cordon7d4ddf62013-07-10 11:58:08 -070054
pkanward702e542017-02-08 15:44:54 -080055 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056 private PreferenceScreen mPrefScreen;
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070057 private int mSubId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070059 public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, int subId) {
pkanward702e542017-02-08 15:44:54 -080060 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080062 mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
jackqdyuleiebf28412018-09-21 13:47:39 -070063 mCarrierConfigManager = new CarrierConfigManager(prefFragment.getContext());
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064
Malcolm Chen833d4ac2017-07-11 17:00:07 -070065 // 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 Chaucfc19162018-02-27 09:44:27 +000071 mButtonAPNExpand = (RestrictedPreference) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070072 mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
73
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070074 updateSubscriptionId(subId);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070075 }
76
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070077 protected void updateSubscriptionId(int subId) {
78 mSubId = subId;
79 int phoneType = TelephonyManager.from(mPrefFragment.getContext())
80 .createForSubscriptionId(mSubId).getPhoneType();
Malcolm Chen833d4ac2017-07-11 17:00:07 -070081
jackqdyuleiebf28412018-09-21 13:47:39 -070082 PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
Jonathan Basseri29386052015-04-23 17:35:28 -070083 // Some CDMA carriers want the APN settings.
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070084 boolean addAPNExpand = shouldAddApnExpandPreference(phoneType, carrierConfig);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070085 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 nyamala3d113762017-12-07 20:32:00 +053098 log("update: addAPNExpand");
Alex Chaucfc19162018-02-27 09:44:27 +000099 mButtonAPNExpand.setDisabledByAdmin(
100 MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
Philip P. Moltmann2edd49b2018-08-28 15:03:31 -0700101 ? RestrictedLockUtilsInternal.getDeviceOwner(
102 mButtonAPNExpand.getContext())
Alex Chaucfc19162018-02-27 09:44:27 +0000103 : null);
Jing Zhao43e95622014-08-25 13:49:19 -0500104 mButtonAPNExpand.setOnPreferenceClickListener(
105 new Preference.OnPreferenceClickListener() {
106 @Override
107 public boolean onPreferenceClick(Preference preference) {
Malcolm Chen3f2dd682017-07-24 16:44:32 -0700108 MetricsLogger.action(mButtonAPNExpand.getContext(),
109 MetricsEvent.ACTION_MOBILE_NETWORK_APN_SETTINGS);
Jing Zhao43e95622014-08-25 13:49:19 -0500110 // 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 Meng7ca05bc2018-08-28 17:20:19 -0700116 intent.putExtra("sub_id", mSubId);
pkanward702e542017-02-08 15:44:54 -0800117 mPrefFragment.startActivity(intent);
Jing Zhao43e95622014-08-25 13:49:19 -0500118 return true;
119 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700120 });
121 mPrefScreen.addPreference(mCategoryAPNExpand);
122 } else {
123 mPrefScreen.removePreference(mCategoryAPNExpand);
Jing Zhao43e95622014-08-25 13:49:19 -0500124 }
125
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700126 if (addCdmaSubscription) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127 log("Both NV and Ruim supported, ENABLE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700128 mPrefScreen.addPreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129 mButtonCdmaSubscription.setEnabled(true);
130 } else {
131 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700132 mPrefScreen.removePreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133 }
134
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700135 if (addCarrierSettings) {
136 mPrefScreen.addPreference(mButtonCarrierSettings);
137 } else {
138 mPrefScreen.removePreference(mButtonCarrierSettings);
Sandeep Gutta91007152014-07-01 12:05:52 +0530139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 }
141
Susheel nyamala3d113762017-12-07 20:32:00 +0530142 /**
143 * Return whether we should add the APN expandable preference based on the phone type and
144 * carrier config
145 */
146 @VisibleForTesting
Pengquan Meng7ca05bc2018-08-28 17:20:19 -0700147 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 nyamala3d113762017-12-07 20:32:00 +0530150 }
151
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 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}