blob: 614587099ff5bdbff66a73c6a4d2852dbf4fbeea [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
Santos Cordon7d4ddf62013-07-10 11:58:08 -070019import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070020import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.preference.Preference;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.preference.PreferenceScreen;
Jonathan Basseri3649bdb2015-04-30 22:39:11 -070023import android.telephony.CarrierConfigManager;
Brad Ebinger9df04562021-07-15 16:16:17 -070024import android.telephony.SubscriptionManager;
25import android.telephony.ims.ImsException;
26import android.telephony.ims.ImsManager;
27import android.telephony.ims.ImsMmTelManager;
28import android.telephony.ims.feature.MmTelFeature;
29import android.util.Log;
Sanket Padawee09a6f62015-03-05 11:59:39 -080030import android.view.MenuItem;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031
Aravind Sreekumarafc08c52018-04-10 15:34:32 -070032import com.android.internal.telephony.PhoneConstants;
33
Jang Hayeong4022b382019-07-16 20:05:17 +090034public class CdmaCallOptions extends TimeConsumingPreferenceActivity {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035 private static final String LOG_TAG = "CdmaCallOptions";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036
37 private static final String BUTTON_VP_KEY = "button_voice_privacy_key";
Jang Hayeong43bd1402019-07-16 15:40:47 +090038 private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
Jang Hayeong4022b382019-07-16 20:05:17 +090039 private static final String CALL_WAITING_KEY = "call_waiting_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040
Brad Ebinger9df04562021-07-15 16:16:17 -070041 private class UtCallback extends ImsMmTelManager.CapabilityCallback {
42 @Override
43 public void onCapabilitiesStatusChanged(MmTelFeature.MmTelCapabilities capabilities) {
44 boolean isUtAvailable = capabilities.isCapable(
45 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT);
46 updatePreferencesEnabled(isUtAvailable);
47 }
48 }
49
50 private Preference mCallForwardingPref;
51 private CdmaCallWaitingPreference mCallWaitingPref;
52 private UtCallback mUtCallback;
53 private ImsMmTelManager mMmTelManager;
54
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055 @Override
56 protected void onCreate(Bundle icicle) {
57 super.onCreate(icicle);
58
59 addPreferencesFromResource(R.xml.cdma_call_privacy);
60
Sanket Padawee09a6f62015-03-05 11:59:39 -080061 SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
62 subInfoHelper.setActionBarTitle(
63 getActionBar(), getResources(), R.string.labelCdmaMore_with_label);
64
Brad Ebinger931ab212021-06-14 11:50:39 -070065 CdmaVoicePrivacySwitchPreference buttonVoicePrivacy =
66 (CdmaVoicePrivacySwitchPreference) findPreference(BUTTON_VP_KEY);
67 buttonVoicePrivacy.setPhone(subInfoHelper.getPhone());
Jonathan Basseric31f1f32015-05-12 10:13:03 -070068 PersistableBundle carrierConfig;
Brad Ebinger9df04562021-07-15 16:16:17 -070069 int subId;
Jonathan Basseri3649bdb2015-04-30 22:39:11 -070070 if (subInfoHelper.hasSubId()) {
Brad Ebinger9df04562021-07-15 16:16:17 -070071 subId = subInfoHelper.getSubId();
Jonathan Basseri3649bdb2015-04-30 22:39:11 -070072 } else {
Brad Ebinger9df04562021-07-15 16:16:17 -070073 subId = SubscriptionManager.getDefaultSubscriptionId();
Jonathan Basseri3649bdb2015-04-30 22:39:11 -070074 }
Brad Ebinger9df04562021-07-15 16:16:17 -070075 carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(subId);
Sanket Padawee09a6f62015-03-05 11:59:39 -080076 if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_CDMA
Jonathan Basserif0b39112015-06-09 15:14:06 -070077 || carrierConfig.getBoolean(CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Brad Ebinger931ab212021-06-14 11:50:39 -070078 buttonVoicePrivacy.setEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079 }
Jang Hayeong43bd1402019-07-16 15:40:47 +090080
Brad Ebinger9df04562021-07-15 16:16:17 -070081 mCallForwardingPref = getPreferenceScreen().findPreference(CALL_FORWARDING_KEY);
Brad Ebinger931ab212021-06-14 11:50:39 -070082 if (carrierConfig != null && carrierConfig.getBoolean(
83 CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL)) {
Brad Ebinger9df04562021-07-15 16:16:17 -070084 mCallForwardingPref.setIntent(
Brad Ebinger931ab212021-06-14 11:50:39 -070085 subInfoHelper.getIntent(CdmaCallForwardOptions.class));
86 } else {
Brad Ebinger9df04562021-07-15 16:16:17 -070087 getPreferenceScreen().removePreference(mCallForwardingPref);
88 mCallForwardingPref = null;
Brad Ebinger931ab212021-06-14 11:50:39 -070089 }
Jang Hayeong4022b382019-07-16 20:05:17 +090090
Brad Ebinger9df04562021-07-15 16:16:17 -070091 mCallWaitingPref = (CdmaCallWaitingPreference) getPreferenceScreen()
92 .findPreference(CALL_WAITING_KEY);
93 if (carrierConfig == null || !carrierConfig.getBoolean(
Brad Ebinger931ab212021-06-14 11:50:39 -070094 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)) {
Brad Ebinger9df04562021-07-15 16:16:17 -070095 getPreferenceScreen().removePreference(mCallWaitingPref);
96 mCallWaitingPref = null;
97 }
98 // Do not go further if the preferences are removed.
99 if (mCallForwardingPref == null && mCallWaitingPref == null) return;
100
101 boolean isSsOverCdmaEnabled = carrierConfig != null && carrierConfig.getBoolean(
102 CarrierConfigManager.KEY_SUPPORT_SS_OVER_CDMA_BOOL);
103 boolean isSsOverUtEnabled = carrierConfig != null && carrierConfig.getBoolean(
104 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL);
105
106 if (isSsOverCdmaEnabled && mCallWaitingPref != null) {
107 // If SS over CDMA is enabled, then the preference will always be enabled,
108 // independent of SS over UT status. Initialize it now.
109 mCallWaitingPref.init(this, subInfoHelper.getPhone());
110 return;
111 }
112 // Since SS over UT availability can change, first disable the preferences that rely on it
113 // and only enable it if UT is available.
114 updatePreferencesEnabled(false);
115 if (isSsOverUtEnabled) {
116 // Register a callback to listen to SS over UT state. This will enable the preferences
117 // once the callback notifies settings that UT is enabled.
118 registerMmTelCapsCallback(subId);
Brad Ebinger931ab212021-06-14 11:50:39 -0700119 } else {
Brad Ebinger9df04562021-07-15 16:16:17 -0700120 Log.w(LOG_TAG, "SS over UT and CDMA disabled, but preferences are visible.");
121 }
122 }
123
124 @Override
125 public void onStop() {
126 super.onStop();
127 unregisterMmTelCapsCallback();
128 }
129
130 private void unregisterMmTelCapsCallback() {
131 if (mMmTelManager == null || mUtCallback == null) return;
132 mMmTelManager.unregisterMmTelCapabilityCallback(mUtCallback);
133 mUtCallback = null;
134 Log.d(LOG_TAG, "unregisterMmTelCapsCallback: UT availability callback unregistered");
135 }
136
137 private void registerMmTelCapsCallback(int subId) {
138 if (!SubscriptionManager.isValidSubscriptionId(subId)) return;
139 ImsManager imsManager = getSystemService(ImsManager.class);
140 try {
141 if (imsManager != null) {
142 mUtCallback = new UtCallback();
143 mMmTelManager = imsManager.getImsMmTelManager(subId);
144 // Callback will call back with the state as soon as it is available.
145 mMmTelManager.registerMmTelCapabilityCallback(getMainExecutor(), mUtCallback);
146 Log.d(LOG_TAG, "registerMmTelCapsCallback: UT availability callback "
147 + "registered");
148 } else {
149 Log.w(LOG_TAG, "registerMmTelCapsCallback: couldn't get ImsManager, assuming "
150 + "UT is not available: ");
151 updatePreferencesEnabled(false);
152 }
153 } catch (IllegalArgumentException | ImsException e) {
154 Log.w(LOG_TAG, "registerMmTelCapsCallback: couldn't register callback, assuming "
155 + "UT is not available: " + e);
156 updatePreferencesEnabled(false);
157 }
158 }
159
160 private void updatePreferencesEnabled(boolean isEnabled) {
161 Log.d(LOG_TAG, "updatePreferencesEnabled: " + isEnabled);
162 if (mCallForwardingPref != null) mCallForwardingPref.setEnabled(isEnabled);
163
164 if (mCallWaitingPref == null || mCallWaitingPref.isEnabled() == isEnabled) return;
165 mCallWaitingPref.setActionAvailable(isEnabled);
166 if (isEnabled) {
167 SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
168 // kick off the normal process to populate the Call Waiting status.
169 mCallWaitingPref.init(this, subInfoHelper.getPhone());
Brad Ebinger931ab212021-06-14 11:50:39 -0700170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171 }
172
173 @Override
Sanket Padawee09a6f62015-03-05 11:59:39 -0800174 public boolean onOptionsItemSelected(MenuItem item) {
175 final int itemId = item.getItemId();
176 if (itemId == android.R.id.home) {
177 onBackPressed();
178 return true;
179 }
180 return super.onOptionsItemSelected(item);
181 }
182
183 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
185 if (preference.getKey().equals(BUTTON_VP_KEY)) {
186 return true;
187 }
188 return false;
189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190}