blob: 5e0c324908ea785784074aec97395d33169c1644 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070019import android.content.Intent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070020import android.preference.Preference;
21import android.preference.PreferenceActivity;
22import android.preference.PreferenceScreen;
23import android.content.res.Resources;
24
25import com.android.internal.telephony.Phone;
26import com.android.internal.telephony.PhoneConstants;
27import com.android.internal.telephony.PhoneFactory;
28
29/**
30 * List of Network-specific settings screens.
31 */
32public class GsmUmtsOptions {
33 private static final String LOG_TAG = "GsmUmtsOptions";
34
35 private PreferenceScreen mButtonAPNExpand;
36 private PreferenceScreen mButtonOperatorSelectionExpand;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037
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";
Sandeep Gutta91007152014-07-01 12:05:52 +053040 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041 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);
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070053 mButtonAPNExpand.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
54 @Override
55 public boolean onPreferenceClick(Preference preference) {
56 // We need to build the Intent by hand as the Preference Framework does not allow
57 // to add an Intent with some extras into a Preference XML file
58 final Intent intent = new Intent("android.settings.APN_SETTINGS");
59 // This will setup the Home and Search affordance
60 intent.putExtra(":settings:show_fragment_as_subsetting", true);
61 mPrefActivity.startActivity(intent);
62 return true;
63 }
64 });
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065 mButtonOperatorSelectionExpand =
66 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067 if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
68 log("Not a GSM phone");
69 mButtonAPNExpand.setEnabled(false);
70 mButtonOperatorSelectionExpand.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071 } else {
72 log("Not a CDMA phone");
73 Resources res = mPrefActivity.getResources();
74
75 // Determine which options to display, for GSM these are defaulted
76 // are defaulted to true in Phone/res/values/config.xml. But for
77 // some operators like verizon they maybe overriden in operator
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070078 // specific resources or device specific overlays.
79 if (!res.getBoolean(R.bool.config_apn_expand) && mButtonAPNExpand != null) {
80 mPrefScreen.removePreference(mButtonAPNExpand);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081 }
82 if (!res.getBoolean(R.bool.config_operator_selection_expand)) {
83 mPrefScreen.removePreference(mPrefScreen
84 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
85 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086
87 if (res.getBoolean(R.bool.csp_enabled)) {
88 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
89 log("[CSP] Enabling Operator Selection menu.");
90 mButtonOperatorSelectionExpand.setEnabled(true);
91 } else {
92 log("[CSP] Disabling Operator Selection menu.");
93 mPrefScreen.removePreference(mPrefScreen
94 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
95 }
96 }
Sandeep Gutta91007152014-07-01 12:05:52 +053097
98 // Read platform settings for carrier settings
99 final boolean isCarrierSettingsEnabled = mPrefActivity.getResources().getBoolean(
100 R.bool.config_carrier_settings_enable);
101 if (!isCarrierSettingsEnabled) {
102 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
103 if (pref != null) {
104 mPrefScreen.removePreference(pref);
105 }
106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 }
108 }
109
110 public boolean preferenceTreeClick(Preference preference) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111 log("preferenceTreeClick: return false");
112 return false;
113 }
114
115 protected void log(String s) {
116 android.util.Log.d(LOG_TAG, s);
117 }
118}