Handling service number convert while roaming.
Xia Ying [Mon, 22 Sep 2014 20:59:46 +0000 (15:59 -0500)]
When roaming in GSM/UMTS and internal CDMA network,
(1)change VZW custumer service numeber *611 to +19085594899.
(2)change VZW voice mail number *86 to +1MDN.

Change-Id: I69f69fb698f059b7a2365d2906fe0f7cc41636d7

src/java/com/android/internal/telephony/CallTracker.java
src/java/com/android/internal/telephony/Connection.java
src/java/com/android/internal/telephony/PhoneBase.java
src/java/com/android/internal/telephony/cdma/CDMAPhone.java
src/java/com/android/internal/telephony/cdma/CdmaCallTracker.java
src/java/com/android/internal/telephony/cdma/CdmaConnection.java
src/java/com/android/internal/telephony/gsm/GsmCallTracker.java
src/java/com/android/internal/telephony/gsm/GsmConnection.java

index 168b20f..5f5c0d9 100644 (file)
@@ -45,6 +45,9 @@ public abstract class CallTracker extends Handler {
 
     public CommandsInterface mCi;
 
+    protected boolean mNumberConverted = false;
+    private final int VALID_COMPARE_LENGTH   = 3;
+
     //***** Events
 
     protected static final int EVENT_POLL_CALLS_RESULT             = 1;
@@ -171,6 +174,76 @@ public abstract class CallTracker extends Handler {
         return dialString;
     }
 
+    protected String convertNumberIfNecessary(PhoneBase phoneBase, String dialNumber) {
+        if (dialNumber == null) {
+            return dialNumber;
+        }
+        String[] convertMaps = phoneBase.getContext().getResources().getStringArray(
+                com.android.internal.R.array.dial_string_replace);
+        log("convertNumberIfNecessary Roaming"
+            + " convertMaps.length " + convertMaps.length
+            + " dialNumber.length() " + dialNumber.length());
+
+        if (convertMaps.length < 1 || dialNumber.length() < VALID_COMPARE_LENGTH) {
+            return dialNumber;
+        }
+
+        String[] entry;
+        String[] tmpArray;
+        String outNumber = "";
+        for(String convertMap : convertMaps) {
+            log("convertNumberIfNecessary: " + convertMap);
+            entry = convertMap.split(":");
+            if (entry.length > 1) {
+                tmpArray = entry[1].split(",");
+                if (!TextUtils.isEmpty(entry[0]) && dialNumber.equals(entry[0])) {
+                    if (tmpArray.length >= 2 && !TextUtils.isEmpty(tmpArray[1])) {
+                        if (compareGid1(phoneBase, tmpArray[1])) {
+                            mNumberConverted = true;
+                        }
+                    } else if (outNumber.isEmpty()) {
+                        mNumberConverted = true;
+                    }
+                    if (mNumberConverted) {
+                        if(!TextUtils.isEmpty(tmpArray[0]) && tmpArray[0].endsWith("MDN")) {
+                            String prefix = tmpArray[0].substring(0, tmpArray[0].length() -3);
+                            outNumber = prefix + phoneBase.getLine1Number();
+                        } else {
+                            outNumber = tmpArray[0];
+                        }
+                    }
+                }
+            }
+        }
+
+        if (mNumberConverted) {
+            log("convertNumberIfNecessary: convert service number");
+            return outNumber;
+        }
+
+        return dialNumber;
+
+    }
+
+    private boolean compareGid1(PhoneBase phoneBase, String serviceGid1) {
+        String gid1 = phoneBase.getGroupIdLevel1();
+        int gid_length = serviceGid1.length();
+        boolean ret = true;
+
+        if (serviceGid1 == null || serviceGid1.equals("")) {
+            log("compareGid1 serviceGid is empty, return " + ret);
+            return ret;
+        }
+        // Check if gid1 match service GID1
+        if (!((gid1 != null) && (gid1.length() >= gid_length) &&
+                gid1.substring(0, gid_length).equalsIgnoreCase(serviceGid1))) {
+            log(" gid1 " + gid1 + " serviceGid1 " + serviceGid1);
+            ret = false;
+        }
+        log("compareGid1 is " + (ret?"Same":"Different"));
+        return ret;
+    }
+
     //***** Overridden from Handler
     @Override
     public abstract void handleMessage (Message msg);
index a796dc5..8914c12 100644 (file)
@@ -93,6 +93,9 @@ public abstract class Connection {
     private List<PostDialListener> mPostDialListeners = new ArrayList<>();
     public Set<Listener> mListeners = new CopyOnWriteArraySet<>();
 
+    protected boolean mNumberConverted = false;
+    protected String mConvertedNumber;
+
     private static String LOG_TAG = "Connection";
 
     Object mUserData;
@@ -532,6 +535,13 @@ public abstract class Connection {
         }
     }
 
+    public void setConverted(String oriNumber) {
+        mNumberConverted = true;
+        mConvertedNumber = mAddress;
+        mAddress = oriNumber;
+        mDialString = oriNumber;
+    }
+
     /**
      * Build a human representation of a connection instance, suitable for debugging.
      * Don't log personal stuff unless in debug mode.
index a8da88a..564c45d 100644 (file)
@@ -238,6 +238,17 @@ public abstract class PhoneBase extends Handler implements Phone {
         SystemProperties.set(property, value);
     }
 
+    /**
+     * Set a system property, unless we're in unit test mode
+     */
+    // CAF_MSIM TODO this need to be replated with TelephonyManager API ?
+    public String getSystemProperty(String property, String defValue) {
+        if(getUnitTestMode()) {
+            return null;
+        }
+        return SystemProperties.get(property, defValue);
+    }
+
 
     protected final RegistrantList mPreciseCallStateRegistrants
             = new RegistrantList();
index 888d782..60a074d 100644 (file)
@@ -1393,6 +1393,15 @@ public class CDMAPhone extends PhoneBase {
         super.setSystemProperty(property, value);
     }
 
+    // override for allowing access from other classes of this package
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getSystemProperty(String property, String defValue) {
+        return super.getSystemProperty(property, defValue);
+    }
+
     /**
      * Activate or deactivate cell broadcast SMS.
      *
index 2f0873c..91bcfee 100644 (file)
@@ -26,6 +26,7 @@ import android.telephony.PhoneNumberUtils;
 import android.telephony.ServiceState;
 import android.telephony.Rlog;
 import android.os.SystemProperties;
+import android.text.TextUtils;
 
 import com.android.internal.telephony.CallStateException;
 import com.android.internal.telephony.CallTracker;
@@ -172,6 +173,25 @@ public final class CdmaCallTracker extends CallTracker {
             throw new CallStateException("cannot dial in current state");
         }
 
+        String origNumber = dialString;
+        String operatorIsoContry = mPhone.getSystemProperty(
+                TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
+        String simIsoContry = mPhone.getSystemProperty(
+                TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, "");
+        boolean internationalRoaming = !TextUtils.isEmpty(operatorIsoContry)
+                && !TextUtils.isEmpty(simIsoContry)
+                && !simIsoContry.equals(operatorIsoContry);
+        if (internationalRoaming) {
+            if ("us".equals(simIsoContry)) {
+                internationalRoaming = internationalRoaming && !"vi".equals(operatorIsoContry);
+            } else if ("vi".equals(simIsoContry)) {
+                internationalRoaming = internationalRoaming && !"us".equals(operatorIsoContry);
+            }
+        }
+        if (internationalRoaming) {
+            dialString = convertNumberIfNecessary(mPhone, dialString);
+        }
+
         String inEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE, "false");
         boolean isPhoneInEcmMode = inEcm.equals("true");
         boolean isEmergencyCall =
@@ -224,6 +244,11 @@ public final class CdmaCallTracker extends CallTracker {
             }
         }
 
+        if (mNumberConverted) {
+            mPendingMO.setConverted(origNumber);
+            mNumberConverted = false;
+        }
+
         updatePhoneState();
         mPhone.notifyPreciseCallStateChanged();
 
index 4d745f0..8f9ce36 100755 (executable)
@@ -448,7 +448,9 @@ public class CdmaConnection extends Connection {
 
         if (Phone.DEBUG_PHONE) log("parent= " +mParent +", newParent= " + newParent);
 
-        if (!equalsHandlesNulls(mAddress, dc.number)) {
+        log(" mNumberConverted " + mNumberConverted);
+        if (!equalsHandlesNulls(mAddress, dc.number) && (!mNumberConverted
+                || !equalsHandlesNulls(mConvertedNumber, dc.number)))  {
             if (Phone.DEBUG_PHONE) log("update: phone # changed!");
             mAddress = dc.number;
             changed = true;
index 42d45f9..66a7768 100755 (executable)
@@ -51,7 +51,6 @@ import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.util.List;
 import java.util.ArrayList;
-import java.util.HashMap;
 
 /**
  * {@hide}
@@ -93,9 +92,6 @@ public final class GsmCallTracker extends CallTracker {
 
     Call.SrvccState mSrvccState = Call.SrvccState.NONE;
 
-    boolean mNumberConverted = false;
-    private final int VALID_COMPARE_LENGTH   = 3;
-
     //***** Events
 
 
@@ -180,7 +176,7 @@ public final class GsmCallTracker extends CallTracker {
         }
 
         String origNumber = dialString;
-        dialString = convertNumberIfNecessary(dialString);
+        dialString = convertNumberIfNecessary(mPhone, dialString);
 
         // The new call must be assigned to the foreground call.
         // That call must be idle, so place anything that's
@@ -950,74 +946,6 @@ public final class GsmCallTracker extends CallTracker {
         }
     }
 
-    // TODO: This conversion should be applicable to CDMA roaming as well.
-    private String convertNumberIfNecessary(String dialNumber) {
-        if (dialNumber == null) {
-            return dialNumber;
-        }
-        String[] convertMaps = mPhone.getContext().getResources().getStringArray(
-                com.android.internal.R.array.dial_string_replace);
-        log("convertNumberIfNecessary Roaming" + mPhone.getServiceState().getRoaming()
-            + " convertMaps.length " + convertMaps.length
-            + " dialNumber.length() " + dialNumber.length());
-
-        if (convertMaps.length < 1 || dialNumber.length() < VALID_COMPARE_LENGTH) {
-            return dialNumber;
-        }
-
-        String[] entry;
-        String[] tmpArray;
-        String outNumber = "";
-        for(String convertMap : convertMaps) {
-            entry = convertMap.split(":");
-            if (entry.length > 1) {
-                tmpArray = entry[1].split(",");
-                if (!entry[0].isEmpty() && dialNumber.equals(entry[0])) {
-                    log("convertNumberIfNecessary " + entry[0] + " , " + tmpArray[0] + " " + tmpArray[1]);
-                    if (!tmpArray[1].isEmpty()) {
-                        if (compareGid1(tmpArray[1])) {
-                            outNumber = tmpArray[0];
-                            mNumberConverted = true;
-                        }
-                    } else if (outNumber.isEmpty()) {
-                        outNumber = tmpArray[0];
-                        mNumberConverted = true;
-                    }
-                }
-            }
-        }
-
-        if (mNumberConverted) {
-            log("convertNumberIfNecessary: convert service number");
-            return outNumber;
-        }
-
-        return dialNumber;
-
-    }
-
-    private boolean compareGid1(String serviceGid1) {
-        String gid1 = mPhone.getGroupIdLevel1();
-        int gid_length = serviceGid1.length();
-        boolean ret = true;
-
-        if (serviceGid1 == null || serviceGid1.equals("")) {
-            log("compareGid1 serviceGid is empty, return " + ret);
-            return ret;
-        }
-
-
-        // Check if gid1 match service GID1
-        if (!((gid1 != null) && (gid1.length() >= gid_length) &&
-                gid1.substring(0, gid_length).equalsIgnoreCase(serviceGid1))) {
-            log(" gid1 " + gid1 + " serviceGid1 " + serviceGid1);
-            ret = false;
-        }
-
-        log("compareGid1 is " + (ret?"Same":"Different"));
-        return ret;
-    }
-
     @Override
     protected void log(String msg) {
         Rlog.d(LOG_TAG, "[GsmCallTracker] " + msg);
index 398ac7a..718b203 100644 (file)
@@ -49,9 +49,6 @@ public class GsmConnection extends Connection {
     String mPostDialString;      // outgoing calls only
     boolean mDisconnected;
 
-    boolean mNumberConverted = false;
-    String mConvertedNumber;
-
     int mIndex;          // index in GsmCallTracker.connections[], -1 if unassigned
                         // The GSM index is 1 + this
 
@@ -770,10 +767,4 @@ public class GsmConnection extends Connection {
 
         return false;
     }
-    public void setConverted(String oriNumber) {
-        mNumberConverted = true;
-        mConvertedNumber = mAddress;
-        mAddress = oriNumber;
-        mDialString = oriNumber;
-    }
 }