blob: 47c0eb4648e83571cf2b8b7347dc069a7f505540 [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
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;
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070056 private int mSubId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070058 public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, int subId) {
pkanward702e542017-02-08 15:44:54 -080059 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080061 mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062
Malcolm Chen833d4ac2017-07-11 17:00:07 -070063 // Initialize preferences.
64 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen
65 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
66 mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
67 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
68 mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
Alex Chaucfc19162018-02-27 09:44:27 +000069 mButtonAPNExpand = (RestrictedPreference) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070070 mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
71
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070072 updateSubscriptionId(subId);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070073 }
74
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070075 protected void updateSubscriptionId(int subId) {
76 mSubId = subId;
77 int phoneType = TelephonyManager.from(mPrefFragment.getContext())
78 .createForSubscriptionId(mSubId).getPhoneType();
Malcolm Chen833d4ac2017-07-11 17:00:07 -070079
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070080 PersistableBundle carrierConfig =
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070081 PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
Jonathan Basseri29386052015-04-23 17:35:28 -070082 // Some CDMA carriers want the APN settings.
Pengquan Meng7ca05bc2018-08-28 17:20:19 -070083 boolean addAPNExpand = shouldAddApnExpandPreference(phoneType, carrierConfig);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070084 boolean addCdmaSubscription =
85 deviceSupportsNvAndRuim();
86 // Read platform settings for carrier settings
87 boolean addCarrierSettings =
88 carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
89
90 mPrefScreen.addPreference(mButtonCdmaSystemSelect);
91 mButtonCdmaSystemSelect.setEnabled(true);
92
93 // Making no assumptions of whether they are added or removed at this point.
94 // Calling add or remove explicitly to make sure they are updated.
95
96 if (addAPNExpand) {
Susheel nyamala3d113762017-12-07 20:32:00 +053097 log("update: addAPNExpand");
Alex Chaucfc19162018-02-27 09:44:27 +000098 mButtonAPNExpand.setDisabledByAdmin(
99 MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
Philip P. Moltmann2edd49b2018-08-28 15:03:31 -0700100 ? RestrictedLockUtilsInternal.getDeviceOwner(
101 mButtonAPNExpand.getContext())
Alex Chaucfc19162018-02-27 09:44:27 +0000102 : null);
Jing Zhao43e95622014-08-25 13:49:19 -0500103 mButtonAPNExpand.setOnPreferenceClickListener(
104 new Preference.OnPreferenceClickListener() {
105 @Override
106 public boolean onPreferenceClick(Preference preference) {
Malcolm Chen3f2dd682017-07-24 16:44:32 -0700107 MetricsLogger.action(mButtonAPNExpand.getContext(),
108 MetricsEvent.ACTION_MOBILE_NETWORK_APN_SETTINGS);
Jing Zhao43e95622014-08-25 13:49:19 -0500109 // We need to build the Intent by hand as the Preference Framework
110 // does not allow to add an Intent with some extras into a Preference
111 // XML file
112 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
113 // This will setup the Home and Search affordance
114 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Pengquan Meng7ca05bc2018-08-28 17:20:19 -0700115 intent.putExtra("sub_id", mSubId);
pkanward702e542017-02-08 15:44:54 -0800116 mPrefFragment.startActivity(intent);
Jing Zhao43e95622014-08-25 13:49:19 -0500117 return true;
118 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700119 });
120 mPrefScreen.addPreference(mCategoryAPNExpand);
121 } else {
122 mPrefScreen.removePreference(mCategoryAPNExpand);
Jing Zhao43e95622014-08-25 13:49:19 -0500123 }
124
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700125 if (addCdmaSubscription) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 log("Both NV and Ruim supported, ENABLE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700127 mPrefScreen.addPreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128 mButtonCdmaSubscription.setEnabled(true);
129 } else {
130 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700131 mPrefScreen.removePreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132 }
133
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700134 if (addCarrierSettings) {
135 mPrefScreen.addPreference(mButtonCarrierSettings);
136 } else {
137 mPrefScreen.removePreference(mButtonCarrierSettings);
Sandeep Gutta91007152014-07-01 12:05:52 +0530138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 }
140
Susheel nyamala3d113762017-12-07 20:32:00 +0530141 /**
142 * Return whether we should add the APN expandable preference based on the phone type and
143 * carrier config
144 */
145 @VisibleForTesting
Pengquan Meng7ca05bc2018-08-28 17:20:19 -0700146 public static boolean shouldAddApnExpandPreference(int phoneType, PersistableBundle config) {
147 return phoneType == PhoneConstants.PHONE_TYPE_CDMA
148 && config.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
Susheel nyamala3d113762017-12-07 20:32:00 +0530149 }
150
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 private boolean deviceSupportsNvAndRuim() {
152 // retrieve the list of subscription types supported by device.
153 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
154 boolean nvSupported = false;
155 boolean ruimSupported = false;
156
157 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
158 if (!TextUtils.isEmpty(subscriptionsSupported)) {
159 // Searches through the comma-separated list for a match for "NV"
160 // and "RUIM" to update nvSupported and ruimSupported.
161 for (String subscriptionType : subscriptionsSupported.split(",")) {
162 subscriptionType = subscriptionType.trim();
163 if (subscriptionType.equalsIgnoreCase("NV")) {
164 nvSupported = true;
165 }
166 if (subscriptionType.equalsIgnoreCase("RUIM")) {
167 ruimSupported = true;
168 }
169 }
170 }
171
172 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
173 " ruimSupported=" + ruimSupported);
174 return (nvSupported && ruimSupported);
175 }
176
177 public boolean preferenceTreeClick(Preference preference) {
178 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
179 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
180 return true;
181 }
182 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
183 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
184 return true;
185 }
186 return false;
187 }
188
189 public void showDialog(Preference preference) {
190 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
191 mButtonCdmaSystemSelect.showDialog(null);
192 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
193 mButtonCdmaSubscription.showDialog(null);
194 }
195 }
196
197 protected void log(String s) {
198 android.util.Log.d(LOG_TAG, s);
199 }
200}