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.Intent;
     20 import android.preference.Preference;
     21 import android.preference.PreferenceActivity;
     22 import android.preference.PreferenceScreen;
     23 import android.content.res.Resources;
     24 
     25 import android.provider.Settings;
     26 import com.android.internal.telephony.PhoneConstants;
     27 import com.android.internal.telephony.PhoneFactory;
     28 
     29 /**
     30  * List of Network-specific settings screens.
     31  */
     32 public class GsmUmtsOptions {
     33     private static final String LOG_TAG = "GsmUmtsOptions";
     34 
     35     private PreferenceScreen mButtonAPNExpand;
     36     private PreferenceScreen mButtonOperatorSelectionExpand;
     37 
     38     private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
     39     private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
     40     private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
     41     private PreferenceActivity mPrefActivity;
     42     private PreferenceScreen mPrefScreen;
     43 
     44     public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen) {
     45         mPrefActivity = prefActivity;
     46         mPrefScreen = prefScreen;
     47         create();
     48     }
     49 
     50     protected void create() {
     51         mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
     52         mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
     53         boolean removedAPNExpand = false;
     54         mButtonOperatorSelectionExpand =
     55                 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
     56         if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
     57             log("Not a GSM phone");
     58             mButtonAPNExpand.setEnabled(false);
     59             mButtonOperatorSelectionExpand.setEnabled(false);
     60         } else {
     61             log("Not a CDMA phone");
     62             Resources res = mPrefActivity.getResources();
     63 
     64             // Determine which options to display, for GSM these are defaulted
     65             // are defaulted to true in Phone/res/values/config.xml. But for
     66             // some operators like verizon they maybe overriden in operator
     67             // specific resources or device specific overlays.
     68             if (!res.getBoolean(R.bool.config_apn_expand) && mButtonAPNExpand != null) {
     69                 mPrefScreen.removePreference(mButtonAPNExpand);
     70                 removedAPNExpand = true;
     71             }
     72             if (!res.getBoolean(R.bool.config_operator_selection_expand)) {
     73                 mPrefScreen.removePreference(mPrefScreen
     74                         .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
     75             }
     76 
     77             if (res.getBoolean(R.bool.csp_enabled)) {
     78                 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
     79                     log("[CSP] Enabling Operator Selection menu.");
     80                     mButtonOperatorSelectionExpand.setEnabled(true);
     81                 } else {
     82                     log("[CSP] Disabling Operator Selection menu.");
     83                     mPrefScreen.removePreference(mPrefScreen
     84                           .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
     85                 }
     86             }
     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             }
     97         }
     98         if (!removedAPNExpand) {
     99             mButtonAPNExpand.setOnPreferenceClickListener(
    100                     new Preference.OnPreferenceClickListener() {
    101                         @Override
    102                         public boolean onPreferenceClick(Preference preference) {
    103                             // We need to build the Intent by hand as the Preference Framework
    104                             // does not allow to add an Intent with some extras into a Preference
    105                             // XML file
    106                             final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
    107                             // This will setup the Home and Search affordance
    108                             intent.putExtra(":settings:show_fragment_as_subsetting", true);
    109                             mPrefActivity.startActivity(intent);
    110                             return true;
    111                         }
    112             });
    113         }
    114     }
    115 
    116     public boolean preferenceTreeClick(Preference preference) {
    117         log("preferenceTreeClick: return false");
    118         return false;
    119     }
    120 
    121     protected void log(String s) {
    122         android.util.Log.d(LOG_TAG, s);
    123     }
    124 }
    125