Bug 1166675 - Implement GetMessagesListing function, r=btian
authorShawn Huang <shuang@mozilla.com>
Fri, 11 Sep 2015 02:08:41 +0800
changeset 294270 9f6bd98f767c90b5abbe0c5ba90409404f99cc3e
parent 294254 d38a3f773d07946466e09ccb156cbe484070d6bc
child 294271 c4bf8c0c204434c0c83d10caf3e19eeab60a5fd4
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1166675
milestone43.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 1166675 - Implement GetMessagesListing function, r=btian
dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
dom/bluetooth/common/BluetoothCommon.h
--- a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 #include "BluetoothMapSmsManager.h"
 
 #include "BluetoothService.h"
 #include "BluetoothSocket.h"
+#include "BluetoothUtils.h"
 #include "BluetoothUuid.h"
 #include "ObexBase.h"
 
 #include "mozilla/RefPtr.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsAutoPtr.h"
 #include "nsIObserver.h"
@@ -343,17 +344,17 @@ BluetoothMapSmsManager::MasDataHandler(U
           !ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
           ReplyError(ObexResponseCode::BadRequest);
           return;
         }
         pktHeaders.GetContentType(type);
         if (type.EqualsLiteral("x-obex/folder-listing")) {
           HandleSmsMmsFolderListing(pktHeaders);
         } else if (type.EqualsLiteral("x-bt/MAP-msg-listing")) {
-          // TODO: Implement this feature in Bug 1166675
+          HandleSmsMmsMsgListing(pktHeaders);
         } else if (type.EqualsLiteral("x-bt/message"))  {
           // TODO: Implement this feature in Bug 1166679
         } else {
           BT_LOGR("Unknown MAP request type: %s",
             NS_ConvertUTF16toUTF8(type).get());
         }
       }
       break;
@@ -684,16 +685,150 @@ BluetoothMapSmsManager::HandleSmsMmsFold
 
     index += AppendHeaderEndOfBody(&resp[index]);
   }
 
   SendMasObexData(resp, ObexResponseCode::Success, index);
 }
 
 void
+BluetoothMapSmsManager::AppendBtNamedValueByTagId(
+  const ObexHeaderSet& aHeader,
+  InfallibleTArray<BluetoothNamedValue>& aValues,
+  const Map::AppParametersTagId aTagId)
+{
+  uint8_t buf[64];
+  if (!aHeader.GetAppParameter(aTagId, buf, 64)) {
+    return;
+  }
+
+  /*
+   * Follow MAP 6.3.1 Application Parameter Header
+   */
+  switch (aTagId) {
+    case Map::AppParametersTagId::MaxListCount: {
+      uint16_t maxListCount = *((uint16_t *)buf);
+      // convert big endian to little endian
+      maxListCount = (maxListCount >> 8) | (maxListCount << 8);
+      BT_LOGR("max list count: %d", maxListCount);
+      AppendNamedValue(aValues, "maxListCount", maxListCount);
+      break;
+    }
+    case Map::AppParametersTagId::StartOffset: {
+      uint16_t startOffset = *((uint16_t *)buf);
+      // convert big endian to little endian
+      startOffset = (startOffset >> 8) | (startOffset << 8);
+      BT_LOGR("start offset : %d", startOffset);
+      AppendNamedValue(aValues, "startOffset", startOffset);
+      break;
+    }
+    case Map::AppParametersTagId::SubjectLength: {
+      uint8_t subLength = *((uint8_t *)buf);
+      // convert big endian to little endian
+      subLength = (subLength >> 8) | (subLength << 8);
+      BT_LOGR("msg subLength : %d", subLength);
+      AppendNamedValue(aValues, "subLength", subLength);
+      break;
+    }
+    case Map::AppParametersTagId::ParameterMask: {
+      // 4 bytes
+      uint32_t parameterMask = *((uint32_t *)buf);
+      // convert big endian to little endian
+      parameterMask = (parameterMask >> 8) | (parameterMask << 8);
+      BT_LOGR("msg parameterMask : %d", parameterMask);
+      AppendNamedValue(aValues, "parameterMask", parameterMask);
+      break;
+    }
+    case Map::AppParametersTagId::FilterMessageType: {
+      uint8_t filterMessageType = *((uint8_t *)buf);
+      // convert big endian to little endian
+      filterMessageType = (filterMessageType >> 8) | (filterMessageType << 8);
+      BT_LOGR("msg filterMessageType : %d", filterMessageType);
+      AppendNamedValue(aValues, "filterMessageType", filterMessageType);
+      break;
+    }
+    case Map::AppParametersTagId::FilterPeriodBegin: {
+      nsCString filterPeriodBegin((char *) buf);
+      BT_LOGR("msg FilterPeriodBegin : %s", filterPeriodBegin.get());
+      AppendNamedValue(aValues, "filterPeriodBegin", filterPeriodBegin);
+      break;
+    }
+    case Map::AppParametersTagId::FilterPeriodEnd: {
+      nsCString filterPeriodEnd((char*)buf);
+      BT_LOGR("msg filterPeriodEnd : %s", filterPeriodEnd.get());
+      AppendNamedValue(aValues, "filterPeriodEnd", filterPeriodEnd);
+      break;
+    }
+    case Map::AppParametersTagId::FilterReadStatus: {
+      uint8_t filterReadStatus = *((uint8_t *)buf);
+      // convert big endian to little endian
+      filterReadStatus = (filterReadStatus >> 8) | (filterReadStatus << 8);
+      BT_LOGR("msg filter read status : %d", filterReadStatus);
+      AppendNamedValue(aValues, "filterReadStatus", filterReadStatus);
+      break;
+    }
+    case Map::AppParametersTagId::FilterRecipient: {
+      nsCString filterRecipient((char*) buf);
+      BT_LOGR("msg filterRecipient : %s", filterRecipient.get());
+      AppendNamedValue(aValues, "filterRecipient", filterRecipient);
+      break;
+    }
+    case Map::AppParametersTagId::FilterOriginator: {
+      nsCString filterOriginator((char*) buf);
+      BT_LOGR("msg filter Originator : %s", filterOriginator.get());
+      AppendNamedValue(aValues, "filterOriginator", filterOriginator);
+      break;
+    }
+    case Map::AppParametersTagId::FilterPriority: {
+      uint8_t filterPriority = *((uint8_t *)buf);
+      // convert big endian to little endian
+      filterPriority = (filterPriority >> 8) | (filterPriority << 8);
+      BT_LOGR("msg filter priority: %d", filterPriority);
+      AppendNamedValue(aValues, "filterPriority", filterPriority);
+      break;
+    }
+    default:
+      BT_LOGR("Unsupported AppParameterTag: %x", aTagId);
+      break;
+  }
+}
+
+void
+BluetoothMapSmsManager::HandleSmsMmsMsgListing(const ObexHeaderSet& aHeader)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  BluetoothService* bs = BluetoothService::Get();
+
+  InfallibleTArray<BluetoothNamedValue> data;
+
+  static Map::AppParametersTagId sMsgListingParameters[] = {
+    [0] = Map::AppParametersTagId::MaxListCount,
+    [1] = Map::AppParametersTagId::StartOffset,
+    [2] = Map::AppParametersTagId::SubjectLength,
+    [3] = Map::AppParametersTagId::ParameterMask,
+    [4] = Map::AppParametersTagId::FilterMessageType,
+    [5] = Map::AppParametersTagId::FilterPeriodBegin,
+    [6] = Map::AppParametersTagId::FilterPeriodEnd,
+    [7] = Map::AppParametersTagId::FilterReadStatus,
+    [8] = Map::AppParametersTagId::FilterRecipient,
+    [9] = Map::AppParametersTagId::FilterOriginator,
+    [10] = Map::AppParametersTagId::FilterPriority
+  };
+
+  for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sMsgListingParameters); i++) {
+    AppendBtNamedValueByTagId(aHeader, data, sMsgListingParameters[i]);
+  }
+
+  bs->DistributeSignal(NS_LITERAL_STRING(MAP_MESSAGES_LISTING_REQ_ID),
+                       NS_LITERAL_STRING(KEY_ADAPTER),
+                       data);
+}
+
+void
 BluetoothMapSmsManager::BuildDefaultFolderStructure()
 {
   /* MAP specification defines virtual folders structure
    * /
    * /telecom
    * /telecom/msg
    * /telecom/msg/inbox
    * /telecom/msg/draft
--- a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
@@ -91,16 +91,20 @@ private:
   void ReplyToSetPath();
   void ReplyToPut();
   void ReplyError(uint8_t aError);
 
   void HandleNotificationRegistration(const ObexHeaderSet& aHeader);
   void HandleEventReport(const ObexHeaderSet& aHeader);
   void HandleMessageStatus(const ObexHeaderSet& aHeader);
   void HandleSmsMmsFolderListing(const ObexHeaderSet& aHeader);
+  void HandleSmsMmsMsgListing(const ObexHeaderSet& aHeader);
+  void AppendBtNamedValueByTagId(const ObexHeaderSet& aHeader,
+    InfallibleTArray<BluetoothNamedValue>& aValues,
+    const Map::AppParametersTagId aTagId);
   void SendMasObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
   void SendMnsObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
 
   uint8_t SetPath(uint8_t flags, const ObexHeaderSet& aHeader);
   bool CompareHeaderTarget(const ObexHeaderSet& aHeader);
   void AfterMapSmsConnected();
   void AfterMapSmsDisconnected();
   void CreateMnsObexConnection();
--- a/dom/bluetooth/common/BluetoothCommon.h
+++ b/dom/bluetooth/common/BluetoothCommon.h
@@ -181,16 +181,22 @@ extern bool gBluetoothDebugFlag;
 /**
  * When receiving a PBAP request from a remote device, we'll dispatch an event.
  */
 #define PULL_PHONEBOOK_REQ_ID                "pullphonebookreq"
 #define PULL_VCARD_ENTRY_REQ_ID              "pullvcardentryreq"
 #define PULL_VCARD_LISTING_REQ_ID            "pullvcardlistingreq"
 
 /**
+ * When receiving a MAP request of 'messages listing' from a remote device,
+ * we'll dispatch an event.
+ */
+#define MAP_MESSAGES_LISTING_REQ_ID          "mapmessageslistingreq"
+
+/**
  * When the value of a characteristic of a remote BLE device changes, we'll
  * dispatch an event
  */
 #define GATT_CHARACTERISTIC_CHANGED_ID       "characteristicchanged"
 
 /**
  * When a remote BLE device gets connected / disconnected, we'll dispatch an
  * event.