blob: eabbdd2452d24df834dc146492307b76886de487 [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
19import android.content.Context;
20import android.content.Intent;
Jing Zhao43e95622014-08-25 13:49:19 -050021import android.content.res.Resources;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.net.Uri;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070023import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.os.SystemProperties;
25import android.preference.Preference;
26import android.preference.PreferenceActivity;
27import android.preference.PreferenceScreen;
28import android.provider.Settings;
Jonathan Basseri29386052015-04-23 17:35:28 -070029import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.telephony.TelephonyManager;
31import android.text.TextUtils;
32
33import com.android.internal.telephony.Phone;
34import com.android.internal.telephony.PhoneConstants;
35import com.android.internal.telephony.TelephonyProperties;
36
37/**
38 * List of Phone-specific settings screens.
39 */
40public class CdmaOptions {
41 private static final String LOG_TAG = "CdmaOptions";
42
43 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
44 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Jing Zhao43e95622014-08-25 13:49:19 -050045 private PreferenceScreen mButtonAPNExpand;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046
47 private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
48 private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
49 private static final String BUTTON_CDMA_ACTIVATE_DEVICE_KEY = "cdma_activate_device_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053050 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Sanket Padawea564e9b2015-01-07 11:24:49 -080051 private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key_cdma";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052
53 private PreferenceActivity mPrefActivity;
54 private PreferenceScreen mPrefScreen;
55 private Phone mPhone;
56
57 public CdmaOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen, Phone phone) {
58 mPrefActivity = prefActivity;
59 mPrefScreen = prefScreen;
60 mPhone = phone;
61 create();
62 }
63
64 protected void create() {
65 mPrefActivity.addPreferencesFromResource(R.xml.cdma_options);
66
Jing Zhao43e95622014-08-25 13:49:19 -050067 mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
68 boolean removedAPNExpand = false;
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070069 PersistableBundle carrierConfig =
70 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri29386052015-04-23 17:35:28 -070071 // Some CDMA carriers want the APN settings.
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070072 if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)
73 && mButtonAPNExpand != null) {
Jing Zhao43e95622014-08-25 13:49:19 -050074 mPrefScreen.removePreference(mButtonAPNExpand);
75 removedAPNExpand = true;
76 }
77 if (!removedAPNExpand) {
78 mButtonAPNExpand.setOnPreferenceClickListener(
79 new Preference.OnPreferenceClickListener() {
80 @Override
81 public boolean onPreferenceClick(Preference preference) {
82 // We need to build the Intent by hand as the Preference Framework
83 // does not allow to add an Intent with some extras into a Preference
84 // XML file
85 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
86 // This will setup the Home and Search affordance
87 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe9674ff22014-12-18 10:24:22 -080088 intent.putExtra("sub_id", mPhone.getSubId());
Jing Zhao43e95622014-08-25 13:49:19 -050089 mPrefActivity.startActivity(intent);
90 return true;
91 }
92 });
93 }
94
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen
96 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
97
98 mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen
99 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
100
101 mButtonCdmaSystemSelect.setEnabled(true);
102 if(deviceSupportsNvAndRuim()) {
103 log("Both NV and Ruim supported, ENABLE subscription type selection");
104 mButtonCdmaSubscription.setEnabled(true);
105 } else {
106 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
107 mPrefScreen.removePreference(mPrefScreen
108 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY));
109 }
110
111 final boolean voiceCapable = mPrefActivity.getResources().getBoolean(
112 com.android.internal.R.bool.config_voice_capable);
113 final boolean isLTE = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
114 if (voiceCapable || isLTE) {
115 // This option should not be available on voice-capable devices (i.e. regular phones)
116 // and is replaced by the LTE data service item on LTE devices
117 mPrefScreen.removePreference(
118 mPrefScreen.findPreference(BUTTON_CDMA_ACTIVATE_DEVICE_KEY));
119 }
Sandeep Gutta91007152014-07-01 12:05:52 +0530120
121 // Read platform settings for carrier settings
Jonathan Basseri29386052015-04-23 17:35:28 -0700122 final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700123 CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
Sandeep Gutta91007152014-07-01 12:05:52 +0530124 if (!isCarrierSettingsEnabled) {
125 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
126 if (pref != null) {
127 mPrefScreen.removePreference(pref);
128 }
129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130 }
131
132 private boolean deviceSupportsNvAndRuim() {
133 // retrieve the list of subscription types supported by device.
134 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
135 boolean nvSupported = false;
136 boolean ruimSupported = false;
137
138 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
139 if (!TextUtils.isEmpty(subscriptionsSupported)) {
140 // Searches through the comma-separated list for a match for "NV"
141 // and "RUIM" to update nvSupported and ruimSupported.
142 for (String subscriptionType : subscriptionsSupported.split(",")) {
143 subscriptionType = subscriptionType.trim();
144 if (subscriptionType.equalsIgnoreCase("NV")) {
145 nvSupported = true;
146 }
147 if (subscriptionType.equalsIgnoreCase("RUIM")) {
148 ruimSupported = true;
149 }
150 }
151 }
152
153 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
154 " ruimSupported=" + ruimSupported);
155 return (nvSupported && ruimSupported);
156 }
157
158 public boolean preferenceTreeClick(Preference preference) {
159 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
160 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
161 return true;
162 }
163 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
164 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
165 return true;
166 }
167 return false;
168 }
169
170 public void showDialog(Preference preference) {
171 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
172 mButtonCdmaSystemSelect.showDialog(null);
173 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
174 mButtonCdmaSubscription.showDialog(null);
175 }
176 }
177
178 protected void log(String s) {
179 android.util.Log.d(LOG_TAG, s);
180 }
181}