Bug 714352 - B2G RIL: Listen for NITZ updates. r=philikon
authorJim Straus <jstraus@mozilla.com>
Thu, 08 Mar 2012 23:16:06 -0500
changeset 88807 f92e3e6f93a750db10af92f2cd30ab616c4879eb
parent 88806 3463e63451a49bc7ae75931eaba0e991aeabc192
child 88808 170757be69f3d5d24c5cd2ee8fa1a083f5efd5a4
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersphilikon
bugs714352
milestone13.0a1
Bug 714352 - B2G RIL: Listen for NITZ updates. r=philikon
dom/system/b2g/RadioInterfaceLayer.js
dom/system/b2g/ril_worker.js
--- a/dom/system/b2g/RadioInterfaceLayer.js
+++ b/dom/system/b2g/RadioInterfaceLayer.js
@@ -214,16 +214,31 @@ RadioInterfaceLayer.prototype = {
         this.handleSmsSent(message);
         return;
       case "datacallstatechange":
         this.handleDataCallState(message.datacall);
         break;
       case "datacalllist":
         this.handleDataCallList(message);
         break;
+      case "nitzTime":
+        // TODO bug 714349
+        // Send information to time manager to decide what to do with it
+        // Message contains networkTimeInSeconds, networkTimeZoneInMinutes,
+        // dstFlag,localTimeStampInMS
+        // indicating the time, daylight savings flag, and timezone
+        // sent from the network and a timestamp of when the message was received
+        // so an offset can be added if/when the time is actually set.
+        if (DEBUG) {
+          debug("nitzTime networkTime=" + message.networkTimeInSeconds
+               + " timezone=" + message.networkTimeZoneInMinutes
+               + " dst=" + message.dstFlag
+               + " timestamp=" + message.localTimeStampInMS);
+        }
+        break;
       default:
         throw new Error("Don't know about this message type: " + message.type);
     }
   },
 
   /**
    * Track the active call and update the audio system as its state changes.
    *
--- a/dom/system/b2g/ril_worker.js
+++ b/dom/system/b2g/ril_worker.js
@@ -1308,17 +1308,51 @@ RIL[UNSOLICITED_RESPONSE_NEW_SMS_STATUS_
   Phone.onNewSMSStatusReport(info);
 };
 RIL[UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM] = function UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM(length) {
   let info = Buf.readUint32List();
   Phone.onNewSMSOnSIM(message);
 };
 RIL[UNSOLICITED_ON_USSD] = null;
 RIL[UNSOLICITED_ON_USSD_REQUEST] = null;
-RIL[UNSOLICITED_NITZ_TIME_RECEIVED] = null;
+
+RIL[UNSOLICITED_NITZ_TIME_RECEIVED] = function UNSOLICITED_NITZ_TIME_RECEIVED() {
+  let dateString = Buf.readString();
+
+  // The data contained in the NITZ message is
+  // in the form "yy/mm/dd,hh:mm:ss(+/-)tz,dt"
+  // for example: 12/02/16,03:36:08-20,00,310410
+
+  // Always print the NITZ info so we can collection what different providers
+  // send down the pipe (see bug XXX).
+  // TODO once data is collected, add in |if (DEBUG)|
+  
+  debug("DateTimeZone string " + dateString);
+
+  let now = Date.now();
+	
+  let year = parseInt(dateString.substr(0, 2), 10);
+  let month = parseInt(dateString.substr(3, 2), 10);
+  let day = parseInt(dateString.substr(6, 2), 10);
+  let hours = parseInt(dateString.substr(9, 2), 10);
+  let minutes = parseInt(dateString.substr(12, 2), 10);
+  let seconds = parseInt(dateString.substr(15, 2), 10);
+  let tz = parseInt(dateString.substr(17, 3), 10); // TZ is in 15 min. units
+  let dst = parseInt(dateString.substr(21, 2), 10); // DST already is in local time
+
+  let timeInSeconds = Date.UTC(year + PDU_TIMESTAMP_YEAR_OFFSET, month - 1, day,
+                               hours, minutes, seconds) / 1000;
+
+  if (isNaN(timeInSeconds)) {
+    debug("NITZ failed to convert date");
+  } else {
+    Phone.onNITZ(timeInSeconds, tz*15, dst, now);
+  }
+};
+
 RIL[UNSOLICITED_SIGNAL_STRENGTH] = function UNSOLICITED_SIGNAL_STRENGTH() {
   this[REQUEST_SIGNAL_STRENGTH]();
 };
 RIL[UNSOLICITED_DATA_CALL_LIST_CHANGED] = function UNSOLICITED_DATA_CALL_LIST_CHANGED(length) {
   Phone.onDataCallListChanged();
 };
 RIL[UNSOLICITED_SUPP_SVC_NOTIFICATION] = null;
 RIL[UNSOLICITED_STK_SESSION_END] = null;
@@ -2018,16 +2052,25 @@ let Phone = {
       if (DEBUG) debug("Unexpected data call: " + JSON.stringify(datacall));
     }
   },
 
   onDataCallListChanged: function onDataCallListChanged() {
     RIL.getDataCallList();
   },
 
+  onNITZ: function onNITZ(timeInSeconds, timeZoneInMinutes, dstFlag, timeStampInMS) {
+    let message = {type: "nitzTime",
+                   networkTimeInSeconds: timeInSeconds,
+                   networkTimeZoneInMinutes: timeZoneInMinutes,
+                   dstFlag: dstFlag,
+                   localTimeStampInMS: timeStampInMS};
+    this.sendDOMMessage(message);
+  },
+
   /**
    * Outgoing requests to the RIL. These can be triggered from the
    * main thread via messages that look like this:
    *
    *   {type:  "methodName",
    *    extra: "parameters",
    *    go:    "here"}
    *