Bug 1232687: Start bluetoothd with HAL service interface, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 04 Jan 2016 16:08:21 +0100
changeset 278300 ee9973fdfffde07fc89c7101a73b239c55b3a636
parent 278299 7670432d8866bfe462989853eaa6c75f62a6d625
child 278301 daee1e6b4acb39ca9b9fcf3d85e6d39f8210c4f8
push id29848
push usercbook@mozilla.com
push dateTue, 05 Jan 2016 10:55:18 +0000
treeherderautoland@740ebb163d6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1232687
milestone46.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 1232687: Start bluetoothd with HAL service interface, r=shuang This patch replaces Bluetooth's internal implmentation for starting bluetoothd with the portable one provided by the HAL module. Gonk- specific workarounds are preserved within HAL.
dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
@@ -11,21 +11,21 @@
 #include "BluetoothDaemonA2dpInterface.h"
 #include "BluetoothDaemonAvrcpInterface.h"
 #include "BluetoothDaemonCoreInterface.h"
 #include "BluetoothDaemonGattInterface.h"
 #include "BluetoothDaemonHandsfreeInterface.h"
 #include "BluetoothDaemonHelpers.h"
 #include "BluetoothDaemonSetupInterface.h"
 #include "BluetoothDaemonSocketInterface.h"
+#include "mozilla/Hal.h"
 #include "mozilla/ipc/DaemonRunnables.h"
 #include "mozilla/ipc/DaemonSocket.h"
 #include "mozilla/ipc/DaemonSocketConnector.h"
 #include "mozilla/ipc/ListenSocket.h"
-#include "mozilla/unused.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 using namespace mozilla::ipc;
 
 static const int sRetryInterval = 100; // ms
 
 BluetoothNotificationHandler*
@@ -276,29 +276,16 @@ BluetoothDaemonProtocol::FetchResultHand
 
   return userData.forget();
 }
 
 //
 // Interface
 //
 
-static bool
-IsDaemonRunning()
-{
-  char value[PROPERTY_VALUE_MAX];
-  NS_WARN_IF(property_get("init.svc.bluetoothd", value, "") < 0);
-  if (strcmp(value, "running")) {
-    BT_LOGR("[RESTART] Bluetooth daemon state <%s>", value);
-    return false;
-  }
-
-  return true;
-}
-
 BluetoothDaemonInterface*
 BluetoothDaemonInterface::GetInstance()
 {
   static BluetoothDaemonInterface* sBluetoothInterface;
 
   if (sBluetoothInterface) {
     return sBluetoothInterface;
   }
@@ -309,52 +296,16 @@ BluetoothDaemonInterface::GetInstance()
 }
 
 BluetoothDaemonInterface::BluetoothDaemonInterface()
 { }
 
 BluetoothDaemonInterface::~BluetoothDaemonInterface()
 { }
 
-class BluetoothDaemonInterface::StartDaemonTask final : public Task
-{
-public:
-  StartDaemonTask(BluetoothDaemonInterface* aInterface,
-                  const nsACString& aCommand)
-    : mInterface(aInterface)
-    , mCommand(aCommand)
-  {
-    MOZ_ASSERT(mInterface);
-  }
-
-  void Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("Start Daemon Task");
-    // Start Bluetooth daemon again
-    if (NS_WARN_IF(property_set("ctl.start", mCommand.get()) < 0)) {
-      mInterface->OnConnectError(CMD_CHANNEL);
-    }
-
-    // We're done if Bluetooth daemon is already running
-    if (IsDaemonRunning()) {
-      return;
-    }
-
-    // Otherwise try again later
-    MessageLoop::current()->PostDelayedTask(FROM_HERE,
-      new StartDaemonTask(mInterface, mCommand), sRetryInterval);
-  }
-
-private:
-  BluetoothDaemonInterface* mInterface;
-  nsCString mCommand;
-};
-
 class BluetoothDaemonInterface::InitResultHandler final
   : public BluetoothSetupResultHandler
 {
 public:
   InitResultHandler(BluetoothDaemonInterface* aInterface,
                     BluetoothResultHandler* aRes)
     : mInterface(aInterface)
     , mRes(aRes)
@@ -440,17 +391,17 @@ BluetoothDaemonInterface::Init(
 
   // First of all, we set the notification handler. Backend crashes
   // will be reported this way.
   sNotificationHandler = aNotificationHandler;
 
   // If we could not cleanup properly before and an old
   // instance of the daemon is still running, we kill it
   // here.
-  Unused << NS_WARN_IF(property_set("ctl.stop", "bluetoothd"));
+  mozilla::hal::StopSystemService("bluetoothd");
 
   mResultHandlerQ.AppendElement(aRes);
 
   if (!mProtocol) {
     mProtocol = new BluetoothDaemonProtocol();
   }
 
   if (!mListenSocket) {
@@ -689,34 +640,19 @@ void
 BluetoothDaemonInterface::OnConnectSuccess(int aIndex)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!mResultHandlerQ.IsEmpty());
 
   switch (aIndex) {
     case LISTEN_SOCKET: {
         // Init, step 2: Start Bluetooth daemon */
-        nsCString value("bluetoothd:-a ");
-        value.Append(mListenSocketName);
-        if (NS_WARN_IF(property_set("ctl.start", value.get()) < 0)) {
-          OnConnectError(CMD_CHANNEL);
-        }
-
-        /*
-         * If Bluetooth daemon is not running, retry to start it later.
-         *
-         * This condition happens when when we restart Bluetooth daemon
-         * immediately after it crashed, as the daemon state remains 'stopping'
-         * instead of 'stopped'. Due to the limitation of property service,
-         * hereby add delay. See Bug 1143925 Comment 41.
-         */
-        if (!IsDaemonRunning()) {
-          MessageLoop::current()->PostDelayedTask(FROM_HERE,
-              new StartDaemonTask(this, value), sRetryInterval);
-        }
+        nsCString args("-a ");
+        args.Append(mListenSocketName);
+        mozilla::hal::StartSystemService("bluetoothd", args.get());
       }
       break;
     case CMD_CHANNEL:
       // Init, step 3: Listen for notification channel...
       if (!mNtfChannel) {
         mNtfChannel = new DaemonSocket(mProtocol, this, NTF_CHANNEL);
       } else if (
         NS_WARN_IF(mNtfChannel->GetConnectionStatus() == SOCKET_CONNECTED)) {
@@ -752,17 +688,17 @@ BluetoothDaemonInterface::OnConnectError
   MOZ_ASSERT(!mResultHandlerQ.IsEmpty());
 
   switch (aIndex) {
     case NTF_CHANNEL:
       // Close command channel
       mCmdChannel->Close();
     case CMD_CHANNEL:
       // Stop daemon and close listen socket
-      Unused << NS_WARN_IF(property_set("ctl.stop", "bluetoothd"));
+      mozilla::hal::StopSystemService("bluetoothd");
       mListenSocket->Close();
     case LISTEN_SOCKET:
       if (!mResultHandlerQ.IsEmpty()) {
         // Signal error to caller
         RefPtr<BluetoothResultHandler> res = mResultHandlerQ.ElementAt(0);
         mResultHandlerQ.RemoveElementAt(0);
 
         if (res) {
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h
@@ -34,21 +34,19 @@ class BluetoothDaemonSocketInterface;
 class BluetoothDaemonInterface final
   : public BluetoothInterface
   , public mozilla::ipc::DaemonSocketConsumer
   , public mozilla::ipc::ListenSocketConsumer
 {
 public:
   class CleanupResultHandler;
   class InitResultHandler;
-  class StartDaemonTask;
 
   friend class CleanupResultHandler;
   friend class InitResultHandler;
-  friend class StartDaemonTask;
 
   static BluetoothDaemonInterface* GetInstance();
 
   void Init(BluetoothNotificationHandler* aNotificationHandler,
             BluetoothResultHandler* aRes) override;
   void Cleanup(BluetoothResultHandler* aRes) override;
 
   /* Service Interfaces */