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.content.res.Resources;
     22 import android.net.Uri;
     23 import android.os.SystemProperties;
     24 import android.preference.Preference;
     25 import android.preference.PreferenceActivity;
     26 import android.preference.PreferenceScreen;
     27 import android.provider.Settings;
     28 import android.telephony.TelephonyManager;
     29 import android.text.TextUtils;
     30 
     31 import com.android.internal.telephony.Phone;
     32 import com.android.internal.telephony.PhoneConstants;
     33 import com.android.internal.telephony.TelephonyProperties;
     34 
     35 /**
     36  * List of Phone-specific settings screens.
     37  */
     38 public class CdmaOptions {
     39     private static final String LOG_TAG = "CdmaOptions";
     40 
     41     private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
     42     private CdmaSubscriptionListPreference mButtonCdmaSubscription;
     43     private PreferenceScreen mButtonAPNExpand;
     44 
     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";
     48     private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
     49     private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
     50 
     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 
     65         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 
     90         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         }
    115 
    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         }
    125     }
    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 }
    177