blob: b8597f76282c685e2fd89d9b8a7745f0f6e41056 [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;
22import android.os.Bundle;
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 Basseri29386052015-04-23 17:35:28 -070069 Bundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070
Jonathan Basseri29386052015-04-23 17:35:28 -070071 // Determine which options to display. For GSM these are defaulted to true in
72 // CarrierConfigManager, but they maybe overriden by DefaultCarrierConfigService or a
73 // carrier app.
74 // Note: these settings used to be controlled with overlays in
75 // Telephony/res/values/config.xml
76 if (!carrierConfig.getBoolean(CarrierConfigManager.BOOL_APN_EXPAND) && mButtonAPNExpand != null) {
Fabrice Di Meglioebfecae2014-08-14 15:54:18 -070077 mPrefScreen.removePreference(mButtonAPNExpand);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -070078 removedAPNExpand = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079 }
Jonathan Basseri29386052015-04-23 17:35:28 -070080 if (!carrierConfig.getBoolean(CarrierConfigManager.BOOL_OPERATOR_SELECTION_EXPAND)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081 mPrefScreen.removePreference(mPrefScreen
82 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
83 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084
85 if (res.getBoolean(R.bool.csp_enabled)) {
86 if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
87 log("[CSP] Enabling Operator Selection menu.");
88 mButtonOperatorSelectionExpand.setEnabled(true);
89 } else {
90 log("[CSP] Disabling Operator Selection menu.");
91 mPrefScreen.removePreference(mPrefScreen
92 .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
93 }
94 }
Sandeep Gutta91007152014-07-01 12:05:52 +053095
96 // Read platform settings for carrier settings
Jonathan Basseri29386052015-04-23 17:35:28 -070097 final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
98 CarrierConfigManager.BOOL_CARRIER_SETTINGS_ENABLE);
Sandeep Gutta91007152014-07-01 12:05:52 +053099 if (!isCarrierSettingsEnabled) {
100 Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
101 if (pref != null) {
102 mPrefScreen.removePreference(pref);
103 }
104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105 }
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700106 if (!removedAPNExpand) {
107 mButtonAPNExpand.setOnPreferenceClickListener(
108 new Preference.OnPreferenceClickListener() {
109 @Override
110 public boolean onPreferenceClick(Preference preference) {
111 // We need to build the Intent by hand as the Preference Framework
112 // does not allow to add an Intent with some extras into a Preference
113 // XML file
114 final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
115 // This will setup the Home and Search affordance
116 intent.putExtra(":settings:show_fragment_as_subsetting", true);
PauloftheWest375e27d2014-12-08 08:43:07 -0800117 intent.putExtra("sub_id", mSubId);
Fabrice Di Megliofbd80c02014-08-15 12:54:24 -0700118 mPrefActivity.startActivity(intent);
119 return true;
120 }
121 });
122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123 }
124
125 public boolean preferenceTreeClick(Preference preference) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 log("preferenceTreeClick: return false");
127 return false;
128 }
129
130 protected void log(String s) {
131 android.util.Log.d(LOG_TAG, s);
132 }
133}