Ensure mForwardNumber is null if modem returns empty String or null

We populate EXTRA_FORWARDED_NUMBER if mForwardedNumber is non null.
This was happening on some hardware where DriverCall#forwardedNumber
was an empty String instead of null. In either case, we should
set mForwardedNumber to null.

Test: atest FrameworkTelephonyTests:GsmCdmaConnectionTest
Bug: 187826275
Change-Id: Icb225ef012046ef30eb324b666168ce42f2af174
(cherry picked from commit a68707ee8c89fde33af13fbb7bce48802f11cdb0)
diff --git a/src/java/com/android/internal/telephony/GsmCdmaConnection.java b/src/java/com/android/internal/telephony/GsmCdmaConnection.java
index e9ecb79..b79bdef 100644
--- a/src/java/com/android/internal/telephony/GsmCdmaConnection.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaConnection.java
@@ -42,7 +42,7 @@
 import com.android.telephony.Rlog;
 
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
 
 /**
  * {@hide}
@@ -141,7 +141,10 @@
         mAddress = dc.number;
         setEmergencyCallInfo(mOwner);
 
-        mForwardedNumber = new ArrayList<String>(Arrays.asList(dc.forwardedNumber));
+        String forwardedNumber = TextUtils.isEmpty(dc.forwardedNumber) ? null : dc.forwardedNumber;
+        Rlog.i(LOG_TAG, "create, forwardedNumber=" + Rlog.pii(LOG_TAG, forwardedNumber));
+        mForwardedNumber =  forwardedNumber == null ? null :
+                new ArrayList<>(Collections.singletonList(dc.forwardedNumber));
         mIsIncoming = dc.isMT;
         mCreateTime = System.currentTimeMillis();
         mCnapName = dc.name;
@@ -710,11 +713,13 @@
             mOwner.getPhone().getVoiceCallSessionStats().onAudioCodecChanged(this, dc.audioQuality);
         }
 
-        ArrayList<String> forwardedNumber =
-                new ArrayList<String>(Arrays.asList(dc.forwardedNumber));
-        if (!equalsHandlesNulls(mForwardedNumber, forwardedNumber)) {
-            if (Phone.DEBUG_PHONE) log("update: mForwardedNumber, # changed!");
-            mForwardedNumber = forwardedNumber;
+        String forwardedNumber = TextUtils.isEmpty(dc.forwardedNumber) ? null : dc.forwardedNumber;
+        Rlog.i(LOG_TAG, "update: forwardedNumber=" + Rlog.pii(LOG_TAG, forwardedNumber));
+        ArrayList<String> forwardedNumbers =  forwardedNumber == null ? null :
+                new ArrayList<>(Collections.singletonList(dc.forwardedNumber));
+        if (!equalsHandlesNulls(mForwardedNumber, forwardedNumbers)) {
+            if (Phone.DEBUG_PHONE) log("update: mForwardedNumber, # changed");
+            mForwardedNumber = forwardedNumbers;
             changed = true;
         }
 
diff --git a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaConnectionTest.java b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaConnectionTest.java
index a5d0b4d..a078642 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaConnectionTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/GsmCdmaConnectionTest.java
@@ -278,4 +278,22 @@
         assertEquals(new ArrayList<String>(Arrays.asList(forwardedNumber)),
                 connection.getForwardedNumber());
     }
+
+    @Test @SmallTest
+    public void testForwardedNumberEmptyNull() {
+        mDC.state = DriverCall.State.INCOMING;
+        mDC.forwardedNumber = "";
+        connection = new GsmCdmaConnection(mPhone, mDC, mCT, 0);
+        assertNull(connection.getForwardedNumber());
+        mDC.forwardedNumber = null;
+        connection.update(mDC);
+        assertNull(connection.getForwardedNumber());
+
+        mDC.forwardedNumber = null;
+        connection = new GsmCdmaConnection(mPhone, mDC, mCT, 0);
+        assertNull(connection.getForwardedNumber());
+        mDC.forwardedNumber = "";
+        connection.update(mDC);
+        assertNull(connection.getForwardedNumber());
+    }
 }