blob: df5f2cd3b3424b1158ccbc428a42d66fc3ef6fec [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;
28
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import com.android.internal.telephony.PhoneConstants;
30import com.android.internal.telephony.PhoneFactory;
31
32/**
33 * List of Network-specific settings screens.
34 */
35public class GsmUmtsOptions {
36 private static final String LOG_TAG = "GsmUmtsOptions";
37
38 private PreferenceScreen mButtonAPNExpand;
39 private PreferenceScreen mButtonOperatorSelectionExpand;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040
41 private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
42 private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
Sandeep Gutta91007152014-07-01 12:05:52 +053043 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044 private PreferenceActivity mPrefActivity;
45 private PreferenceScreen mPrefScreen;
PauloftheWest375e27d2014-12-08 08:43:07 -080046 private int mSubId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047
PauloftheWest375e27d2014-12-08 08:43:07 -080048 public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen,
49 final int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050 mPrefActivity = prefActivity;
51 mPrefScreen = prefScreen;
PauloftheWest375e27d2014-12-08 08:43:07 -080052 mSubId = subId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053 create();
54 }
55
56 protected void create() {
57 mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
58 mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070059 boolean removedAPNExpand = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060 mButtonOperatorSelectionExpand =
61 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062 if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
63 log("Not a GSM phone");
64 mButtonAPNExpand.setEnabled(false);
65 mButtonOperatorSelectionExpand.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066 } else {
67 log("Not a CDMA phone");
68 Resources res = mPrefActivity.getResources();
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070069 PersistableBundle carrierConfig =
70 PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071
Jonathan Basseri29386052015-04-23 17:35:28 -070072 // Determine which options to display. For GSM these are defaulted to true in
73 // CarrierConfigManager, but they maybe overriden by DefaultCarrierConfigService or a
74 // carrier app.
75 // Note: these settings used to be controlled with overlays in
76 // Telephony/res/values/config.xml
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070077 if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL)
78 && mButtonAPNExpand != null) {
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070079 mPrefScreen.removePreference(mButtonAPNExpand);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070080 removedAPNExpand = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081 }
Jonathan Basseri9504c6b2015-06-04 14:23:32 -070082 if (!carrierConfig.getBoolean(
83 CarrierConfigManager.KEY_OPERATOR_SELECTION_EXPAND_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084 mPrefScreen.removePreference(mPrefScreen
85 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
86 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087
88 if (res.getBoolean(R.bool.csp_enabled)) {
89 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
90 log("[CSP] Enabling Operator Selection menu.");
91 mButtonOperatorSelectionExpand.setEnabled(true);
92 } else {
93 log("[CSP] Disabling Operator Selection menu.");
94 mPrefScreen.removePreference(mPrefScreen
95 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
96 }
97 }
Sandeep Gutta91007152014-07-01 12:05:52 +053098
99 // Read platform settings for carrier settings
Jonathan Basseri29386052015-04-23 17:35:28 -0700100 final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700101 CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
Sandeep Gutta91007152014-07-01 12:05:52 +0530102 if (!isCarrierSettingsEnabled) {
103 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
104 if (pref != null) {
105 mPrefScreen.removePreference(pref);
106 }
107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 }
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700109 if (!removedAPNExpand) {
110 mButtonAPNExpand.setOnPreferenceClickListener(
111 new Preference.OnPreferenceClickListener() {
112 @Override
113 public boolean onPreferenceClick(Preference preference) {
114 // We need to build the Intent by hand as the Preference Framework
115 // does not allow to add an Intent with some extras into a Preference
116 // XML file
117 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
118 // This will setup the Home and Search affordance
119 intent.putExtra(":settings:show_fragment_as_subsetting", true);
PauloftheWest375e27d2014-12-08 08:43:07 -0800120 intent.putExtra("sub_id", mSubId);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700121 mPrefActivity.startActivity(intent);
122 return true;
123 }
124 });
125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 }
127
128 public boolean preferenceTreeClick(Preference preference) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129 log("preferenceTreeClick: return false");
130 return false;
131 }
132
133 protected void log(String s) {
134 android.util.Log.d(LOG_TAG, s);
135 }
136}