@@ -866,6 +866,12 @@ protected void fixTimeZone(String isoCountryCode) {
866866 // If the offset is (0, false) and the time zone property
867867 // is set, use the time zone property rather than GMT.
868868 String zoneName = SystemProperties .get (TIMEZONE_PROPERTY );
869+ if (DBG ) {
870+ log ("fixTimeZone zoneName='" + zoneName +
871+ "' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
872+ " iso-cc='" + isoCountryCode +
873+ "' iso-cc-idx=" + Arrays .binarySearch (GMT_COUNTRY_CODES , isoCountryCode ));
874+ }
869875 if ((mZoneOffset == 0 ) && (mZoneDst == false ) && (zoneName != null )
870876 && (zoneName .length () > 0 )
871877 && (Arrays .binarySearch (GMT_COUNTRY_CODES , isoCountryCode ) < 0 )) {
@@ -880,19 +886,25 @@ protected void fixTimeZone(String isoCountryCode) {
880886 // Adjust the saved NITZ time to account for tzOffset.
881887 mSavedTime = mSavedTime - tzOffset ;
882888 }
889+ if (DBG ) log ("fixTimeZone: using default TimeZone" );
883890 } else if (isoCountryCode .equals ("" )) {
884891 // Country code not found. This is likely a test network.
885892 // Get a TimeZone based only on the NITZ parameters (best guess).
886893 zone = getNitzTimeZone (mZoneOffset , mZoneDst , mZoneTime );
894+ if (DBG ) log ("fixTimeZone: using NITZ TimeZone" );
887895 } else {
888896 zone = TimeUtils .getTimeZone (mZoneOffset , mZoneDst , mZoneTime , isoCountryCode );
897+ if (DBG ) log ("fixTimeZone: using getTimeZone(off, dst, time, iso)" );
889898 }
890899
891900 mNeedFixZone = false ;
892901
893902 if (zone != null ) {
903+ log ("fixTimeZone: zone != null zone.getID=" + zone .getID ());
894904 if (getAutoTimeZone ()) {
895905 setAndBroadcastNetworkSetTimeZone (zone .getID ());
906+ } else {
907+ log ("fixTimeZone: zone == null" );
896908 }
897909 saveNitzTimeZone (zone .getID ());
898910 }
@@ -985,14 +997,23 @@ protected void pollStateDone() {
985997 phone .setSystemProperty (TelephonyProperties .PROPERTY_OPERATOR_ALPHA ,
986998 ss .getOperatorAlphaLong ());
987999
1000+ String prevOperatorNumeric =
1001+ SystemProperties .get (TelephonyProperties .PROPERTY_OPERATOR_NUMERIC , "" );
9881002 operatorNumeric = ss .getOperatorNumeric ();
9891003 phone .setSystemProperty (TelephonyProperties .PROPERTY_OPERATOR_NUMERIC , operatorNumeric );
9901004
9911005 if (operatorNumeric == null ) {
1006+ if (DBG ) {
1007+ log ("pollStateDone: operatorNumeric=" + operatorNumeric +
1008+ " prevOperatorNumeric=" + prevOperatorNumeric +
1009+ " mNeedFixZone=" + mNeedFixZone +
1010+ " clear PROPERTY_OPERATOR_ISO_COUNTRY" );
1011+ }
9921012 phone .setSystemProperty (TelephonyProperties .PROPERTY_OPERATOR_ISO_COUNTRY , "" );
9931013 mGotCountryCode = false ;
9941014 } else {
9951015 String isoCountryCode = "" ;
1016+ String mcc = operatorNumeric .substring (0 , 3 );
9961017 try {
9971018 isoCountryCode = MccTable .countryCodeForMcc (Integer .parseInt (
9981019 operatorNumeric .substring (0 ,3 )));
@@ -1001,11 +1022,20 @@ protected void pollStateDone() {
10011022 } catch ( StringIndexOutOfBoundsException ex ) {
10021023 loge ("pollStateDone: countryCodeForMcc error" + ex );
10031024 }
1025+ if (DBG ) {
1026+ log ("pollStateDone: operatorNumeric=" + operatorNumeric +
1027+ " prevOperatorNumeric=" + prevOperatorNumeric +
1028+ " mNeedFixZone=" + mNeedFixZone +
1029+ " mcc=" + mcc + " iso-cc=" + isoCountryCode );
1030+ }
10041031
10051032 phone .setSystemProperty (TelephonyProperties .PROPERTY_OPERATOR_ISO_COUNTRY ,
10061033 isoCountryCode );
10071034 mGotCountryCode = true ;
1008- if (mNeedFixZone ) {
1035+
1036+ // Fix the time zone If the operator changed or we need to fix it because
1037+ // when the NITZ time came in we didn't know the country code.
1038+ if ( ! operatorNumeric .equals (prevOperatorNumeric ) || mNeedFixZone ) {
10091039 fixTimeZone (isoCountryCode );
10101040 }
10111041 }
@@ -1316,7 +1346,6 @@ void setTimeFromNITZString (String nitz, long nitzReceiveTime)
13161346 String iso = SystemProperties .get (TelephonyProperties .PROPERTY_OPERATOR_ISO_COUNTRY );
13171347
13181348 if (zone == null ) {
1319-
13201349 if (mGotCountryCode ) {
13211350 if (iso != null && iso .length () > 0 ) {
13221351 zone = TimeUtils .getTimeZone (tzOffset , dst != 0 ,
@@ -1332,16 +1361,21 @@ void setTimeFromNITZString (String nitz, long nitzReceiveTime)
13321361 }
13331362 }
13341363
1335- if (zone == null ) {
1336- // We got the time before the country, so we don't know
1337- // how to identify the DST rules yet. Save the information
1338- // and hope to fix it up later.
1364+ if (( zone == null ) || ( mZoneOffset != tzOffset ) || ( mZoneDst != ( dst != 0 ))) {
1365+ // We got the time before the country or the zone has changed
1366+ // so we don't know how to identify the DST rules yet. Save
1367+ // the information and hope to fix it up later.
13391368
13401369 mNeedFixZone = true ;
13411370 mZoneOffset = tzOffset ;
13421371 mZoneDst = dst != 0 ;
13431372 mZoneTime = c .getTimeInMillis ();
13441373 }
1374+ if (DBG ) {
1375+ log ("NITZ: tzOffset=" + tzOffset + " dst=" + dst + " zone=" + zone .getID () +
1376+ " iso=" + iso + " mGotCountryCode=" + mGotCountryCode +
1377+ " mNeedFixZone=" + mNeedFixZone );
1378+ }
13451379
13461380 if (zone != null ) {
13471381 if (getAutoTimeZone ()) {
@@ -1461,6 +1495,7 @@ private void saveNitzTimeZone(String zoneId) {
14611495 * @param zoneId timezone set by carrier
14621496 */
14631497 private void setAndBroadcastNetworkSetTimeZone (String zoneId ) {
1498+ if (DBG ) log ("setAndBroadcastNetworkSetTimeZone: setTimeZone=" + zoneId );
14641499 AlarmManager alarm =
14651500 (AlarmManager ) phone .getContext ().getSystemService (Context .ALARM_SERVICE );
14661501 alarm .setTimeZone (zoneId );
@@ -1477,6 +1512,7 @@ private void setAndBroadcastNetworkSetTimeZone(String zoneId) {
14771512 * @param time time set by network
14781513 */
14791514 private void setAndBroadcastNetworkSetTime (long time ) {
1515+ if (DBG ) log ("setAndBroadcastNetworkSetTime: time=" + time + "ms" );
14801516 SystemClock .setCurrentTimeMillis (time );
14811517 Intent intent = new Intent (TelephonyIntents .ACTION_NETWORK_SET_TIME );
14821518 intent .addFlags (Intent .FLAG_RECEIVER_REPLACE_PENDING );
0 commit comments