blob: 220cf34d0cc61fa2a3c76267e4b0b28734027d23 [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;
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070024import android.provider.Settings;
Jonathan Basseri29386052015-04-23 17:35:28 -070025import android.telephony.CarrierConfigManager;
26
Malcolm Chen3f2dd682017-07-24 16:44:32 -070027import com.android.internal.logging.MetricsLogger;
28import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import com.android.internal.telephony.PhoneConstants;
30import com.android.internal.telephony.PhoneFactory;
Alex Chaucfc19162018-02-27 09:44:27 +000031import com.android.settingslib.RestrictedLockUtils;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032
33/**
34 * List of Network-specific settings screens.
35 */
36public class GsmUmtsOptions {
37 private static final String LOG_TAG = "GsmUmtsOptions";
38
Alex Chaucfc19162018-02-27 09:44:27 +000039 private RestrictedPreference mButtonAPNExpand;
Malcolm Chen7b486ea2017-06-28 12:30:18 -070040 private Preference mCategoryAPNExpand;
Malcolm Chen833d4ac2017-07-11 17:00:07 -070041 Preference mCarrierSettingPref;
Malcolm Chen39aa7912017-06-05 19:02:16 -070042
43 private NetworkOperators mNetworkOperator;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044
Malcolm Chen833d4ac2017-07-11 17:00:07 -070045 private static final String BUTTON_APN_EXPAND_KEY = "button_gsm_apn_key";
46 private static final String CATEGORY_APN_EXPAND_KEY = "category_gsm_apn_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053047 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Malcolm Chen39aa7912017-06-05 19:02:16 -070048
Sanket Padawe3e1073d2015-07-15 18:28:12 -070049 public static final String EXTRA_SUB_ID = "sub_id";
pkanward702e542017-02-08 15:44:54 -080050 private PreferenceFragment mPrefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051 private PreferenceScreen mPrefScreen;
52
pkanward702e542017-02-08 15:44:54 -080053 public GsmUmtsOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen,
Malcolm Chen39aa7912017-06-05 19:02:16 -070054 final int subId, INetworkQueryService queryService) {
pkanward702e542017-02-08 15:44:54 -080055 mPrefFragment = prefFragment;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056 mPrefScreen = prefScreen;
pkanward702e542017-02-08 15:44:54 -080057 mPrefFragment.addPreferencesFromResource(R.xml.gsm_umts_options);
Alex Chaucfc19162018-02-27 09:44:27 +000058 mButtonAPNExpand = (RestrictedPreference) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Malcolm Chen7b486ea2017-06-28 12:30:18 -070059 mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
Malcolm Chen39aa7912017-06-05 19:02:16 -070060 mNetworkOperator = (NetworkOperators) mPrefScreen
61 .findPreference(NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY);
Malcolm Chen833d4ac2017-07-11 17:00:07 -070062 mCarrierSettingPref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
Malcolm Chen39aa7912017-06-05 19:02:16 -070063
Malcolm Chen833d4ac2017-07-11 17:00:07 -070064 mNetworkOperator.initialize();
65
66 update(subId, queryService);
67 }
68
69 // Unlike mPrefFragment or mPrefScreen, subId or queryService may change during lifecycle of
70 // GsmUmtsOptions. When that happens, we update GsmUmtsOptions with new parameters.
71 protected void update(final int subId, INetworkQueryService queryService) {
72 boolean addAPNExpand = true;
73 boolean addNetworkOperatorsCategory = true;
74 boolean addCarrierSettings = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075 if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
76 log("Not a GSM phone");
Malcolm Chen7b486ea2017-06-28 12:30:18 -070077 mCategoryAPNExpand.setEnabled(false);
Malcolm Chen39aa7912017-06-05 19:02:16 -070078 mNetworkOperator.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079 } else {
80 log("Not a CDMA phone");
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070081 PersistableBundle carrierConfig =
Malcolm Chen833d4ac2017-07-11 17:00:07 -070082 PhoneGlobals.getInstance().getCarrierConfigForSubId(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083
Jonathan Basseri29386052015-04-23 17:35:28 -070084 // Determine which options to display. For GSM these are defaulted to true in
85 // CarrierConfigManager, but they maybe overriden by DefaultCarrierConfigService or a
86 // carrier app.
87 // Note: these settings used to be controlled with overlays in
88 // Telephony/res/values/config.xml
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070089 if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL)
Malcolm Chen7b486ea2017-06-28 12:30:18 -070090 && mCategoryAPNExpand != null) {
Malcolm Chen833d4ac2017-07-11 17:00:07 -070091 addAPNExpand = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070093 if (!carrierConfig.getBoolean(
94 CarrierConfigManager.KEY_OPERATOR_SELECTION_EXPAND_BOOL)) {
Malcolm Chen833d4ac2017-07-11 17:00:07 -070095 addNetworkOperatorsCategory = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097
Jonathan Basserif180dc72015-06-19 13:47:51 -070098 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_CSP_ENABLED_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
100 log("[CSP] Enabling Operator Selection menu.");
Malcolm Chen39aa7912017-06-05 19:02:16 -0700101 mNetworkOperator.setEnabled(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102 } else {
103 log("[CSP] Disabling Operator Selection menu.");
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700104 addNetworkOperatorsCategory = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105 }
106 }
Sandeep Gutta91007152014-07-01 12:05:52 +0530107
108 // Read platform settings for carrier settings
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700109 addCarrierSettings = carrierConfig.getBoolean(
110 CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700112
113 // Making no assumptions of whether they are added or removed at this point.
114 // Calling add or remove explicitly to make sure they are updated.
115
116 if (addAPNExpand) {
Alex Chaucfc19162018-02-27 09:44:27 +0000117 mButtonAPNExpand.setDisabledByAdmin(
118 MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
119 ? RestrictedLockUtils.getDeviceOwner(mButtonAPNExpand.getContext())
120 : null);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700121 mButtonAPNExpand.setOnPreferenceClickListener(
122 new Preference.OnPreferenceClickListener() {
123 @Override
124 public boolean onPreferenceClick(Preference preference) {
Malcolm Chen3f2dd682017-07-24 16:44:32 -0700125 MetricsLogger.action(mButtonAPNExpand.getContext(),
126 MetricsEvent.ACTION_MOBILE_NETWORK_APN_SETTINGS);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700127 // We need to build the Intent by hand as the Preference Framework
128 // does not allow to add an Intent with some extras into a Preference
129 // XML file
130 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
131 // This will setup the Home and Search affordance
132 intent.putExtra(":settings:show_fragment_as_subsetting", true);
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700133 intent.putExtra(EXTRA_SUB_ID, subId);
pkanward702e542017-02-08 15:44:54 -0800134 mPrefFragment.startActivity(intent);
Sanket Padawe3e1073d2015-07-15 18:28:12 -0700135 return true;
136 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700137 });
138 mPrefScreen.addPreference(mCategoryAPNExpand);
Malcolm Chen7b486ea2017-06-28 12:30:18 -0700139 } else {
140 mPrefScreen.removePreference(mCategoryAPNExpand);
Sanket Padawe3e1073d2015-07-15 18:28:12 -0700141 }
Malcolm Chen39aa7912017-06-05 19:02:16 -0700142
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700143 if (addNetworkOperatorsCategory) {
144 mPrefScreen.addPreference(mNetworkOperator);
145 mNetworkOperator.update(subId, queryService);
146 } else {
147 mPrefScreen.removePreference(mNetworkOperator);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700148 }
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700149
150 if (addCarrierSettings) {
151 mPrefScreen.addPreference(mCarrierSettingPref);
152 } else {
153 mPrefScreen.removePreference(mCarrierSettingPref);
154 }
155
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 }
157
Malcolm Chen833d4ac2017-07-11 17:00:07 -0700158 protected boolean preferenceTreeClick(Preference preference) {
159 return mNetworkOperator.preferenceTreeClick(preference);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 }
161
162 protected void log(String s) {
163 android.util.Log.d(LOG_TAG, s);
164 }
165}