Skip to content

Commit dd7bdb0

Browse files
Wink SavilleAndroid (Google) Code Review
authored andcommitted
Merge "Fix phone is sometimes in America/Dawson canadian time zone"
2 parents 84d5e21 + 335ef47 commit dd7bdb0

File tree

3 files changed

+83
-27
lines changed

3 files changed

+83
-27
lines changed

telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.telephony.cdma.CdmaCellLocation;
2929
import android.os.AsyncResult;
3030
import android.os.Message;
31+
import android.os.SystemProperties;
3132
import android.provider.Telephony.Intents;
3233

3334
import android.text.TextUtils;
@@ -370,14 +371,23 @@ protected void pollStateDone() {
370371
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
371372
ss.getOperatorAlphaLong());
372373

374+
String prevOperatorNumeric =
375+
SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
373376
operatorNumeric = ss.getOperatorNumeric();
374377
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
375378

376379
if (operatorNumeric == null) {
380+
if (DBG) {
381+
log("pollStateDone: operatorNumeric=" + operatorNumeric +
382+
" prevOperatorNumeric=" + prevOperatorNumeric +
383+
" mNeedFixZone=" + mNeedFixZone +
384+
" clear PROPERTY_OPERATOR_ISO_COUNTRY");
385+
}
377386
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
378387
mGotCountryCode = false;
379388
} else {
380389
String isoCountryCode = "";
390+
String mcc = operatorNumeric.substring(0, 3);
381391
try {
382392
isoCountryCode = MccTable.countryCodeForMcc(Integer.parseInt(operatorNumeric
383393
.substring(0, 3)));
@@ -386,11 +396,20 @@ protected void pollStateDone() {
386396
} catch (StringIndexOutOfBoundsException ex) {
387397
loge("countryCodeForMcc error" + ex);
388398
}
399+
if (DBG) {
400+
log("pollStateDone: operatorNumeric=" + operatorNumeric +
401+
" prevOperatorNumeric=" + prevOperatorNumeric +
402+
" mNeedFixZone=" + mNeedFixZone +
403+
" mcc=" + mcc + " iso-cc=" + isoCountryCode);
404+
}
389405

390406
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY,
391407
isoCountryCode);
392408
mGotCountryCode = true;
393-
if (mNeedFixZone) {
409+
410+
// Fix the time zone If the operator changed or we need to fix it because
411+
// when the NITZ time came in we didn't know the country code.
412+
if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
394413
fixTimeZone(isoCountryCode);
395414
}
396415
}

telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,16 @@ private void pollStateDone() {
852852
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
853853
ss.getOperatorAlphaLong());
854854

855+
String prevOperatorNumeric =
856+
SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
855857
operatorNumeric = ss.getOperatorNumeric();
856858
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
857859

858860
if (operatorNumeric == null) {
859861
if (DBG) {
860-
log("pollStateDone: operatorNumeric is null:" +
862+
log("pollStateDone: operatorNumeric=" + operatorNumeric +
863+
" prevOperatorNumeric=" + prevOperatorNumeric +
864+
" mNeedFixZone=" + mNeedFixZone +
861865
" clear PROPERTY_OPERATOR_ISO_COUNTRY");
862866
}
863867
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
@@ -875,7 +879,9 @@ private void pollStateDone() {
875879
}
876880
if (DBG) {
877881
log("pollStateDone: operatorNumeric=" + operatorNumeric +
878-
" mcc=" + mcc + " iso=" + iso);
882+
" prevOperatorNumeric=" + prevOperatorNumeric +
883+
" mNeedFixZone=" + mNeedFixZone +
884+
" mcc=" + mcc + " iso-cc=" + iso);
879885
}
880886

881887
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso);
@@ -895,30 +901,32 @@ private void pollStateDone() {
895901
if ((uniqueZones.size() == 1) || testOneUniqueOffsetPath) {
896902
zone = uniqueZones.get(0);
897903
if (DBG) {
898-
log("pollStateDone: no nitz but one TZ for iso=" + iso +
904+
log("pollStateDone: no nitz but one TZ for iso-cc=" + iso +
899905
" with zone.getID=" + zone.getID() +
900906
" testOneUniqueOffsetPath=" + testOneUniqueOffsetPath);
901907
}
902908
setAndBroadcastNetworkSetTimeZone(zone.getID());
903909
} else {
904910
if (DBG) {
905911
log("pollStateDone: there are " + uniqueZones.size() +
906-
" unique offsets for iso='" + iso +
912+
" unique offsets for iso-cc='" + iso +
907913
" testOneUniqueOffsetPath=" + testOneUniqueOffsetPath +
908914
"', do nothing");
909915
}
910916
}
911917
}
912918

913-
if (mNeedFixZone) {
919+
// Fix the time zone If the operator changed or we need to fix it because
920+
// when the NITZ time came in we didn't know the country code.
921+
if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
914922
// If the offset is (0, false) and the timezone property
915923
// is set, use the timezone property rather than
916924
// GMT.
917925
String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
918926
if (DBG) {
919-
log("pollStateDone: mNeedFixZone==true zoneName='" + zoneName +
927+
log("pollStateDone: fix time zone zoneName='" + zoneName +
920928
"' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
921-
" iso='" + iso +
929+
" iso-cc='" + iso +
922930
"' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, iso));
923931
}
924932
if ((mZoneOffset == 0) && (mZoneDst == false) &&
@@ -957,15 +965,6 @@ private void pollStateDone() {
957965
} else {
958966
log("pollStateDone: zone == null");
959967
}
960-
} else {
961-
if (DBG) {
962-
String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
963-
zone = TimeZone.getDefault();
964-
log("pollStateDone: mNeedFixZone==false zoneName='" + zoneName +
965-
"' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
966-
" iso='" + iso +
967-
"' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, iso));
968-
}
969968
}
970969
}
971970

@@ -1442,10 +1441,10 @@ private void setTimeFromNITZString (String nitz, long nitzReceiveTime) {
14421441
}
14431442
}
14441443

1445-
if (zone == null) {
1446-
// We got the time before the country, so we don't know
1447-
// how to identify the DST rules yet. Save the information
1448-
// and hope to fix it up later.
1444+
if ((zone == null) || (mZoneOffset != tzOffset) || (mZoneDst != (dst != 0))){
1445+
// We got the time before the country or the zone has changed
1446+
// so we don't know how to identify the DST rules yet. Save
1447+
// the information and hope to fix it up later.
14491448

14501449
mNeedFixZone = true;
14511450
mZoneOffset = tzOffset;
@@ -1556,6 +1555,7 @@ private void saveNitzTime(long time) {
15561555
* @param zoneId timezone set by carrier
15571556
*/
15581557
private void setAndBroadcastNetworkSetTimeZone(String zoneId) {
1558+
if (DBG) log("setAndBroadcastNetworkSetTimeZone: setTimeZone=" + zoneId);
15591559
AlarmManager alarm =
15601560
(AlarmManager) phone.getContext().getSystemService(Context.ALARM_SERVICE);
15611561
alarm.setTimeZone(zoneId);
@@ -1576,6 +1576,7 @@ private void setAndBroadcastNetworkSetTimeZone(String zoneId) {
15761576
* @param time time set by network
15771577
*/
15781578
private void setAndBroadcastNetworkSetTime(long time) {
1579+
if (DBG) log("setAndBroadcastNetworkSetTime: time=" + time + "ms");
15791580
SystemClock.setCurrentTimeMillis(time);
15801581
Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIME);
15811582
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

0 commit comments

Comments
 (0)