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

This commit is contained in:
Shawn Huang 2014-04-04 08:19:48 -04:00
parent bfc008464e
commit b140a61fc3
3 changed files with 83 additions and 19 deletions

View File

@ -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

View File

@ -107,29 +107,40 @@ 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!");
JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(),
JS::NullPtr()));
if (!obj) {
BT_WARNING("Failed to new JSObject for system message!");
return false;
}
if (!SetJsObject(cx, aData, obj)) {
BT_WARNING("Failed to set properties of system message!");
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));
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) {
BT_WARNING("Failed to new JSObject for system message!");
return false;
}
if (!SetJsObject(cx, aData, obj)) {
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;
}
systemMessenger->BroadcastMessage(aType, value,
JS::UndefinedHandleValue);

View File

@ -36,7 +36,7 @@ SetJsObject(JSContext* aContext,
bool
BroadcastSystemMessage(const nsAString& aType,
const InfallibleTArray<BluetoothNamedValue>& aData);
const BluetoothValue& aData);
void
DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,