Add support for recognizing WPS calls which change caller ID state.

WPS calls can use the *31# or #31# prefixes to enable or disable caller ID when dialed.  This CL adds support for recognizing calls with these prefixes as a WPS call.

Test: Added new unit tests to verify dial behavior for WPS calls with
caller ID activate/deactivate prefix.
Fixes: 173797422
Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1511375
Merged-In: I4cb717630ade3f7e4195dcdbef34952450c42ba0
Change-Id: I4cb717630ade3f7e4195dcdbef34952450c42ba0
(cherry picked from commit 5906e562b6ff1393a1862c0c7ae5f91984f7ee7c)
diff --git a/src/java/com/android/internal/telephony/GsmCdmaPhone.java b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
index 52ce7bd..651cf9e 100644
--- a/src/java/com/android/internal/telephony/GsmCdmaPhone.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
@@ -152,6 +152,10 @@
     public static final int RESTART_ECM_TIMER = 0; // restart Ecm timer
     public static final int CANCEL_ECM_TIMER = 1; // cancel Ecm timer
     private static final String PREFIX_WPS = "*272";
+    // WPS prefix when CLIR is being deactivated for the call.
+    private static final String PREFIX_WPS_CLIR_DEACTIVATE = "#31#*272";
+    // WPS prefix when CLIS is being activated for the call.
+    private static final String PREFIX_WPS_CLIR_ACTIVATE = "*31#*272";
     private CdmaSubscriptionSourceManager mCdmaSSM;
     public int mCdmaSubscriptionSource = CdmaSubscriptionSourceManager.SUBSCRIPTION_SOURCE_UNKNOWN;
     private PowerManager.WakeLock mWakeLock;
@@ -1326,7 +1330,9 @@
                 .getBoolean(CarrierConfigManager.KEY_CARRIER_USE_IMS_FIRST_FOR_EMERGENCY_BOOL);
 
         /** Check if the call is Wireless Priority Service call */
-        boolean isWpsCall = dialString != null ? dialString.startsWith(PREFIX_WPS) : false;
+        boolean isWpsCall = dialString != null ? (dialString.startsWith(PREFIX_WPS)
+                || dialString.startsWith(PREFIX_WPS_CLIR_ACTIVATE)
+                || dialString.startsWith(PREFIX_WPS_CLIR_DEACTIVATE)) : false;
         boolean allowWpsOverIms = configManager.getConfigForSubId(getSubId())
                 .getBoolean(CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL);
 
diff --git a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java
index 0dd9121..664fd0a 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java
@@ -502,8 +502,8 @@
             mContextFixture.getCarrierConfigBundle().putBoolean(
                     CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, false);
 
-            Connection connection = mPhoneUT.dial("*27216505551212",
-                    new PhoneInternalInterface.DialArgs.Builder().build());
+            mPhoneUT.dial("*27216505551212", new PhoneInternalInterface.DialArgs.Builder().build());
+
             verify(mCT).dialGsm("*27216505551212", null, null);
             verify(mImsCT).hangupAllConnections();
         } catch (CallStateException e) {
@@ -513,6 +513,44 @@
 
     @Test
     @SmallTest
+    public void testWpsClirActiveDialOverCs() throws Exception {
+        try {
+            setupForWpsCallTest();
+
+            mContextFixture.getCarrierConfigBundle().putBoolean(
+                    CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, false);
+
+            mPhoneUT.dial("*31#*27216505551212",
+                    new PhoneInternalInterface.DialArgs.Builder().build());
+
+            verify(mCT).dialGsm("*27216505551212", CommandsInterface.CLIR_SUPPRESSION, null, null);
+            verify(mImsCT).hangupAllConnections();
+        } catch (CallStateException e) {
+            fail();
+        }
+    }
+
+    @Test
+    @SmallTest
+    public void testWpsClirInactiveDialOverCs() throws Exception {
+        try {
+            setupForWpsCallTest();
+
+            mContextFixture.getCarrierConfigBundle().putBoolean(
+                    CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, false);
+
+            mPhoneUT.dial("#31#*27216505551212",
+                    new PhoneInternalInterface.DialArgs.Builder().build());
+
+            verify(mCT).dialGsm("*27216505551212", CommandsInterface.CLIR_INVOCATION, null, null);
+            verify(mImsCT).hangupAllConnections();
+        } catch (CallStateException e) {
+            fail();
+        }
+    }
+
+    @Test
+    @SmallTest
     public void testWpsDialOverIms() throws Exception {
         try {
             setupForWpsCallTest();
@@ -520,7 +558,7 @@
             mContextFixture.getCarrierConfigBundle().putBoolean(
                     CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, true);
 
-            Connection connection = mPhoneUT.dial("*27216505551212",
+            mPhoneUT.dial("*27216505551212",
                     new PhoneInternalInterface.DialArgs.Builder().build());
             verify(mCT).dialGsm("*27216505551212", null, null);
             verify(mImsCT, never()).hangupAllConnections();
@@ -531,6 +569,43 @@
 
     @Test
     @SmallTest
+    public void testWpsClirActiveDialOverIms() throws Exception {
+        try {
+            setupForWpsCallTest();
+
+            mContextFixture.getCarrierConfigBundle().putBoolean(
+                    CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, true);
+
+            mPhoneUT.dial("*31#*27216505551212",
+                    new PhoneInternalInterface.DialArgs.Builder().build());
+            verify(mCT).dialGsm("*27216505551212", CommandsInterface.CLIR_SUPPRESSION, null, null);
+            verify(mImsCT, never()).hangupAllConnections();
+        } catch (CallStateException e) {
+            fail();
+        }
+    }
+
+    @Test
+    @SmallTest
+    public void testWpsClirInactiveDialOverIms() throws Exception {
+        try {
+            setupForWpsCallTest();
+
+            mContextFixture.getCarrierConfigBundle().putBoolean(
+                    CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, true);
+
+            mPhoneUT.dial("#31#*27216505551212",
+                    new PhoneInternalInterface.DialArgs.Builder().build());
+
+            verify(mCT).dialGsm("*27216505551212", CommandsInterface.CLIR_INVOCATION, null, null);
+            verify(mImsCT, never()).hangupAllConnections();
+        } catch (CallStateException e) {
+            fail();
+        }
+    }
+
+    @Test
+    @SmallTest
     public void testHandlePinMmi() {
         assertFalse(mPhoneUT.handlePinMmi("1234567890"));
     }