Support for detection of international call while on WFC only.
Tyler Gunn [Mon, 27 Feb 2017 21:14:01 +0000 (13:14 -0800)]
Adding new method to detect scenario where we are on WFC only and attempt
to make an international call.

Test: Manual, unit
Bug: 33272455
Change-Id: I5d83710a67b0ebf40df29df87456d92af9bff08b

src/java/com/android/internal/telephony/GsmCdmaPhone.java
tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java

index 73ad1c5..e10620b 100644 (file)
@@ -45,6 +45,7 @@ import android.telephony.CarrierConfigManager;
 import android.telephony.CellLocation;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.ServiceState;
+import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.telephony.UssdResponse;
@@ -72,7 +73,6 @@ import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.telephony.cdma.CdmaMmiCode;
 import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
 import com.android.internal.telephony.cdma.EriManager;
-import com.android.internal.telephony.dataconnection.DcTracker;
 import com.android.internal.telephony.gsm.GsmMmiCode;
 import com.android.internal.telephony.gsm.SuppServiceNotification;
 import com.android.internal.telephony.test.SimulatedRadioControl;
@@ -1142,6 +1142,42 @@ public class GsmCdmaPhone extends Phone {
         }
     }
 
+    /**
+     * @return {@code true} if the user should be informed of an attempt to dial an international
+     * number while on WFC only, {@code false} otherwise.
+     */
+    public boolean isNotificationOfWfcCallRequired(String dialString) {
+        CarrierConfigManager configManager =
+                (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
+        PersistableBundle config = configManager.getConfigForSubId(getSubId());
+
+        // Determine if carrier config indicates that international calls over WFC should trigger a
+        // notification to the user. This is controlled by carrier configuration and is off by
+        // default.
+        boolean shouldNotifyInternationalCallOnWfc = config != null
+                && config.getBoolean(
+                        CarrierConfigManager.KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL);
+
+        if (!shouldNotifyInternationalCallOnWfc) {
+            return false;
+        }
+
+        Phone imsPhone = mImsPhone;
+        boolean isEmergency = PhoneNumberUtils.isEmergencyNumber(getSubId(), dialString);
+        boolean shouldConfirmCall =
+                        // Using IMS
+                        isImsUseEnabled()
+                        && imsPhone != null
+                        // VoLTE not available
+                        && !imsPhone.isVolteEnabled()
+                        // WFC is available
+                        && imsPhone.isWifiCallingEnabled()
+                        && !isEmergency
+                        // Dialing international number
+                        && PhoneNumberUtils.isInternationalNumber(dialString, getCountryIso());
+        return shouldConfirmCall;
+    }
+
     private synchronized boolean addToMMIQueue(MmiCode mmi) {
         if (mPendingMMIs.size() >= 1) {
             mMMIQueue.offerLast(mmi);
@@ -3320,6 +3356,19 @@ public class GsmCdmaPhone extends Phone {
         return operatorNumeric;
     }
 
+    /**
+     * @return The country ISO for the subscription associated with this phone.
+     */
+    public String getCountryIso() {
+        int subId = getSubId();
+        SubscriptionInfo subInfo = SubscriptionManager.from(getContext())
+                .getActiveSubscriptionInfo(subId);
+        if (subInfo == null) {
+            return null;
+        }
+        return subInfo.getCountryIso().toUpperCase();
+    }
+
     public void notifyEcbmTimerReset(Boolean flag) {
         mEcmTimerResetRegistrants.notifyResult(flag);
     }
index 03ecb9e..25fe690 100644 (file)
@@ -19,10 +19,10 @@ package com.android.internal.telephony;
 import android.net.Uri;
 import android.platform.test.annotations.Postsubmit;
 import android.support.test.filters.FlakyTest;
+import android.telephony.PhoneNumberUtils;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.text.SpannableStringBuilder;
-import android.telephony.PhoneNumberUtils;
 
 public class PhoneNumberUtilsTest extends AndroidTestCase {
 
@@ -692,4 +692,17 @@ public class PhoneNumberUtilsTest extends AndroidTestCase {
         converted = PhoneNumberUtils.convertSipUriToTelUri(source);
         assertEquals(expected, converted);
     }
+
+    @SmallTest
+    public void testIsInternational() {
+        assertFalse(PhoneNumberUtils.isInternationalNumber("+16505551212", "US"));
+        assertTrue(PhoneNumberUtils.isInternationalNumber("+16505551212", "UK"));
+        assertTrue(PhoneNumberUtils.isInternationalNumber("+16505551212", "JP"));
+        assertTrue(PhoneNumberUtils.isInternationalNumber("+86 10 8888 0000", "US"));
+        assertTrue(PhoneNumberUtils.isInternationalNumber("001-541-754-3010", "DE"));
+        assertFalse(PhoneNumberUtils.isInternationalNumber("001-541-754-3010", "US"));
+        assertTrue(PhoneNumberUtils.isInternationalNumber("01161396694916", "US"));
+        assertTrue(PhoneNumberUtils.isInternationalNumber("011-613-966-94916", "US"));
+        assertFalse(PhoneNumberUtils.isInternationalNumber("011-613-966-94916", "AU"));
+    }
 }