Bug 792002 - patch 1: HFP message handler, r=qdot
authorEric Chou <echou@mozilla.com>
Thu, 27 Sep 2012 10:24:39 +0800
changeset 108223 355e9f8b0c67b1db68184f07f982158e386730a1
parent 108222 4280a881fef0d1d6b8bfde16bf7682ae66de06cf
child 108224 d76eac692a190f0a7cd83f81a9b622a0f8861fcd
push id15445
push userechou@mozilla.com
push dateThu, 27 Sep 2012 02:25:18 +0000
treeherdermozilla-inbound@d76eac692a19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs792002
milestone18.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 792002 - patch 1: HFP message handler, r=qdot
dom/bluetooth/BluetoothHfpManager.cpp
dom/bluetooth/BluetoothHfpManager.h
--- a/dom/bluetooth/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/BluetoothHfpManager.cpp
@@ -36,16 +36,64 @@ BluetoothHfpManager::Get()
   return sInstance;
 }
 
 // Virtual function of class SocketConsumer
 void
 BluetoothHfpManager::ReceiveSocketData(UnixSocketRawData* aMessage)
 {
   MOZ_ASSERT(NS_IsMainThread());
+
+  const char* msg = (const char*)aMessage->mData;
+
+  // For more information, please refer to 4.34.1 "Bluetooth Defined AT
+  // Capabilities" in Bluetooth hands-free profile 1.6
+  if (!strncmp(msg, "AT+BRSF=", 8)) {
+    SendLine("+BRSF: 23");
+    SendLine("OK");
+  } else if (!strncmp(msg, "AT+CIND=?", 9)) {
+    nsAutoCString cindRange;
+
+    cindRange += "+CIND: ";
+    cindRange += "(\"battchg\",(0-5)),";
+    cindRange += "(\"signal\",(0-5)),";
+    cindRange += "(\"service\",(0,1)),";
+    cindRange += "(\"call\",(0,1)),";
+    cindRange += "(\"callsetup\",(0-3)),";
+    cindRange += "(\"callheld\",(0-2)),";
+    cindRange += "(\"roam\",(0,1))";
+
+    SendLine(cindRange.get());
+    SendLine("OK");
+  } else if (!strncmp(msg, "AT+CIND", 7)) {
+    // FIXME - Bug 794349
+    // This value reflects current status of telephony, roaming, battery ...,
+    // so obviously fixed value must be wrong if there is an ongoing call. 
+    // Need a patch for this, but currently just using fixed value for basic 
+    // SLC establishment.
+    SendLine("+CIND: 5,5,1,0,0,0,0");
+    SendLine("OK");
+  } else if (!strncmp(msg, "AT+CMER=", 8)) {
+    SendLine("OK");
+  } else if (!strncmp(msg, "AT+CHLD=?", 9)) {
+    SendLine("+CHLD: (0,1,2,3)");
+    SendLine("OK");
+  } else if (!strncmp(msg, "AT+CHLD=", 8)) {
+    SendLine("OK");
+  } else if (!strncmp(msg, "AT+VGS=", 7)) {
+    SendLine("OK");
+  } else {
+#ifdef DEBUG
+    nsCString warningMsg;
+    warningMsg.AssignLiteral("Not handling HFP message, reply ok: ");
+    warningMsg.Append(msg);
+    NS_WARNING(warningMsg.get());
+#endif
+    SendLine("OK");
+  }
 }
 
 bool
 BluetoothHfpManager::Connect(const nsAString& aDeviceObjectPath,
                              BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -73,8 +121,21 @@ BluetoothHfpManager::Connect(const nsASt
 }
 
 void
 BluetoothHfpManager::Disconnect()
 {
   CloseSocket();
 }
 
+bool
+BluetoothHfpManager::SendLine(const char* aMessage)
+{
+  const char* kHfpCrlf = "\xd\xa";
+  nsAutoCString msg;
+
+  msg += kHfpCrlf;
+  msg += aMessage;
+  msg += kHfpCrlf;
+
+  return SendSocketData(msg);
+}
+
--- a/dom/bluetooth/BluetoothHfpManager.h
+++ b/dom/bluetooth/BluetoothHfpManager.h
@@ -20,16 +20,17 @@ public:
   ~BluetoothHfpManager();
 
   static BluetoothHfpManager* Get();
   void ReceiveSocketData(mozilla::ipc::UnixSocketRawData* aMessage);
 
   bool Connect(const nsAString& aDeviceObjectPath,
                BluetoothReplyRunnable* aRunnable);
   void Disconnect();
+  bool SendLine(const char* aMessage);
 
 private:
   BluetoothHfpManager();
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif