From d3ef250e1ca16e720faaf89832c6ea2ef2e57cce Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 26 Mar 2012 00:46:21 -0700 Subject: [PATCH] Bug 739137: Try harder to ensure that b2g shuts down when we ask it to. r=fabrice --- b2g/components/UpdatePrompt.js | 24 ++++++++++++++++++++++++ dom/wifi/WifiWorker.js | 1 + 2 files changed, 25 insertions(+) diff --git a/b2g/components/UpdatePrompt.js b/b2g/components/UpdatePrompt.js index 8331b03d6340..904f7cc66800 100644 --- a/b2g/components/UpdatePrompt.js +++ b/b2g/components/UpdatePrompt.js @@ -24,6 +24,8 @@ 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 @@ -39,6 +41,10 @@ UpdatePrompt.prototype = { 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 @@ -51,6 +57,24 @@ UpdatePrompt.prototype = { ); }, + _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) { diff --git a/dom/wifi/WifiWorker.js b/dom/wifi/WifiWorker.js index 7e3947f64172..61a7b3906d68 100644 --- a/dom/wifi/WifiWorker.js +++ b/dom/wifi/WifiWorker.js @@ -1500,6 +1500,7 @@ WifiWorker.prototype = { get worker() { throw "Not implemented"; }, shutdown: function() { + debug("shutting down ..."); this.setWifiEnabled(false); } };