blob: 8964cb5acaa1d8c73df5d459cdf089b62d9722e3 [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
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070025import android.provider.Settings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import 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 Megliofbd80c02014-08-15 12:54:24 -070053 boolean removedAPNExpand = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054 mButtonOperatorSelectionExpand =
55 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056 if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
57 log("Not a GSM phone");
58 mButtonAPNExpand.setEnabled(false);
59 mButtonOperatorSelectionExpand.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060 } 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
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070067 // specific resources or device specific overlays.
68 if (!res.getBoolean(R.bool.config_apn_expand) && mButtonAPNExpand != null) {
69 mPrefScreen.removePreference(mButtonAPNExpand);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070070 removedAPNExpand = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071 }
72 if (!res.getBoolean(R.bool.config_operator_selection_expand)) {
73 mPrefScreen.removePreference(mPrefScreen
74 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
75 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076
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 }
Sandeep Gutta91007152014-07-01 12:05:52 +053087
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 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097 }
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070098 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 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114 }
115
116 public boolean preferenceTreeClick(Preference preference) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117 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}