Bug 739137: Try harder to ensure that b2g shuts down when we ask it to. r=fabrice
authorChris Jones <jones.chris.g@gmail.com>
Mon, 26 Mar 2012 00:46:21 -0700
changeset 93588 6e4ae5caddf49cc86c116a452a52af8c5c7778b4
parent 93587 9673b80d6bb15f37a9714cb9740ae436e9fab45c
child 93589 ba4983d9c1f9de34648146b7189edf9a294b8ff6
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs739137
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739137: Try harder to ensure that b2g shuts down when we ask it to. r=fabrice
b2g/components/UpdatePrompt.js
dom/wifi/WifiWorker.js
--- a/b2g/components/UpdatePrompt.js
+++ b/b2g/components/UpdatePrompt.js
@@ -19,43 +19,67 @@ let log =
   function log_noop(msg) { };
 
 function UpdatePrompt() { }
 
 UpdatePrompt.prototype = {
   classID: Components.ID("{88b3eb21-d072-4e3b-886d-f89d8c49fe59}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdatePrompt]),
 
+  _selfDestructTimer: null,
+
   // nsIUpdatePrompt
 
   // FIXME/bug 737601: we should have users opt-in to downloading
   // updates when on a billed pipe.  Initially, opt-in for 3g, but
   // that doesn't cover all cases.
   checkForUpdates: function UP_checkForUpdates() { },
   showUpdateAvailable: function UP_showUpdateAvailable(aUpdate) { },
 
   showUpdateDownloaded: function UP_showUpdateDownloaded(aUpdate, aBackground) {
     // FIXME/bug 737598: we should let the user request that the
     // update be applied later, e.g. if they're in the middle of a
     // phone call ;).
 
     log("Update downloaded, restarting to apply it");
 
+    // If not cleanly shut down within 5 seconds, this process will
+    // explode.
+    this._setSelfDestructTimer(5000);
+
     let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
     // NB: on Gonk, we rely on the system process manager to restart
     // us.  Trying to restart here would conflict with the process
     // manager.  We should be using a runtime check to detect Gonk
     // instead of this gross ifdef, but the ifdef works for now.
     appStartup.quit(appStartup.eForceQuit
 #ifndef ANDROID
                     | appStartup.eRestart
 #endif
       );
   },
 
+  _setSelfDestructTimer: function UP__setSelfDestructTimer(timeoutMs) {
+#ifdef ANDROID
+    Cu.import("resource://gre/modules/ctypes.jsm");
+    let libc = ctypes.open("libc.so");
+    let _exit = libc.declare("_exit",  ctypes.default_abi,
+                             ctypes.void_t, // [return]
+                             ctypes.int);   // status
+    this.notify = function UP_notify(_) {
+      log("Self-destruct timer fired; didn't cleanly shut down.  BOOM");
+      _exit(0);
+    }
+
+    let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+    timer.initWithCallback(this, timeoutMs, timer.TYPE_ONE_SHOT);
+    this._selfDestructTimer = timer;
+#endif
+  },
+
   showUpdateInstalled: function UP_showUpdateInstalled() { },
 
   showUpdateError: function UP_showUpdateError(aUpdate) {
     if (aUpdate.state == "failed") {
       log("Failed to download update");
     }
   },
 
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -1495,16 +1495,17 @@ WifiWorker.prototype = {
     }
   },
 
   // This is a bit ugly, but works. In particular, this depends on the fact
   // that RadioManager never actually tries to get the worker from us.
   get worker() { throw "Not implemented"; },
 
   shutdown: function() {
+    debug("shutting down ...");
     this.setWifiEnabled(false);
   }
 };
 
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiWorker]);
 
 let debug;
 if (DEBUG) {