blob: fa3db1364b7d18b42eaa6e40cf050606698dcc4e [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 Basseri29386052015-04-23 17:35:28 -070023import android.os.Bundle;
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 Basseri29386052015-04-23 17:35:28 -070069 Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
70 // Some CDMA carriers want the APN settings.
71 if (!carrierConfig.getBoolean(CarrierConfigManager.BOOL_SHOW_APN_SETTING_CDMA) && mButtonAPNExpand != null) {
Jing Zhao43e95622014-08-25 13:49:19 -050072 mPrefScreen.removePreference(mButtonAPNExpand);
73 removedAPNExpand = true;
74 }
75 if (!removedAPNExpand) {
76 mButtonAPNExpand.setOnPreferenceClickListener(
77 new Preference.OnPreferenceClickListener() {
78 @Override
79 public boolean onPreferenceClick(Preference preference) {
80 // We need to build the Intent by hand as the Preference Framework
81 // does not allow to add an Intent with some extras into a Preference
82 // XML file
83 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
84 // This will setup the Home and Search affordance
85 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe9674ff22014-12-18 10:24:22 -080086 intent.putExtra("sub_id", mPhone.getSubId());
Jing Zhao43e95622014-08-25 13:49:19 -050087 mPrefActivity.startActivity(intent);
88 return true;
89 }
90 });
91 }
92
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen
94 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
95
96 mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen
97 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
98
99 mButtonCdmaSystemSelect.setEnabled(true);
100 if(deviceSupportsNvAndRuim()) {
101 log("Both NV and Ruim supported, ENABLE subscription type selection");
102 mButtonCdmaSubscription.setEnabled(true);
103 } else {
104 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
105 mPrefScreen.removePreference(mPrefScreen
106 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY));
107 }
108
109 final boolean voiceCapable = mPrefActivity.getResources().getBoolean(
110 com.android.internal.R.bool.config_voice_capable);
111 final boolean isLTE = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
112 if (voiceCapable || isLTE) {
113 // This option should not be available on voice-capable devices (i.e. regular phones)
114 // and is replaced by the LTE data service item on LTE devices
115 mPrefScreen.removePreference(
116 mPrefScreen.findPreference(BUTTON_CDMA_ACTIVATE_DEVICE_KEY));
117 }
Sandeep Gutta91007152014-07-01 12:05:52 +0530118
119 // Read platform settings for carrier settings
Jonathan Basseri29386052015-04-23 17:35:28 -0700120 final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
121 CarrierConfigManager.BOOL_CARRIER_SETTINGS_ENABLE);
Sandeep Gutta91007152014-07-01 12:05:52 +0530122 if (!isCarrierSettingsEnabled) {
123 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
124 if (pref != null) {
125 mPrefScreen.removePreference(pref);
126 }
127 }
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}