blob: 7c0926550fef34782982c7e74c38bba3b3d8241b [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032
33/**
34 * List of Phone-specific settings screens.
35 */
36public class CdmaOptions {
37 private static final String LOG_TAG = "CdmaOptions";
38
39 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
40 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Malcolm Chen833d4ac2017-07-11 17:00:07 -070041 private Preference mButtonAPNExpand;
42 private Preference mCategoryAPNExpand;
43 private Preference mButtonCarrierSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044
45 private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
46 private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053047 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Malcolm Chen833d4ac2017-07-11 17:00:07 -070048 private static final String BUTTON_APN_EXPAND_KEY = "button_cdma_apn_key";
49 private static final String CATEGORY_APN_EXPAND_KEY = "category_cdma_apn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050
pkanward702e542017-02-08 15:44:54 -080051 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052 private PreferenceScreen mPrefScreen;
53 private Phone mPhone;
54
pkanward702e542017-02-08 15:44:54 -080055 public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
56 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080058 mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059
Malcolm Chen833d4ac2017-07-11 17:00:07 -070060 // Initialize preferences.
61 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen
62 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
63 mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
64 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
65 mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
66 mButtonAPNExpand = mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
67 mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
68
69 update(phone);
70 }
71
72 // Unlike mPrefFragment or mPrefScreen, mPhone may change during lifecycle of CdmaOptions.
73 // For example, a new sim card is inserted. When that happens, we update CdmaOptions with new
74 // phone.
75 protected void update(Phone phone) {
76 mPhone = phone;
77
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070078 PersistableBundle carrierConfig =
79 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri29386052015-04-23 17:35:28 -070080 // Some CDMA carriers want the APN settings.
Malcolm Chen833d4ac2017-07-11 17:00:07 -070081 boolean addAPNExpand =
82 carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
83 boolean addCdmaSubscription =
84 deviceSupportsNvAndRuim();
85 // Read platform settings for carrier settings
86 boolean addCarrierSettings =
87 carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
88
89 mPrefScreen.addPreference(mButtonCdmaSystemSelect);
90 mButtonCdmaSystemSelect.setEnabled(true);
91
92 // Making no assumptions of whether they are added or removed at this point.
93 // Calling add or remove explicitly to make sure they are updated.
94
95 if (addAPNExpand) {
Jing Zhao43e95622014-08-25 13:49:19 -050096 mButtonAPNExpand.setOnPreferenceClickListener(
97 new Preference.OnPreferenceClickListener() {
98 @Override
99 public boolean onPreferenceClick(Preference preference) {
Malcolm Chen3f2dd682017-07-24 16:44:32 -0700100 MetricsLogger.action(mButtonAPNExpand.getContext(),
101 MetricsEvent.ACTION_MOBILE_NETWORK_APN_SETTINGS);
Jing Zhao43e95622014-08-25 13:49:19 -0500102 // We need to build the Intent by hand as the Preference Framework
103 // does not allow to add an Intent with some extras into a Preference
104 // XML file
105 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
106 // This will setup the Home and Search affordance
107 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe9674ff22014-12-18 10:24:22 -0800108 intent.putExtra("sub_id", mPhone.getSubId());
pkanward702e542017-02-08 15:44:54 -0800109 mPrefFragment.startActivity(intent);
Jing Zhao43e95622014-08-25 13:49:19 -0500110 return true;
111 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700112 });
113 mPrefScreen.addPreference(mCategoryAPNExpand);
114 } else {
115 mPrefScreen.removePreference(mCategoryAPNExpand);
Jing Zhao43e95622014-08-25 13:49:19 -0500116 }
117
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700118 if (addCdmaSubscription) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119 log("Both NV and Ruim supported, ENABLE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700120 mPrefScreen.addPreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 mButtonCdmaSubscription.setEnabled(true);
122 } else {
123 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700124 mPrefScreen.removePreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125 }
126
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700127 if (addCarrierSettings) {
128 mPrefScreen.addPreference(mButtonCarrierSettings);
129 } else {
130 mPrefScreen.removePreference(mButtonCarrierSettings);
Sandeep Gutta91007152014-07-01 12:05:52 +0530131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132 }
133
134 private boolean deviceSupportsNvAndRuim() {
135 // retrieve the list of subscription types supported by device.
136 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
137 boolean nvSupported = false;
138 boolean ruimSupported = false;
139
140 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
141 if (!TextUtils.isEmpty(subscriptionsSupported)) {
142 // Searches through the comma-separated list for a match for "NV"
143 // and "RUIM" to update nvSupported and ruimSupported.
144 for (String subscriptionType : subscriptionsSupported.split(",")) {
145 subscriptionType = subscriptionType.trim();
146 if (subscriptionType.equalsIgnoreCase("NV")) {
147 nvSupported = true;
148 }
149 if (subscriptionType.equalsIgnoreCase("RUIM")) {
150 ruimSupported = true;
151 }
152 }
153 }
154
155 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
156 " ruimSupported=" + ruimSupported);
157 return (nvSupported && ruimSupported);
158 }
159
160 public boolean preferenceTreeClick(Preference preference) {
161 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
162 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
163 return true;
164 }
165 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
166 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
167 return true;
168 }
169 return false;
170 }
171
172 public void showDialog(Preference preference) {
173 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
174 mButtonCdmaSystemSelect.showDialog(null);
175 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
176 mButtonCdmaSubscription.showDialog(null);
177 }
178 }
179
180 protected void log(String s) {
181 android.util.Log.d(LOG_TAG, s);
182 }
183}