• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.phone;
18 
19 import android.app.ActionBar;
20 import android.app.Activity;
21 import android.app.ActivityOptions;
22 import android.app.AlertDialog;
23 import android.app.Dialog;
24 import android.content.ContentResolver;
25 import android.content.Context;
26 import android.content.DialogInterface;
27 import android.content.Intent;
28 import android.content.pm.PackageManager;
29 import android.content.pm.ResolveInfo;
30 import android.os.Bundle;
31 import android.os.PersistableBundle;
32 import android.os.UserHandle;
33 import android.preference.CheckBoxPreference;
34 import android.preference.ListPreference;
35 import android.preference.Preference;
36 import android.preference.PreferenceActivity;
37 import android.preference.PreferenceScreen;
38 import android.provider.Settings;
39 import android.telecom.PhoneAccountHandle;
40 import android.telecom.TelecomManager;
41 import android.telephony.CarrierConfigManager;
42 import android.telephony.TelephonyManager;
43 import android.text.TextUtils;
44 import android.util.Log;
45 import android.view.MenuItem;
46 import android.widget.Toast;
47 
48 import com.android.ims.ImsConfig;
49 import com.android.ims.ImsManager;
50 import com.android.internal.telephony.CallForwardInfo;
51 import com.android.internal.telephony.Phone;
52 import com.android.internal.telephony.PhoneConstants;
53 import com.android.phone.common.util.SettingsUtil;
54 import com.android.phone.settings.AccountSelectionPreference;
55 import com.android.phone.settings.PhoneAccountSettingsFragment;
56 import com.android.phone.settings.VoicemailSettingsActivity;
57 import com.android.phone.settings.fdn.FdnSetting;
58 import com.android.services.telephony.sip.SipUtil;
59 
60 import java.lang.String;
61 import java.util.ArrayList;
62 import java.util.List;
63 
64 /**
65  * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
66  *
67  * This preference screen is the root of the "Call settings" hierarchy available from the Phone
68  * app; the settings here let you control various features related to phone calls (including
69  * voicemail settings, the "Respond via SMS" feature, and others.)  It's used only on
70  * voice-capable phone devices.
71  *
72  * Note that this activity is part of the package com.android.phone, even
73  * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
74  * is from the package com.android.contacts.
75  *
76  * For the "Mobile network settings" screen under the main Settings app,
77  * See {@link MobileNetworkSettings}.
78  *
79  * @see com.android.phone.MobileNetworkSettings
80  */
81 public class CallFeaturesSetting extends PreferenceActivity
82         implements Preference.OnPreferenceChangeListener {
83     private static final String LOG_TAG = "CallFeaturesSetting";
84     private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
85     // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting.
86     private static final boolean ENABLE_VT_FLAG = true;
87 
88     // String keys for preference lookup
89     // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
90     // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
91     // in the layout files. These strings need to be treated carefully; if the setting is
92     // persistent, they are used as the key to store shared preferences and the name should not be
93     // changed unless the settings are also migrated.
94     private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
95     private static final String BUTTON_FDN_KEY   = "button_fdn_key";
96     private static final String BUTTON_RETRY_KEY       = "button_auto_retry_key";
97     private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
98     private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
99 
100     private static final String PHONE_ACCOUNT_SETTINGS_KEY =
101             "phone_account_settings_preference_screen";
102 
103     private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
104 
105     private Phone mPhone;
106     private SubscriptionInfoHelper mSubscriptionInfoHelper;
107     private TelecomManager mTelecomManager;
108 
109     private CheckBoxPreference mButtonAutoRetry;
110     private PreferenceScreen mVoicemailSettingsScreen;
111     private CheckBoxPreference mEnableVideoCalling;
112 
113     /*
114      * Click Listeners, handle click based on objects attached to UI.
115      */
116 
117     // Click listener for all toggle events
118     @Override
onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)119     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
120         if (preference == mButtonAutoRetry) {
121             android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
122                     android.provider.Settings.Global.CALL_AUTO_RETRY,
123                     mButtonAutoRetry.isChecked() ? 1 : 0);
124             return true;
125         }
126         return false;
127     }
128 
129     /**
130      * Implemented to support onPreferenceChangeListener to look for preference
131      * changes.
132      *
133      * @param preference is the preference to be changed
134      * @param objValue should be the value of the selection, NOT its localized
135      * display value.
136      */
137     @Override
onPreferenceChange(Preference preference, Object objValue)138     public boolean onPreferenceChange(Preference preference, Object objValue) {
139         if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
140 
141         if (preference == mEnableVideoCalling) {
142             if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
143                 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
144             } else {
145                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
146                 DialogInterface.OnClickListener networkSettingsClickListener =
147                         new Dialog.OnClickListener() {
148                             @Override
149                             public void onClick(DialogInterface dialog, int which) {
150                                 startActivity(new Intent(mPhone.getContext(),
151                                         com.android.phone.MobileNetworkSettings.class));
152                             }
153                         };
154                 builder.setMessage(getResources().getString(
155                                 R.string.enable_video_calling_dialog_msg))
156                         .setNeutralButton(getResources().getString(
157                                 R.string.enable_video_calling_dialog_settings),
158                                 networkSettingsClickListener)
159                         .setPositiveButton(android.R.string.ok, null)
160                         .show();
161                 return false;
162             }
163         }
164 
165         // Always let the preference setting proceed.
166         return true;
167     }
168 
169     @Override
onCreate(Bundle icicle)170     protected void onCreate(Bundle icicle) {
171         super.onCreate(icicle);
172         if (DBG) log("onCreate: Intent is " + getIntent());
173 
174         // Make sure we are running as the primary user.
175         if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
176             Toast.makeText(this, R.string.call_settings_primary_user_only,
177                     Toast.LENGTH_SHORT).show();
178             finish();
179             return;
180         }
181 
182         mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
183         mSubscriptionInfoHelper.setActionBarTitle(
184                 getActionBar(), getResources(), R.string.call_settings_with_label);
185         mPhone = mSubscriptionInfoHelper.getPhone();
186         mTelecomManager = TelecomManager.from(this);
187     }
188 
189     @Override
onResume()190     protected void onResume() {
191         super.onResume();
192 
193         PreferenceScreen preferenceScreen = getPreferenceScreen();
194         if (preferenceScreen != null) {
195             preferenceScreen.removeAll();
196         }
197 
198         addPreferencesFromResource(R.xml.call_feature_setting);
199 
200         TelephonyManager telephonyManager =
201                 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
202 
203         Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
204         if (telephonyManager.isMultiSimEnabled() || !SipUtil.isVoipSupported(mPhone.getContext())) {
205             getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
206         }
207 
208         PreferenceScreen prefSet = getPreferenceScreen();
209         mVoicemailSettingsScreen =
210                 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
211         mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
212                 VoicemailSettingsActivity.class));
213 
214         mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
215 
216         mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
217 
218         PersistableBundle carrierConfig =
219                 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
220 
221         if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
222             mButtonAutoRetry.setOnPreferenceChangeListener(this);
223             int autoretry = Settings.Global.getInt(
224                     getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
225             mButtonAutoRetry.setChecked(autoretry != 0);
226         } else {
227             prefSet.removePreference(mButtonAutoRetry);
228             mButtonAutoRetry = null;
229         }
230 
231         Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
232         Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
233         if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
234             cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
235             gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
236         } else {
237             prefSet.removePreference(cdmaOptions);
238             prefSet.removePreference(gsmOptions);
239 
240             int phoneType = mPhone.getPhoneType();
241             Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
242             if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
243                 prefSet.removePreference(fdnButton);
244             } else {
245                 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
246                     prefSet.removePreference(fdnButton);
247 
248                     if (!carrierConfig.getBoolean(
249                             CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
250                         addPreferencesFromResource(R.xml.cdma_call_privacy);
251                     }
252                 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
253                     fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
254 
255                     if (carrierConfig.getBoolean(
256                             CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
257                         addPreferencesFromResource(R.xml.gsm_umts_call_options);
258                         GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
259                     }
260                 } else {
261                     throw new IllegalStateException("Unexpected phone type: " + phoneType);
262                 }
263             }
264         }
265 
266         if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
267             boolean currentValue =
268                     ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
269                     ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
270                             getOpPackageName()) : false;
271             mEnableVideoCalling.setChecked(currentValue);
272             mEnableVideoCalling.setOnPreferenceChangeListener(this);
273         } else {
274             prefSet.removePreference(mEnableVideoCalling);
275         }
276 
277         if (ImsManager.isVolteEnabledByPlatform(this) &&
278                 !carrierConfig.getBoolean(
279                         CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
280             TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
281             /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
282         }
283 
284         Preference wifiCallingSettings = findPreference(
285                 getResources().getString(R.string.wifi_calling_settings_key));
286 
287         final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
288         if (simCallManager != null) {
289             Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
290                     this, simCallManager);
291             if (intent != null) {
292                 wifiCallingSettings.setTitle(R.string.wifi_calling);
293                 wifiCallingSettings.setSummary(null);
294                 wifiCallingSettings.setIntent(intent);
295             } else {
296                 prefSet.removePreference(wifiCallingSettings);
297             }
298         } else if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
299             prefSet.removePreference(wifiCallingSettings);
300         } else {
301             int resId = com.android.internal.R.string.wifi_calling_off_summary;
302             if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
303                 int wfcMode = ImsManager.getWfcMode(mPhone.getContext());
304                 switch (wfcMode) {
305                     case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
306                         resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
307                         break;
308                     case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
309                         resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
310                         break;
311                     case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
312                         resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
313                         break;
314                     default:
315                         if (DBG) log("Unexpected WFC mode value: " + wfcMode);
316                 }
317             }
318             wifiCallingSettings.setSummary(resId);
319         }
320     }
321 
322     @Override
onNewIntent(Intent newIntent)323     protected void onNewIntent(Intent newIntent) {
324         setIntent(newIntent);
325 
326         mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
327         mSubscriptionInfoHelper.setActionBarTitle(
328                 getActionBar(), getResources(), R.string.call_settings_with_label);
329         mPhone = mSubscriptionInfoHelper.getPhone();
330     }
331 
log(String msg)332     private static void log(String msg) {
333         Log.d(LOG_TAG, msg);
334     }
335 
336     @Override
onOptionsItemSelected(MenuItem item)337     public boolean onOptionsItemSelected(MenuItem item) {
338         final int itemId = item.getItemId();
339         if (itemId == android.R.id.home) {  // See ActionBar#setDisplayHomeAsUpEnabled()
340             onBackPressed();
341             return true;
342         }
343         return super.onOptionsItemSelected(item);
344     }
345 
346     /**
347      * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
348      * This is useful for implementing "HomeAsUp" capability for second-level Settings.
349      */
goUpToTopLevelSetting( Activity activity, SubscriptionInfoHelper subscriptionInfoHelper)350     public static void goUpToTopLevelSetting(
351             Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
352         Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
353         intent.setAction(Intent.ACTION_MAIN);
354         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
355         activity.startActivity(intent);
356         activity.finish();
357     }
358 }
359