implement feature for Supplementary Service over UT precautions.
Some carriers only support SS over UT via INTERNET PDN.
When mobile data is OFF or data roaming OFF during roaming,
we should block the supplementary service and notify the user
that the function only works if data is available.
Bug: 80404623
Test: manual - test case as below :
1.flag cf_precautions true ,turn off mobile data, enter CF ,show dialog
for blocking supplementary services.(PASS)
2.flag cf_precautions true ,turn on mobile data, enter CF ,do CF init.(PASS)
3.flag cb_precautions true ,turn off mobile data, enter CB ,show dialog
for blocking supplementary services.(PASS)
4.flag cb_precautions true ,turn on mobile data, enter CB ,do CB init.(PASS)
5.CW hide,flag clir_precautions true ,turn off mobile data, enter Additional
setting ,show dialog for blocking supplementary services.(PASS)
6.CW hide,flag clir_precautions true ,turn on mobile data, enter Additional
setting ,do CLIR init.(PASS)
7.CLIR hide,flag cw_precautions true ,turn off mobile data, enter Additional
setting ,show dialog for blocking supplementary services.(PASS)
8.CLIR hide,flag cw_precautions true ,turn on mobile data, enter
Additional setting ,do CW init.(PASS)
9.flag clir_precautions and cw_precautions true ,turn off mobile data, enter
Additional setting ,show dialog for blocking supplementary services.(PASS)
10.flag clir_precautions and cw_precautions true ,turn on mobile data,
enter Additional setting ,do CW init and CLIR init.(PASS)
11.flag clir_precautions false and cw_precautions true ,turn off mobile data,
enter Additional setting ,show dialog for blocking supplementary services
and do CW init.(PASS)
12.flag clir_precautions false and cw_precautions true ,turn on mobile data,
enter Additional setting ,do CW init and CLIR init.(PASS)
13.flag clir_precautions true and cw_precautions false ,turn off mobile data,
enter Additional setting ,show dialog for blocking supplementary services
and do CLIR init.(PASS)
14.flag clir_precautions false and cw_precautions true ,turn on mobile data,
enter Additional setting ,do CW init and CLIR init.(PASS)
15.flag clir_precautions and cw_precautions false ,turn on mobile data,
enter Additional setting ,do CW init and CLIR init.(PASS)
Change-Id: Iff828e57ef87ec6c97492b89e2b0fb5a9437f0d6
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index e2f4fee..5c744a7 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -49,6 +49,7 @@
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.phone.settings.PhoneAccountSettingsFragment;
+import com.android.phone.settings.SuppServicesUiUtil;
import com.android.phone.settings.VoicemailSettingsActivity;
import com.android.phone.settings.fdn.FdnSetting;
@@ -115,6 +116,37 @@
android.provider.Settings.Global.CALL_AUTO_RETRY,
mButtonAutoRetry.isChecked() ? 1 : 0);
return true;
+ } else if (preference == preferenceScreen.findPreference(
+ GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
+ return doSsOverUtPrecautions(preference);
+ } else if (preference == preferenceScreen.findPreference(
+ GsmUmtsCallOptions.CALL_BARRING_KEY)) {
+ return doSsOverUtPrecautions(preference);
+ }
+ return false;
+ }
+
+ private boolean doSsOverUtPrecautions(Preference preference) {
+ PersistableBundle b = null;
+ if (mSubscriptionInfoHelper.hasSubId()) {
+ b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
+ mSubscriptionInfoHelper.getSubId());
+ } else {
+ b = PhoneGlobals.getInstance().getCarrierConfig();
+ }
+
+ String configKey;
+ if (preference.getKey().equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
+ configKey = CarrierConfigManager.KEY_CALL_FORWARDING_OVER_UT_WARNING_BOOL;
+ } else {
+ configKey = CarrierConfigManager.KEY_CALL_BARRING_OVER_UT_WARNING_BOOL;
+ }
+ if (b != null && b.getBoolean(configKey)
+ && mPhone != null
+ && SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone)) {
+ SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone,
+ preference.getKey()).show();
+ return true;
}
return false;
}
diff --git a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
index b79cdd8..6e28922 100644
--- a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
+++ b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
@@ -1,6 +1,7 @@
package com.android.phone;
import android.app.ActionBar;
+import android.app.Dialog;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.preference.Preference;
@@ -10,6 +11,7 @@
import android.view.MenuItem;
import com.android.internal.telephony.Phone;
+import com.android.phone.settings.SuppServicesUiUtil;
import java.util.ArrayList;
@@ -17,8 +19,11 @@
private static final String LOG_TAG = "GsmUmtsAdditionalCallOptions";
private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
- private static final String BUTTON_CLIR_KEY = "button_clir_key";
- private static final String BUTTON_CW_KEY = "button_cw_key";
+ public static final String BUTTON_CLIR_KEY = "button_clir_key";
+ public static final String BUTTON_CW_KEY = "button_cw_key";
+
+ private static final int CW_WARNING_DIALOG = 201;
+ private static final int CALLER_ID_WARNING_DIALOG = 202;
private CLIRListPreference mCLIRButton;
private CallWaitingSwitchPreference mCWButton;
@@ -28,8 +33,10 @@
private Phone mPhone;
private SubscriptionInfoHelper mSubscriptionInfoHelper;
- private boolean mShowCLIRButton;
- private boolean mShowCWButton;
+ private boolean mShowCLIRButton = true;
+ private boolean mShowCWButton = true;
+ private boolean mCLIROverUtPrecautions = false;
+ private boolean mCWOverUtPrecautions = false;
@Override
protected void onCreate(Bundle icicle) {
@@ -59,11 +66,25 @@
CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL);
mShowCWButton = b.getBoolean(
CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL);
+ mCLIROverUtPrecautions = mShowCLIRButton && b.getBoolean(
+ CarrierConfigManager.KEY_CALLER_ID_OVER_UT_WARNING_BOOL);
+ mCWOverUtPrecautions = mShowCWButton && b.getBoolean(
+ CarrierConfigManager.KEY_CALL_WAITING_OVER_UT_WARNING_BOOL);
+ if (DBG) {
+ Log.d(LOG_TAG, "mCLIROverUtPrecautions:" + mCLIROverUtPrecautions
+ + ",mCWOverUtPrecautions:" + mCWOverUtPrecautions);
+ }
}
+ boolean isSsOverUtPrecautions = SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone);
+
if (mCLIRButton != null) {
if (mShowCLIRButton) {
- mPreferences.add(mCLIRButton);
+ if (mCLIROverUtPrecautions && isSsOverUtPrecautions) {
+ mCLIRButton.setEnabled(false);
+ } else {
+ mPreferences.add(mCLIRButton);
+ }
} else {
prefSet.removePreference(mCLIRButton);
}
@@ -71,7 +92,11 @@
if (mCWButton != null) {
if (mShowCWButton) {
- mPreferences.add(mCWButton);
+ if (mCWOverUtPrecautions && isSsOverUtPrecautions) {
+ mCWButton.setEnabled(false);
+ } else {
+ mPreferences.add(mCWButton);
+ }
} else {
prefSet.removePreference(mCWButton);
}
@@ -84,10 +109,10 @@
} else {
if (DBG) Log.d(LOG_TAG, "restore stored states");
mInitIndex = mPreferences.size();
- if (mShowCWButton) {
+ if (mShowCWButton && mCWButton != null && mCWButton.isEnabled()) {
mCWButton.init(this, true, mPhone);
}
- if (mShowCLIRButton) {
+ if (mShowCLIRButton && mCLIRButton != null && mCLIRButton.isEnabled()) {
mCLIRButton.init(this, true, mPhone);
int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
if (clirArray != null) {
@@ -111,6 +136,52 @@
}
@Override
+ public void onResume() {
+ super.onResume();
+ int indexOfStartInit = mPreferences.size();
+ boolean isPrecaution = SuppServicesUiUtil.isSsOverUtPrecautions(this, mPhone);
+ dismissWarningDialog();
+
+ if (mShowCLIRButton && mCLIROverUtPrecautions && mCLIRButton != null) {
+ if (isPrecaution) {
+ showWarningDialog(CW_WARNING_DIALOG);
+ if (mCLIRButton.isEnabled()) {
+ if (mPreferences.contains(mCLIRButton)) {
+ mPreferences.remove(mCLIRButton);
+ }
+ mCLIRButton.setEnabled(false);
+ }
+ } else {
+ if (!mPreferences.contains(mCLIRButton)) {
+ mCLIRButton.setEnabled(true);
+ mPreferences.add(mCLIRButton);
+ }
+ }
+ }
+ if (mShowCWButton && mCWOverUtPrecautions && mCWButton != null) {
+ if (isPrecaution) {
+ showWarningDialog(CALLER_ID_WARNING_DIALOG);
+ if (mCWButton.isEnabled()) {
+ if (mPreferences.contains(mCWButton)) {
+ mPreferences.remove(mCWButton);
+ }
+ mCWButton.setEnabled(false);
+ }
+ } else {
+ if (!mPreferences.contains(mCWButton)) {
+ mCWButton.setEnabled(true);
+ mPreferences.add(mCWButton);
+ }
+ }
+ }
+
+ if (indexOfStartInit < mPreferences.size()) {
+ mInitIndex = indexOfStartInit;
+ doPreferenceInit(indexOfStartInit);
+ }
+ }
+
+ @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@@ -139,7 +210,7 @@
}
private void doPreferenceInit(int index) {
- if (mPreferences.size() != 0) {
+ if (mPreferences.size() > index) {
Preference pref = mPreferences.get(index);
if (pref instanceof CallWaitingSwitchPreference) {
((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
@@ -148,4 +219,23 @@
}
}
}
+
+ @Override
+ protected Dialog onCreateDialog(int id) {
+ if (id == CW_WARNING_DIALOG) {
+ return SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone, BUTTON_CW_KEY);
+ } else if (id == CALLER_ID_WARNING_DIALOG) {
+ return SuppServicesUiUtil.showBlockingSuppServicesDialog(this, mPhone, BUTTON_CLIR_KEY);
+ }
+ return super.onCreateDialog(id);
+ }
+
+ private void showWarningDialog(int id) {
+ showDialog(id);
+ }
+
+ private void dismissWarningDialog() {
+ dismissDialogSafely(CW_WARNING_DIALOG);
+ dismissDialogSafely(CALLER_ID_WARNING_DIALOG);
+ }
}
diff --git a/src/com/android/phone/GsmUmtsCallOptions.java b/src/com/android/phone/GsmUmtsCallOptions.java
index ab44b54..88cae54 100644
--- a/src/com/android/phone/GsmUmtsCallOptions.java
+++ b/src/com/android/phone/GsmUmtsCallOptions.java
@@ -30,8 +30,8 @@
private static final String LOG_TAG = "GsmUmtsCallOptions";
private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
- private static final String CALL_FORWARDING_KEY = "call_forwarding_key";
- private static final String CALL_BARRING_KEY = "call_barring_key";
+ public static final String CALL_FORWARDING_KEY = "call_forwarding_key";
+ public static final String CALL_BARRING_KEY = "call_barring_key";
private static final String ADDITIONAL_GSM_SETTINGS_KEY = "additional_gsm_call_settings_key";
@Override
diff --git a/src/com/android/phone/TimeConsumingPreferenceActivity.java b/src/com/android/phone/TimeConsumingPreferenceActivity.java
index 354c4bb..8c5ae6d 100644
--- a/src/com/android/phone/TimeConsumingPreferenceActivity.java
+++ b/src/com/android/phone/TimeConsumingPreferenceActivity.java
@@ -222,7 +222,7 @@
finish();
}
- private void dismissDialogSafely(int id) {
+ protected void dismissDialogSafely(int id) {
try {
dismissDialog(id);
} catch (IllegalArgumentException e) {
diff --git a/src/com/android/phone/settings/SuppServicesUiUtil.java b/src/com/android/phone/settings/SuppServicesUiUtil.java
new file mode 100644
index 0000000..7c647f4
--- /dev/null
+++ b/src/com/android/phone/settings/SuppServicesUiUtil.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.phone.settings;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.telephony.TelephonyManager;
+
+import com.android.internal.telephony.Phone;
+import com.android.phone.GsmUmtsAdditionalCallOptions;
+import com.android.phone.GsmUmtsCallOptions;
+import com.android.phone.R;
+
+/**
+ * Utility class to help supplementary service functions and UI.
+ */
+public class SuppServicesUiUtil {
+ static final String LOG_TAG = "SuppServicesUiUtil";
+
+ /**
+ * show dialog for supplementary services over ut precaution.
+ *
+ * @param context The context.
+ * @param phone The Phone object.
+ * @param preferenceKey The preference's key.
+ */
+ public static Dialog showBlockingSuppServicesDialog(Context context, Phone phone,
+ String preferenceKey) {
+ if (context == null || phone == null) {
+ return null;
+ }
+
+ String message = makeMessage(context, preferenceKey, phone);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ DialogInterface.OnClickListener networkSettingsClickListener =
+ new Dialog.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ context.startActivity(new Intent(context,
+ com.android.phone.MobileNetworkSettings.class));
+ }
+ };
+ return builder.setMessage(message)
+ .setNeutralButton(context.getResources().getString(
+ R.string.settings_label),
+ networkSettingsClickListener)
+ .setPositiveButton(context.getResources().getString(
+ R.string.supp_service_over_ut_precautions_dialog_dismiss), null)
+ .create();
+ }
+
+ private static String makeMessage(Context context, String preferenceKey, Phone phone) {
+ String message = "";
+ int simSlot = (phone.getPhoneId() == 0) ? 1 : 2;
+ String suppServiceName = getSuppServiceName(context, preferenceKey);
+
+ TelephonyManager telephonyManager =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ boolean isRoaming = telephonyManager.isNetworkRoaming(phone.getSubId());
+ boolean isMultiSim = (telephonyManager.getSimCount() > 1);
+
+ if (!isMultiSim) {
+ if (isRoaming) {
+ message = context.getResources().getString(
+ R.string.supp_service_over_ut_precautions_roaming, suppServiceName);
+ } else {
+ message = context.getResources().getString(
+ R.string.supp_service_over_ut_precautions, suppServiceName);
+ }
+ } else {
+ if (isRoaming) {
+ message = context.getResources().getString(
+ R.string.supp_service_over_ut_precautions_roaming_dual_sim, suppServiceName,
+ simSlot);
+ } else {
+ message = context.getResources().getString(
+ R.string.supp_service_over_ut_precautions_dual_sim, suppServiceName,
+ simSlot);
+ }
+ }
+ return message;
+ }
+
+ private static String getSuppServiceName(Context context, String preferenceKey) {
+ String suppServiceName = "";
+ if (preferenceKey.equals(GsmUmtsCallOptions.CALL_FORWARDING_KEY)) {
+ suppServiceName = context.getResources().getString(R.string.labelCF);
+ } else if (preferenceKey.equals(GsmUmtsCallOptions.CALL_BARRING_KEY)) {
+ suppServiceName = context.getResources().getString(R.string.labelCallBarring);
+ } else if (preferenceKey.equals(GsmUmtsAdditionalCallOptions.BUTTON_CLIR_KEY)) {
+ suppServiceName = context.getResources().getString(R.string.labelCallerId);
+ } else if (preferenceKey.equals(GsmUmtsAdditionalCallOptions.BUTTON_CW_KEY)) {
+ suppServiceName = context.getResources().getString(R.string.labelCW);
+ }
+ return suppServiceName;
+ }
+
+ /**
+ * Check SS over Ut precautions in condition which is
+ * "mobile data button is off" or "Roaming button is off during roaming".
+ *
+ * @param context The context.
+ * @param phone The Phone object.
+ * @return "mobile data button is off" or "Roaming button is off during roaming", return true.
+ */
+ public static boolean isSsOverUtPrecautions(Context context, Phone phone) {
+ if (phone == null || context == null) {
+ return false;
+ }
+ return isMobileDataOff(context, phone) || isDataRoamingOffUnderRoaming(context, phone);
+ }
+
+ private static boolean isMobileDataOff(Context context, Phone phone) {
+ TelephonyManager telephonyManager =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ return !telephonyManager.getDataEnabled(phone.getSubId());
+ }
+
+ private static boolean isDataRoamingOffUnderRoaming(Context context, Phone phone) {
+ TelephonyManager telephonyManager =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ return telephonyManager.isNetworkRoaming(phone.getSubId())
+ && !phone.getDataRoamingEnabled();
+ }
+}