blob: a68b1cb453ef37967283dec3ac98e7c3dc25ba73 [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;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070020import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.preference.Preference;
pkanward702e542017-02-08 15:44:54 -080022import android.preference.PreferenceFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.preference.PreferenceScreen;
Malcolm Chen39aa7912017-06-05 19:02:16 -070024import android.preference.TwoStatePreference;
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070025import android.provider.Settings;
Jonathan Basseri29386052015-04-23 17:35:28 -070026import android.telephony.CarrierConfigManager;
27
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import com.android.internal.telephony.PhoneConstants;
29import com.android.internal.telephony.PhoneFactory;
30
31/**
32 * List of Network-specific settings screens.
33 */
34public class GsmUmtsOptions {
35 private static final String LOG_TAG = "GsmUmtsOptions";
36
Malcolm Chen7b486ea2017-06-28 12:30:18 -070037 private Preference mButtonAPNExpand;
38 private Preference mCategoryAPNExpand;
Malcolm Chen833d4ac2017-07-11 17:00:07 -070039 Preference mCarrierSettingPref;
Malcolm Chen39aa7912017-06-05 19:02:16 -070040
41 private NetworkOperators mNetworkOperator;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042
Malcolm Chen833d4ac2017-07-11 17:00:07 -070043 private static final String BUTTON_APN_EXPAND_KEY = "button_gsm_apn_key";
44 private static final String CATEGORY_APN_EXPAND_KEY = "category_gsm_apn_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053045 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Malcolm Chen39aa7912017-06-05 19:02:16 -070046
Sanket Padawe3e1073d2015-07-15 18:28:12 -070047 public static final String EXTRA_SUB_ID = "sub_id";
pkanward702e542017-02-08 15:44:54 -080048 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049 private PreferenceScreen mPrefScreen;
50
pkanward702e542017-02-08 15:44:54 -080051 public GsmUmtsOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen,
Malcolm Chen39aa7912017-06-05 19:02:16 -070052 final int subId, INetworkQueryService queryService) {
pkanward702e542017-02-08 15:44:54 -080053 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080055 mPrefFragment.addPreferencesFromResource(R.xml.gsm_umts_options);
Malcolm Chen7b486ea2017-06-28 12:30:18 -070056 mButtonAPNExpand = mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
57 mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
Malcolm Chen39aa7912017-06-05 19:02:16 -070058 mNetworkOperator = (NetworkOperators) mPrefScreen
59 .findPreference(NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070060 mCarrierSettingPref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
Malcolm Chen39aa7912017-06-05 19:02:16 -070061
Malcolm Chen833d4ac2017-07-11 17:00:07 -070062 mNetworkOperator.initialize();
63
64 update(subId, queryService);
65 }
66
67 // Unlike mPrefFragment or mPrefScreen, subId or queryService may change during lifecycle of
68 // GsmUmtsOptions. When that happens, we update GsmUmtsOptions with new parameters.
69 protected void update(final int subId, INetworkQueryService queryService) {
70 boolean addAPNExpand = true;
71 boolean addNetworkOperatorsCategory = true;
72 boolean addCarrierSettings = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073 if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
74 log("Not a GSM phone");
Malcolm Chen7b486ea2017-06-28 12:30:18 -070075 mCategoryAPNExpand.setEnabled(false);
Malcolm Chen39aa7912017-06-05 19:02:16 -070076 mNetworkOperator.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077 } else {
78 log("Not a CDMA phone");
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070079 PersistableBundle carrierConfig =
Malcolm Chen833d4ac2017-07-11 17:00:07 -070080 PhoneGlobals.getInstance().getCarrierConfigForSubId(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081
Jonathan Basseri29386052015-04-23 17:35:28 -070082 // Determine which options to display. For GSM these are defaulted to true in
83 // CarrierConfigManager, but they maybe overriden by DefaultCarrierConfigService or a
84 // carrier app.
85 // Note: these settings used to be controlled with overlays in
86 // Telephony/res/values/config.xml
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070087 if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL)
Malcolm Chen7b486ea2017-06-28 12:30:18 -070088 && mCategoryAPNExpand != null) {
Malcolm Chen833d4ac2017-07-11 17:00:07 -070089 addAPNExpand = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070091 if (!carrierConfig.getBoolean(
92 CarrierConfigManager.KEY_OPERATOR_SELECTION_EXPAND_BOOL)) {
Malcolm Chen833d4ac2017-07-11 17:00:07 -070093 addNetworkOperatorsCategory = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095
Jonathan Basserif180dc72015-06-19 13:47:51 -070096 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_CSP_ENABLED_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
98 log("[CSP] Enabling Operator Selection menu.");
Malcolm Chen39aa7912017-06-05 19:02:16 -070099 mNetworkOperator.setEnabled(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100 } else {
101 log("[CSP] Disabling Operator Selection menu.");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700102 addNetworkOperatorsCategory = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103 }
104 }
Sandeep Gutta91007152014-07-01 12:05:52 +0530105
106 // Read platform settings for carrier settings
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700107 addCarrierSettings = carrierConfig.getBoolean(
108 CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700110
111 // Making no assumptions of whether they are added or removed at this point.
112 // Calling add or remove explicitly to make sure they are updated.
113
114 if (addAPNExpand) {
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700115 mButtonAPNExpand.setOnPreferenceClickListener(
116 new Preference.OnPreferenceClickListener() {
117 @Override
118 public boolean onPreferenceClick(Preference preference) {
119 // We need to build the Intent by hand as the Preference Framework
120 // does not allow to add an Intent with some extras into a Preference
121 // XML file
122 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
123 // This will setup the Home and Search affordance
124 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700125 intent.putExtra(EXTRA_SUB_ID, subId);
pkanward702e542017-02-08 15:44:54 -0800126 mPrefFragment.startActivity(intent);
Sanket Padawe3e1073d2015-07-15 18:28:12 -0700127 return true;
128 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700129 });
130 mPrefScreen.addPreference(mCategoryAPNExpand);
Malcolm Chen7b486ea2017-06-28 12:30:18 -0700131 } else {
132 mPrefScreen.removePreference(mCategoryAPNExpand);
Sanket Padawe3e1073d2015-07-15 18:28:12 -0700133 }
Malcolm Chen39aa7912017-06-05 19:02:16 -0700134
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700135 if (addNetworkOperatorsCategory) {
136 mPrefScreen.addPreference(mNetworkOperator);
137 mNetworkOperator.update(subId, queryService);
138 } else {
139 mPrefScreen.removePreference(mNetworkOperator);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700140 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700141
142 if (addCarrierSettings) {
143 mPrefScreen.addPreference(mCarrierSettingPref);
144 } else {
145 mPrefScreen.removePreference(mCarrierSettingPref);
146 }
147
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148 }
149
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700150 protected boolean preferenceTreeClick(Preference preference) {
151 return mNetworkOperator.preferenceTreeClick(preference);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 }
153
154 protected void log(String s) {
155 android.util.Log.d(LOG_TAG, s);
156 }
157}