Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
| 17 | package com.android.phone; |
| 18 | |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Aida Takeshi | 7c3b4a3 | 2016-08-11 13:42:24 +0800 | [diff] [blame] | 21 | import android.os.PersistableBundle; |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 22 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 23 | import android.preference.Preference; |
| 24 | import android.preference.PreferenceActivity; |
| 25 | import android.preference.PreferenceScreen; |
SongFerngWang | 022b5da | 2019-11-25 22:52:03 +0800 | [diff] [blame] | 26 | import android.provider.Settings; |
Aida Takeshi | 7c3b4a3 | 2016-08-11 13:42:24 +0800 | [diff] [blame] | 27 | import android.telephony.CarrierConfigManager; |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 28 | import android.util.Log; |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 29 | import android.view.MenuItem; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import com.android.internal.telephony.PhoneConstants; |
| 32 | |
| 33 | public class GsmUmtsCallOptions extends PreferenceActivity { |
| 34 | private static final String LOG_TAG = "GsmUmtsCallOptions"; |
| 35 | private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 36 | |
SongFerngWang | bed485e | 2018-07-09 21:15:29 +0800 | [diff] [blame] | 37 | public static final String CALL_FORWARDING_KEY = "call_forwarding_key"; |
| 38 | public static final String CALL_BARRING_KEY = "call_barring_key"; |
SongFerngWang | 022b5da | 2019-11-25 22:52:03 +0800 | [diff] [blame] | 39 | public static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key"; |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 40 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | @Override |
| 42 | protected void onCreate(Bundle icicle) { |
| 43 | super.onCreate(icicle); |
| 44 | |
| 45 | addPreferencesFromResource(R.xml.gsm_umts_call_options); |
| 46 | |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 47 | SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent()); |
| 48 | subInfoHelper.setActionBarTitle( |
| 49 | getActionBar(), getResources(), R.string.labelGsmMore_with_label); |
| 50 | init(getPreferenceScreen(), subInfoHelper); |
| 51 | |
| 52 | if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | //disable the entire screen |
| 54 | getPreferenceScreen().setEnabled(false); |
| 55 | } |
| 56 | } |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 57 | |
| 58 | @Override |
| 59 | public boolean onOptionsItemSelected(MenuItem item) { |
| 60 | final int itemId = item.getItemId(); |
| 61 | if (itemId == android.R.id.home) { |
| 62 | onBackPressed(); |
| 63 | return true; |
| 64 | } |
| 65 | return super.onOptionsItemSelected(item); |
| 66 | } |
| 67 | |
| 68 | public static void init(PreferenceScreen prefScreen, SubscriptionInfoHelper subInfoHelper) { |
Aida Takeshi | 7c3b4a3 | 2016-08-11 13:42:24 +0800 | [diff] [blame] | 69 | PersistableBundle b = null; |
| 70 | if (subInfoHelper.hasSubId()) { |
| 71 | b = PhoneGlobals.getInstance().getCarrierConfigForSubId(subInfoHelper.getSubId()); |
| 72 | } else { |
| 73 | b = PhoneGlobals.getInstance().getCarrierConfig(); |
| 74 | } |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 75 | |
SongFerngWang | 022b5da | 2019-11-25 22:52:03 +0800 | [diff] [blame] | 76 | boolean isAirplaneModeOff = true; |
| 77 | if (b != null && b.getBoolean( |
| 78 | CarrierConfigManager.KEY_DISABLE_SUPPLEMENTARY_SERVICES_IN_AIRPLANE_MODE_BOOL)) { |
| 79 | int airplaneMode = Settings.Global.getInt( |
| 80 | subInfoHelper.getPhone().getContext().getContentResolver(), |
| 81 | Settings.Global.AIRPLANE_MODE_ON, PhoneGlobals.AIRPLANE_OFF); |
| 82 | isAirplaneModeOff = PhoneGlobals.AIRPLANE_ON != airplaneMode; |
| 83 | } |
| 84 | |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 85 | // If mobile network configs are restricted, then hide the GsmUmtsCallForwardOptions, |
| 86 | // GsmUmtsAdditionalCallOptions, and GsmUmtsCallBarringOptions. |
| 87 | UserManager userManager = (UserManager) subInfoHelper.getPhone().getContext() |
| 88 | .getSystemService(Context.USER_SERVICE); |
| 89 | boolean mobileNetworkConfigsRestricted = |
| 90 | userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS); |
| 91 | if (mobileNetworkConfigsRestricted) { |
| 92 | Log.i(LOG_TAG, "Mobile network configs are restricted, hiding GSM call " |
| 93 | + "forwarding, additional call settings, and call options."); |
| 94 | } |
| 95 | |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 96 | Preference callForwardingPref = prefScreen.findPreference(CALL_FORWARDING_KEY); |
| 97 | if (callForwardingPref != null) { |
| 98 | if (b != null && b.getBoolean( |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 99 | CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL) && |
| 100 | !mobileNetworkConfigsRestricted) { |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 101 | callForwardingPref.setIntent( |
| 102 | subInfoHelper.getIntent(GsmUmtsCallForwardOptions.class)); |
SongFerngWang | 022b5da | 2019-11-25 22:52:03 +0800 | [diff] [blame] | 103 | callForwardingPref.setEnabled(isAirplaneModeOff); |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 104 | } else { |
| 105 | prefScreen.removePreference(callForwardingPref); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | Preference additionalGsmSettingsPref = |
| 110 | prefScreen.findPreference(ADDITIONAL_GSM_SETTINGS_KEY); |
| 111 | if (additionalGsmSettingsPref != null) { |
| 112 | if (b != null && (b.getBoolean( |
| 113 | CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL) |
| 114 | || b.getBoolean( |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 115 | CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL)) && |
| 116 | !mobileNetworkConfigsRestricted) { |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 117 | additionalGsmSettingsPref.setIntent( |
| 118 | subInfoHelper.getIntent(GsmUmtsAdditionalCallOptions.class)); |
SongFerngWang | 022b5da | 2019-11-25 22:52:03 +0800 | [diff] [blame] | 119 | additionalGsmSettingsPref.setEnabled(isAirplaneModeOff); |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 120 | } else { |
| 121 | prefScreen.removePreference(additionalGsmSettingsPref); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | Preference callBarringPref = prefScreen.findPreference(CALL_BARRING_KEY); |
| 126 | if (callBarringPref != null) { |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 127 | if (b != null && b.getBoolean(CarrierConfigManager.KEY_CALL_BARRING_VISIBILITY_BOOL) && |
| 128 | !mobileNetworkConfigsRestricted) { |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 129 | callBarringPref.setIntent(subInfoHelper.getIntent(GsmUmtsCallBarringOptions.class)); |
SongFerngWang | 022b5da | 2019-11-25 22:52:03 +0800 | [diff] [blame] | 130 | callBarringPref.setEnabled(isAirplaneModeOff); |
SongFerngWang | f6fd992 | 2018-06-28 17:21:43 +0800 | [diff] [blame] | 131 | } else { |
| 132 | prefScreen.removePreference(callBarringPref); |
| 133 | } |
Aida Takeshi | 7c3b4a3 | 2016-08-11 13:42:24 +0800 | [diff] [blame] | 134 | } |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 135 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | } |