Use dataRoaming in dataConnectionTracker.

Seperate dataRoaming from gsmRoaming. dataRoaming is based on +CGREG returns in GSM while gsmRoaming is based on +CREG returns. Previously, the status of dataRoaming is always treated the same as gsmRoaming. However there is a situation where +CREG returns 0 and +CGREG returns 5, i.e., gsmRoaming is off and dataRoaming is on. In such situation, the phone should setup data connection if the phone enables data service when roaming (for example, data only card). The phone shouldn't setup data connection if the phone disable data service when roaming (to prevent roaming data charge). So gsmDataConnectionTracker should use dataRoaming instead of gsmRoaming to decide if data service allowed.

	modified:   GsmDataConnectionTracker.java
	modified:   GsmServiceStateTracker.java
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
index c33d4b6..d48c941 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
@@ -412,7 +412,7 @@
      * @return false while no data connection if all above requirements are met.
      */
     public boolean isDataConnectionAsDesired() {
-        boolean roaming = phone.getServiceState().getRoaming();
+        boolean roaming = getDataRoaming();
 
         if (mGsmPhone.mSIMRecords.getRecordsLoaded() &&
                 mGsmPhone.mSST.getCurrentGprsState() == ServiceState.STATE_IN_SERVICE &&
@@ -424,6 +424,10 @@
         return true;
     }
 
+    private boolean getDataRoaming() {
+        return mGsmPhone.mSST.getDataRoaming();
+    }
+
     private boolean isApnTypeActive(String type) {
         // TODO: to support simultaneous, mActiveApn can be a List instead.
         return mActiveApn != null && mActiveApn.canHandleType(type);
@@ -533,7 +537,7 @@
     }
 
     private boolean isDataAllowed() {
-        boolean roaming = phone.getServiceState().getRoaming();
+        boolean roaming = getDataRoaming();
         return getAnyDataEnabled() && (!roaming || getDataOnRoamingEnabled());
     }
 
@@ -580,7 +584,7 @@
         }
 
         int gprsState = mGsmPhone.mSST.getCurrentGprsState();
-        boolean roaming = phone.getServiceState().getRoaming();
+        boolean roaming = getDataRoaming();
         boolean desiredPowerState = mGsmPhone.mSST.getDesiredPowerState();
 
         if ((state == State.IDLE || state == State.SCANNING)
@@ -1245,16 +1249,38 @@
         }
     }
 
+    /**
+     * Check the data roaming consistency since this can be triggered by
+     * voice roaming flag of ServiceState in setDataOnRoamingEnabled()
+     *
+     * TODO make this triggered by data roaming state only
+     */
+    @Override
     protected void onRoamingOff() {
-        trySetupData(Phone.REASON_ROAMING_OFF);
+        if (!getDataRoaming()) { //data roaming is off
+            trySetupData(Phone.REASON_ROAMING_OFF);
+        } else { // Inconsistent! data roaming is on
+            sendMessage(obtainMessage(EVENT_ROAMING_ON));
+        }
     }
 
+    /**
+     * Check the data roaming consistency since this can be triggered by
+     * voice roaming flag of ServiceState in setDataOnRoamingEnabled()
+     *
+     * TODO make this triggered by data roaming state only
+     */
+    @Override
     protected void onRoamingOn() {
-        if (getDataOnRoamingEnabled()) {
-            trySetupData(Phone.REASON_ROAMING_ON);
-        } else {
-            if (DBG) log("Tear down data connection on roaming.");
-            cleanUpConnection(true, Phone.REASON_ROAMING_ON);
+        if (getDataRoaming()) { // data roaming is on
+            if (getDataOnRoamingEnabled()) {
+                trySetupData(Phone.REASON_ROAMING_ON);
+            } else {
+                if (DBG) log("Tear down data connection on roaming.");
+                cleanUpConnection(true, Phone.REASON_ROAMING_ON);
+            }
+        } else { // Inconsistent! data roaming is off
+            sendMessage(obtainMessage(EVENT_ROAMING_OFF));
         }
     }
 
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
index b3b4345..60d4e8f 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
@@ -88,6 +88,9 @@
     private int newNetworkType = 0;
     /* gsm roaming status solely based on TS 27.007 7.2 CREG */
     private boolean mGsmRoaming = false;
+    /* data roaming status solely based on TS 27.007 10.1.19 CGREG */
+    private boolean mDataRoaming = false;
+    private boolean newDataRoaming = false;
 
     private RegistrantList gprsAttachedRegistrants = new RegistrantList();
     private RegistrantList gprsDetachedRegistrants = new RegistrantList();
@@ -309,6 +312,10 @@
         psRestrictDisabledRegistrants.remove(h);
     }
 
+    /*protected*/ boolean getDataRoaming() {
+        return mDataRoaming;
+    }
+
     //***** Called from GSMPhone
     public void
     getLacAndCid(Message onComplete) {
@@ -666,6 +673,7 @@
                         }
                     }
                     newGPRSState = regCodeToServiceState(regState);
+                    newDataRoaming = regCodeIsRoaming(regState);
                     newNetworkType = type;
                 break;
 
@@ -693,6 +701,11 @@
 
         if (pollingContext[0] == 0) {
             newSS.setRoaming(isRoamingBetweenOperators(mGsmRoaming, newSS));
+            // when both roaming indicators are true but not roaming between
+            // operators, roaming should set to false.
+            if (newDataRoaming && mGsmRoaming && !newSS.getRoaming()) {
+                newDataRoaming = false;
+            }
             pollStateDone();
         }
 
@@ -722,6 +735,7 @@
                 newCellLoc.setStateInvalid();
                 setSignalStrengthDefaultValues();
                 mGotCountryCode = false;
+                newDataRoaming = false;
 
                 pollStateDone();
             break;
@@ -731,6 +745,7 @@
                 newCellLoc.setStateInvalid();
                 setSignalStrengthDefaultValues();
                 mGotCountryCode = false;
+                newDataRoaming = false;
 
                 pollStateDone();
             break;
@@ -745,6 +760,8 @@
                 newCellLoc.setStateInvalid();
                 setSignalStrengthDefaultValues();
                 mGotCountryCode = false;
+                newDataRoaming = false;
+                mDataRoaming = false;
 
                 //NOTE: pollStateDone() is not needed in this case
                 break;
@@ -829,9 +846,9 @@
 
         boolean hasChanged = !newSS.equals(ss);
 
-        boolean hasRoamingOn = !ss.getRoaming() && newSS.getRoaming();
+        boolean hasRoamingOn = !mDataRoaming && newDataRoaming;
 
-        boolean hasRoamingOff = ss.getRoaming() && !newSS.getRoaming();
+        boolean hasRoamingOff = mDataRoaming && !newDataRoaming;
 
         boolean hasLocationChanged = !newCellLoc.equals(cellLoc);
 
@@ -848,6 +865,7 @@
 
         gprsState = newGPRSState;
         networkType = newNetworkType;
+        mDataRoaming = newDataRoaming;
 
         newSS.setStateOutOfService(); // clean slate for next time