• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     private int mSubId;
44 
GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen, final int subId)45     public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen,
46             final int subId) {
47         mPrefActivity = prefActivity;
48         mPrefScreen = prefScreen;
49         mSubId = subId;
50         create();
51     }
52 
create()53     protected void create() {
54         mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
55         mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
56         boolean removedAPNExpand = false;
57         mButtonOperatorSelectionExpand =
58                 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
59         if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
60             log("Not a GSM phone");
61             mButtonAPNExpand.setEnabled(false);
62             mButtonOperatorSelectionExpand.setEnabled(false);
63         } else {
64             log("Not a CDMA phone");
65             Resources res = mPrefActivity.getResources();
66 
67             // Determine which options to display, for GSM these are defaulted
68             // are defaulted to true in Phone/res/values/config.xml. But for
69             // some operators like verizon they maybe overriden in operator
70             // specific resources or device specific overlays.
71             if (!res.getBoolean(R.bool.config_apn_expand) && mButtonAPNExpand != null) {
72                 mPrefScreen.removePreference(mButtonAPNExpand);
73                 removedAPNExpand = true;
74             }
75             if (!res.getBoolean(R.bool.config_operator_selection_expand)) {
76                 mPrefScreen.removePreference(mPrefScreen
77                         .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
78             }
79 
80             if (res.getBoolean(R.bool.csp_enabled)) {
81                 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
82                     log("[CSP] Enabling Operator Selection menu.");
83                     mButtonOperatorSelectionExpand.setEnabled(true);
84                 } else {
85                     log("[CSP] Disabling Operator Selection menu.");
86                     mPrefScreen.removePreference(mPrefScreen
87                           .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
88                 }
89             }
90 
91             // Read platform settings for carrier settings
92             final boolean isCarrierSettingsEnabled = mPrefActivity.getResources().getBoolean(
93                     R.bool.config_carrier_settings_enable);
94             if (!isCarrierSettingsEnabled) {
95                 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
96                 if (pref != null) {
97                     mPrefScreen.removePreference(pref);
98                 }
99             }
100         }
101         if (!removedAPNExpand) {
102             mButtonAPNExpand.setOnPreferenceClickListener(
103                     new Preference.OnPreferenceClickListener() {
104                         @Override
105                         public boolean onPreferenceClick(Preference preference) {
106                             // We need to build the Intent by hand as the Preference Framework
107                             // does not allow to add an Intent with some extras into a Preference
108                             // XML file
109                             final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
110                             // This will setup the Home and Search affordance
111                             intent.putExtra(":settings:show_fragment_as_subsetting", true);
112                             intent.putExtra("sub_id", mSubId);
113                             mPrefActivity.startActivity(intent);
114                             return true;
115                         }
116             });
117         }
118     }
119 
preferenceTreeClick(Preference preference)120     public boolean preferenceTreeClick(Preference preference) {
121         log("preferenceTreeClick: return false");
122         return false;
123     }
124 
log(String s)125     protected void log(String s) {
126         android.util.Log.d(LOG_TAG, s);
127     }
128 }
129