OSDN Git Service

Set roaming based on both data and voice.
authorJohn Wang <johnwang@google.com>
Sat, 26 Sep 2009 02:20:48 +0000 (19:20 -0700)
committerJohn Wang <johnwang@google.com>
Tue, 29 Sep 2009 01:53:16 +0000 (18:53 -0700)
In GSM network the data roaming (from +CGREG) and the voice roaming (from +CREG) could be different. Set GSM roaming based on both data and voice roaming status and set it true if either indicates roaming.

This solves the unwanted roaming billing issues and respects the download roaming setting in systemUpdater, DownloadProvider, and MMS downloader. For more details refer to bug 2052473.

telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java

index b063e0a..c85b9bd 100644 (file)
@@ -351,7 +351,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
      * @return false while no data connection if all above requirements are met.
      */
     public boolean isDataConnectionAsDesired() {
-        boolean roaming = getDataRoaming();
+        boolean roaming = phone.getServiceState().getRoaming();
 
         if (mGsmPhone.mSIMRecords.getRecordsLoaded() &&
                 mGsmPhone.mSST.getCurrentGprsState() == ServiceState.STATE_IN_SERVICE &&
@@ -363,10 +363,6 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
         return true;
     }
 
-    private boolean getDataRoaming() {
-        return mGsmPhone.mSST.getDataRoaming();
-    }
-
     @Override
     protected boolean isApnTypeActive(String type) {
         // TODO: support simultaneous with List instead
@@ -394,7 +390,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
     }
 
     private boolean isDataAllowed() {
-        boolean roaming = getDataRoaming();
+        boolean roaming = phone.getServiceState().getRoaming();
         return getAnyDataEnabled() && (!roaming || getDataOnRoamingEnabled());
     }
 
@@ -441,7 +437,6 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
         }
 
         int gprsState = mGsmPhone.mSST.getCurrentGprsState();
-        boolean roaming = getDataRoaming();
         boolean desiredPowerState = mGsmPhone.mSST.getDesiredPowerState();
 
         if ((state == State.IDLE || state == State.SCANNING)
@@ -477,7 +472,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
                     " phoneState=" + phone.getState() +
                     " isDataAllowed=" + isDataAllowed() +
                     " dataEnabled=" + getAnyDataEnabled() +
-                    " roaming=" + roaming +
+                    " roaming=" + phone.getServiceState().getRoaming() +
                     " dataOnRoamingEnable=" + getDataOnRoamingEnabled() +
                     " ps restricted=" + mIsPsRestricted +
                     " desiredPowerState=" + desiredPowerState);
@@ -1112,38 +1107,18 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
         return trySetupData(reason);
     }
 
-    /**
-     * 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() {
-        if (!getDataRoaming()) { //data roaming is off
-            trySetupData(Phone.REASON_ROAMING_OFF);
-        } else { // Inconsistent! data roaming is on
-            sendMessage(obtainMessage(EVENT_ROAMING_ON));
-        }
+        trySetupData(Phone.REASON_ROAMING_OFF);
     }
 
-    /**
-     * 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 (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));
+        if (getDataOnRoamingEnabled()) {
+            trySetupData(Phone.REASON_ROAMING_ON);
+        } else {
+            if (DBG) log("Tear down data connection on roaming.");
+            cleanUpConnection(true, Phone.REASON_ROAMING_ON);
         }
     }
 
index 003899b..8140654 100644 (file)
@@ -83,12 +83,17 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
     private int networkType = 0;
     private int newNetworkType = 0;
 
-    /** GSM roaming status solely based on TS 27.007 7.2 CREG. */
+    /**
+     * GSM roaming status solely based on TS 27.007 7.2 CREG. Only used by
+     * handlePollStateResult to store CREG roaming result.
+     */
     private boolean mGsmRoaming = false;
 
-    /** Data roaming status solely based on TS 27.007 10.1.19 CGREG. */
+    /**
+     * Data roaming status solely based on TS 27.007 10.1.19 CGREG. Only used by
+     * handlePollStateResult to store CGREG roaming result.
+     */
     private boolean mDataRoaming = false;
-    private boolean newDataRoaming = false;
 
     private RegistrantList gprsAttachedRegistrants = new RegistrantList();
     private RegistrantList gprsDetachedRegistrants = new RegistrantList();
@@ -310,10 +315,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
         psRestrictDisabledRegistrants.remove(h);
     }
 
-    boolean getDataRoaming() {
-        return mDataRoaming;
-    }
-
     public void handleMessage (Message msg) {
         AsyncResult ar;
         int[] ints;
@@ -627,7 +628,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
 
                     mGsmRoaming = regCodeIsRoaming(regState);
                     newSS.setState (regCodeToServiceState(regState));
-
                     // LAC and CID are -1 if not avail
                     newCellLoc.setLacAndCid(lac, cid);
                 break;
@@ -650,7 +650,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                         }
                     }
                     newGPRSState = regCodeToServiceState(regState);
-                    newDataRoaming = regCodeIsRoaming(regState);
+                    mDataRoaming = regCodeIsRoaming(regState);
                     newNetworkType = type;
                     newSS.setRadioTechnology(type);
                 break;
@@ -678,15 +678,22 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
         pollingContext[0]--;
 
         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;
+            /**
+             *  Since the roaming states of gsm service (from +CREG) and
+             *  data service (from +CGREG) could be different, the new SS
+             *  is set roaming while either one is roaming.
+             *
+             *  There is an exception for the above rule. The new SS is not set
+             *  as roaming while gsm service reports roaming but indeed it is
+             *  not roaming between operators.
+             */
+            boolean roaming = (mGsmRoaming || mDataRoaming);
+            if (mGsmRoaming && !isRoamingBetweenOperators(mGsmRoaming, newSS)) {
+                roaming = false;
             }
+            newSS.setRoaming(roaming);
             pollStateDone();
         }
-
     }
 
     private void setSignalStrengthDefaultValues() {
@@ -711,8 +718,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                 newCellLoc.setStateInvalid();
                 setSignalStrengthDefaultValues();
                 mGotCountryCode = false;
-                newDataRoaming = false;
-
                 pollStateDone();
             break;
 
@@ -721,8 +726,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                 newCellLoc.setStateInvalid();
                 setSignalStrengthDefaultValues();
                 mGotCountryCode = false;
-                newDataRoaming = false;
-
                 pollStateDone();
             break;
 
@@ -736,8 +739,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                 newCellLoc.setStateInvalid();
                 setSignalStrengthDefaultValues();
                 mGotCountryCode = false;
-                newDataRoaming = false;
-                mDataRoaming = false;
 
                 //NOTE: pollStateDone() is not needed in this case
                 break;
@@ -830,9 +831,9 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
 
         boolean hasChanged = !newSS.equals(ss);
 
-        boolean hasRoamingOn = !mDataRoaming && newDataRoaming;
+        boolean hasRoamingOn = !ss.getRoaming() && newSS.getRoaming();
 
-        boolean hasRoamingOff = mDataRoaming && !newDataRoaming;
+        boolean hasRoamingOff = ss.getRoaming() && !newSS.getRoaming();
 
         boolean hasLocationChanged = !newCellLoc.equals(cellLoc);
 
@@ -849,7 +850,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
 
         gprsState = newGPRSState;
         networkType = newNetworkType;
-        mDataRoaming = newDataRoaming;
 
         newSS.setStateOutOfService(); // clean slate for next time