Bug 848004 - Set the time to a minimum plausible time when necessary, r=gene
authorMichael Wu <mwu@mozilla.com>
Tue, 18 Feb 2014 15:41:36 +0100
changeset 169729 503ddb7e125e05a6b46dd5bdbb3ce35897373d10
parent 169728 aa1d1f75e73edba6de3f5bab8d85b1ded0916806
child 169730 288cb11e26bdf0ac9900abe4fa910ba8809c2f2c
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersgene
bugs848004
milestone30.0a1
Bug 848004 - Set the time to a minimum plausible time when necessary, r=gene
dom/system/gonk/RadioInterfaceLayer.js
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -17,16 +17,17 @@
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Sntp.jsm");
 Cu.import("resource://gre/modules/systemlibs.js");
 Cu.import("resource://gre/modules/Promise.jsm");
+Cu.import("resource://gre/modules/FileUtils.jsm");
 
 var RIL = {};
 Cu.import("resource://gre/modules/ril_consts.js", RIL);
 
 // set to true in ril_consts.js to see debug messages
 var DEBUG = RIL.DEBUG_RIL;
 
 // Read debug setting from pref
@@ -3294,16 +3295,26 @@ RadioInterface.prototype = {
                  Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED) {
           // Set the latest cached SNTP time if it's available.
           if (!this._sntp.isExpired()) {
             this.setClockBySntp(this._sntp.getOffset());
           } else {
             // Or refresh the SNTP.
             this._sntp.request();
           }
+        } else {
+          // Set a sane minimum time.
+          let buildTime = libcutils.property_get("ro.build.date.utc", "0") * 1000;
+          let file = FileUtils.File("/system/b2g/b2g");
+          if (file.lastModifiedTime > buildTime) {
+            buildTime = file.lastModifiedTime;
+          }
+          if (buildTime > Date.now()) {
+            gTimeService.set(buildTime);
+          }
         }
         break;
       case kSettingsTimezoneAutoUpdateEnabled:
         this._timezoneAutoUpdateEnabled = aResult;
 
         if (this._timezoneAutoUpdateEnabled) {
           // Apply the latest cached NITZ for timezone if it's available.
           if (this._timezoneAutoUpdateEnabled && this._lastNitzMessage) {