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