blob: a760cda87fcc73b8dce832f9205b93dfacf6576e [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;
pkanwarc8a02842017-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 -070030import com.android.internal.telephony.TelephonyProperties;
31
32/**
33 * List of Phone-specific settings screens.
34 */
35public class CdmaOptions {
36 private static final String LOG_TAG = "CdmaOptions";
37
38 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
39 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Jing Zhao43e95622014-08-25 13:49:19 -050040 private PreferenceScreen mButtonAPNExpand;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041
42 private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
43 private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053044 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Sanket Padawea564e9b2015-01-07 11:24:49 -080045 private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key_cdma";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046
pkanwarc8a02842017-02-08 15:44:54 -080047 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048 private PreferenceScreen mPrefScreen;
49 private Phone mPhone;
50
pkanwarc8a02842017-02-08 15:44:54 -080051 public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
52 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053 mPrefScreen = prefScreen;
54 mPhone = phone;
55 create();
56 }
57
58 protected void create() {
pkanwarc8a02842017-02-08 15:44:54 -080059 mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060
Jing Zhao43e95622014-08-25 13:49:19 -050061 mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
62 boolean removedAPNExpand = false;
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070063 PersistableBundle carrierConfig =
64 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri29386052015-04-23 17:35:28 -070065 // Some CDMA carriers want the APN settings.
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070066 if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)
67 && mButtonAPNExpand != null) {
Jing Zhao43e95622014-08-25 13:49:19 -050068 mPrefScreen.removePreference(mButtonAPNExpand);
69 removedAPNExpand = true;
70 }
71 if (!removedAPNExpand) {
72 mButtonAPNExpand.setOnPreferenceClickListener(
73 new Preference.OnPreferenceClickListener() {
74 @Override
75 public boolean onPreferenceClick(Preference preference) {
76 // We need to build the Intent by hand as the Preference Framework
77 // does not allow to add an Intent with some extras into a Preference
78 // XML file
79 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
80 // This will setup the Home and Search affordance
81 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe9674ff22014-12-18 10:24:22 -080082 intent.putExtra("sub_id", mPhone.getSubId());
pkanwarc8a02842017-02-08 15:44:54 -080083 mPrefFragment.startActivity(intent);
Jing Zhao43e95622014-08-25 13:49:19 -050084 return true;
85 }
86 });
87 }
88
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen
90 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
91
92 mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen
93 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
94
95 mButtonCdmaSystemSelect.setEnabled(true);
96 if(deviceSupportsNvAndRuim()) {
97 log("Both NV and Ruim supported, ENABLE subscription type selection");
98 mButtonCdmaSubscription.setEnabled(true);
99 } else {
100 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
101 mPrefScreen.removePreference(mPrefScreen
102 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY));
103 }
104
Sandeep Gutta91007152014-07-01 12:05:52 +0530105 // Read platform settings for carrier settings
Jonathan Basseri29386052015-04-23 17:35:28 -0700106 final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700107 CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
Sandeep Gutta91007152014-07-01 12:05:52 +0530108 if (!isCarrierSettingsEnabled) {
109 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
110 if (pref != null) {
111 mPrefScreen.removePreference(pref);
112 }
113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114 }
115
116 private boolean deviceSupportsNvAndRuim() {
117 // retrieve the list of subscription types supported by device.
118 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
119 boolean nvSupported = false;
120 boolean ruimSupported = false;
121
122 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
123 if (!TextUtils.isEmpty(subscriptionsSupported)) {
124 // Searches through the comma-separated list for a match for "NV"
125 // and "RUIM" to update nvSupported and ruimSupported.
126 for (String subscriptionType : subscriptionsSupported.split(",")) {
127 subscriptionType = subscriptionType.trim();
128 if (subscriptionType.equalsIgnoreCase("NV")) {
129 nvSupported = true;
130 }
131 if (subscriptionType.equalsIgnoreCase("RUIM")) {
132 ruimSupported = true;
133 }
134 }
135 }
136
137 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
138 " ruimSupported=" + ruimSupported);
139 return (nvSupported && ruimSupported);
140 }
141
142 public boolean preferenceTreeClick(Preference preference) {
143 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
144 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
145 return true;
146 }
147 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
148 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
149 return true;
150 }
151 return false;
152 }
153
154 public void showDialog(Preference preference) {
155 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
156 mButtonCdmaSystemSelect.showDialog(null);
157 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
158 mButtonCdmaSubscription.showDialog(null);
159 }
160 }
161
162 protected void log(String s) {
163 android.util.Log.d(LOG_TAG, s);
164 }
165}