blob: a02d3df12f277ef10575c72e720434903d9d1ebc [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import com.android.internal.telephony.TelephonyProperties;
35
36/**
37 * List of Phone-specific settings screens.
38 */
39public class CdmaOptions {
40 private static final String LOG_TAG = "CdmaOptions";
41
42 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
43 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
Jing Zhao43e95622014-08-25 13:49:19 -050044 private PreferenceScreen mButtonAPNExpand;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045
46 private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
47 private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053048 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Sanket Padawea564e9b2015-01-07 11:24:49 -080049 private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key_cdma";
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;
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070067 PersistableBundle carrierConfig =
68 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri29386052015-04-23 17:35:28 -070069 // Some CDMA carriers want the APN settings.
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070070 if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)
71 && 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
Sandeep Gutta91007152014-07-01 12:05:52 +0530109 // Read platform settings for carrier settings
Jonathan Basseri29386052015-04-23 17:35:28 -0700110 final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700111 CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
Sandeep Gutta91007152014-07-01 12:05:52 +0530112 if (!isCarrierSettingsEnabled) {
113 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
114 if (pref != null) {
115 mPrefScreen.removePreference(pref);
116 }
117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118 }
119
120 private boolean deviceSupportsNvAndRuim() {
121 // retrieve the list of subscription types supported by device.
122 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
123 boolean nvSupported = false;
124 boolean ruimSupported = false;
125
126 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
127 if (!TextUtils.isEmpty(subscriptionsSupported)) {
128 // Searches through the comma-separated list for a match for "NV"
129 // and "RUIM" to update nvSupported and ruimSupported.
130 for (String subscriptionType : subscriptionsSupported.split(",")) {
131 subscriptionType = subscriptionType.trim();
132 if (subscriptionType.equalsIgnoreCase("NV")) {
133 nvSupported = true;
134 }
135 if (subscriptionType.equalsIgnoreCase("RUIM")) {
136 ruimSupported = true;
137 }
138 }
139 }
140
141 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
142 " ruimSupported=" + ruimSupported);
143 return (nvSupported && ruimSupported);
144 }
145
146 public boolean preferenceTreeClick(Preference preference) {
147 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
148 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
149 return true;
150 }
151 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
152 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
153 return true;
154 }
155 return false;
156 }
157
158 public void showDialog(Preference preference) {
159 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
160 mButtonCdmaSystemSelect.showDialog(null);
161 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
162 mButtonCdmaSubscription.showDialog(null);
163 }
164 }
165
166 protected void log(String s) {
167 android.util.Log.d(LOG_TAG, s);
168 }
169}