blob: ee6a7380428c071b3172ed3369252cae3de59f64 [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;
PauloftheWest375e27d2014-12-08 08:43:07 -080043 private int mSubId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044
PauloftheWest375e27d2014-12-08 08:43:07 -080045 public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen,
46 final int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047 mPrefActivity = prefActivity;
48 mPrefScreen = prefScreen;
PauloftheWest375e27d2014-12-08 08:43:07 -080049 mSubId = subId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050 create();
51 }
52
53 protected void create() {
54 mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
55 mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070056 boolean removedAPNExpand = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057 mButtonOperatorSelectionExpand =
58 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059 if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
60 log("Not a GSM phone");
61 mButtonAPNExpand.setEnabled(false);
62 mButtonOperatorSelectionExpand.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063 } 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
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070070 // specific resources or device specific overlays.
71 if (!res.getBoolean(R.bool.config_apn_expand) && mButtonAPNExpand != null) {
72 mPrefScreen.removePreference(mButtonAPNExpand);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070073 removedAPNExpand = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074 }
75 if (!res.getBoolean(R.bool.config_operator_selection_expand)) {
76 mPrefScreen.removePreference(mPrefScreen
77 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
78 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079
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 }
Sandeep Gutta91007152014-07-01 12:05:52 +053090
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 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100 }
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700101 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);
PauloftheWest375e27d2014-12-08 08:43:07 -0800112 intent.putExtra("sub_id", mSubId);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700113 mPrefActivity.startActivity(intent);
114 return true;
115 }
116 });
117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118 }
119
120 public boolean preferenceTreeClick(Preference preference) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 log("preferenceTreeClick: return false");
122 return false;
123 }
124
125 protected void log(String s) {
126 android.util.Log.d(LOG_TAG, s);
127 }
128}