Commit 470f6229 authored by Shawn Huang's avatar Shawn Huang
Browse files

Bug 977023 - [bluedroid][KK] AVRCP 1.3/1.4 Pass Through command for fastwd and...

Bug 977023 - [bluedroid][KK] AVRCP 1.3/1.4 Pass Through command for fastwd and rewind command. r=gyeh
parent 51c3d84a
Loading
Loading
Loading
Loading
+57 −4
Original line number Diff line number Diff line
@@ -28,6 +28,11 @@

using namespace mozilla;
USING_BLUETOOTH_NAMESPACE
// AVRC_ID op code follows bluedroid avrc_defs.h
#define AVRC_ID_REWIND  0x48
#define AVRC_ID_FAST_FOR 0x49
#define AVRC_KEY_PRESS_STATE  1
#define AVRC_KEY_RELEASE_STATE  0

namespace {
  StaticRefPtr<BluetoothA2dpManager> sBluetoothA2dpManager;
@@ -178,6 +183,29 @@ private:
  uint8_t mNumAttr;
  btrc_media_attr_t* mPlayerAttrs;
};

class UpdatePassthroughCmdTask : public nsRunnable
{
public:
  UpdatePassthroughCmdTask(const nsAString& aName)
    : mName(aName)
  {
    MOZ_ASSERT(!NS_IsMainThread());
  }

  nsresult Run()
  {
    MOZ_ASSERT(NS_IsMainThread());

    NS_NAMED_LITERAL_STRING(type, "media-button");
    BroadcastSystemMessage(type, BluetoothValue(mName));

    return NS_OK;
  }
private:
  nsString mName;
};

#endif

NS_IMETHODIMP
@@ -409,13 +437,38 @@ AvrcpRemoteVolumeChangedCallback(uint8_t aVolume, uint8_t aCType)
}

/*
 * This callback function is to get notification that volume changed on the
 * remote car kit (if it supports Avrcp 1.4), not notification from phone.
 * This callback function is to handle passthrough commands.
 */
static void
AvrcpPassThroughCallback(int id, int key_state)
AvrcpPassThroughCallback(int aId, int aKeyState)
{
// TODO: Support avrcp 1.4 absolute volume/browse
  // Fast-forward and rewind key events won't be generated from bluedroid
  // stack after ANDROID_VERSION > 18, but via passthrough callback.
  nsAutoString name;
  NS_ENSURE_TRUE_VOID(aKeyState == AVRC_KEY_PRESS_STATE ||
                      aKeyState == AVRC_KEY_RELEASE_STATE);
  switch (aId) {
    case AVRC_ID_FAST_FOR:
      if (aKeyState == AVRC_KEY_PRESS_STATE) {
        name.AssignLiteral("media-fast-forward-button-press");
      } else {
        name.AssignLiteral("media-fast-forward-button-release");
      }
      break;
    case AVRC_ID_REWIND:
      if (aKeyState == AVRC_KEY_PRESS_STATE) {
        name.AssignLiteral("media-rewind-button-press");
      } else {
        name.AssignLiteral("media-rewind-button-release");
      }
      break;
    default:
      BT_WARNING("Unable to handle the unknown PassThrough command %d", aId);
      break;
  }
  if (!name.IsEmpty()) {
    NS_DispatchToMainThread(new UpdatePassthroughCmdTask(name));
  }
}
#endif

+25 −14
Original line number Diff line number Diff line
@@ -107,12 +107,23 @@ SetJsObject(JSContext* aContext,

bool
BroadcastSystemMessage(const nsAString& aType,
                       const InfallibleTArray<BluetoothNamedValue>& aData)
                       const BluetoothValue& aData)
{
  mozilla::AutoSafeJSContext cx;
  NS_ASSERTION(!::JS_IsExceptionPending(cx),
      "Shouldn't get here when an exception is pending!");

  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
    do_GetService("@mozilla.org/system-message-internal;1");
  NS_ENSURE_TRUE(systemMessenger, false);

  JS::Rooted<JS::Value> value(cx);
  if (aData.type() == BluetoothValue::TnsString) {
    JSString* jsData = JS_NewUCStringCopyN(cx,
                                           aData.get_nsString().BeginReading(),
                                           aData.get_nsString().Length());
    value = STRING_TO_JSVAL(jsData);
  } else if (aData.type() == BluetoothValue::TArrayOfBluetoothNamedValue) {
    JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(),
                                               JS::NullPtr()));
    if (!obj) {
@@ -124,12 +135,12 @@ BroadcastSystemMessage(const nsAString& aType,
      BT_WARNING("Failed to set properties of system message!");
      return false;
    }
    value = JS::ObjectValue(*obj);
  } else {
    BT_WARNING("Not support the unknown BluetoothValue type");
    return false;
  }

  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
    do_GetService("@mozilla.org/system-message-internal;1");
  NS_ENSURE_TRUE(systemMessenger, false);

  JS::Rooted<JS::Value> value(cx, JS::ObjectValue(*obj));
  systemMessenger->BroadcastMessage(aType, value,
                                    JS::UndefinedHandleValue);

+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ SetJsObject(JSContext* aContext,

bool
BroadcastSystemMessage(const nsAString& aType,
                       const InfallibleTArray<BluetoothNamedValue>& aData);
                       const BluetoothValue& aData);

void
DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,