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