• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.os.Bundle;
20 import android.os.PersistableBundle;
21 import android.preference.Preference;
22 import android.preference.PreferenceScreen;
23 import android.telephony.CarrierConfigManager;
24 import android.telephony.SubscriptionManager;
25 import android.telephony.ims.ImsException;
26 import android.telephony.ims.ImsManager;
27 import android.telephony.ims.ImsMmTelManager;
28 import android.telephony.ims.feature.MmTelFeature;
29 import android.util.Log;
30 import android.view.MenuItem;
31 
32 import com.android.internal.telephony.PhoneConstants;
33 
34 public class CdmaCallOptions extends TimeConsumingPreferenceActivity {
35     private static final String LOG_TAG = "CdmaCallOptions";
36 
37     private static final String BUTTON_VP_KEY = "button_voice_privacy_key";
38     private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
39     private static final String CALL_WAITING_KEY = "call_waiting_key";
40 
41     private class UtCallback extends ImsMmTelManager.CapabilityCallback {
42         @Override
onCapabilitiesStatusChanged(MmTelFeature.MmTelCapabilities capabilities)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 
55     @Override
onCreate(Bundle icicle)56     protected void onCreate(Bundle icicle) {
57         super.onCreate(icicle);
58 
59         addPreferencesFromResource(R.xml.cdma_call_privacy);
60 
61         SubscriptionInfoHelper subInfoHelper = new SubscriptionInfoHelper(this, getIntent());
62         subInfoHelper.setActionBarTitle(
63                 getActionBar(), getResources(), R.string.labelCdmaMore_with_label);
64 
65         CdmaVoicePrivacySwitchPreference buttonVoicePrivacy =
66                 (CdmaVoicePrivacySwitchPreference) findPreference(BUTTON_VP_KEY);
67         buttonVoicePrivacy.setPhone(subInfoHelper.getPhone());
68         PersistableBundle carrierConfig;
69         int subId;
70         if (subInfoHelper.hasSubId()) {
71             subId = subInfoHelper.getSubId();
72         } else {
73             subId = SubscriptionManager.getDefaultSubscriptionId();
74         }
75         carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(subId);
76         if (subInfoHelper.getPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_CDMA
77                 || carrierConfig.getBoolean(CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
78             buttonVoicePrivacy.setEnabled(false);
79         }
80 
81         mCallForwardingPref = getPreferenceScreen().findPreference(CALL_FORWARDING_KEY);
82         if (carrierConfig != null && carrierConfig.getBoolean(
83                 CarrierConfigManager.KEY_CALL_FORWARDING_VISIBILITY_BOOL)) {
84             mCallForwardingPref.setIntent(
85                     subInfoHelper.getIntent(CdmaCallForwardOptions.class));
86         } else {
87             getPreferenceScreen().removePreference(mCallForwardingPref);
88             mCallForwardingPref = null;
89         }
90 
91         mCallWaitingPref = (CdmaCallWaitingPreference) getPreferenceScreen()
92                 .findPreference(CALL_WAITING_KEY);
93         if (carrierConfig == null || !carrierConfig.getBoolean(
94                 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL)) {
95             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);
119         } else {
120             Log.w(LOG_TAG, "SS over UT and CDMA disabled, but preferences are visible.");
121         }
122     }
123 
124     @Override
onStop()125     public void onStop() {
126         super.onStop();
127         unregisterMmTelCapsCallback();
128     }
129 
unregisterMmTelCapsCallback()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 
registerMmTelCapsCallback(int subId)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 
updatePreferencesEnabled(boolean isEnabled)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());
170         }
171     }
172 
173     @Override
onOptionsItemSelected(MenuItem item)174     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
onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)184     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
185         if (preference.getKey().equals(BUTTON_VP_KEY)) {
186             return true;
187         }
188         return false;
189     }
190 }
191