Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.preference.PreferenceScreen; |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 25 | import android.telephony.CarrierConfigManager; |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 26 | import android.telephony.SubscriptionManager; |
| 27 | import android.telephony.ims.ImsException; |
| 28 | import android.telephony.ims.ImsManager; |
| 29 | import android.telephony.ims.ImsMmTelManager; |
| 30 | import android.telephony.ims.feature.MmTelFeature; |
| 31 | import android.util.Log; |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 32 | import android.view.MenuItem; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | |
Aravind Sreekumar | afc08c5 | 2018-04-10 15:34:32 -0700 | [diff] [blame] | 34 | import com.android.internal.telephony.PhoneConstants; |
Grant Menke | 549b51c | 2023-11-08 10:31:37 -0800 | [diff] [blame] | 35 | import com.android.internal.telephony.flags.Flags; |
Aravind Sreekumar | afc08c5 | 2018-04-10 15:34:32 -0700 | [diff] [blame] | 36 | |
Jang Hayeong | 4022b38 | 2019-07-16 20:05:17 +0900 | [diff] [blame] | 37 | public class CdmaCallOptions extends TimeConsumingPreferenceActivity { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | private static final String LOG_TAG = "CdmaCallOptions"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | |
| 40 | private static final String BUTTON_VP_KEY = "button_voice_privacy_key"; |
Jang Hayeong | 43bd140 | 2019-07-16 15:40:47 +0900 | [diff] [blame] | 41 | private static final String CALL_FORWARDING_KEY = "call_forwarding_key"; |
Jang Hayeong | 4022b38 | 2019-07-16 20:05:17 +0900 | [diff] [blame] | 42 | private static final String CALL_WAITING_KEY = "call_waiting_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 44 | private class UtCallback extends ImsMmTelManager.CapabilityCallback { |
| 45 | @Override |
| 46 | public void onCapabilitiesStatusChanged(MmTelFeature.MmTelCapabilities capabilities) { |
| 47 | boolean isUtAvailable = capabilities.isCapable( |
| 48 | MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT); |
| 49 | updatePreferencesEnabled(isUtAvailable); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | private Preference mCallForwardingPref; |
| 54 | private CdmaCallWaitingPreference mCallWaitingPref; |
| 55 | private UtCallback mUtCallback; |
| 56 | private ImsMmTelManager mMmTelManager; |
| 57 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | @Override |
| 59 | protected void onCreate(Bundle icicle) { |
| 60 | super.onCreate(icicle); |
| 61 | |
Tyler Gunn | 662cb39 | 2025-01-17 23:34:46 +0000 | [diff] [blame] | 62 | getWindow().addSystemFlags( |
| 63 | android.view.WindowManager.LayoutParams |
| 64 | .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); |
| 65 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | addPreferencesFromResource(R.xml.cdma_call_privacy); |
| 67 | |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 68 | SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent()); |
| 69 | subInfoHelper.setActionBarTitle( |
| 70 | getActionBar(), getResources(), R.string.labelCdmaMore_with_label); |
| 71 | |
Brad Ebinger | 931ab21 | 2021-06-14 11:50:39 -0700 | [diff] [blame] | 72 | CdmaVoicePrivacySwitchPreference buttonVoicePrivacy = |
| 73 | (CdmaVoicePrivacySwitchPreference) findPreference(BUTTON_VP_KEY); |
| 74 | buttonVoicePrivacy.setPhone(subInfoHelper.getPhone()); |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 75 | PersistableBundle carrierConfig; |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 76 | int subId; |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 77 | if (subInfoHelper.hasSubId()) { |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 78 | subId = subInfoHelper.getSubId(); |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 79 | } else { |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 80 | subId = SubscriptionManager.getDefaultSubscriptionId(); |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 81 | } |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 82 | carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(subId); |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 83 | if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_CDMA |
Jonathan Basseri | f0b3911 | 2015-06-09 15:14:06 -0700 | [diff] [blame] | 84 | || carrierConfig.getBoolean(CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) { |
Brad Ebinger | 931ab21 | 2021-06-14 11:50:39 -0700 | [diff] [blame] | 85 | buttonVoicePrivacy.setEnabled(false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 86 | } |
Jang Hayeong | 43bd140 | 2019-07-16 15:40:47 +0900 | [diff] [blame] | 87 | |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 88 | // If mobile network configs are restricted, then hide the mCallForwardingPref and |
| 89 | // mCallWaitingPref. |
| 90 | UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); |
| 91 | boolean mobileNetworkConfigsRestricted = |
| 92 | userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS); |
Grant Menke | 549b51c | 2023-11-08 10:31:37 -0800 | [diff] [blame] | 93 | if (Flags.ensureAccessToCallSettingsIsRestricted() && mobileNetworkConfigsRestricted) { |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 94 | Log.i(LOG_TAG, "Mobile network configs are restricted, hiding CDMA call forwarding " |
| 95 | + "and CDMA call waiting options."); |
| 96 | } |
| 97 | |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 98 | mCallForwardingPref = getPreferenceScreen().findPreference(CALL_FORWARDING_KEY); |
Brad Ebinger | 931ab21 | 2021-06-14 11:50:39 -0700 | [diff] [blame] | 99 | if (carrierConfig != null && carrierConfig.getBoolean( |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 100 | CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL) && |
Grant Menke | 549b51c | 2023-11-08 10:31:37 -0800 | [diff] [blame] | 101 | (!mobileNetworkConfigsRestricted || |
| 102 | !Flags.ensureAccessToCallSettingsIsRestricted())) { |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 103 | mCallForwardingPref.setIntent( |
Brad Ebinger | 931ab21 | 2021-06-14 11:50:39 -0700 | [diff] [blame] | 104 | subInfoHelper.getIntent(CdmaCallForwardOptions.class)); |
| 105 | } else { |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 106 | getPreferenceScreen().removePreference(mCallForwardingPref); |
| 107 | mCallForwardingPref = null; |
Brad Ebinger | 931ab21 | 2021-06-14 11:50:39 -0700 | [diff] [blame] | 108 | } |
Jang Hayeong | 4022b38 | 2019-07-16 20:05:17 +0900 | [diff] [blame] | 109 | |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 110 | mCallWaitingPref = (CdmaCallWaitingPreference) getPreferenceScreen() |
| 111 | .findPreference(CALL_WAITING_KEY); |
| 112 | if (carrierConfig == null || !carrierConfig.getBoolean( |
Grant Menke | 8661837 | 2023-08-10 17:04:22 -0700 | [diff] [blame] | 113 | CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL) || |
Grant Menke | 549b51c | 2023-11-08 10:31:37 -0800 | [diff] [blame] | 114 | (Flags.ensureAccessToCallSettingsIsRestricted() && |
| 115 | mobileNetworkConfigsRestricted)) { |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 116 | getPreferenceScreen().removePreference(mCallWaitingPref); |
| 117 | mCallWaitingPref = null; |
| 118 | } |
| 119 | // Do not go further if the preferences are removed. |
| 120 | if (mCallForwardingPref == null && mCallWaitingPref == null) return; |
| 121 | |
| 122 | boolean isSsOverCdmaEnabled = carrierConfig != null && carrierConfig.getBoolean( |
| 123 | CarrierConfigManager.KEY_SUPPORT_SS_OVER_CDMA_BOOL); |
| 124 | boolean isSsOverUtEnabled = carrierConfig != null && carrierConfig.getBoolean( |
| 125 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL); |
| 126 | |
| 127 | if (isSsOverCdmaEnabled && mCallWaitingPref != null) { |
| 128 | // If SS over CDMA is enabled, then the preference will always be enabled, |
| 129 | // independent of SS over UT status. Initialize it now. |
| 130 | mCallWaitingPref.init(this, subInfoHelper.getPhone()); |
| 131 | return; |
| 132 | } |
| 133 | // Since SS over UT availability can change, first disable the preferences that rely on it |
| 134 | // and only enable it if UT is available. |
| 135 | updatePreferencesEnabled(false); |
| 136 | if (isSsOverUtEnabled) { |
| 137 | // Register a callback to listen to SS over UT state. This will enable the preferences |
| 138 | // once the callback notifies settings that UT is enabled. |
| 139 | registerMmTelCapsCallback(subId); |
Brad Ebinger | 931ab21 | 2021-06-14 11:50:39 -0700 | [diff] [blame] | 140 | } else { |
Brad Ebinger | 9df0456 | 2021-07-15 16:16:17 -0700 | [diff] [blame] | 141 | Log.w(LOG_TAG, "SS over UT and CDMA disabled, but preferences are visible."); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void onStop() { |
| 147 | super.onStop(); |
| 148 | unregisterMmTelCapsCallback(); |
| 149 | } |
| 150 | |
| 151 | private void unregisterMmTelCapsCallback() { |
| 152 | if (mMmTelManager == null || mUtCallback == null) return; |
| 153 | mMmTelManager.unregisterMmTelCapabilityCallback(mUtCallback); |
| 154 | mUtCallback = null; |
| 155 | Log.d(LOG_TAG, "unregisterMmTelCapsCallback: UT availability callback unregistered"); |
| 156 | } |
| 157 | |
| 158 | private void registerMmTelCapsCallback(int subId) { |
| 159 | if (!SubscriptionManager.isValidSubscriptionId(subId)) return; |
| 160 | ImsManager imsManager = getSystemService(ImsManager.class); |
| 161 | try { |
| 162 | if (imsManager != null) { |
| 163 | mUtCallback = new UtCallback(); |
| 164 | mMmTelManager = imsManager.getImsMmTelManager(subId); |
| 165 | // Callback will call back with the state as soon as it is available. |
| 166 | mMmTelManager.registerMmTelCapabilityCallback(getMainExecutor(), mUtCallback); |
| 167 | Log.d(LOG_TAG, "registerMmTelCapsCallback: UT availability callback " |
| 168 | + "registered"); |
| 169 | } else { |
| 170 | Log.w(LOG_TAG, "registerMmTelCapsCallback: couldn't get ImsManager, assuming " |
| 171 | + "UT is not available: "); |
| 172 | updatePreferencesEnabled(false); |
| 173 | } |
| 174 | } catch (IllegalArgumentException | ImsException e) { |
| 175 | Log.w(LOG_TAG, "registerMmTelCapsCallback: couldn't register callback, assuming " |
| 176 | + "UT is not available: " + e); |
| 177 | updatePreferencesEnabled(false); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | private void updatePreferencesEnabled(boolean isEnabled) { |
| 182 | Log.d(LOG_TAG, "updatePreferencesEnabled: " + isEnabled); |
| 183 | if (mCallForwardingPref != null) mCallForwardingPref.setEnabled(isEnabled); |
| 184 | |
| 185 | if (mCallWaitingPref == null || mCallWaitingPref.isEnabled() == isEnabled) return; |
| 186 | mCallWaitingPref.setActionAvailable(isEnabled); |
| 187 | if (isEnabled) { |
| 188 | SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent()); |
| 189 | // kick off the normal process to populate the Call Waiting status. |
| 190 | mCallWaitingPref.init(this, subInfoHelper.getPhone()); |
Brad Ebinger | 931ab21 | 2021-06-14 11:50:39 -0700 | [diff] [blame] | 191 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
Sanket Padawe | e09a6f6 | 2015-03-05 11:59:39 -0800 | [diff] [blame] | 195 | public boolean onOptionsItemSelected(MenuItem item) { |
| 196 | final int itemId = item.getItemId(); |
| 197 | if (itemId == android.R.id.home) { |
| 198 | onBackPressed(); |
| 199 | return true; |
| 200 | } |
| 201 | return super.onOptionsItemSelected(item); |
| 202 | } |
| 203 | |
| 204 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
| 206 | if (preference.getKey().equals(BUTTON_VP_KEY)) { |
| 207 | return true; |
| 208 | } |
| 209 | return false; |
| 210 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 | } |