diff --git a/dom/wifi/WifiProxyService.cpp b/dom/wifi/WifiProxyService.cpp index 63e36d90cef..1a310a5eaf8 100644 --- a/dom/wifi/WifiProxyService.cpp +++ b/dom/wifi/WifiProxyService.cpp @@ -248,6 +248,10 @@ WifiProxyService::SendCommand(JS::Handle aOptions, return NS_ERROR_FAILURE; } + if (!mControlThread) { + return NS_ERROR_FAILURE; + } + // Dispatch the command to the control thread. CommandOptions commandOptions(options); nsCOMPtr runnable = new ControlRunnable(commandOptions, aInterface); @@ -293,8 +297,10 @@ WifiProxyService::DispatchWifiResult(const WifiResultOptions& aOptions, const ns return; } - // Call the listener with a JS value. - mListener->OnCommand(val, aInterface); + if (mListener) { + // Call the listener with a JS value. + mListener->OnCommand(val, aInterface); + } } void diff --git a/dom/wifi/WifiWorker.js b/dom/wifi/WifiWorker.js index 4abf19794e8..5e7128c52ba 100644 --- a/dom/wifi/WifiWorker.js +++ b/dom/wifi/WifiWorker.js @@ -1432,6 +1432,14 @@ var WifiManager = (function() { ? wifiCommand.getConnectionInfoICS : wifiCommand.getConnectionInfoGB; + manager.ensureSupplicantDetached = aCallback => { + if (!manager.enabled) { + aCallback(); + return; + } + wifiCommand.closeSupplicantConnection(aCallback); + }; + manager.isHandShakeState = function(state) { switch (state) { case "AUTHENTICATING": @@ -3820,10 +3828,14 @@ WifiWorker.prototype = { break; case "xpcom-shutdown": - let wifiService = Cc["@mozilla.org/wifi/service;1"].getService(Ci.nsIWifiProxyService); - wifiService.shutdown(); - let wifiCertService = Cc["@mozilla.org/wifi/certservice;1"].getService(Ci.nsIWifiCertService); - wifiCertService.shutdown(); + // Ensure the supplicant is detached from B2G to avoid XPCOM shutdown + // blocks forever. + WifiManager.ensureSupplicantDetached(() => { + let wifiService = Cc["@mozilla.org/wifi/service;1"].getService(Ci.nsIWifiProxyService); + wifiService.shutdown(); + let wifiCertService = Cc["@mozilla.org/wifi/certservice;1"].getService(Ci.nsIWifiCertService); + wifiCertService.shutdown(); + }); break; } },