blob: ff37c7005397a18d55324c05e0dd8b8eae05a745 [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
Malcolm Chen3f2dd682017-07-24 16:44:32 -070029import com.android.internal.logging.MetricsLogger;
30import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import com.android.internal.telephony.Phone;
Alex Chaucfc19162018-02-27 09:44:27 +000032import com.android.settingslib.RestrictedLockUtils;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033
34/**
35 * List of Phone-specific settings screens.
36 */
37public class CdmaOptions {
38 private static final String LOG_TAG = "CdmaOptions";
39
40 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
41 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Alex Chaucfc19162018-02-27 09:44:27 +000042 private RestrictedPreference mButtonAPNExpand;
Malcolm Chen833d4ac2017-07-11 17:00:07 -070043 private Preference mCategoryAPNExpand;
44 private Preference mButtonCarrierSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045
46 private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
47 private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053048 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Malcolm Chen833d4ac2017-07-11 17:00:07 -070049 private static final String BUTTON_APN_EXPAND_KEY = "button_cdma_apn_key";
50 private static final String CATEGORY_APN_EXPAND_KEY = "category_cdma_apn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051
pkanward702e542017-02-08 15:44:54 -080052 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053 private PreferenceScreen mPrefScreen;
54 private Phone mPhone;
55
pkanward702e542017-02-08 15:44:54 -080056 public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
57 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080059 mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060
Malcolm Chen833d4ac2017-07-11 17:00:07 -070061 // Initialize preferences.
62 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen
63 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
64 mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
65 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
66 mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
Alex Chaucfc19162018-02-27 09:44:27 +000067 mButtonAPNExpand = (RestrictedPreference) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070068 mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
69
70 update(phone);
71 }
72
73 // Unlike mPrefFragment or mPrefScreen, mPhone may change during lifecycle of CdmaOptions.
74 // For example, a new sim card is inserted. When that happens, we update CdmaOptions with new
75 // phone.
76 protected void update(Phone phone) {
77 mPhone = phone;
78
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070079 PersistableBundle carrierConfig =
80 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri29386052015-04-23 17:35:28 -070081 // Some CDMA carriers want the APN settings.
Malcolm Chen833d4ac2017-07-11 17:00:07 -070082 boolean addAPNExpand =
83 carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
84 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) {
Alex Chaucfc19162018-02-27 09:44:27 +000097 mButtonAPNExpand.setDisabledByAdmin(
98 MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
99 ? RestrictedLockUtils.getDeviceOwner(mButtonAPNExpand.getContext())
100 : null);
Jing Zhao43e95622014-08-25 13:49:19 -0500101 mButtonAPNExpand.setOnPreferenceClickListener(
102 new Preference.OnPreferenceClickListener() {
103 @Override
104 public boolean onPreferenceClick(Preference preference) {
Malcolm Chen3f2dd682017-07-24 16:44:32 -0700105 MetricsLogger.action(mButtonAPNExpand.getContext(),
106 MetricsEvent.ACTION_MOBILE_NETWORK_APN_SETTINGS);
Jing Zhao43e95622014-08-25 13:49:19 -0500107 // We need to build the Intent by hand as the Preference Framework
108 // does not allow to add an Intent with some extras into a Preference
109 // XML file
110 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
111 // This will setup the Home and Search affordance
112 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe9674ff22014-12-18 10:24:22 -0800113 intent.putExtra("sub_id", mPhone.getSubId());
pkanward702e542017-02-08 15:44:54 -0800114 mPrefFragment.startActivity(intent);
Jing Zhao43e95622014-08-25 13:49:19 -0500115 return true;
116 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700117 });
118 mPrefScreen.addPreference(mCategoryAPNExpand);
119 } else {
120 mPrefScreen.removePreference(mCategoryAPNExpand);
Jing Zhao43e95622014-08-25 13:49:19 -0500121 }
122
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700123 if (addCdmaSubscription) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124 log("Both NV and Ruim supported, ENABLE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700125 mPrefScreen.addPreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 mButtonCdmaSubscription.setEnabled(true);
127 } else {
128 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700129 mPrefScreen.removePreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130 }
131
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700132 if (addCarrierSettings) {
133 mPrefScreen.addPreference(mButtonCarrierSettings);
134 } else {
135 mPrefScreen.removePreference(mButtonCarrierSettings);
Sandeep Gutta91007152014-07-01 12:05:52 +0530136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137 }
138
139 private boolean deviceSupportsNvAndRuim() {
140 // retrieve the list of subscription types supported by device.
141 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
142 boolean nvSupported = false;
143 boolean ruimSupported = false;
144
145 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
146 if (!TextUtils.isEmpty(subscriptionsSupported)) {
147 // Searches through the comma-separated list for a match for "NV"
148 // and "RUIM" to update nvSupported and ruimSupported.
149 for (String subscriptionType : subscriptionsSupported.split(",")) {
150 subscriptionType = subscriptionType.trim();
151 if (subscriptionType.equalsIgnoreCase("NV")) {
152 nvSupported = true;
153 }
154 if (subscriptionType.equalsIgnoreCase("RUIM")) {
155 ruimSupported = true;
156 }
157 }
158 }
159
160 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
161 " ruimSupported=" + ruimSupported);
162 return (nvSupported && ruimSupported);
163 }
164
165 public boolean preferenceTreeClick(Preference preference) {
166 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
167 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
168 return true;
169 }
170 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
171 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
172 return true;
173 }
174 return false;
175 }
176
177 public void showDialog(Preference preference) {
178 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
179 mButtonCdmaSystemSelect.showDialog(null);
180 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
181 mButtonCdmaSubscription.showDialog(null);
182 }
183 }
184
185 protected void log(String s) {
186 android.util.Log.d(LOG_TAG, s);
187 }
188}