blob: 11f81ffc191291e9bdb07c786a1ca456a5302ae5 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
19import android.app.ActionBar;
20import android.app.Activity;
Evan Charlton1c696832014-04-15 14:24:23 -070021import android.app.ActivityOptions;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AlertDialog;
23import android.app.Dialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.DialogInterface;
27import android.content.Intent;
Yorke Lee0b8d2252015-06-10 16:31:20 -070028import android.content.pm.PackageManager;
29import android.content.pm.ResolveInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070031import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.os.UserHandle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.preference.CheckBoxPreference;
34import android.preference.ListPreference;
35import android.preference.Preference;
36import android.preference.PreferenceActivity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.preference.PreferenceScreen;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070039import android.telecom.PhoneAccountHandle;
40import android.telecom.TelecomManager;
Jonathan Basseri4b40ff42015-04-30 21:54:10 -070041import android.telephony.CarrierConfigManager;
Andrew Lee93c345f2014-10-27 15:25:07 -070042import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.text.TextUtils;
44import android.util.Log;
45import android.view.MenuItem;
Jay Shraunerc2684732014-11-12 12:10:37 -080046import android.widget.Toast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047
Andrew Leeeffef9c2015-02-19 16:02:37 -080048import com.android.ims.ImsConfig;
Andrew Lee312e8172014-10-23 17:01:36 -070049import com.android.ims.ImsManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import com.android.internal.telephony.CallForwardInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import com.android.internal.telephony.Phone;
52import com.android.internal.telephony.PhoneConstants;
Andrew Lee2170a972014-08-13 18:13:01 -070053import com.android.phone.common.util.SettingsUtil;
Andrew Leedb2fe562014-09-03 15:40:43 -070054import com.android.phone.settings.AccountSelectionPreference;
Andrew Leebf07f762015-04-07 19:05:50 -070055import com.android.phone.settings.VoicemailSettingsActivity;
Andrew Lee5ed870c2014-10-29 11:47:49 -070056import com.android.phone.settings.fdn.FdnSetting;
Sailesh Nepal788959e2014-07-08 23:36:40 -070057import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058
Andrew Lee2170a972014-08-13 18:13:01 -070059import java.lang.String;
Andrew Leef1776d82014-11-04 14:45:02 -080060import java.util.ArrayList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import java.util.List;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062
63/**
64 * Top level "Call settings" UI; see res/xml/call_feature_setting.xml
65 *
Andrew Leece8ae2a2014-09-10 10:41:48 -070066 * This preference screen is the root of the "Call settings" hierarchy available from the Phone
67 * app; the settings here let you control various features related to phone calls (including
68 * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
69 * voice-capable phone devices.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070 *
71 * Note that this activity is part of the package com.android.phone, even
72 * though you reach it from the "Phone" app (i.e. DialtactsActivity) which
73 * is from the package com.android.contacts.
74 *
75 * For the "Mobile network settings" screen under the main Settings app,
76 * See {@link MobileNetworkSettings}.
77 *
78 * @see com.android.phone.MobileNetworkSettings
79 */
80public class CallFeaturesSetting extends PreferenceActivity
Andrew Leebf07f762015-04-07 19:05:50 -070081 implements Preference.OnPreferenceChangeListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082 private static final String LOG_TAG = "CallFeaturesSetting";
83 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
Andrew Lee77527ac2014-10-21 16:57:39 -070084 // STOPSHIP if true. Flag to override behavior default behavior to hide VT setting.
Etan Cohenfd9760e2015-04-29 16:26:14 -070085 private static final boolean ENABLE_VT_FLAG = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087 // String keys for preference lookup
88 // TODO: Naming these "BUTTON_*" is confusing since they're not actually buttons(!)
Andrew Lee8d66d812014-11-24 14:54:02 -080089 // TODO: Consider moving these strings to strings.xml, so that they are not duplicated here and
90 // in the layout files. These strings need to be treated carefully; if the setting is
91 // persistent, they are used as the key to store shared preferences and the name should not be
92 // changed unless the settings are also migrated.
Andrew Lee97708a42014-09-25 12:39:07 -070093 private static final String VOICEMAIL_SETTING_SCREEN_PREF_KEY = "button_voicemail_category_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094 private static final String BUTTON_FDN_KEY = "button_fdn_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095 private static final String BUTTON_RETRY_KEY = "button_auto_retry_key";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096 private static final String BUTTON_GSM_UMTS_OPTIONS = "button_gsm_more_expand_key";
97 private static final String BUTTON_CDMA_OPTIONS = "button_cdma_more_expand_key";
98
Andrew Leece8ae2a2014-09-10 10:41:48 -070099 private static final String PHONE_ACCOUNT_SETTINGS_KEY =
100 "phone_account_settings_preference_screen";
Andrew Leedb2fe562014-09-03 15:40:43 -0700101
Andrew Leedf14ead2014-10-17 14:22:52 -0700102 private static final String ENABLE_VIDEO_CALLING_KEY = "button_enable_video_calling";
103
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104 private Phone mPhone;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700105 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Yorke Lee0b8d2252015-06-10 16:31:20 -0700106 private TelecomManager mTelecomManager;
Andrew Lee5ed870c2014-10-29 11:47:49 -0700107
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 private CheckBoxPreference mButtonAutoRetry;
Andrew Lee97708a42014-09-25 12:39:07 -0700109 private PreferenceScreen mVoicemailSettingsScreen;
Andrew Leedf14ead2014-10-17 14:22:52 -0700110 private CheckBoxPreference mEnableVideoCalling;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112 /*
113 * Click Listeners, handle click based on objects attached to UI.
114 */
115
116 // Click listener for all toggle events
117 @Override
118 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Andrew Leebf07f762015-04-07 19:05:50 -0700119 if (preference == mButtonAutoRetry) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
121 android.provider.Settings.Global.CALL_AUTO_RETRY,
122 mButtonAutoRetry.isChecked() ? 1 : 0);
123 return true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124 }
125 return false;
126 }
127
128 /**
129 * Implemented to support onPreferenceChangeListener to look for preference
130 * changes.
131 *
132 * @param preference is the preference to be changed
133 * @param objValue should be the value of the selection, NOT its localized
134 * display value.
135 */
136 @Override
137 public boolean onPreferenceChange(Preference preference, Object objValue) {
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800138 if (DBG) log("onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
Andrew Lee2170a972014-08-13 18:13:01 -0700139
Andrew Leebf07f762015-04-07 19:05:50 -0700140 if (preference == mEnableVideoCalling) {
Andrew Lee312e8172014-10-23 17:01:36 -0700141 if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
142 PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
143 } else {
144 AlertDialog.Builder builder = new AlertDialog.Builder(this);
145 DialogInterface.OnClickListener networkSettingsClickListener =
146 new Dialog.OnClickListener() {
147 @Override
148 public void onClick(DialogInterface dialog, int which) {
149 startActivity(new Intent(mPhone.getContext(),
150 com.android.phone.MobileNetworkSettings.class));
151 }
152 };
153 builder.setMessage(getResources().getString(
154 R.string.enable_video_calling_dialog_msg))
155 .setNeutralButton(getResources().getString(
156 R.string.enable_video_calling_dialog_settings),
157 networkSettingsClickListener)
158 .setPositiveButton(android.R.string.ok, null)
159 .show();
160 return false;
161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 }
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800163
164 // Always let the preference setting proceed.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 return true;
166 }
167
168 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169 protected void onCreate(Bundle icicle) {
170 super.onCreate(icicle);
Andrew Lee4ddb9bb2014-11-05 15:03:20 -0800171 if (DBG) log("onCreate: Intent is " + getIntent());
172
Jay Shraunerc2684732014-11-12 12:10:37 -0800173 // Make sure we are running as the primary user.
174 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
175 Toast.makeText(this, R.string.call_settings_primary_user_only,
176 Toast.LENGTH_SHORT).show();
177 finish();
178 return;
179 }
180
Andrew Leedd4f6df2014-12-09 19:13:51 -0800181 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5ed870c2014-10-29 11:47:49 -0700182 mSubscriptionInfoHelper.setActionBarTitle(
183 getActionBar(), getResources(), R.string.call_settings_with_label);
Andrew Lee1479dd12014-11-06 23:06:32 -0800184 mPhone = mSubscriptionInfoHelper.getPhone();
Yorke Lee0b8d2252015-06-10 16:31:20 -0700185 mTelecomManager = TelecomManager.from(this);
Tyler Gunnbaee2952014-09-10 16:01:02 -0700186 }
187
Tyler Gunnbaee2952014-09-10 16:01:02 -0700188 @Override
189 protected void onResume() {
190 super.onResume();
Tyler Gunnbaee2952014-09-10 16:01:02 -0700191
192 PreferenceScreen preferenceScreen = getPreferenceScreen();
193 if (preferenceScreen != null) {
194 preferenceScreen.removeAll();
195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 addPreferencesFromResource(R.xml.call_feature_setting);
Andrew Lee5ed870c2014-10-29 11:47:49 -0700198
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800199 TelephonyManager telephonyManager =
200 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
201
202 Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
Santos Cordonc9c48432015-06-12 17:01:21 -0700203 if (telephonyManager.isMultiSimEnabled() || !SipUtil.isVoipSupported(mPhone.getContext())) {
Andrew Lee6fee2cb2014-12-09 16:42:18 -0800204 getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
205 }
Andrew Leedb2fe562014-09-03 15:40:43 -0700206
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207 PreferenceScreen prefSet = getPreferenceScreen();
Andrew Lee2c027892014-10-29 11:29:54 -0700208 mVoicemailSettingsScreen =
209 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
Andrew Leebf07f762015-04-07 19:05:50 -0700210 mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
211 VoicemailSettingsActivity.class));
Andrew Lee8d66d812014-11-24 14:54:02 -0800212
Andrew Leebf07f762015-04-07 19:05:50 -0700213 mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
Andrew Lee64e5c9d2014-11-26 12:00:10 -0800214
215 mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700217 PersistableBundle carrierConfig =
218 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
Jonathan Basseri4b40ff42015-04-30 21:54:10 -0700219
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700220 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL)) {
Andrew Lee64a7d792014-10-15 17:38:38 -0700221 mButtonAutoRetry.setOnPreferenceChangeListener(this);
222 int autoretry = Settings.Global.getInt(
223 getContentResolver(), Settings.Global.CALL_AUTO_RETRY, 0);
224 mButtonAutoRetry.setChecked(autoretry != 0);
225 } else {
226 prefSet.removePreference(mButtonAutoRetry);
227 mButtonAutoRetry = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 }
229
Sanket Padawee09a6f62015-03-05 11:59:39 -0800230 Preference cdmaOptions = prefSet.findPreference(BUTTON_CDMA_OPTIONS);
231 Preference gsmOptions = prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS);
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700232 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
Sanket Padawee09a6f62015-03-05 11:59:39 -0800233 cdmaOptions.setIntent(mSubscriptionInfoHelper.getIntent(CdmaCallOptions.class));
234 gsmOptions.setIntent(mSubscriptionInfoHelper.getIntent(GsmUmtsCallOptions.class));
235 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -0800236 prefSet.removePreference(cdmaOptions);
Andrew Lee2b36ba22014-11-05 17:08:49 -0800237 prefSet.removePreference(gsmOptions);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239 int phoneType = mPhone.getPhoneType();
Andrew Lee5ed870c2014-10-29 11:47:49 -0700240 Preference fdnButton = prefSet.findPreference(BUTTON_FDN_KEY);
Junda Liua9ba9d42015-06-01 01:26:52 -0700241 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
Andrew Lee5ed870c2014-10-29 11:47:49 -0700242 prefSet.removePreference(fdnButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 } else {
Junda Liua09d6962014-11-12 13:39:02 -0800244 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
245 prefSet.removePreference(fdnButton);
246
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700247 if (!carrierConfig.getBoolean(
Jonathan Basseri38c58552015-06-09 15:14:06 -0700248 CarrierConfigManager.KEY_VOICE_PRIVACY_DISABLE_UI_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800249 addPreferencesFromResource(R.xml.cdma_call_privacy);
250 }
251 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
Andrew Leedd4f6df2014-12-09 19:13:51 -0800252 fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
Junda Liua09d6962014-11-12 13:39:02 -0800253
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700254 if (carrierConfig.getBoolean(
255 CarrierConfigManager.KEY_ADDITIONAL_CALL_SETTING_BOOL)) {
Junda Liua09d6962014-11-12 13:39:02 -0800256 addPreferencesFromResource(R.xml.gsm_umts_call_options);
Sanket Padawee09a6f62015-03-05 11:59:39 -0800257 GsmUmtsCallOptions.init(prefSet, mSubscriptionInfoHelper);
Junda Liua09d6962014-11-12 13:39:02 -0800258 }
259 } else {
260 throw new IllegalStateException("Unexpected phone type: " + phoneType);
261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 }
263 }
264
Andrew Lee312e8172014-10-23 17:01:36 -0700265 if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
266 boolean currentValue =
267 ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Svet Ganovb320e182015-04-16 12:30:10 -0700268 ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled(
269 getOpPackageName()) : false;
Andrew Lee312e8172014-10-23 17:01:36 -0700270 mEnableVideoCalling.setChecked(currentValue);
Andrew Lee77527ac2014-10-21 16:57:39 -0700271 mEnableVideoCalling.setOnPreferenceChangeListener(this);
272 } else {
273 prefSet.removePreference(mEnableVideoCalling);
274 }
Etan Cohena51d4ef2014-12-15 10:44:42 -0800275
276 if (ImsManager.isVolteEnabledByPlatform(this) &&
277 !mPhone.getContext().getResources().getBoolean(
278 com.android.internal.R.bool.config_carrier_volte_tty_supported)) {
279 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Vinit Deshpande84cccac2015-03-16 00:08:19 -0700280 /* tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); */
Etan Cohena51d4ef2014-12-15 10:44:42 -0800281 }
Andrew Leeb97fad82015-01-27 15:31:39 -0800282
Andrew Leeeffef9c2015-02-19 16:02:37 -0800283 Preference wifiCallingSettings = findPreference(
284 getResources().getString(R.string.wifi_calling_settings_key));
Yorke Lee0b8d2252015-06-10 16:31:20 -0700285
286 final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
287 String simCallManagerPackage = simCallManager != null
288 && simCallManager.getComponentName() != null
289 ? simCallManager.getComponentName().getPackageName()
290 : null;
291
292 if (!TextUtils.isEmpty(simCallManagerPackage)) {
293 final Intent intent = new Intent(TelecomManager.ACTION_CONNECTION_SERVICE_CONFIGURE)
294 .addCategory(Intent.CATEGORY_DEFAULT)
295 .setPackage(simCallManagerPackage);
296
297 // Check whether the configuration intent is supported.
298 PackageManager pm = getPackageManager();
299 List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
300 if (resolutions.size() > 0) {
301 wifiCallingSettings.setTitle(R.string.wifi_calling);
302 wifiCallingSettings.setSummary(null);
303 wifiCallingSettings.setIntent(intent);
304 } else {
305 prefSet.removePreference(wifiCallingSettings);
306 }
307 } else if (!ImsManager.isWfcEnabledByPlatform(mPhone.getContext())) {
Andrew Leeb97fad82015-01-27 15:31:39 -0800308 prefSet.removePreference(wifiCallingSettings);
Andrew Leeeffef9c2015-02-19 16:02:37 -0800309 } else {
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700310 int resId = com.android.internal.R.string.wifi_calling_off_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800311 if (ImsManager.isWfcEnabledByUser(mPhone.getContext())) {
312 int wfcMode = ImsManager.getWfcMode(mPhone.getContext());
313 switch (wfcMode) {
314 case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700315 resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800316 break;
317 case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700318 resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800319 break;
320 case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
Pavel Zhamaitsiakecae65a2015-03-23 14:45:34 -0700321 resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
Andrew Leeeffef9c2015-02-19 16:02:37 -0800322 break;
323 default:
324 if (DBG) log("Unexpected WFC mode value: " + wfcMode);
325 }
326 }
327 wifiCallingSettings.setSummary(resId);
Andrew Leeb97fad82015-01-27 15:31:39 -0800328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 }
330
Andrew Lee785ca2a2014-12-18 12:46:41 -0800331 @Override
332 protected void onNewIntent(Intent newIntent) {
333 setIntent(newIntent);
334
335 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
336 mSubscriptionInfoHelper.setActionBarTitle(
337 getActionBar(), getResources(), R.string.call_settings_with_label);
338 mPhone = mSubscriptionInfoHelper.getPhone();
339 }
340
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 private static void log(String msg) {
342 Log.d(LOG_TAG, msg);
343 }
344
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 @Override
346 public boolean onOptionsItemSelected(MenuItem item) {
347 final int itemId = item.getItemId();
348 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Yorke Leef2d0cac2013-09-09 19:42:56 -0700349 onBackPressed();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 return true;
351 }
352 return super.onOptionsItemSelected(item);
353 }
Andrew Lee8d66d812014-11-24 14:54:02 -0800354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 /**
356 * Finish current Activity and go up to the top level Settings ({@link CallFeaturesSetting}).
357 * This is useful for implementing "HomeAsUp" capability for second-level Settings.
358 */
Andrew Lee5efb1122014-12-05 04:20:42 -0800359 public static void goUpToTopLevelSetting(
Andrew Leedd4f6df2014-12-09 19:13:51 -0800360 Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
361 Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 intent.setAction(Intent.ACTION_MAIN);
363 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
364 activity.startActivity(intent);
365 activity.finish();
366 }
367}