blob: 3e3c8b5de4320ae43e3f82271943beb641e0da5d [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;
21import android.net.Uri;
22import android.os.SystemProperties;
23import android.preference.Preference;
24import android.preference.PreferenceActivity;
25import android.preference.PreferenceScreen;
26import android.provider.Settings;
27import android.telephony.TelephonyManager;
28import android.text.TextUtils;
29
30import com.android.internal.telephony.Phone;
31import com.android.internal.telephony.PhoneConstants;
32import com.android.internal.telephony.TelephonyProperties;
33
34/**
35 * List of Phone-specific settings screens.
36 */
37public class CdmaOptions {
38 private static final String LOG_TAG = "CdmaOptions";
39
40 private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
41 private CdmaSubscriptionListPreference mButtonCdmaSubscription;
42
43 private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
44 private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
45 private static final String BUTTON_CDMA_ACTIVATE_DEVICE_KEY = "cdma_activate_device_key";
46
47 private PreferenceActivity mPrefActivity;
48 private PreferenceScreen mPrefScreen;
49 private Phone mPhone;
50
51 public CdmaOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen, Phone phone) {
52 mPrefActivity = prefActivity;
53 mPrefScreen = prefScreen;
54 mPhone = phone;
55 create();
56 }
57
58 protected void create() {
59 mPrefActivity.addPreferencesFromResource(R.xml.cdma_options);
60
61 mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen
62 .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
63
64 mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen
65 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
66
67 mButtonCdmaSystemSelect.setEnabled(true);
68 if(deviceSupportsNvAndRuim()) {
69 log("Both NV and Ruim supported, ENABLE subscription type selection");
70 mButtonCdmaSubscription.setEnabled(true);
71 } else {
72 log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
73 mPrefScreen.removePreference(mPrefScreen
74 .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY));
75 }
76
77 final boolean voiceCapable = mPrefActivity.getResources().getBoolean(
78 com.android.internal.R.bool.config_voice_capable);
79 final boolean isLTE = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
80 if (voiceCapable || isLTE) {
81 // This option should not be available on voice-capable devices (i.e. regular phones)
82 // and is replaced by the LTE data service item on LTE devices
83 mPrefScreen.removePreference(
84 mPrefScreen.findPreference(BUTTON_CDMA_ACTIVATE_DEVICE_KEY));
85 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086 }
87
88 private boolean deviceSupportsNvAndRuim() {
89 // retrieve the list of subscription types supported by device.
90 String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
91 boolean nvSupported = false;
92 boolean ruimSupported = false;
93
94 log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
95 if (!TextUtils.isEmpty(subscriptionsSupported)) {
96 // Searches through the comma-separated list for a match for "NV"
97 // and "RUIM" to update nvSupported and ruimSupported.
98 for (String subscriptionType : subscriptionsSupported.split(",")) {
99 subscriptionType = subscriptionType.trim();
100 if (subscriptionType.equalsIgnoreCase("NV")) {
101 nvSupported = true;
102 }
103 if (subscriptionType.equalsIgnoreCase("RUIM")) {
104 ruimSupported = true;
105 }
106 }
107 }
108
109 log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
110 " ruimSupported=" + ruimSupported);
111 return (nvSupported && ruimSupported);
112 }
113
114 public boolean preferenceTreeClick(Preference preference) {
115 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
116 log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
117 return true;
118 }
119 if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
120 log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
121 return true;
122 }
123 return false;
124 }
125
126 public void showDialog(Preference preference) {
127 if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
128 mButtonCdmaSystemSelect.showDialog(null);
129 } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
130 mButtonCdmaSubscription.showDialog(null);
131 }
132 }
133
134 protected void log(String s) {
135 android.util.Log.d(LOG_TAG, s);
136 }
137}