blob: 50a6def2d8fa4fed0023ce7a7c10a61909113e78 [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;
23import android.os.SystemProperties;
24import android.preference.Preference;
25import android.preference.PreferenceActivity;
26import android.preference.PreferenceScreen;
27import android.provider.Settings;
28import android.telephony.TelephonyManager;
29import android.text.TextUtils;
30
31import com.android.internal.telephony.Phone;
32import com.android.internal.telephony.PhoneConstants;
33import com.android.internal.telephony.TelephonyProperties;
34
35/**
36 * List of Phone-specific settings screens.
37 */
38public class CdmaOptions {
39 private static final String LOG_TAG = "CdmaOptions";
40
41 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
42 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Jing Zhao43e95622014-08-25 13:49:19 -050043 private PreferenceScreen mButtonAPNExpand;
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";
47 private static final String BUTTON_CDMA_ACTIVATE_DEVICE_KEY = "cdma_activate_device_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053048 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Jing Zhao43e95622014-08-25 13:49:19 -050049 private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050
51 private PreferenceActivity mPrefActivity;
52 private PreferenceScreen mPrefScreen;
53 private Phone mPhone;
54
55 public CdmaOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen, Phone phone) {
56 mPrefActivity = prefActivity;
57 mPrefScreen = prefScreen;
58 mPhone = phone;
59 create();
60 }
61
62 protected void create() {
63 mPrefActivity.addPreferencesFromResource(R.xml.cdma_options);
64
Jing Zhao43e95622014-08-25 13:49:19 -050065 mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
66 boolean removedAPNExpand = false;
67 Resources res = mPrefActivity.getResources();
68 // Some CDMA carriers want the APN settings
69 if (!res.getBoolean(R.bool.config_show_apn_setting_cdma) && mButtonAPNExpand != null) {
70 mPrefScreen.removePreference(mButtonAPNExpand);
71 removedAPNExpand = true;
72 }
73 if (!removedAPNExpand) {
74 mButtonAPNExpand.setOnPreferenceClickListener(
75 new Preference.OnPreferenceClickListener() {
76 @Override
77 public boolean onPreferenceClick(Preference preference) {
78 // We need to build the Intent by hand as the Preference Framework
79 // does not allow to add an Intent with some extras into a Preference
80 // XML file
81 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
82 // This will setup the Home and Search affordance
83 intent.putExtra(":settings:show_fragment_as_subsetting", true);
84 mPrefActivity.startActivity(intent);
85 return true;
86 }
87 });
88 }
89
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen
91 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
92
93 mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen
94 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
95
96 mButtonCdmaSystemSelect.setEnabled(true);
97 if(deviceSupportsNvAndRuim()) {
98 log("Both NV and Ruim supported, ENABLE subscription type selection");
99 mButtonCdmaSubscription.setEnabled(true);
100 } else {
101 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
102 mPrefScreen.removePreference(mPrefScreen
103 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY));
104 }
105
106 final boolean voiceCapable = mPrefActivity.getResources().getBoolean(
107 com.android.internal.R.bool.config_voice_capable);
108 final boolean isLTE = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
109 if (voiceCapable || isLTE) {
110 // This option should not be available on voice-capable devices (i.e. regular phones)
111 // and is replaced by the LTE data service item on LTE devices
112 mPrefScreen.removePreference(
113 mPrefScreen.findPreference(BUTTON_CDMA_ACTIVATE_DEVICE_KEY));
114 }
Sandeep Gutta91007152014-07-01 12:05:52 +0530115
116 // Read platform settings for carrier settings
117 final boolean isCarrierSettingsEnabled = mPrefActivity.getResources().getBoolean(
118 R.bool.config_carrier_settings_enable);
119 if (!isCarrierSettingsEnabled) {
120 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
121 if (pref != null) {
122 mPrefScreen.removePreference(pref);
123 }
124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125 }
126
127 private boolean deviceSupportsNvAndRuim() {
128 // retrieve the list of subscription types supported by device.
129 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
130 boolean nvSupported = false;
131 boolean ruimSupported = false;
132
133 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
134 if (!TextUtils.isEmpty(subscriptionsSupported)) {
135 // Searches through the comma-separated list for a match for "NV"
136 // and "RUIM" to update nvSupported and ruimSupported.
137 for (String subscriptionType : subscriptionsSupported.split(",")) {
138 subscriptionType = subscriptionType.trim();
139 if (subscriptionType.equalsIgnoreCase("NV")) {
140 nvSupported = true;
141 }
142 if (subscriptionType.equalsIgnoreCase("RUIM")) {
143 ruimSupported = true;
144 }
145 }
146 }
147
148 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
149 " ruimSupported=" + ruimSupported);
150 return (nvSupported && ruimSupported);
151 }
152
153 public boolean preferenceTreeClick(Preference preference) {
154 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
155 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
156 return true;
157 }
158 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
159 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
160 return true;
161 }
162 return false;
163 }
164
165 public void showDialog(Preference preference) {
166 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
167 mButtonCdmaSystemSelect.showDialog(null);
168 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
169 mButtonCdmaSubscription.showDialog(null);
170 }
171 }
172
173 protected void log(String s) {
174 android.util.Log.d(LOG_TAG, s);
175 }
176}