blob: 2e9d88a52f23a018a74d1d8372ee5b23f786a429 [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
Jonathan Basseri29386052015-04-23 17:35:28 -070019import android.content.Context;
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070020import android.content.Intent;
Jonathan Basseri29386052015-04-23 17:35:28 -070021import android.content.res.Resources;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070022import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.preference.Preference;
24import android.preference.PreferenceActivity;
25import android.preference.PreferenceScreen;
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070026import android.provider.Settings;
Jonathan Basseri29386052015-04-23 17:35:28 -070027import android.telephony.CarrierConfigManager;
Sanket Padawe3e1073d2015-07-15 18:28:12 -070028import android.content.ComponentName;
Jonathan Basseri29386052015-04-23 17:35:28 -070029
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import com.android.internal.telephony.PhoneConstants;
31import com.android.internal.telephony.PhoneFactory;
32
33/**
34 * List of Network-specific settings screens.
35 */
36public class GsmUmtsOptions {
37 private static final String LOG_TAG = "GsmUmtsOptions";
38
39 private PreferenceScreen mButtonAPNExpand;
40 private PreferenceScreen mButtonOperatorSelectionExpand;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041
42 private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
43 private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053044 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Sanket Padawe3e1073d2015-07-15 18:28:12 -070045 public static final String EXTRA_SUB_ID = "sub_id";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046 private PreferenceActivity mPrefActivity;
47 private PreferenceScreen mPrefScreen;
PauloftheWest375e27d2014-12-08 08:43:07 -080048 private int mSubId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049
PauloftheWest375e27d2014-12-08 08:43:07 -080050 public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen,
51 final int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052 mPrefActivity = prefActivity;
53 mPrefScreen = prefScreen;
PauloftheWest375e27d2014-12-08 08:43:07 -080054 mSubId = subId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055 create();
56 }
57
58 protected void create() {
59 mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
60 mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070061 boolean removedAPNExpand = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062 mButtonOperatorSelectionExpand =
63 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064 if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
65 log("Not a GSM phone");
66 mButtonAPNExpand.setEnabled(false);
67 mButtonOperatorSelectionExpand.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068 } else {
69 log("Not a CDMA phone");
70 Resources res = mPrefActivity.getResources();
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070071 PersistableBundle carrierConfig =
72 PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073
Jonathan Basseri29386052015-04-23 17:35:28 -070074 // Determine which options to display. For GSM these are defaulted to true in
75 // CarrierConfigManager, but they maybe overriden by DefaultCarrierConfigService or a
76 // carrier app.
77 // Note: these settings used to be controlled with overlays in
78 // Telephony/res/values/config.xml
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070079 if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL)
80 && mButtonAPNExpand != null) {
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070081 mPrefScreen.removePreference(mButtonAPNExpand);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070082 removedAPNExpand = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070084 if (!carrierConfig.getBoolean(
85 CarrierConfigManager.KEY_OPERATOR_SELECTION_EXPAND_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086 mPrefScreen.removePreference(mPrefScreen
87 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
88 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089
Jonathan Basserif180dc72015-06-19 13:47:51 -070090 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_CSP_ENABLED_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
92 log("[CSP] Enabling Operator Selection menu.");
93 mButtonOperatorSelectionExpand.setEnabled(true);
94 } else {
95 log("[CSP] Disabling Operator Selection menu.");
96 mPrefScreen.removePreference(mPrefScreen
97 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
98 }
99 }
Sandeep Gutta91007152014-07-01 12:05:52 +0530100
101 // Read platform settings for carrier settings
Jonathan Basseri29386052015-04-23 17:35:28 -0700102 final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700103 CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
Sandeep Gutta91007152014-07-01 12:05:52 +0530104 if (!isCarrierSettingsEnabled) {
105 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
106 if (pref != null) {
107 mPrefScreen.removePreference(pref);
108 }
109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110 }
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700111 if (!removedAPNExpand) {
112 mButtonAPNExpand.setOnPreferenceClickListener(
113 new Preference.OnPreferenceClickListener() {
114 @Override
115 public boolean onPreferenceClick(Preference preference) {
116 // We need to build the Intent by hand as the Preference Framework
117 // does not allow to add an Intent with some extras into a Preference
118 // XML file
119 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
120 // This will setup the Home and Search affordance
121 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Sanket Padawe3e1073d2015-07-15 18:28:12 -0700122 intent.putExtra(EXTRA_SUB_ID, mSubId);
123 mPrefActivity.startActivity(intent);
124 return true;
125 }
126 });
127 }
128 if (mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY) != null) {
129 mButtonOperatorSelectionExpand.setOnPreferenceClickListener(
130 new Preference.OnPreferenceClickListener() {
131 @Override
132 public boolean onPreferenceClick(Preference preference) {
133 final Intent intent = new Intent(Intent.ACTION_MAIN);
134 intent.setComponent(new ComponentName("com.android.phone",
135 "com.android.phone.NetworkSetting"));
136 intent.putExtra(EXTRA_SUB_ID, mSubId);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700137 mPrefActivity.startActivity(intent);
138 return true;
139 }
140 });
141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142 }
143
144 public boolean preferenceTreeClick(Preference preference) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 log("preferenceTreeClick: return false");
146 return false;
147 }
148
149 protected void log(String s) {
150 android.util.Log.d(LOG_TAG, s);
151 }
152}