blob: 87495655341893223b59a7de43dd726115a16322 [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
29import com.android.internal.telephony.Phone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030
31/**
32 * List of Phone-specific settings screens.
33 */
34public class CdmaOptions {
35 private static final String LOG_TAG = "CdmaOptions";
36
37 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
38 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Malcolm Chen833d4ac2017-07-11 17:00:07 -070039 private Preference mButtonAPNExpand;
40 private Preference mCategoryAPNExpand;
41 private Preference mButtonCarrierSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042
43 private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
44 private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053045 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Malcolm Chen833d4ac2017-07-11 17:00:07 -070046 private static final String BUTTON_APN_EXPAND_KEY = "button_cdma_apn_key";
47 private static final String CATEGORY_APN_EXPAND_KEY = "category_cdma_apn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048
pkanward702e542017-02-08 15:44:54 -080049 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050 private PreferenceScreen mPrefScreen;
51 private Phone mPhone;
52
pkanward702e542017-02-08 15:44:54 -080053 public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
54 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080056 mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057
Malcolm Chen833d4ac2017-07-11 17:00:07 -070058 // Initialize preferences.
59 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen
60 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
61 mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
62 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
63 mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
64 mButtonAPNExpand = mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
65 mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
66
67 update(phone);
68 }
69
70 // Unlike mPrefFragment or mPrefScreen, mPhone may change during lifecycle of CdmaOptions.
71 // For example, a new sim card is inserted. When that happens, we update CdmaOptions with new
72 // phone.
73 protected void update(Phone phone) {
74 mPhone = phone;
75
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070076 PersistableBundle carrierConfig =
77 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri29386052015-04-23 17:35:28 -070078 // Some CDMA carriers want the APN settings.
Malcolm Chen833d4ac2017-07-11 17:00:07 -070079 boolean addAPNExpand =
80 carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
81 boolean addCdmaSubscription =
82 deviceSupportsNvAndRuim();
83 // Read platform settings for carrier settings
84 boolean addCarrierSettings =
85 carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
86
87 mPrefScreen.addPreference(mButtonCdmaSystemSelect);
88 mButtonCdmaSystemSelect.setEnabled(true);
89
90 // Making no assumptions of whether they are added or removed at this point.
91 // Calling add or remove explicitly to make sure they are updated.
92
93 if (addAPNExpand) {
Jing Zhao43e95622014-08-25 13:49:19 -050094 mButtonAPNExpand.setOnPreferenceClickListener(
95 new Preference.OnPreferenceClickListener() {
96 @Override
97 public boolean onPreferenceClick(Preference preference) {
98 // We need to build the Intent by hand as the Preference Framework
99 // does not allow to add an Intent with some extras into a Preference
100 // XML file
101 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
102 // This will setup the Home and Search affordance
103 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe9674ff22014-12-18 10:24:22 -0800104 intent.putExtra("sub_id", mPhone.getSubId());
pkanward702e542017-02-08 15:44:54 -0800105 mPrefFragment.startActivity(intent);
Jing Zhao43e95622014-08-25 13:49:19 -0500106 return true;
107 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700108 });
109 mPrefScreen.addPreference(mCategoryAPNExpand);
110 } else {
111 mPrefScreen.removePreference(mCategoryAPNExpand);
Jing Zhao43e95622014-08-25 13:49:19 -0500112 }
113
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700114 if (addCdmaSubscription) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 log("Both NV and Ruim supported, ENABLE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700116 mPrefScreen.addPreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117 mButtonCdmaSubscription.setEnabled(true);
118 } else {
119 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700120 mPrefScreen.removePreference(mButtonCdmaSubscription);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 }
122
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700123 if (addCarrierSettings) {
124 mPrefScreen.addPreference(mButtonCarrierSettings);
125 } else {
126 mPrefScreen.removePreference(mButtonCarrierSettings);
Sandeep Gutta91007152014-07-01 12:05:52 +0530127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128 }
129
130 private boolean deviceSupportsNvAndRuim() {
131 // retrieve the list of subscription types supported by device.
132 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
133 boolean nvSupported = false;
134 boolean ruimSupported = false;
135
136 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
137 if (!TextUtils.isEmpty(subscriptionsSupported)) {
138 // Searches through the comma-separated list for a match for "NV"
139 // and "RUIM" to update nvSupported and ruimSupported.
140 for (String subscriptionType : subscriptionsSupported.split(",")) {
141 subscriptionType = subscriptionType.trim();
142 if (subscriptionType.equalsIgnoreCase("NV")) {
143 nvSupported = true;
144 }
145 if (subscriptionType.equalsIgnoreCase("RUIM")) {
146 ruimSupported = true;
147 }
148 }
149 }
150
151 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
152 " ruimSupported=" + ruimSupported);
153 return (nvSupported && ruimSupported);
154 }
155
156 public boolean preferenceTreeClick(Preference preference) {
157 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
158 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
159 return true;
160 }
161 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
162 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
163 return true;
164 }
165 return false;
166 }
167
168 public void showDialog(Preference preference) {
169 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
170 mButtonCdmaSystemSelect.showDialog(null);
171 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
172 mButtonCdmaSubscription.showDialog(null);
173 }
174 }
175
176 protected void log(String s) {
177 android.util.Log.d(LOG_TAG, s);
178 }
179}