зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1146355: Remove original directory of Bluetooth v2, r=joliu
All code from dom/bluetoth2 has been moved to dom/bluetooth/bluetooth2 and integrated into the Bluetooth code base.
This commit is contained in:
Родитель
c50cdfe9dd
Коммит
1a67ac753b
|
@ -1,184 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothA2dpHALInterface.h"
|
||||
#include "BluetoothHALHelpers.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable0<BluetoothA2dpResultHandler, void>
|
||||
BluetoothA2dpHALResultRunnable;
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable1<BluetoothA2dpResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
BluetoothA2dpHALErrorRunnable;
|
||||
|
||||
static nsresult
|
||||
DispatchBluetoothA2dpHALResult(
|
||||
BluetoothA2dpResultHandler* aRes,
|
||||
void (BluetoothA2dpResultHandler::*aMethod)(),
|
||||
BluetoothStatus aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
nsRunnable* runnable;
|
||||
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
runnable = new BluetoothA2dpHALResultRunnable(aRes, aMethod);
|
||||
} else {
|
||||
runnable = new BluetoothA2dpHALErrorRunnable(aRes,
|
||||
&BluetoothA2dpResultHandler::OnError, aStatus);
|
||||
}
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_FAILED(rv)) {
|
||||
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Notification handling
|
||||
//
|
||||
|
||||
static BluetoothA2dpNotificationHandler* sA2dpNotificationHandler;
|
||||
|
||||
struct BluetoothA2dpHALCallback
|
||||
{
|
||||
class A2dpNotificationHandlerWrapper
|
||||
{
|
||||
public:
|
||||
typedef BluetoothA2dpNotificationHandler ObjectType;
|
||||
|
||||
static ObjectType* GetInstance()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return sA2dpNotificationHandler;
|
||||
}
|
||||
};
|
||||
|
||||
// Notifications
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<
|
||||
A2dpNotificationHandlerWrapper, void,
|
||||
BluetoothA2dpConnectionState, nsString,
|
||||
BluetoothA2dpConnectionState, const nsAString&>
|
||||
ConnectionStateNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<
|
||||
A2dpNotificationHandlerWrapper, void,
|
||||
BluetoothA2dpAudioState, nsString,
|
||||
BluetoothA2dpAudioState, const nsAString&>
|
||||
AudioStateNotification;
|
||||
|
||||
// Bluedroid A2DP callbacks
|
||||
|
||||
static void
|
||||
ConnectionState(btav_connection_state_t aState, bt_bdaddr_t* aBdAddr)
|
||||
{
|
||||
ConnectionStateNotification::Dispatch(
|
||||
&BluetoothA2dpNotificationHandler::ConnectionStateNotification,
|
||||
aState, aBdAddr);
|
||||
}
|
||||
|
||||
static void
|
||||
AudioState(btav_audio_state_t aState, bt_bdaddr_t* aBdAddr)
|
||||
{
|
||||
AudioStateNotification::Dispatch(
|
||||
&BluetoothA2dpNotificationHandler::AudioStateNotification,
|
||||
aState, aBdAddr);
|
||||
}
|
||||
};
|
||||
|
||||
// Interface
|
||||
//
|
||||
|
||||
BluetoothA2dpHALInterface::BluetoothA2dpHALInterface(
|
||||
const btav_interface_t* aInterface)
|
||||
: mInterface(aInterface)
|
||||
{
|
||||
MOZ_ASSERT(mInterface);
|
||||
}
|
||||
|
||||
BluetoothA2dpHALInterface::~BluetoothA2dpHALInterface()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothA2dpHALInterface::Init(
|
||||
BluetoothA2dpNotificationHandler* aNotificationHandler,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
static btav_callbacks_t sCallbacks = {
|
||||
sizeof(sCallbacks),
|
||||
BluetoothA2dpHALCallback::ConnectionState,
|
||||
BluetoothA2dpHALCallback::AudioState
|
||||
};
|
||||
|
||||
sA2dpNotificationHandler = aNotificationHandler;
|
||||
|
||||
bt_status_t status = mInterface->init(&sCallbacks);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothA2dpHALResult(aRes,
|
||||
&BluetoothA2dpResultHandler::Init,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpHALInterface::Cleanup(BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
mInterface->cleanup();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothA2dpHALResult(aRes,
|
||||
&BluetoothA2dpResultHandler::Cleanup,
|
||||
STATUS_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpHALInterface::Connect(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->connect(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothA2dpHALResult(
|
||||
aRes, &BluetoothA2dpResultHandler::Connect,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpHALInterface::Disconnect(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->disconnect(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothA2dpHALResult(
|
||||
aRes, &BluetoothA2dpResultHandler::Disconnect,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,44 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetootha2dphalinterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetootha2dphalinterface_h__
|
||||
|
||||
#include <hardware/bluetooth.h>
|
||||
#include <hardware/bt_av.h>
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothHALInterface;
|
||||
|
||||
class BluetoothA2dpHALInterface final
|
||||
: public BluetoothA2dpInterface
|
||||
{
|
||||
public:
|
||||
friend class BluetoothHALInterface;
|
||||
|
||||
void Init(BluetoothA2dpNotificationHandler* aNotificationHandler,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
void Cleanup(BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
void Connect(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
void Disconnect(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
BluetoothA2dpHALInterface(const btav_interface_t* aInterface);
|
||||
~BluetoothA2dpHALInterface();
|
||||
|
||||
private:
|
||||
const btav_interface_t* mInterface;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,166 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetootha2dpmanager_h__
|
||||
#define mozilla_dom_bluetooth_bluetootha2dpmanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothProfileController.h"
|
||||
#include "BluetoothProfileManagerBase.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
class BluetoothA2dpManager : public BluetoothProfileManagerBase
|
||||
, public BluetoothA2dpNotificationHandler
|
||||
, public BluetoothAvrcpNotificationHandler
|
||||
{
|
||||
public:
|
||||
BT_DECL_PROFILE_MGR_BASE
|
||||
virtual void GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("A2DP");
|
||||
}
|
||||
|
||||
enum SinkState {
|
||||
SINK_UNKNOWN,
|
||||
SINK_DISCONNECTED,
|
||||
SINK_CONNECTING,
|
||||
SINK_CONNECTED,
|
||||
SINK_PLAYING,
|
||||
};
|
||||
|
||||
static BluetoothA2dpManager* Get();
|
||||
static void InitA2dpInterface(BluetoothProfileResultHandler* aRes);
|
||||
static void DeinitA2dpInterface(BluetoothProfileResultHandler* aRes);
|
||||
virtual ~BluetoothA2dpManager();
|
||||
|
||||
void OnConnectError();
|
||||
void OnDisconnectError();
|
||||
|
||||
// A2DP-specific functions
|
||||
void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
|
||||
|
||||
// AVRCP-specific functions
|
||||
void SetAvrcpConnected(bool aConnected);
|
||||
bool IsAvrcpConnected();
|
||||
void UpdateMetaData(const nsAString& aTitle,
|
||||
const nsAString& aArtist,
|
||||
const nsAString& aAlbum,
|
||||
uint64_t aMediaNumber,
|
||||
uint64_t aTotalMediaCount,
|
||||
uint32_t aDuration);
|
||||
void UpdatePlayStatus(uint32_t aDuration,
|
||||
uint32_t aPosition,
|
||||
ControlPlayStatus aPlayStatus);
|
||||
void UpdateRegisterNotification(BluetoothAvrcpEvent aEvent, uint32_t aParam);
|
||||
void GetAlbum(nsAString& aAlbum);
|
||||
uint32_t GetDuration();
|
||||
ControlPlayStatus GetPlayStatus();
|
||||
uint32_t GetPosition();
|
||||
uint64_t GetMediaNumber();
|
||||
uint64_t GetTotalMediaNumber();
|
||||
void GetTitle(nsAString& aTitle);
|
||||
void GetArtist(nsAString& aArtist);
|
||||
|
||||
private:
|
||||
class CleanupA2dpResultHandler;
|
||||
class CleanupA2dpResultHandlerRunnable;
|
||||
class CleanupAvrcpResultHandler;
|
||||
class ConnectResultHandler;
|
||||
class DisconnectResultHandler;
|
||||
class InitA2dpResultHandler;
|
||||
class InitAvrcpResultHandler;
|
||||
class OnErrorProfileResultHandlerRunnable;
|
||||
|
||||
BluetoothA2dpManager();
|
||||
void ResetA2dp();
|
||||
void ResetAvrcp();
|
||||
|
||||
void HandleShutdown();
|
||||
void NotifyConnectionStatusChanged();
|
||||
|
||||
void ConnectionStateNotification(BluetoothA2dpConnectionState aState,
|
||||
const nsAString& aBdAddr) override;
|
||||
void AudioStateNotification(BluetoothA2dpAudioState aState,
|
||||
const nsAString& aBdAddr) override;
|
||||
|
||||
void GetPlayStatusNotification() override;
|
||||
|
||||
void ListPlayerAppAttrNotification() override;
|
||||
|
||||
void ListPlayerAppValuesNotification(
|
||||
BluetoothAvrcpPlayerAttribute aAttrId) override;
|
||||
|
||||
void GetPlayerAppValueNotification(
|
||||
uint8_t aNumAttrs,
|
||||
const BluetoothAvrcpPlayerAttribute* aAttrs) override;
|
||||
|
||||
void GetPlayerAppAttrsTextNotification(
|
||||
uint8_t aNumAttrs,
|
||||
const BluetoothAvrcpPlayerAttribute* aAttrs) override;
|
||||
|
||||
void GetPlayerAppValuesTextNotification(
|
||||
uint8_t aAttrId, uint8_t aNumVals, const uint8_t* aValues) override;
|
||||
|
||||
void SetPlayerAppValueNotification(
|
||||
const BluetoothAvrcpPlayerSettings& aSettings) override;
|
||||
|
||||
void GetElementAttrNotification(
|
||||
uint8_t aNumAttrs,
|
||||
const BluetoothAvrcpMediaAttribute* aAttrs) override;
|
||||
|
||||
void RegisterNotificationNotification(
|
||||
BluetoothAvrcpEvent aEvent, uint32_t aParam) override;
|
||||
|
||||
void RemoteFeatureNotification(
|
||||
const nsAString& aBdAddr, unsigned long aFeatures) override;
|
||||
|
||||
void VolumeChangeNotification(uint8_t aVolume, uint8_t aCType) override;
|
||||
|
||||
void PassthroughCmdNotification(int aId, int aKeyState) override;
|
||||
|
||||
nsString mDeviceAddress;
|
||||
nsRefPtr<BluetoothProfileController> mController;
|
||||
|
||||
// A2DP data member
|
||||
bool mA2dpConnected;
|
||||
SinkState mSinkState;
|
||||
|
||||
// AVRCP data member
|
||||
bool mAvrcpConnected;
|
||||
nsString mAlbum;
|
||||
nsString mArtist;
|
||||
nsString mTitle;
|
||||
uint32_t mDuration;
|
||||
uint64_t mMediaNumber;
|
||||
uint64_t mTotalMediaCount;
|
||||
uint32_t mPosition;
|
||||
/*
|
||||
* mPlaybackInterval specifies the time interval (in seconds) at which
|
||||
* the change in playback position will be notified. If the song is being
|
||||
* forwarded / rewound, a notification will be received whenever the playback
|
||||
* position will change by this value.
|
||||
*/
|
||||
uint32_t mPlaybackInterval;
|
||||
ControlPlayStatus mPlayStatus;
|
||||
/*
|
||||
* Notification types: 1. INTERIM 2. CHANGED
|
||||
* 1. The initial response to this Notify command shall be an INTERIM
|
||||
* response with current status.
|
||||
* 2. The following response shall be a CHANGED response with the updated
|
||||
* status.
|
||||
* mPlayStatusChangedNotifType, mTrackChangedNotifType,
|
||||
* mPlayPosChangedNotifType represents current RegisterNotification
|
||||
* notification type.
|
||||
*/
|
||||
BluetoothAvrcpNotification mPlayStatusChangedNotifyType;
|
||||
BluetoothAvrcpNotification mTrackChangedNotifyType;
|
||||
BluetoothAvrcpNotification mPlayPosChangedNotifyType;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,601 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothAvrcpHALInterface.h"
|
||||
#include "BluetoothHALHelpers.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable0<BluetoothAvrcpResultHandler, void>
|
||||
BluetoothAvrcpHALResultRunnable;
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable1<BluetoothAvrcpResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
BluetoothAvrcpHALErrorRunnable;
|
||||
|
||||
static nsresult
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
BluetoothAvrcpResultHandler* aRes,
|
||||
void (BluetoothAvrcpResultHandler::*aMethod)(),
|
||||
BluetoothStatus aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
nsRunnable* runnable;
|
||||
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
runnable = new BluetoothAvrcpHALResultRunnable(aRes, aMethod);
|
||||
} else {
|
||||
runnable = new BluetoothAvrcpHALErrorRunnable(aRes,
|
||||
&BluetoothAvrcpResultHandler::OnError, aStatus);
|
||||
}
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_FAILED(rv)) {
|
||||
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Notification handling
|
||||
//
|
||||
|
||||
static BluetoothAvrcpNotificationHandler* sAvrcpNotificationHandler;
|
||||
|
||||
struct BluetoothAvrcpCallback
|
||||
{
|
||||
class AvrcpNotificationHandlerWrapper
|
||||
{
|
||||
public:
|
||||
typedef BluetoothAvrcpNotificationHandler ObjectType;
|
||||
|
||||
static ObjectType* GetInstance()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return sAvrcpNotificationHandler;
|
||||
}
|
||||
};
|
||||
|
||||
// Notifications
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<AvrcpNotificationHandlerWrapper,
|
||||
void>
|
||||
GetPlayStatusNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<AvrcpNotificationHandlerWrapper,
|
||||
void>
|
||||
ListPlayerAppAttrNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<AvrcpNotificationHandlerWrapper,
|
||||
void,
|
||||
BluetoothAvrcpPlayerAttribute>
|
||||
ListPlayerAppValuesNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper, void,
|
||||
uint8_t, nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
|
||||
uint8_t, const BluetoothAvrcpPlayerAttribute*>
|
||||
GetPlayerAppValueNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper, void,
|
||||
uint8_t, nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
|
||||
uint8_t, const BluetoothAvrcpPlayerAttribute*>
|
||||
GetPlayerAppAttrsTextNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable3<AvrcpNotificationHandlerWrapper,
|
||||
void,
|
||||
uint8_t, uint8_t,
|
||||
nsAutoArrayPtr<uint8_t>,
|
||||
uint8_t, uint8_t, const uint8_t*>
|
||||
GetPlayerAppValuesTextNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<AvrcpNotificationHandlerWrapper,
|
||||
void,
|
||||
BluetoothAvrcpPlayerSettings,
|
||||
const BluetoothAvrcpPlayerSettings&>
|
||||
SetPlayerAppValueNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper, void,
|
||||
uint8_t, nsAutoArrayPtr<BluetoothAvrcpMediaAttribute>,
|
||||
uint8_t, const BluetoothAvrcpMediaAttribute*>
|
||||
GetElementAttrNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
|
||||
void,
|
||||
BluetoothAvrcpEvent, uint32_t>
|
||||
RegisterNotificationNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
|
||||
void,
|
||||
nsString, unsigned long,
|
||||
const nsAString&>
|
||||
RemoteFeatureNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
|
||||
void,
|
||||
uint8_t, uint8_t>
|
||||
VolumeChangeNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<AvrcpNotificationHandlerWrapper,
|
||||
void,
|
||||
int, int>
|
||||
PassthroughCmdNotification;
|
||||
|
||||
// Bluedroid AVRCP callbacks
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
static void
|
||||
GetPlayStatus()
|
||||
{
|
||||
GetPlayStatusNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::GetPlayStatusNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
ListPlayerAppAttr()
|
||||
{
|
||||
ListPlayerAppAttrNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::ListPlayerAppAttrNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
ListPlayerAppValues(btrc_player_attr_t aAttrId)
|
||||
{
|
||||
ListPlayerAppValuesNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::ListPlayerAppValuesNotification,
|
||||
aAttrId);
|
||||
}
|
||||
|
||||
static void
|
||||
GetPlayerAppValue(uint8_t aNumAttrs, btrc_player_attr_t* aAttrs)
|
||||
{
|
||||
GetPlayerAppValueNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::GetPlayerAppValueNotification,
|
||||
aNumAttrs, ConvertArray<btrc_player_attr_t>(aAttrs, aNumAttrs));
|
||||
}
|
||||
|
||||
static void
|
||||
GetPlayerAppAttrsText(uint8_t aNumAttrs, btrc_player_attr_t* aAttrs)
|
||||
{
|
||||
GetPlayerAppAttrsTextNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::GetPlayerAppAttrsTextNotification,
|
||||
aNumAttrs, ConvertArray<btrc_player_attr_t>(aAttrs, aNumAttrs));
|
||||
}
|
||||
|
||||
static void
|
||||
GetPlayerAppValuesText(uint8_t aAttrId, uint8_t aNumVals, uint8_t* aVals)
|
||||
{
|
||||
GetPlayerAppValuesTextNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::GetPlayerAppValuesTextNotification,
|
||||
aAttrId, aNumVals, ConvertArray<uint8_t>(aVals, aNumVals));
|
||||
}
|
||||
|
||||
static void
|
||||
SetPlayerAppValue(btrc_player_settings_t* aVals)
|
||||
{
|
||||
SetPlayerAppValueNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::SetPlayerAppValueNotification,
|
||||
*aVals);
|
||||
}
|
||||
|
||||
static void
|
||||
GetElementAttr(uint8_t aNumAttrs, btrc_media_attr_t* aAttrs)
|
||||
{
|
||||
GetElementAttrNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::GetElementAttrNotification,
|
||||
aNumAttrs, ConvertArray<btrc_media_attr_t>(aAttrs, aNumAttrs));
|
||||
}
|
||||
|
||||
static void
|
||||
RegisterNotification(btrc_event_id_t aEvent, uint32_t aParam)
|
||||
{
|
||||
RegisterNotificationNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::RegisterNotificationNotification,
|
||||
aEvent, aParam);
|
||||
}
|
||||
#endif // ANDROID_VERSION >= 18
|
||||
|
||||
#if ANDROID_VERSION >= 19
|
||||
static void
|
||||
RemoteFeature(bt_bdaddr_t* aBdAddr, btrc_remote_features_t aFeatures)
|
||||
{
|
||||
RemoteFeatureNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::RemoteFeatureNotification,
|
||||
aBdAddr, aFeatures);
|
||||
}
|
||||
|
||||
static void
|
||||
VolumeChange(uint8_t aVolume, uint8_t aCType)
|
||||
{
|
||||
VolumeChangeNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::VolumeChangeNotification,
|
||||
aVolume, aCType);
|
||||
}
|
||||
|
||||
static void
|
||||
PassthroughCmd(int aId, int aKeyState)
|
||||
{
|
||||
PassthroughCmdNotification::Dispatch(
|
||||
&BluetoothAvrcpNotificationHandler::PassthroughCmdNotification,
|
||||
aId, aKeyState);
|
||||
}
|
||||
#endif // ANDROID_VERSION >= 19
|
||||
};
|
||||
|
||||
// Interface
|
||||
//
|
||||
|
||||
BluetoothAvrcpHALInterface::BluetoothAvrcpHALInterface(
|
||||
#if ANDROID_VERSION >= 18
|
||||
const btrc_interface_t* aInterface
|
||||
#endif
|
||||
)
|
||||
#if ANDROID_VERSION >= 18
|
||||
: mInterface(aInterface)
|
||||
#endif
|
||||
{
|
||||
#if ANDROID_VERSION >= 18
|
||||
MOZ_ASSERT(mInterface);
|
||||
#endif
|
||||
}
|
||||
|
||||
BluetoothAvrcpHALInterface::~BluetoothAvrcpHALInterface()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::Init(
|
||||
BluetoothAvrcpNotificationHandler* aNotificationHandler,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
#if ANDROID_VERSION >= 18
|
||||
static btrc_callbacks_t sCallbacks = {
|
||||
sizeof(sCallbacks),
|
||||
#if ANDROID_VERSION >= 19
|
||||
BluetoothAvrcpCallback::RemoteFeature,
|
||||
#endif
|
||||
BluetoothAvrcpCallback::GetPlayStatus,
|
||||
BluetoothAvrcpCallback::ListPlayerAppAttr,
|
||||
BluetoothAvrcpCallback::ListPlayerAppValues,
|
||||
BluetoothAvrcpCallback::GetPlayerAppValue,
|
||||
BluetoothAvrcpCallback::GetPlayerAppAttrsText,
|
||||
BluetoothAvrcpCallback::GetPlayerAppValuesText,
|
||||
BluetoothAvrcpCallback::SetPlayerAppValue,
|
||||
BluetoothAvrcpCallback::GetElementAttr,
|
||||
BluetoothAvrcpCallback::RegisterNotification
|
||||
#if ANDROID_VERSION >= 19
|
||||
,
|
||||
BluetoothAvrcpCallback::VolumeChange,
|
||||
BluetoothAvrcpCallback::PassthroughCmd
|
||||
#endif
|
||||
};
|
||||
#endif // ANDROID_VERSION >= 18
|
||||
|
||||
sAvrcpNotificationHandler = aNotificationHandler;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
bt_status_t status = mInterface->init(&sCallbacks);
|
||||
#else
|
||||
bt_status_t status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(aRes, &BluetoothAvrcpResultHandler::Init,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::Cleanup(BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
mInterface->cleanup();
|
||||
|
||||
status = BT_STATUS_SUCCESS;
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes,
|
||||
&BluetoothAvrcpResultHandler::Cleanup,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::GetPlayStatusRsp(
|
||||
ControlPlayStatus aPlayStatus, uint32_t aSongLen, uint32_t aSongPos,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
btrc_play_status_t playStatus = BTRC_PLAYSTATE_STOPPED;
|
||||
|
||||
if (!(NS_FAILED(Convert(aPlayStatus, playStatus)))) {
|
||||
status = mInterface->get_play_status_rsp(playStatus, aSongLen, aSongPos);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::GetPlayStatusRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::ListPlayerAppAttrRsp(
|
||||
int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
ConvertArray<BluetoothAvrcpPlayerAttribute> pAttrsArray(aPAttrs, aNumAttr);
|
||||
nsAutoArrayPtr<btrc_player_attr_t> pAttrs;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(pAttrsArray, pAttrs))) {
|
||||
status = mInterface->list_player_app_attr_rsp(aNumAttr, pAttrs);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::ListPlayerAppAttrRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::ListPlayerAppValueRsp(
|
||||
int aNumVal, uint8_t* aPVals, BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
#if ANDROID_VERSION >= 18
|
||||
bt_status_t status = mInterface->list_player_app_value_rsp(aNumVal, aPVals);
|
||||
#else
|
||||
bt_status_t status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::ListPlayerAppValueRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::GetPlayerAppValueRsp(
|
||||
uint8_t aNumAttrs, const uint8_t* aIds, const uint8_t* aValues,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
btrc_player_settings_t pVals;
|
||||
|
||||
/* FIXME: you need to implement the missing conversion functions */
|
||||
NS_NOTREACHED("Conversion function missing");
|
||||
|
||||
if (false /* TODO: we don't support any player app values currently */) {
|
||||
status = mInterface->get_player_app_value_rsp(&pVals);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::GetPlayerAppValueRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::GetPlayerAppAttrTextRsp(
|
||||
int aNumAttr, const uint8_t* aIds, const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
btrc_player_setting_text_t* aPAttrs;
|
||||
|
||||
/* FIXME: you need to implement the missing conversion functions */
|
||||
NS_NOTREACHED("Conversion function missing");
|
||||
|
||||
if (false /* TODO: we don't support any attributes currently */) {
|
||||
status = mInterface->get_player_app_attr_text_rsp(aNumAttr, aPAttrs);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::GetPlayerAppAttrTextRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::GetPlayerAppValueTextRsp(
|
||||
int aNumVal, const uint8_t* aIds, const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
btrc_player_setting_text_t* pVals;
|
||||
|
||||
/* FIXME: you need to implement the missing conversion functions */
|
||||
NS_NOTREACHED("Conversion function missing");
|
||||
|
||||
if (false /* TODO: we don't support any values currently */) {
|
||||
status = mInterface->get_player_app_value_text_rsp(aNumVal, pVals);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::GetPlayerAppValueTextRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::GetElementAttrRsp(
|
||||
uint8_t aNumAttr, const BluetoothAvrcpElementAttribute* aAttrs,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
ConvertArray<BluetoothAvrcpElementAttribute> pAttrsArray(aAttrs, aNumAttr);
|
||||
nsAutoArrayPtr<btrc_element_attr_val_t> pAttrs;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(pAttrsArray, pAttrs))) {
|
||||
status = mInterface->get_element_attr_rsp(aNumAttr, pAttrs);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::GetElementAttrRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::SetPlayerAppValueRsp(
|
||||
BluetoothAvrcpStatus aRspStatus, BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
btrc_status_t rspStatus = BTRC_STS_BAD_CMD; // silences compiler warning
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aRspStatus, rspStatus))) {
|
||||
status = mInterface->set_player_app_value_rsp(rspStatus);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::SetPlayerAppValueRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::RegisterNotificationRsp(
|
||||
BluetoothAvrcpEvent aEvent, BluetoothAvrcpNotification aType,
|
||||
const BluetoothAvrcpNotificationParam& aParam,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
nsresult rv;
|
||||
btrc_event_id_t event = { };
|
||||
btrc_notification_type_t type = BTRC_NOTIFICATION_TYPE_INTERIM;
|
||||
btrc_register_notification_t param;
|
||||
|
||||
switch (aEvent) {
|
||||
case AVRCP_EVENT_PLAY_STATUS_CHANGED:
|
||||
rv = Convert(aParam.mPlayStatus, param.play_status);
|
||||
break;
|
||||
case AVRCP_EVENT_TRACK_CHANGE:
|
||||
MOZ_ASSERT(sizeof(aParam.mTrack) == sizeof(param.track));
|
||||
memcpy(param.track, aParam.mTrack, sizeof(param.track));
|
||||
rv = NS_OK;
|
||||
break;
|
||||
case AVRCP_EVENT_TRACK_REACHED_END:
|
||||
NS_NOTREACHED("Unknown conversion");
|
||||
rv = NS_ERROR_ILLEGAL_VALUE;
|
||||
break;
|
||||
case AVRCP_EVENT_TRACK_REACHED_START:
|
||||
NS_NOTREACHED("Unknown conversion");
|
||||
rv = NS_ERROR_ILLEGAL_VALUE;
|
||||
break;
|
||||
case AVRCP_EVENT_PLAY_POS_CHANGED:
|
||||
param.song_pos = aParam.mSongPos;
|
||||
rv = NS_OK;
|
||||
break;
|
||||
case AVRCP_EVENT_APP_SETTINGS_CHANGED:
|
||||
NS_NOTREACHED("Unknown conversion");
|
||||
rv = NS_ERROR_ILLEGAL_VALUE;
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("Unknown conversion");
|
||||
rv = NS_ERROR_ILLEGAL_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
NS_SUCCEEDED(Convert(aEvent, event)) &&
|
||||
NS_SUCCEEDED(Convert(aType, type))) {
|
||||
status = mInterface->register_notification_rsp(event, type, ¶m);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
#else
|
||||
status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::RegisterNotificationRsp,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothAvrcpHALInterface::SetVolume(uint8_t aVolume,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
#if ANDROID_VERSION >= 19
|
||||
bt_status_t status = mInterface->set_volume(aVolume);
|
||||
#else
|
||||
bt_status_t status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothAvrcpHALResult(
|
||||
aRes, &BluetoothAvrcpResultHandler::SetVolume,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,84 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothavrcphalinterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetoothavrcphalinterface_h__
|
||||
|
||||
#include <hardware/bluetooth.h>
|
||||
#if ANDROID_VERSION >= 18
|
||||
#include <hardware/bt_rc.h>
|
||||
#endif
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothHALInterface;
|
||||
|
||||
class BluetoothAvrcpHALInterface final
|
||||
: public BluetoothAvrcpInterface
|
||||
{
|
||||
public:
|
||||
friend class BluetoothHALInterface;
|
||||
|
||||
void Init(BluetoothAvrcpNotificationHandler* aNotificationHandler,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
void Cleanup(BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void GetPlayStatusRsp(ControlPlayStatus aPlayStatus,
|
||||
uint32_t aSongLen, uint32_t aSongPos,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void ListPlayerAppAttrRsp(int aNumAttr,
|
||||
const BluetoothAvrcpPlayerAttribute* aPAttrs,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
void ListPlayerAppValueRsp(int aNumVal, uint8_t* aPVals,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
/* TODO: redesign this interface once we actually use it */
|
||||
void GetPlayerAppValueRsp(uint8_t aNumAttrs,
|
||||
const uint8_t* aIds, const uint8_t* aValues,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
/* TODO: redesign this interface once we actually use it */
|
||||
void GetPlayerAppAttrTextRsp(int aNumAttr,
|
||||
const uint8_t* aIds, const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
/* TODO: redesign this interface once we actually use it */
|
||||
void GetPlayerAppValueTextRsp(int aNumVal,
|
||||
const uint8_t* aIds, const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void GetElementAttrRsp(uint8_t aNumAttr,
|
||||
const BluetoothAvrcpElementAttribute* aAttr,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void SetPlayerAppValueRsp(BluetoothAvrcpStatus aRspStatus,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void RegisterNotificationRsp(BluetoothAvrcpEvent aEvent,
|
||||
BluetoothAvrcpNotification aType,
|
||||
const BluetoothAvrcpNotificationParam& aParam,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void SetVolume(uint8_t aVolume, BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
BluetoothAvrcpHALInterface(
|
||||
#if ANDROID_VERSION >= 18
|
||||
const btrc_interface_t* aInterface
|
||||
#endif
|
||||
);
|
||||
~BluetoothAvrcpHALInterface();
|
||||
|
||||
private:
|
||||
#if ANDROID_VERSION >= 18
|
||||
const btrc_interface_t* mInterface;
|
||||
#endif
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,429 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothDaemonA2dpInterface.h"
|
||||
#include "BluetoothDaemonSetupInterface.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
//
|
||||
// A2DP module
|
||||
//
|
||||
|
||||
BluetoothA2dpNotificationHandler*
|
||||
BluetoothDaemonA2dpModule::sNotificationHandler;
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::SetNotificationHandler(
|
||||
BluetoothA2dpNotificationHandler* aNotificationHandler)
|
||||
{
|
||||
sNotificationHandler = aNotificationHandler;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonA2dpModule::Send(BluetoothDaemonPDU* aPDU,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
aRes->AddRef(); // Keep reference for response
|
||||
return Send(aPDU, static_cast<void*>(aRes));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::HandleSvc(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU, void* aUserData)
|
||||
{
|
||||
static void (BluetoothDaemonA2dpModule::* const HandleOp[])(
|
||||
const BluetoothDaemonPDUHeader&, BluetoothDaemonPDU&, void*) = {
|
||||
INIT_ARRAY_AT(0, &BluetoothDaemonA2dpModule::HandleRsp),
|
||||
INIT_ARRAY_AT(1, &BluetoothDaemonA2dpModule::HandleNtf),
|
||||
};
|
||||
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
// negate twice to map bit to 0/1
|
||||
unsigned int isNtf = !!(aHeader.mOpcode & 0x80);
|
||||
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aUserData);
|
||||
}
|
||||
|
||||
// Commands
|
||||
//
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonA2dpModule::ConnectCmd(
|
||||
const nsAString& aRemoteAddr, BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(SERVICE_ID,
|
||||
OPCODE_CONNECT,
|
||||
6)); // Address
|
||||
nsresult rv = PackPDU(
|
||||
PackConversion<nsAString, BluetoothAddress>(aRemoteAddr), *pdu);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = Send(pdu, aRes);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << pdu.forget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonA2dpModule::DisconnectCmd(
|
||||
const nsAString& aRemoteAddr, BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(SERVICE_ID,
|
||||
OPCODE_DISCONNECT,
|
||||
6)); // Address
|
||||
nsresult rv = PackPDU(
|
||||
PackConversion<nsAString, BluetoothAddress>(aRemoteAddr), *pdu);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = Send(pdu, aRes);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << pdu.forget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Responses
|
||||
//
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::ErrorRsp(
|
||||
const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU, BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
ErrorRunnable::Dispatch(
|
||||
aRes, &BluetoothA2dpResultHandler::OnError, UnpackPDUInitOp(aPDU));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::ConnectRsp(
|
||||
const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
ResultRunnable::Dispatch(
|
||||
aRes, &BluetoothA2dpResultHandler::Connect, UnpackPDUInitOp(aPDU));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::DisconnectRsp(
|
||||
const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
ResultRunnable::Dispatch(
|
||||
aRes, &BluetoothA2dpResultHandler::Disconnect, UnpackPDUInitOp(aPDU));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::HandleRsp(
|
||||
const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData)
|
||||
{
|
||||
static void (BluetoothDaemonA2dpModule::* const HandleRsp[])(
|
||||
const BluetoothDaemonPDUHeader&,
|
||||
BluetoothDaemonPDU&,
|
||||
BluetoothA2dpResultHandler*) = {
|
||||
INIT_ARRAY_AT(OPCODE_ERROR,
|
||||
&BluetoothDaemonA2dpModule::ErrorRsp),
|
||||
INIT_ARRAY_AT(OPCODE_CONNECT,
|
||||
&BluetoothDaemonA2dpModule::ConnectRsp),
|
||||
INIT_ARRAY_AT(OPCODE_DISCONNECT,
|
||||
&BluetoothDaemonA2dpModule::DisconnectRsp),
|
||||
};
|
||||
|
||||
MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
|
||||
|
||||
if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
|
||||
NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothA2dpResultHandler> res =
|
||||
already_AddRefed<BluetoothA2dpResultHandler>(
|
||||
static_cast<BluetoothA2dpResultHandler*>(aUserData));
|
||||
|
||||
if (!res) {
|
||||
return; // Return early if no result handler has been set for response
|
||||
}
|
||||
|
||||
(this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
|
||||
}
|
||||
|
||||
// Notifications
|
||||
//
|
||||
|
||||
// Returns the current notification handler to a notification runnable
|
||||
class BluetoothDaemonA2dpModule::NotificationHandlerWrapper final
|
||||
{
|
||||
public:
|
||||
typedef BluetoothA2dpNotificationHandler ObjectType;
|
||||
|
||||
static ObjectType* GetInstance()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return sNotificationHandler;
|
||||
}
|
||||
};
|
||||
|
||||
// Init operator class for ConnectionStateNotification
|
||||
class BluetoothDaemonA2dpModule::ConnectionStateInitOp final
|
||||
: private PDUInitOp
|
||||
{
|
||||
public:
|
||||
ConnectionStateInitOp(BluetoothDaemonPDU& aPDU)
|
||||
: PDUInitOp(aPDU)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
operator () (BluetoothA2dpConnectionState& aArg1, nsString& aArg2) const
|
||||
{
|
||||
BluetoothDaemonPDU& pdu = GetPDU();
|
||||
|
||||
/* Read state */
|
||||
nsresult rv = UnpackPDU(pdu, aArg1);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Read address */
|
||||
rv = UnpackPDU(
|
||||
pdu, UnpackConversion<BluetoothAddress, nsAString>(aArg2));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
WarnAboutTrailingData();
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::ConnectionStateNtf(
|
||||
const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU)
|
||||
{
|
||||
ConnectionStateNotification::Dispatch(
|
||||
&BluetoothA2dpNotificationHandler::ConnectionStateNotification,
|
||||
ConnectionStateInitOp(aPDU));
|
||||
}
|
||||
|
||||
// Init operator class for AudioStateNotification
|
||||
class BluetoothDaemonA2dpModule::AudioStateInitOp final
|
||||
: private PDUInitOp
|
||||
{
|
||||
public:
|
||||
AudioStateInitOp(BluetoothDaemonPDU& aPDU)
|
||||
: PDUInitOp(aPDU)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
operator () (BluetoothA2dpAudioState& aArg1,
|
||||
nsString& aArg2) const
|
||||
{
|
||||
BluetoothDaemonPDU& pdu = GetPDU();
|
||||
|
||||
/* Read state */
|
||||
nsresult rv = UnpackPDU(pdu, aArg1);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Read address */
|
||||
rv = UnpackPDU(
|
||||
pdu, UnpackConversion<BluetoothAddress, nsAString>(aArg2));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
WarnAboutTrailingData();
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::AudioStateNtf(
|
||||
const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU)
|
||||
{
|
||||
AudioStateNotification::Dispatch(
|
||||
&BluetoothA2dpNotificationHandler::AudioStateNotification,
|
||||
AudioStateInitOp(aPDU));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::HandleNtf(
|
||||
const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData)
|
||||
{
|
||||
static void (BluetoothDaemonA2dpModule::* const HandleNtf[])(
|
||||
const BluetoothDaemonPDUHeader&, BluetoothDaemonPDU&) = {
|
||||
INIT_ARRAY_AT(0, &BluetoothDaemonA2dpModule::ConnectionStateNtf),
|
||||
INIT_ARRAY_AT(1, &BluetoothDaemonA2dpModule::AudioStateNtf),
|
||||
};
|
||||
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
uint8_t index = aHeader.mOpcode - 0x81;
|
||||
|
||||
if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
|
||||
NS_WARN_IF(!HandleNtf[index])) {
|
||||
return;
|
||||
}
|
||||
|
||||
(this->*(HandleNtf[index]))(aHeader, aPDU);
|
||||
}
|
||||
|
||||
//
|
||||
// A2DP interface
|
||||
//
|
||||
|
||||
BluetoothDaemonA2dpInterface::BluetoothDaemonA2dpInterface(
|
||||
BluetoothDaemonA2dpModule* aModule)
|
||||
: mModule(aModule)
|
||||
{ }
|
||||
|
||||
BluetoothDaemonA2dpInterface::~BluetoothDaemonA2dpInterface()
|
||||
{ }
|
||||
|
||||
class BluetoothDaemonA2dpInterface::InitResultHandler final
|
||||
: public BluetoothSetupResultHandler
|
||||
{
|
||||
public:
|
||||
InitResultHandler(BluetoothA2dpResultHandler* aRes)
|
||||
: mRes(aRes)
|
||||
{
|
||||
MOZ_ASSERT(mRes);
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mRes->OnError(aStatus);
|
||||
}
|
||||
|
||||
void RegisterModule() override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mRes->Init();
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<BluetoothA2dpResultHandler> mRes;
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpInterface::Init(
|
||||
BluetoothA2dpNotificationHandler* aNotificationHandler,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
// Set notification handler _before_ registering the module. It could
|
||||
// happen that we receive notifications, before the result handler runs.
|
||||
mModule->SetNotificationHandler(aNotificationHandler);
|
||||
|
||||
InitResultHandler* res;
|
||||
|
||||
if (aRes) {
|
||||
res = new InitResultHandler(aRes);
|
||||
} else {
|
||||
// We don't need a result handler if the caller is not interested.
|
||||
res = nullptr;
|
||||
}
|
||||
|
||||
nsresult rv = mModule->RegisterModule(BluetoothDaemonA2dpModule::SERVICE_ID,
|
||||
0x00, res);
|
||||
if (NS_FAILED(rv) && aRes) {
|
||||
DispatchError(aRes, STATUS_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
class BluetoothDaemonA2dpInterface::CleanupResultHandler final
|
||||
: public BluetoothSetupResultHandler
|
||||
{
|
||||
public:
|
||||
CleanupResultHandler(BluetoothDaemonA2dpModule* aModule,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
: mModule(aModule)
|
||||
, mRes(aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mRes) {
|
||||
mRes->OnError(aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void UnregisterModule() override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Clear notification handler _after_ module has been
|
||||
// unregistered. While unregistering the module, we might
|
||||
// still receive notifications.
|
||||
mModule->SetNotificationHandler(nullptr);
|
||||
|
||||
if (mRes) {
|
||||
mRes->Cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
BluetoothDaemonA2dpModule* mModule;
|
||||
nsRefPtr<BluetoothA2dpResultHandler> mRes;
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpInterface::Cleanup(
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
mModule->UnregisterModule(BluetoothDaemonA2dpModule::SERVICE_ID,
|
||||
new CleanupResultHandler(mModule, aRes));
|
||||
}
|
||||
|
||||
/* Connect / Disconnect */
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpInterface::Connect(
|
||||
const nsAString& aBdAddr, BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
mModule->ConnectCmd(aBdAddr, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpInterface::Disconnect(
|
||||
const nsAString& aBdAddr, BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
mModule->DisconnectCmd(aBdAddr, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpInterface::DispatchError(
|
||||
BluetoothA2dpResultHandler* aRes, BluetoothStatus aStatus)
|
||||
{
|
||||
BluetoothResultRunnable1<BluetoothA2dpResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>::Dispatch(
|
||||
aRes, &BluetoothA2dpResultHandler::OnError,
|
||||
ConstantInitOp1<BluetoothStatus>(aStatus));
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,152 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothdaemona2dpinterface_h
|
||||
#define mozilla_dom_bluetooth_bluetoothdaemona2dpinterface_h
|
||||
|
||||
#include "BluetoothDaemonHelpers.h"
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothInterfaceHelpers.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSetupResultHandler;
|
||||
|
||||
class BluetoothDaemonA2dpModule
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
SERVICE_ID = 0x06
|
||||
};
|
||||
|
||||
enum {
|
||||
OPCODE_ERROR = 0x00,
|
||||
OPCODE_CONNECT = 0x01,
|
||||
OPCODE_DISCONNECT = 0x02
|
||||
};
|
||||
|
||||
virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
|
||||
|
||||
virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
|
||||
BluetoothSetupResultHandler* aRes) = 0;
|
||||
|
||||
virtual nsresult UnregisterModule(uint8_t aId,
|
||||
BluetoothSetupResultHandler* aRes) = 0;
|
||||
|
||||
void SetNotificationHandler(
|
||||
BluetoothA2dpNotificationHandler* aNotificationHandler);
|
||||
|
||||
//
|
||||
// Commands
|
||||
//
|
||||
|
||||
nsresult ConnectCmd(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
nsresult DisconnectCmd(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
nsresult Send(BluetoothDaemonPDU* aPDU,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
void HandleSvc(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU, void* aUserData);
|
||||
|
||||
//
|
||||
// Responses
|
||||
//
|
||||
|
||||
typedef BluetoothResultRunnable0<BluetoothA2dpResultHandler, void>
|
||||
ResultRunnable;
|
||||
|
||||
typedef BluetoothResultRunnable1<BluetoothA2dpResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
ErrorRunnable;
|
||||
|
||||
void ErrorRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
void ConnectRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
void DisconnectRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
void HandleRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData);
|
||||
|
||||
//
|
||||
// Notifications
|
||||
//
|
||||
|
||||
class NotificationHandlerWrapper;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
BluetoothA2dpConnectionState,
|
||||
nsString,
|
||||
BluetoothA2dpConnectionState,
|
||||
const nsAString&>
|
||||
ConnectionStateNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
BluetoothA2dpAudioState,
|
||||
nsString,
|
||||
BluetoothA2dpAudioState,
|
||||
const nsAString&>
|
||||
AudioStateNotification;
|
||||
|
||||
class AudioStateInitOp;
|
||||
class ConnectionStateInitOp;
|
||||
|
||||
void ConnectionStateNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void AudioStateNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void HandleNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData);
|
||||
|
||||
static BluetoothA2dpNotificationHandler* sNotificationHandler;
|
||||
};
|
||||
|
||||
class BluetoothDaemonA2dpInterface final
|
||||
: public BluetoothA2dpInterface
|
||||
{
|
||||
class CleanupResultHandler;
|
||||
class InitResultHandler;
|
||||
|
||||
public:
|
||||
BluetoothDaemonA2dpInterface(BluetoothDaemonA2dpModule* aModule);
|
||||
~BluetoothDaemonA2dpInterface();
|
||||
|
||||
void Init(
|
||||
BluetoothA2dpNotificationHandler* aNotificationHandler,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
void Cleanup(BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
/* Connect / Disconnect */
|
||||
|
||||
void Connect(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
void Disconnect(const nsAString& aBdAddr,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
private:
|
||||
void DispatchError(BluetoothA2dpResultHandler* aRes,
|
||||
BluetoothStatus aStatus);
|
||||
|
||||
BluetoothDaemonA2dpModule* mModule;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,352 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothdaemonavrcpinterface_h
|
||||
#define mozilla_dom_bluetooth_bluetoothdaemonavrcpinterface_h
|
||||
|
||||
#include "BluetoothDaemonHelpers.h"
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothInterfaceHelpers.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSetupResultHandler;
|
||||
|
||||
class BluetoothDaemonAvrcpModule
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
SERVICE_ID = 0x08
|
||||
};
|
||||
|
||||
enum {
|
||||
OPCODE_ERROR = 0x00,
|
||||
OPCODE_GET_PLAY_STATUS_RSP = 0x01,
|
||||
OPCODE_LIST_PLAYER_APP_ATTR_RSP = 0x02,
|
||||
OPCODE_LIST_PLAYER_APP_VALUE_RSP = 0x03,
|
||||
OPCODE_GET_PLAYER_APP_VALUE_RSP = 0x04,
|
||||
OPCODE_GET_PLAYER_APP_ATTR_TEXT_RSP = 0x05,
|
||||
OPCODE_GET_PLAYER_APP_VALUE_TEXT_RSP = 0x06,
|
||||
OPCODE_GET_ELEMENT_ATTR_RSP = 0x07,
|
||||
OPCODE_SET_PLAYER_APP_VALUE_RSP = 0x08,
|
||||
OPCODE_REGISTER_NOTIFICATION_RSP = 0x09,
|
||||
OPCODE_SET_VOLUME = 0x0a,
|
||||
#if ANDROID_VERSION >= 19
|
||||
OPCODE_REMOTE_FEATURES_NTF = 0x81,
|
||||
OPCODE_GET_PLAY_STATUS_NTF = 0x82,
|
||||
OPCODE_LIST_PLAYER_APP_ATTR_NTF = 0x83,
|
||||
OPCODE_LIST_PLAYER_APP_VALUES_NTF = 0x84,
|
||||
OPCODE_GET_PLAYER_APP_VALUE_NTF = 0x85,
|
||||
OPCODE_GET_PLAYER_APP_ATTRS_TEXT_NTF = 0x86,
|
||||
OPCODE_GET_PLAYER_APP_VALUES_TEXT_NTF = 0x87,
|
||||
OPCODE_SET_PLAYER_APP_VALUE_NTF = 0x88,
|
||||
OPCODE_GET_ELEMENT_ATTR_NTF = 0x89,
|
||||
OPCODE_REGISTER_NOTIFICATION_NTF = 0x8a,
|
||||
OPCODE_VOLUME_CHANGE_NTF = 0x8b,
|
||||
OPCODE_PASSTHROUGH_CMD_NTF = 0x8c
|
||||
#else /* defined by BlueZ 5.14 */
|
||||
OPCODE_GET_PLAY_STATUS_NTF = 0x81,
|
||||
OPCODE_LIST_PLAYER_APP_ATTR_NTF = 0x82,
|
||||
OPCODE_LIST_PLAYER_APP_VALUES_NTF = 0x83,
|
||||
OPCODE_GET_PLAYER_APP_VALUE_NTF = 0x84,
|
||||
OPCODE_GET_PLAYER_APP_ATTRS_TEXT_NTF = 0x85,
|
||||
OPCODE_GET_PLAYER_APP_VALUES_TEXT_NTF = 0x86,
|
||||
OPCODE_SET_PLAYER_APP_VALUE_NTF = 0x87,
|
||||
OPCODE_GET_ELEMENT_ATTR_NTF = 0x88,
|
||||
OPCODE_REGISTER_NOTIFICATION_NTF = 0x89
|
||||
#endif
|
||||
};
|
||||
|
||||
virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
|
||||
|
||||
virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
|
||||
BluetoothSetupResultHandler* aRes) = 0;
|
||||
|
||||
virtual nsresult UnregisterModule(uint8_t aId,
|
||||
BluetoothSetupResultHandler* aRes) = 0;
|
||||
|
||||
void SetNotificationHandler(
|
||||
BluetoothAvrcpNotificationHandler* aNotificationHandler);
|
||||
|
||||
//
|
||||
// Commands
|
||||
//
|
||||
|
||||
nsresult GetPlayStatusRspCmd(
|
||||
ControlPlayStatus aPlayStatus, uint32_t aSongLen, uint32_t aSongPos,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult ListPlayerAppAttrRspCmd(
|
||||
int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult ListPlayerAppValueRspCmd(
|
||||
int aNumVal, uint8_t* aPVals, BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult GetPlayerAppValueRspCmd(
|
||||
uint8_t aNumAttrs, const uint8_t* aIds, const uint8_t* aValues,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult GetPlayerAppAttrTextRspCmd(
|
||||
int aNumAttr, const uint8_t* aIds, const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult GetPlayerAppValueTextRspCmd(
|
||||
int aNumVal, const uint8_t* aIds, const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult GetElementAttrRspCmd(
|
||||
uint8_t aNumAttr, const BluetoothAvrcpElementAttribute* aAttr,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult SetPlayerAppValueRspCmd(
|
||||
BluetoothAvrcpStatus aRspStatus, BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult RegisterNotificationRspCmd(
|
||||
BluetoothAvrcpEvent aEvent, BluetoothAvrcpNotification aType,
|
||||
const BluetoothAvrcpNotificationParam& aParam,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
nsresult SetVolumeCmd(uint8_t aVolume, BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
nsresult Send(BluetoothDaemonPDU* aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void HandleSvc(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU, void* aUserData);
|
||||
|
||||
//
|
||||
// Responses
|
||||
//
|
||||
|
||||
typedef BluetoothResultRunnable0<BluetoothAvrcpResultHandler, void>
|
||||
ResultRunnable;
|
||||
|
||||
typedef BluetoothResultRunnable1<BluetoothAvrcpResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
ErrorRunnable;
|
||||
|
||||
void ErrorRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void GetPlayStatusRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void ListPlayerAppAttrRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void ListPlayerAppValueRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void GetPlayerAppValueRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void GetPlayerAppAttrTextRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void GetPlayerAppValueTextRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void GetElementAttrRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void SetPlayerAppValueRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void RegisterNotificationRspRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void SetVolumeRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void HandleRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData);
|
||||
|
||||
//
|
||||
// Notifications
|
||||
//
|
||||
|
||||
class NotificationHandlerWrapper;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
nsString, unsigned long,
|
||||
const nsAString&>
|
||||
RemoteFeatureNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
GetPlayStatusNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
ListPlayerAppAttrNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
BluetoothAvrcpPlayerAttribute>
|
||||
ListPlayerAppValuesNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
uint8_t, nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
|
||||
uint8_t, const BluetoothAvrcpPlayerAttribute*>
|
||||
GetPlayerAppValueNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
uint8_t, nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
|
||||
uint8_t, const BluetoothAvrcpPlayerAttribute*>
|
||||
GetPlayerAppAttrsTextNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable3<NotificationHandlerWrapper, void,
|
||||
uint8_t, uint8_t,
|
||||
nsAutoArrayPtr<uint8_t>, uint8_t,
|
||||
uint8_t, const uint8_t*>
|
||||
GetPlayerAppValuesTextNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
BluetoothAvrcpPlayerSettings,
|
||||
const BluetoothAvrcpPlayerSettings&>
|
||||
SetPlayerAppValueNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
uint8_t, nsAutoArrayPtr<BluetoothAvrcpMediaAttribute>,
|
||||
uint8_t, const BluetoothAvrcpMediaAttribute*>
|
||||
GetElementAttrNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
BluetoothAvrcpEvent, uint32_t>
|
||||
RegisterNotificationNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
uint8_t, uint8_t>
|
||||
VolumeChangeNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
int, int>
|
||||
PassthroughCmdNotification;
|
||||
|
||||
class GetElementAttrInitOp;
|
||||
class GetPlayerAppAttrsTextInitOp;
|
||||
class GetPlayerAppValueInitOp;
|
||||
class GetPlayerAppValuesTextInitOp;
|
||||
class PassthroughCmdInitOp;
|
||||
class RemoteFeatureInitOp;
|
||||
|
||||
void RemoteFeatureNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void GetPlayStatusNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void ListPlayerAppAttrNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void ListPlayerAppValuesNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void GetPlayerAppValueNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void GetPlayerAppAttrsTextNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void GetPlayerAppValuesTextNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void SetPlayerAppValueNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void GetElementAttrNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void RegisterNotificationNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void VolumeChangeNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void PassthroughCmdNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void HandleNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData);
|
||||
|
||||
static BluetoothAvrcpNotificationHandler* sNotificationHandler;
|
||||
};
|
||||
|
||||
class BluetoothDaemonAvrcpInterface final
|
||||
: public BluetoothAvrcpInterface
|
||||
{
|
||||
class CleanupResultHandler;
|
||||
class InitResultHandler;
|
||||
|
||||
public:
|
||||
BluetoothDaemonAvrcpInterface(BluetoothDaemonAvrcpModule* aModule);
|
||||
~BluetoothDaemonAvrcpInterface();
|
||||
|
||||
void Init(BluetoothAvrcpNotificationHandler* aNotificationHandler,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void Cleanup(BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void GetPlayStatusRsp(ControlPlayStatus aPlayStatus,
|
||||
uint32_t aSongLen, uint32_t aSongPos,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void ListPlayerAppAttrRsp(int aNumAttr,
|
||||
const BluetoothAvrcpPlayerAttribute* aPAttrs,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void ListPlayerAppValueRsp(int aNumVal, uint8_t* aPVals,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void GetPlayerAppValueRsp(uint8_t aNumAttrs, const uint8_t* aIds,
|
||||
const uint8_t* aValues,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void GetPlayerAppAttrTextRsp(int aNumAttr, const uint8_t* aIds,
|
||||
const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void GetPlayerAppValueTextRsp(int aNumVal, const uint8_t* aIds,
|
||||
const char** aTexts,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void GetElementAttrRsp(uint8_t aNumAttr,
|
||||
const BluetoothAvrcpElementAttribute* aAttr,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void SetPlayerAppValueRsp(BluetoothAvrcpStatus aRspStatus,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void RegisterNotificationRsp(BluetoothAvrcpEvent aEvent,
|
||||
BluetoothAvrcpNotification aType,
|
||||
const BluetoothAvrcpNotificationParam& aParam,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
void SetVolume(uint8_t aVolume,
|
||||
BluetoothAvrcpResultHandler* aRes) override;
|
||||
|
||||
private:
|
||||
void DispatchError(BluetoothAvrcpResultHandler* aRes,
|
||||
BluetoothStatus aStatus);
|
||||
|
||||
BluetoothDaemonAvrcpModule* mModule;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,412 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothdaemonhandsfreeinterface_h
|
||||
#define mozilla_dom_bluetooth_bluetoothdaemonhandsfreeinterface_h
|
||||
|
||||
#include "BluetoothDaemonHelpers.h"
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothInterfaceHelpers.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSetupResultHandler;
|
||||
|
||||
class BluetoothDaemonHandsfreeModule
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
SERVICE_ID = 0x05
|
||||
};
|
||||
|
||||
enum {
|
||||
OPCODE_ERROR = 0x00,
|
||||
OPCODE_CONNECT = 0x01,
|
||||
OPCODE_DISCONNECT = 0x02,
|
||||
OPCODE_CONNECT_AUDIO = 0x03,
|
||||
OPCODE_DISCONNECT_AUDIO = 0x04,
|
||||
OPCODE_START_VOICE_RECOGNITION = 0x05,
|
||||
OPCODE_STOP_VOICE_RECOGNITION =0x06,
|
||||
OPCODE_VOLUME_CONTROL = 0x07,
|
||||
OPCODE_DEVICE_STATUS_NOTIFICATION = 0x08,
|
||||
OPCODE_COPS_RESPONSE = 0x09,
|
||||
OPCODE_CIND_RESPONSE = 0x0a,
|
||||
OPCODE_FORMATTED_AT_RESPONSE = 0x0b,
|
||||
OPCODE_AT_RESPONSE = 0x0c,
|
||||
OPCODE_CLCC_RESPONSE = 0x0d,
|
||||
OPCODE_PHONE_STATE_CHANGE = 0x0e
|
||||
};
|
||||
|
||||
virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
|
||||
|
||||
virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
|
||||
BluetoothSetupResultHandler* aRes) = 0;
|
||||
|
||||
virtual nsresult UnregisterModule(uint8_t aId,
|
||||
BluetoothSetupResultHandler* aRes) = 0;
|
||||
|
||||
void SetNotificationHandler(
|
||||
BluetoothHandsfreeNotificationHandler* aNotificationHandler);
|
||||
|
||||
//
|
||||
// Commands
|
||||
//
|
||||
|
||||
nsresult ConnectCmd(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult DisconnectCmd(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult ConnectAudioCmd(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult DisconnectAudioCmd(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Voice Recognition */
|
||||
|
||||
nsresult StartVoiceRecognitionCmd(BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult StopVoiceRecognitionCmd(BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Volume */
|
||||
|
||||
nsresult VolumeControlCmd(BluetoothHandsfreeVolumeType aType, int aVolume,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Device status */
|
||||
|
||||
nsresult DeviceStatusNotificationCmd(
|
||||
BluetoothHandsfreeNetworkState aNtkState,
|
||||
BluetoothHandsfreeServiceType aSvcType,
|
||||
int aSignal, int aBattChg,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Responses */
|
||||
|
||||
nsresult CopsResponseCmd(const char* aCops,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult CindResponseCmd(int aSvc, int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState,
|
||||
int aSignal, int aRoam, int aBattChg,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult FormattedAtResponseCmd(const char* aRsp,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult AtResponseCmd(BluetoothHandsfreeAtResponse aResponseCode,
|
||||
int aErrorCode,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
nsresult ClccResponseCmd(int aIndex, BluetoothHandsfreeCallDirection aDir,
|
||||
BluetoothHandsfreeCallState aState,
|
||||
BluetoothHandsfreeCallMode aMode,
|
||||
BluetoothHandsfreeCallMptyType aMpty,
|
||||
const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Phone State */
|
||||
|
||||
nsresult PhoneStateChangeCmd(int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState,
|
||||
const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
nsresult Send(BluetoothDaemonPDU* aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void HandleSvc(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU, void* aUserData);
|
||||
|
||||
//
|
||||
// Responses
|
||||
//
|
||||
|
||||
typedef BluetoothResultRunnable0<BluetoothHandsfreeResultHandler, void>
|
||||
ResultRunnable;
|
||||
|
||||
typedef BluetoothResultRunnable1<BluetoothHandsfreeResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
ErrorRunnable;
|
||||
|
||||
void ErrorRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void ConnectRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void DisconnectRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void ConnectAudioRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void DisconnectAudioRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void StartVoiceRecognitionRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void StopVoiceRecognitionRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void VolumeControlRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void DeviceStatusNotificationRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void CopsResponseRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void CindResponseRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void FormattedAtResponseRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void AtResponseRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void ClccResponseRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void PhoneStateChangeRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void HandleRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData);
|
||||
|
||||
//
|
||||
// Notifications
|
||||
//
|
||||
|
||||
class NotificationHandlerWrapper;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeConnectionState,
|
||||
nsString,
|
||||
BluetoothHandsfreeConnectionState,
|
||||
const nsAString&>
|
||||
ConnectionStateNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeAudioState,
|
||||
nsString,
|
||||
BluetoothHandsfreeAudioState,
|
||||
const nsAString&>
|
||||
AudioStateNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeVoiceRecognitionState>
|
||||
VoiceRecognitionNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
AnswerCallNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
HangupCallNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable2<NotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeVolumeType, int>
|
||||
VolumeNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
nsString, const nsAString&>
|
||||
DialCallNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
char>
|
||||
DtmfNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeNRECState>
|
||||
NRECNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeCallHoldType>
|
||||
CallHoldNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
CnumNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
CindNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
CopsNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
ClccNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable1<NotificationHandlerWrapper, void,
|
||||
nsCString, const nsACString&>
|
||||
UnknownAtNotification;
|
||||
|
||||
typedef BluetoothNotificationRunnable0<NotificationHandlerWrapper, void>
|
||||
KeyPressedNotification;
|
||||
|
||||
class AudioStateInitOp;
|
||||
class ConnectionStateInitOp;
|
||||
class DialCallInitOp;
|
||||
class VolumeInitOp;
|
||||
class UnknownAtInitOp;
|
||||
|
||||
void ConnectionStateNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void AudioStateNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void VoiceRecognitionNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void AnswerCallNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void HangupCallNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void VolumeNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void DialCallNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void DtmfNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void NRECNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void CallHoldNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void CnumNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void CindNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void CopsNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void ClccNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void UnknownAtNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void KeyPressedNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU);
|
||||
|
||||
void HandleNtf(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData);
|
||||
|
||||
static BluetoothHandsfreeNotificationHandler* sNotificationHandler;
|
||||
};
|
||||
|
||||
class BluetoothDaemonHandsfreeInterface final
|
||||
: public BluetoothHandsfreeInterface
|
||||
{
|
||||
class CleanupResultHandler;
|
||||
class InitResultHandler;
|
||||
|
||||
enum {
|
||||
MODE_HEADSET = 0x00,
|
||||
MODE_NARROWBAND_SPEECH = 0x01,
|
||||
MODE_NARROWBAND_WIDEBAND_SPEECH = 0x02
|
||||
};
|
||||
|
||||
public:
|
||||
BluetoothDaemonHandsfreeInterface(BluetoothDaemonHandsfreeModule* aModule);
|
||||
~BluetoothDaemonHandsfreeInterface();
|
||||
|
||||
void Init(
|
||||
BluetoothHandsfreeNotificationHandler* aNotificationHandler,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void Cleanup(BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Connect / Disconnect */
|
||||
|
||||
void Connect(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void Disconnect(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void ConnectAudio(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void DisconnectAudio(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Voice Recognition */
|
||||
|
||||
void StartVoiceRecognition(BluetoothHandsfreeResultHandler* aRes);
|
||||
void StopVoiceRecognition(BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Volume */
|
||||
|
||||
void VolumeControl(BluetoothHandsfreeVolumeType aType, int aVolume,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Device status */
|
||||
|
||||
void DeviceStatusNotification(BluetoothHandsfreeNetworkState aNtkState,
|
||||
BluetoothHandsfreeServiceType aSvcType,
|
||||
int aSignal, int aBattChg,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Responses */
|
||||
|
||||
void CopsResponse(const char* aCops,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void CindResponse(int aSvc, int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState,
|
||||
int aSignal, int aRoam, int aBattChg,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void FormattedAtResponse(const char* aRsp,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void AtResponse(BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void ClccResponse(int aIndex, BluetoothHandsfreeCallDirection aDir,
|
||||
BluetoothHandsfreeCallState aState,
|
||||
BluetoothHandsfreeCallMode aMode,
|
||||
BluetoothHandsfreeCallMptyType aMpty,
|
||||
const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Phone State */
|
||||
|
||||
void PhoneStateChange(int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState,
|
||||
const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
private:
|
||||
void DispatchError(BluetoothHandsfreeResultHandler* aRes,
|
||||
BluetoothStatus aStatus);
|
||||
|
||||
BluetoothDaemonHandsfreeModule* mModule;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,146 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothdaemoninterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetoothdaemoninterface_h__
|
||||
|
||||
#include "BluetoothInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothDaemonListenSocket;
|
||||
class BluetoothDaemonChannel;
|
||||
class BluetoothDaemonA2dpInterface;
|
||||
class BluetoothDaemonAvrcpInterface;
|
||||
class BluetoothDaemonHandsfreeInterface;
|
||||
class BluetoothDaemonProtocol;
|
||||
class BluetoothDaemonSocketInterface;
|
||||
|
||||
class BluetoothDaemonInterface final : public BluetoothInterface
|
||||
{
|
||||
public:
|
||||
class CleanupResultHandler;
|
||||
class InitResultHandler;
|
||||
|
||||
friend class BluetoothDaemonListenSocket;
|
||||
friend class BluetoothDaemonChannel;
|
||||
friend class CleanupResultHandler;
|
||||
friend class InitResultHandler;
|
||||
|
||||
static BluetoothDaemonInterface* GetInstance();
|
||||
|
||||
void Init(BluetoothNotificationHandler* aNotificationHandler,
|
||||
BluetoothResultHandler* aRes);
|
||||
void Cleanup(BluetoothResultHandler* aRes);
|
||||
|
||||
void Enable(BluetoothResultHandler* aRes);
|
||||
void Disable(BluetoothResultHandler* aRes);
|
||||
|
||||
/* Adapter Properties */
|
||||
|
||||
void GetAdapterProperties(BluetoothResultHandler* aRes);
|
||||
void GetAdapterProperty(const nsAString& aName,
|
||||
BluetoothResultHandler* aRes);
|
||||
void SetAdapterProperty(const BluetoothNamedValue& aProperty,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Remote Device Properties */
|
||||
|
||||
void GetRemoteDeviceProperties(const nsAString& aRemoteAddr,
|
||||
BluetoothResultHandler* aRes);
|
||||
void GetRemoteDeviceProperty(const nsAString& aRemoteAddr,
|
||||
const nsAString& aName,
|
||||
BluetoothResultHandler* aRes);
|
||||
void SetRemoteDeviceProperty(const nsAString& aRemoteAddr,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Remote Services */
|
||||
|
||||
void GetRemoteServiceRecord(const nsAString& aRemoteAddr,
|
||||
const uint8_t aUuid[16],
|
||||
BluetoothResultHandler* aRes);
|
||||
void GetRemoteServices(const nsAString& aRemoteAddr,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Discovery */
|
||||
|
||||
void StartDiscovery(BluetoothResultHandler* aRes);
|
||||
void CancelDiscovery(BluetoothResultHandler* aRes);
|
||||
|
||||
/* Bonds */
|
||||
|
||||
void CreateBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
|
||||
void RemoveBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
|
||||
void CancelBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
|
||||
|
||||
/* Authentication */
|
||||
|
||||
void PinReply(const nsAString& aBdAddr, bool aAccept,
|
||||
const nsAString& aPinCode,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
|
||||
bool aAccept, uint32_t aPasskey,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* DUT Mode */
|
||||
|
||||
void DutModeConfigure(bool aEnable, BluetoothResultHandler* aRes);
|
||||
void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* LE Mode */
|
||||
|
||||
void LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Profile Interfaces */
|
||||
|
||||
BluetoothSocketInterface* GetBluetoothSocketInterface() override;
|
||||
BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface() override;
|
||||
BluetoothA2dpInterface* GetBluetoothA2dpInterface() override;
|
||||
BluetoothAvrcpInterface* GetBluetoothAvrcpInterface() override;
|
||||
BluetoothGattInterface* GetBluetoothGattInterface() override;
|
||||
|
||||
protected:
|
||||
enum Channel {
|
||||
LISTEN_SOCKET,
|
||||
CMD_CHANNEL,
|
||||
NTF_CHANNEL
|
||||
};
|
||||
|
||||
BluetoothDaemonInterface();
|
||||
~BluetoothDaemonInterface();
|
||||
|
||||
void OnConnectSuccess(enum Channel aChannel);
|
||||
void OnConnectError(enum Channel aChannel);
|
||||
void OnDisconnect(enum Channel aChannel);
|
||||
|
||||
nsresult CreateRandomAddressString(const nsACString& aPrefix,
|
||||
unsigned long aPostfixLength,
|
||||
nsACString& aAddress);
|
||||
|
||||
private:
|
||||
void DispatchError(BluetoothResultHandler* aRes, BluetoothStatus aStatus);
|
||||
|
||||
nsCString mListenSocketName;
|
||||
nsRefPtr<BluetoothDaemonListenSocket> mListenSocket;
|
||||
nsRefPtr<BluetoothDaemonChannel> mCmdChannel;
|
||||
nsRefPtr<BluetoothDaemonChannel> mNtfChannel;
|
||||
nsAutoPtr<BluetoothDaemonProtocol> mProtocol;
|
||||
|
||||
nsTArray<nsRefPtr<BluetoothResultHandler> > mResultHandlerQ;
|
||||
|
||||
nsAutoPtr<BluetoothDaemonSocketInterface> mSocketInterface;
|
||||
nsAutoPtr<BluetoothDaemonHandsfreeInterface> mHandsfreeInterface;
|
||||
nsAutoPtr<BluetoothDaemonA2dpInterface> mA2dpInterface;
|
||||
nsAutoPtr<BluetoothDaemonAvrcpInterface> mAvrcpInterface;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothDaemonSetupInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
BluetoothSetupResultHandler::~BluetoothSetupResultHandler()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothSetupResultHandler::OnError(BluetoothStatus aStatus)
|
||||
{
|
||||
BT_WARNING("Received error code %d", (int)aStatus);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSetupResultHandler::RegisterModule()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothSetupResultHandler::UnregisterModule()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothSetupResultHandler::Configuration()
|
||||
{ }
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,29 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothdaemonsetupinterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetoothdaemonsetupinterface_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSetupResultHandler
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothSetupResultHandler)
|
||||
|
||||
virtual ~BluetoothSetupResultHandler();
|
||||
|
||||
virtual void OnError(BluetoothStatus aStatus);
|
||||
virtual void RegisterModule();
|
||||
virtual void UnregisterModule();
|
||||
virtual void Configuration();
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,352 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothDaemonSocketInterface.h"
|
||||
#include "BluetoothSocketMessageWatcher.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
//
|
||||
// Socket module
|
||||
//
|
||||
|
||||
// Commands
|
||||
//
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonSocketModule::ListenCmd(BluetoothSocketType aType,
|
||||
const nsAString& aServiceName,
|
||||
const uint8_t aServiceUuid[16],
|
||||
int aChannel, bool aEncrypt,
|
||||
bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(
|
||||
SERVICE_ID, OPCODE_LISTEN, 0));
|
||||
|
||||
nsresult rv = PackPDU(
|
||||
aType,
|
||||
PackConversion<nsAString, BluetoothServiceName>(aServiceName),
|
||||
PackArray<uint8_t>(aServiceUuid, 16),
|
||||
PackConversion<int, int32_t>(aChannel),
|
||||
SocketFlags(aEncrypt, aAuth), *pdu);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = Send(pdu, aRes);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << pdu.forget();
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonSocketModule::ConnectCmd(const nsAString& aBdAddr,
|
||||
BluetoothSocketType aType,
|
||||
const uint8_t aUuid[16],
|
||||
int aChannel, bool aEncrypt,
|
||||
bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(
|
||||
SERVICE_ID, OPCODE_CONNECT, 0));
|
||||
|
||||
nsresult rv = PackPDU(
|
||||
PackConversion<nsAString, BluetoothAddress>(aBdAddr),
|
||||
aType,
|
||||
PackArray<uint8_t>(aUuid, 16),
|
||||
PackConversion<int, int32_t>(aChannel),
|
||||
SocketFlags(aEncrypt, aAuth), *pdu);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = Send(pdu, aRes);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << pdu.forget();
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* |DeleteTask| deletes a class instance on the I/O thread
|
||||
*/
|
||||
template <typename T>
|
||||
class DeleteTask final : public Task
|
||||
{
|
||||
public:
|
||||
DeleteTask(T* aPtr)
|
||||
: mPtr(aPtr)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
{
|
||||
mPtr = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
nsAutoPtr<T> mPtr;
|
||||
};
|
||||
|
||||
/* |AcceptWatcher| specializes SocketMessageWatcher for Accept
|
||||
* operations by reading the socket messages from Bluedroid and
|
||||
* forwarding the received client socket to the resource handler.
|
||||
* The first message is received immediately. When there's a new
|
||||
* connection, Bluedroid sends the 2nd message with the socket
|
||||
* info and socket file descriptor.
|
||||
*/
|
||||
class BluetoothDaemonSocketModule::AcceptWatcher final
|
||||
: public SocketMessageWatcher
|
||||
{
|
||||
public:
|
||||
AcceptWatcher(int aFd, BluetoothSocketResultHandler* aRes)
|
||||
: SocketMessageWatcher(aFd, aRes)
|
||||
{ }
|
||||
|
||||
void Proceed(BluetoothStatus aStatus) override
|
||||
{
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
IntStringIntResultRunnable::Dispatch(
|
||||
GetResultHandler(), &BluetoothSocketResultHandler::Accept,
|
||||
ConstantInitOp3<int, nsString, int>(GetClientFd(), GetBdAddress(),
|
||||
GetConnectionStatus()));
|
||||
} else {
|
||||
ErrorRunnable::Dispatch(GetResultHandler(),
|
||||
&BluetoothSocketResultHandler::OnError,
|
||||
ConstantInitOp1<BluetoothStatus>(aStatus));
|
||||
}
|
||||
|
||||
MessageLoopForIO::current()->PostTask(
|
||||
FROM_HERE, new DeleteTask<AcceptWatcher>(this));
|
||||
}
|
||||
};
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonSocketModule::AcceptCmd(int aFd,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/* receive Bluedroid's socket-setup messages and client fd */
|
||||
Task* t = new SocketMessageWatcherTask(new AcceptWatcher(aFd, aRes));
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonSocketModule::CloseCmd(BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/* stop the watcher corresponding to |aRes| */
|
||||
Task* t = new DeleteSocketMessageWatcherTask(aRes);
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketModule::HandleSvc(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
void* aUserData)
|
||||
{
|
||||
static void (BluetoothDaemonSocketModule::* const HandleRsp[])(
|
||||
const BluetoothDaemonPDUHeader&,
|
||||
BluetoothDaemonPDU&,
|
||||
BluetoothSocketResultHandler*) = {
|
||||
INIT_ARRAY_AT(OPCODE_ERROR, &BluetoothDaemonSocketModule::ErrorRsp),
|
||||
INIT_ARRAY_AT(OPCODE_LISTEN, &BluetoothDaemonSocketModule::ListenRsp),
|
||||
INIT_ARRAY_AT(OPCODE_CONNECT, &BluetoothDaemonSocketModule::ConnectRsp),
|
||||
};
|
||||
|
||||
if (NS_WARN_IF(MOZ_ARRAY_LENGTH(HandleRsp) <= aHeader.mOpcode) ||
|
||||
NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothSocketResultHandler> res =
|
||||
already_AddRefed<BluetoothSocketResultHandler>(
|
||||
static_cast<BluetoothSocketResultHandler*>(aUserData));
|
||||
|
||||
if (!res) {
|
||||
return; // Return early if no result handler has been set
|
||||
}
|
||||
|
||||
(this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonSocketModule::Send(BluetoothDaemonPDU* aPDU,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
aRes->AddRef(); // Keep reference for response
|
||||
return Send(aPDU, static_cast<void*>(aRes));
|
||||
}
|
||||
|
||||
uint8_t
|
||||
BluetoothDaemonSocketModule::SocketFlags(bool aEncrypt, bool aAuth)
|
||||
{
|
||||
return (0x01 * aEncrypt) | (0x02 * aAuth);
|
||||
}
|
||||
|
||||
// Responses
|
||||
//
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketModule::ErrorRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
ErrorRunnable::Dispatch(
|
||||
aRes, &BluetoothSocketResultHandler::OnError, UnpackPDUInitOp(aPDU));
|
||||
}
|
||||
|
||||
class BluetoothDaemonSocketModule::ListenInitOp final : private PDUInitOp
|
||||
{
|
||||
public:
|
||||
ListenInitOp(BluetoothDaemonPDU& aPDU)
|
||||
: PDUInitOp(aPDU)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
operator () (int& aArg1) const
|
||||
{
|
||||
BluetoothDaemonPDU& pdu = GetPDU();
|
||||
|
||||
aArg1 = pdu.AcquireFd();
|
||||
|
||||
if (NS_WARN_IF(aArg1 < 0)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
WarnAboutTrailingData();
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketModule::ListenRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
IntResultRunnable::Dispatch(
|
||||
aRes, &BluetoothSocketResultHandler::Listen, ListenInitOp(aPDU));
|
||||
}
|
||||
|
||||
/* |ConnectWatcher| specializes SocketMessageWatcher for
|
||||
* connect operations by reading the socket messages from
|
||||
* Bluedroid and forwarding the connected socket to the
|
||||
* resource handler.
|
||||
*/
|
||||
class BluetoothDaemonSocketModule::ConnectWatcher final
|
||||
: public SocketMessageWatcher
|
||||
{
|
||||
public:
|
||||
ConnectWatcher(int aFd, BluetoothSocketResultHandler* aRes)
|
||||
: SocketMessageWatcher(aFd, aRes)
|
||||
{ }
|
||||
|
||||
void Proceed(BluetoothStatus aStatus) override
|
||||
{
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
IntStringIntResultRunnable::Dispatch(
|
||||
GetResultHandler(), &BluetoothSocketResultHandler::Connect,
|
||||
ConstantInitOp3<int, nsString, int>(GetFd(), GetBdAddress(),
|
||||
GetConnectionStatus()));
|
||||
} else {
|
||||
ErrorRunnable::Dispatch(GetResultHandler(),
|
||||
&BluetoothSocketResultHandler::OnError,
|
||||
ConstantInitOp1<BluetoothStatus>(aStatus));
|
||||
}
|
||||
|
||||
MessageLoopForIO::current()->PostTask(
|
||||
FROM_HERE, new DeleteTask<ConnectWatcher>(this));
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketModule::ConnectRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
/* the file descriptor is attached in the PDU's ancillary data */
|
||||
int fd = aPDU.AcquireFd();
|
||||
if (fd < 0) {
|
||||
ErrorRunnable::Dispatch(aRes, &BluetoothSocketResultHandler::OnError,
|
||||
ConstantInitOp1<BluetoothStatus>(STATUS_FAIL));
|
||||
return;
|
||||
}
|
||||
|
||||
/* receive Bluedroid's socket-setup messages */
|
||||
Task* t = new SocketMessageWatcherTask(new ConnectWatcher(fd, aRes));
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
|
||||
}
|
||||
|
||||
//
|
||||
// Socket interface
|
||||
//
|
||||
|
||||
BluetoothDaemonSocketInterface::BluetoothDaemonSocketInterface(
|
||||
BluetoothDaemonSocketModule* aModule)
|
||||
: mModule(aModule)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
}
|
||||
|
||||
BluetoothDaemonSocketInterface::~BluetoothDaemonSocketInterface()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketInterface::Listen(BluetoothSocketType aType,
|
||||
const nsAString& aServiceName,
|
||||
const uint8_t aServiceUuid[16],
|
||||
int aChannel, bool aEncrypt,
|
||||
bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
mModule->ListenCmd(aType, aServiceName, aServiceUuid, aChannel,
|
||||
aEncrypt, aAuth, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketInterface::Connect(const nsAString& aBdAddr,
|
||||
BluetoothSocketType aType,
|
||||
const uint8_t aUuid[16],
|
||||
int aChannel, bool aEncrypt,
|
||||
bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
mModule->ConnectCmd(aBdAddr, aType, aUuid, aChannel, aEncrypt, aAuth, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketInterface::Accept(int aFd,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
mModule->AcceptCmd(aFd, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonSocketInterface::Close(BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
mModule->CloseCmd(aRes);
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,129 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothdaemonsocketinterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetoothdaemonsocketinterface_h__
|
||||
|
||||
#include "BluetoothDaemonHelpers.h"
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothInterfaceHelpers.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
class BlutoothDaemonInterface;
|
||||
|
||||
class BluetoothDaemonSocketModule
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
SERVICE_ID = 0x02
|
||||
};
|
||||
|
||||
enum {
|
||||
OPCODE_ERROR = 0x00,
|
||||
OPCODE_LISTEN = 0x01,
|
||||
OPCODE_CONNECT = 0x02
|
||||
};
|
||||
|
||||
virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
|
||||
|
||||
// Commands
|
||||
//
|
||||
|
||||
nsresult ListenCmd(BluetoothSocketType aType,
|
||||
const nsAString& aServiceName,
|
||||
const uint8_t aServiceUuid[16],
|
||||
int aChannel, bool aEncrypt, bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
nsresult ConnectCmd(const nsAString& aBdAddr,
|
||||
BluetoothSocketType aType,
|
||||
const uint8_t aUuid[16],
|
||||
int aChannel, bool aEncrypt, bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
nsresult AcceptCmd(int aFd, BluetoothSocketResultHandler* aRes);
|
||||
|
||||
nsresult CloseCmd(BluetoothSocketResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
|
||||
void HandleSvc(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU, void* aUserData);
|
||||
|
||||
nsresult Send(BluetoothDaemonPDU* aPDU, BluetoothSocketResultHandler* aRes);
|
||||
|
||||
private:
|
||||
class AcceptWatcher;
|
||||
class ConnectWatcher;
|
||||
class ListenInitOp;
|
||||
|
||||
uint8_t SocketFlags(bool aEncrypt, bool aAuth);
|
||||
|
||||
// Responses
|
||||
//
|
||||
|
||||
typedef BluetoothResultRunnable0<BluetoothSocketResultHandler, void>
|
||||
ResultRunnable;
|
||||
|
||||
typedef BluetoothResultRunnable1<BluetoothSocketResultHandler, void,
|
||||
int, int>
|
||||
IntResultRunnable;
|
||||
|
||||
typedef BluetoothResultRunnable1<BluetoothSocketResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
ErrorRunnable;
|
||||
|
||||
typedef BluetoothResultRunnable3<BluetoothSocketResultHandler, void,
|
||||
int, nsString, int,
|
||||
int, const nsAString_internal&, int>
|
||||
IntStringIntResultRunnable;
|
||||
|
||||
void ErrorRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void ListenRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void ConnectRsp(const BluetoothDaemonPDUHeader& aHeader,
|
||||
BluetoothDaemonPDU& aPDU,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
};
|
||||
|
||||
class BluetoothDaemonSocketInterface final
|
||||
: public BluetoothSocketInterface
|
||||
{
|
||||
public:
|
||||
BluetoothDaemonSocketInterface(BluetoothDaemonSocketModule* aModule);
|
||||
~BluetoothDaemonSocketInterface();
|
||||
|
||||
void Listen(BluetoothSocketType aType,
|
||||
const nsAString& aServiceName,
|
||||
const uint8_t aServiceUuid[16],
|
||||
int aChannel, bool aEncrypt, bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void Connect(const nsAString& aBdAddr,
|
||||
BluetoothSocketType aType,
|
||||
const uint8_t aUuid[16],
|
||||
int aChannel, bool aEncrypt, bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void Accept(int aFd, BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void Close(BluetoothSocketResultHandler* aRes);
|
||||
|
||||
private:
|
||||
BluetoothDaemonSocketModule* mModule;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,401 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothHALHelpers.h"
|
||||
|
||||
#define MAX_UUID_SIZE 16
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
//
|
||||
// Conversion
|
||||
//
|
||||
|
||||
nsresult
|
||||
Convert(const nsAString& aIn, bt_property_type_t& aOut)
|
||||
{
|
||||
if (aIn.EqualsLiteral("Name")) {
|
||||
aOut = BT_PROPERTY_BDNAME;
|
||||
} else if (aIn.EqualsLiteral("Discoverable")) {
|
||||
aOut = BT_PROPERTY_ADAPTER_SCAN_MODE;
|
||||
} else if (aIn.EqualsLiteral("DiscoverableTimeout")) {
|
||||
aOut = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
|
||||
} else {
|
||||
BT_LOGR("Invalid property name: %s", NS_ConvertUTF16toUTF8(aIn).get());
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(ConvertNamedValue& aIn, bt_property_t& aOut)
|
||||
{
|
||||
nsresult rv = Convert(aIn.mNamedValue.name(), aOut.type);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aIn.mNamedValue.value().type() == BluetoothValue::Tuint32_t) {
|
||||
// Set discoverable timeout
|
||||
aOut.val = const_cast<void*>(static_cast<const void*>(
|
||||
&(aIn.mNamedValue.value().get_uint32_t())));
|
||||
aOut.len = sizeof(uint32_t);
|
||||
} else if (aIn.mNamedValue.value().type() == BluetoothValue::TnsString) {
|
||||
// Set name
|
||||
aIn.mStringValue =
|
||||
NS_ConvertUTF16toUTF8(aIn.mNamedValue.value().get_nsString());
|
||||
aOut.val =
|
||||
const_cast<void*>(static_cast<const void*>(aIn.mStringValue.get()));
|
||||
aOut.len = strlen(static_cast<char*>(aOut.val));
|
||||
} else if (aIn.mNamedValue.value().type() == BluetoothValue::Tbool) {
|
||||
// Set scan mode
|
||||
rv = Convert(aIn.mNamedValue.value().get_bool(), aIn.mScanMode);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
aOut.val = &aIn.mScanMode;
|
||||
aOut.len = sizeof(aIn.mScanMode);
|
||||
} else {
|
||||
BT_LOGR("Invalid property value type");
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const nsAString& aIn, bt_bdaddr_t& aOut)
|
||||
{
|
||||
NS_ConvertUTF16toUTF8 bdAddressUTF8(aIn);
|
||||
const char* str = bdAddressUTF8.get();
|
||||
|
||||
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aOut.address); ++i, ++str) {
|
||||
aOut.address[i] =
|
||||
static_cast<uint8_t>(strtoul(str, const_cast<char**>(&str), 16));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const uint8_t aIn[16], bt_uuid_t& aOut)
|
||||
{
|
||||
if (sizeof(aOut.uu) != 16) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
memcpy(aOut.uu, aIn, sizeof(aOut.uu));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const bt_uuid_t& aIn, BluetoothUuid& aOut)
|
||||
{
|
||||
if (sizeof(aIn.uu) != sizeof(aOut.mUuid)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
memcpy(aOut.mUuid, aIn.uu, sizeof(aOut.mUuid));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const BluetoothUuid& aIn, bt_uuid_t& aOut)
|
||||
{
|
||||
if (sizeof(aIn.mUuid) != sizeof(aOut.uu)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
memcpy(aOut.uu, aIn.mUuid, sizeof(aOut.uu));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const nsAString& aIn, bt_pin_code_t& aOut)
|
||||
{
|
||||
if (aIn.Length() > MOZ_ARRAY_LENGTH(aOut.pin)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8 pinCodeUTF8(aIn);
|
||||
const char* str = pinCodeUTF8.get();
|
||||
|
||||
nsAString::size_type i;
|
||||
|
||||
// Fill pin into aOut
|
||||
for (i = 0; i < aIn.Length(); ++i, ++str) {
|
||||
aOut.pin[i] = static_cast<uint8_t>(*str);
|
||||
}
|
||||
|
||||
// Clear remaining bytes in aOut
|
||||
size_t ntrailing =
|
||||
(MOZ_ARRAY_LENGTH(aOut.pin) - aIn.Length()) * sizeof(aOut.pin[0]);
|
||||
memset(aOut.pin + aIn.Length(), 0, ntrailing);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const bt_bdaddr_t& aIn, nsAString& aOut)
|
||||
{
|
||||
char str[BLUETOOTH_ADDRESS_LENGTH + 1];
|
||||
|
||||
int res = snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
static_cast<int>(aIn.address[0]),
|
||||
static_cast<int>(aIn.address[1]),
|
||||
static_cast<int>(aIn.address[2]),
|
||||
static_cast<int>(aIn.address[3]),
|
||||
static_cast<int>(aIn.address[4]),
|
||||
static_cast<int>(aIn.address[5]));
|
||||
if (res < 0) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
} else if ((size_t)res >= sizeof(str)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY; /* string buffer too small */
|
||||
}
|
||||
|
||||
aOut = NS_ConvertUTF8toUTF16(str);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const bt_service_record_t& aIn, BluetoothServiceRecord& aOut)
|
||||
{
|
||||
nsresult rv = Convert(aIn.uuid, aOut.mUuid);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
aOut.mChannel = aIn.channel;
|
||||
|
||||
MOZ_ASSERT(sizeof(aIn.name) == sizeof(aOut.mName));
|
||||
memcpy(aOut.mName, aIn.name, sizeof(aOut.mName));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
nsresult
|
||||
Convert(const BluetoothAvrcpElementAttribute& aIn, btrc_element_attr_val_t& aOut)
|
||||
{
|
||||
const NS_ConvertUTF16toUTF8 value(aIn.mValue);
|
||||
size_t len = std::min<size_t>(strlen(value.get()), sizeof(aOut.text) - 1);
|
||||
|
||||
memcpy(aOut.text, value.get(), len);
|
||||
aOut.text[len] = '\0';
|
||||
aOut.attr_id = aIn.mId;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const btrc_player_settings_t& aIn, BluetoothAvrcpPlayerSettings& aOut)
|
||||
{
|
||||
aOut.mNumAttr = aIn.num_attr;
|
||||
memcpy(aOut.mIds, aIn.attr_ids, aIn.num_attr);
|
||||
memcpy(aOut.mValues, aIn.attr_values, aIn.num_attr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
#endif // ANDROID_VERSION >= 18
|
||||
|
||||
nsresult
|
||||
Convert(const uint8_t* aIn, BluetoothGattAdvData& aOut)
|
||||
{
|
||||
memcpy(aOut.mAdvData, aIn, sizeof(aOut.mAdvData));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if ANDROID_VERSION >= 19
|
||||
nsresult
|
||||
Convert(const BluetoothGattId& aIn, btgatt_gatt_id_t& aOut)
|
||||
{
|
||||
aOut.inst_id = aIn.mInstanceId;
|
||||
return Convert(aIn.mUuid, aOut.uuid);
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const btgatt_gatt_id_t& aIn, BluetoothGattId& aOut)
|
||||
{
|
||||
aOut.mInstanceId = aIn.inst_id;
|
||||
return Convert(aIn.uuid, aOut.mUuid);
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const BluetoothGattServiceId& aIn, btgatt_srvc_id_t& aOut)
|
||||
{
|
||||
aOut.is_primary = aIn.mIsPrimary;
|
||||
return Convert(aIn.mId, aOut.id);
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const btgatt_srvc_id_t& aIn, BluetoothGattServiceId& aOut)
|
||||
{
|
||||
aOut.mIsPrimary = aIn.is_primary;
|
||||
return Convert(aIn.id, aOut.mId);
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const btgatt_read_params_t& aIn, BluetoothGattReadParam& aOut)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = Convert(aIn.srvc_id, aOut.mServiceId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Convert(aIn.char_id, aOut.mCharId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Convert(aIn.descr_id, aOut.mDescriptorId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
memcpy(aOut.mValue, aIn.value.value, aIn.value.len);
|
||||
aOut.mValueLength = aIn.value.len;
|
||||
aOut.mValueType = aIn.value_type;
|
||||
aOut.mStatus = aIn.status;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const btgatt_write_params_t& aIn, BluetoothGattWriteParam& aOut)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = Convert(aIn.srvc_id, aOut.mServiceId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Convert(aIn.char_id, aOut.mCharId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Convert(aIn.descr_id, aOut.mDescriptorId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aOut.mStatus = aIn.status;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const btgatt_notify_params_t& aIn, BluetoothGattNotifyParam& aOut)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = Convert(aIn.bda, aOut.mBdAddr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Convert(aIn.srvc_id, aOut.mServiceId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Convert(aIn.char_id, aOut.mCharId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
memcpy(aOut.mValue, aIn.value, aIn.len);
|
||||
aOut.mLength = aIn.len;
|
||||
aOut.mIsNotify = aIn.is_notify;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
#endif // ANDROID_VERSION >= 19
|
||||
|
||||
nsresult
|
||||
Convert(const ArrayBuffer& aIn, char* aOut) {
|
||||
aIn.ComputeLengthAndData();
|
||||
memcpy(aOut, aIn.Data(), aIn.Length());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const bt_property_t& aIn, BluetoothProperty& aOut)
|
||||
{
|
||||
/* type conversion */
|
||||
|
||||
nsresult rv = Convert(aIn.type, aOut.mType);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* value conversion */
|
||||
|
||||
switch (aOut.mType) {
|
||||
case PROPERTY_UNKNOWN:
|
||||
/* Bug 1065999: working around unknown properties */
|
||||
break;
|
||||
case PROPERTY_BDNAME:
|
||||
/* fall through */
|
||||
case PROPERTY_REMOTE_FRIENDLY_NAME:
|
||||
{
|
||||
// We construct an nsCString here because bdname
|
||||
// returned from Bluedroid is not 0-terminated.
|
||||
aOut.mString = NS_ConvertUTF8toUTF16(
|
||||
nsCString(static_cast<char*>(aIn.val), aIn.len));
|
||||
}
|
||||
break;
|
||||
case PROPERTY_BDADDR:
|
||||
rv = Convert(*static_cast<bt_bdaddr_t*>(aIn.val), aOut.mString);
|
||||
break;
|
||||
case PROPERTY_UUIDS:
|
||||
{
|
||||
size_t numUuids = aIn.len / MAX_UUID_SIZE;
|
||||
ConvertArray<bt_uuid_t> array(
|
||||
static_cast<bt_uuid_t*>(aIn.val), numUuids);
|
||||
aOut.mUuidArray.SetLength(numUuids);
|
||||
rv = Convert(array, aOut.mUuidArray);
|
||||
}
|
||||
break;
|
||||
case PROPERTY_CLASS_OF_DEVICE:
|
||||
/* fall through */
|
||||
case PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
|
||||
aOut.mUint32 = *static_cast<uint32_t*>(aIn.val);
|
||||
break;
|
||||
case PROPERTY_TYPE_OF_DEVICE:
|
||||
rv = Convert(*static_cast<bt_device_type_t*>(aIn.val),
|
||||
aOut.mTypeOfDevice);
|
||||
break;
|
||||
case PROPERTY_SERVICE_RECORD:
|
||||
rv = Convert(*static_cast<bt_service_record_t*>(aIn.val),
|
||||
aOut.mServiceRecord);
|
||||
break;
|
||||
case PROPERTY_ADAPTER_SCAN_MODE:
|
||||
rv = Convert(*static_cast<bt_scan_mode_t*>(aIn.val),
|
||||
aOut.mScanMode);
|
||||
break;
|
||||
case PROPERTY_ADAPTER_BONDED_DEVICES:
|
||||
{
|
||||
size_t numAddresses = aIn.len / BLUETOOTH_ADDRESS_BYTES;
|
||||
ConvertArray<bt_bdaddr_t> array(
|
||||
static_cast<bt_bdaddr_t*>(aIn.val), numAddresses);
|
||||
aOut.mStringArray.SetLength(numAddresses);
|
||||
rv = Convert(array, aOut.mStringArray);
|
||||
}
|
||||
break;
|
||||
case PROPERTY_REMOTE_RSSI:
|
||||
aOut.mInt32 = *static_cast<int8_t*>(aIn.val);
|
||||
break;
|
||||
#if ANDROID_VERSION >= 18
|
||||
case PROPERTY_REMOTE_VERSION_INFO:
|
||||
rv = Convert(*static_cast<bt_remote_version_t*>(aIn.val),
|
||||
aOut.mRemoteInfo);
|
||||
break;
|
||||
#endif
|
||||
case PROPERTY_REMOTE_DEVICE_TIMESTAMP:
|
||||
/* nothing to do */
|
||||
break;
|
||||
default:
|
||||
/* mismatch with type conversion */
|
||||
NS_NOTREACHED("Unhandled property type");
|
||||
break;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,951 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothHALInterface.h"
|
||||
#include "BluetoothHALHelpers.h"
|
||||
#include "BluetoothA2dpHALInterface.h"
|
||||
#include "BluetoothAvrcpHALInterface.h"
|
||||
#include "BluetoothGattHALInterface.h"
|
||||
#include "BluetoothHandsfreeHALInterface.h"
|
||||
#include "BluetoothSocketHALInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
template<class T>
|
||||
struct interface_traits
|
||||
{ };
|
||||
|
||||
template<>
|
||||
struct interface_traits<BluetoothSocketHALInterface>
|
||||
{
|
||||
typedef const btsock_interface_t const_interface_type;
|
||||
|
||||
static const char* profile_id()
|
||||
{
|
||||
return BT_PROFILE_SOCKETS_ID;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct interface_traits<BluetoothHandsfreeHALInterface>
|
||||
{
|
||||
typedef const bthf_interface_t const_interface_type;
|
||||
|
||||
static const char* profile_id()
|
||||
{
|
||||
return BT_PROFILE_HANDSFREE_ID;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct interface_traits<BluetoothA2dpHALInterface>
|
||||
{
|
||||
typedef const btav_interface_t const_interface_type;
|
||||
|
||||
static const char* profile_id()
|
||||
{
|
||||
return BT_PROFILE_ADVANCED_AUDIO_ID;
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
template<>
|
||||
struct interface_traits<BluetoothAvrcpHALInterface>
|
||||
{
|
||||
typedef const btrc_interface_t const_interface_type;
|
||||
|
||||
static const char* profile_id()
|
||||
{
|
||||
return BT_PROFILE_AV_RC_ID;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#if ANDROID_VERSION >= 19
|
||||
template<>
|
||||
struct interface_traits<BluetoothGattHALInterface>
|
||||
{
|
||||
typedef const btgatt_interface_t const_interface_type;
|
||||
|
||||
static const char* profile_id()
|
||||
{
|
||||
return BT_PROFILE_GATT_ID;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable0<BluetoothResultHandler, void>
|
||||
BluetoothHALResultRunnable;
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable1<BluetoothResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
BluetoothHALErrorRunnable;
|
||||
|
||||
static nsresult
|
||||
DispatchBluetoothHALResult(BluetoothResultHandler* aRes,
|
||||
void (BluetoothResultHandler::*aMethod)(),
|
||||
BluetoothStatus aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
nsRunnable* runnable;
|
||||
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
runnable = new BluetoothHALResultRunnable(aRes, aMethod);
|
||||
} else {
|
||||
runnable = new BluetoothHALErrorRunnable(
|
||||
aRes, &BluetoothResultHandler::OnError, aStatus);
|
||||
}
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_FAILED(rv)) {
|
||||
BT_LOGR("NS_DispatchToMainThread failed: %X", rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Notification handling
|
||||
//
|
||||
|
||||
static BluetoothNotificationHandler* sNotificationHandler;
|
||||
|
||||
struct BluetoothCallback
|
||||
{
|
||||
class NotificationHandlerWrapper
|
||||
{
|
||||
public:
|
||||
typedef BluetoothNotificationHandler ObjectType;
|
||||
|
||||
static ObjectType* GetInstance()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return sNotificationHandler;
|
||||
}
|
||||
};
|
||||
|
||||
// Notifications
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<NotificationHandlerWrapper, void,
|
||||
bool>
|
||||
AdapterStateChangedNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
|
||||
BluetoothStatus, int,
|
||||
nsAutoArrayPtr<BluetoothProperty>,
|
||||
BluetoothStatus, int,
|
||||
const BluetoothProperty*>
|
||||
AdapterPropertiesNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable4<NotificationHandlerWrapper, void,
|
||||
BluetoothStatus, nsString, int,
|
||||
nsAutoArrayPtr<BluetoothProperty>,
|
||||
BluetoothStatus, const nsAString&,
|
||||
int, const BluetoothProperty*>
|
||||
RemoteDevicePropertiesNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<NotificationHandlerWrapper, void,
|
||||
int,
|
||||
nsAutoArrayPtr<BluetoothProperty>,
|
||||
int, const BluetoothProperty*>
|
||||
DeviceFoundNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<NotificationHandlerWrapper, void,
|
||||
bool>
|
||||
DiscoveryStateChangedNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
|
||||
nsString, nsString, uint32_t,
|
||||
const nsAString&, const nsAString&>
|
||||
PinRequestNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable5<NotificationHandlerWrapper, void,
|
||||
nsString, nsString, uint32_t,
|
||||
BluetoothSspVariant, uint32_t,
|
||||
const nsAString&, const nsAString&>
|
||||
SspRequestNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
|
||||
BluetoothStatus, nsString,
|
||||
BluetoothBondState,
|
||||
BluetoothStatus, const nsAString&>
|
||||
BondStateChangedNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
|
||||
BluetoothStatus, nsString, bool,
|
||||
BluetoothStatus, const nsAString&>
|
||||
AclStateChangedNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable3<NotificationHandlerWrapper, void,
|
||||
uint16_t, nsAutoArrayPtr<uint8_t>,
|
||||
uint8_t, uint16_t, const uint8_t*>
|
||||
DutModeRecvNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<NotificationHandlerWrapper, void,
|
||||
BluetoothStatus, uint16_t>
|
||||
LeTestModeNotification;
|
||||
|
||||
// Bluedroid callbacks
|
||||
|
||||
static const bt_property_t*
|
||||
AlignedProperties(bt_property_t* aProperties, size_t aNumProperties,
|
||||
nsAutoArrayPtr<bt_property_t>& aPropertiesArray)
|
||||
{
|
||||
// See Bug 989976: consider aProperties address is not aligned. If
|
||||
// it is aligned, we return the pointer directly; otherwise we make
|
||||
// an aligned copy. The argument |aPropertiesArray| keeps track of
|
||||
// the memory buffer.
|
||||
if (!(reinterpret_cast<uintptr_t>(aProperties) % sizeof(void*))) {
|
||||
return aProperties;
|
||||
}
|
||||
|
||||
bt_property_t* properties = new bt_property_t[aNumProperties];
|
||||
memcpy(properties, aProperties, aNumProperties * sizeof(*properties));
|
||||
aPropertiesArray = properties;
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
static void
|
||||
AdapterStateChanged(bt_state_t aStatus)
|
||||
{
|
||||
AdapterStateChangedNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::AdapterStateChangedNotification,
|
||||
aStatus);
|
||||
}
|
||||
|
||||
static void
|
||||
AdapterProperties(bt_status_t aStatus, int aNumProperties,
|
||||
bt_property_t* aProperties)
|
||||
{
|
||||
nsAutoArrayPtr<bt_property_t> propertiesArray;
|
||||
|
||||
AdapterPropertiesNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::AdapterPropertiesNotification,
|
||||
ConvertDefault(aStatus, STATUS_FAIL), aNumProperties,
|
||||
ConvertArray<bt_property_t>(
|
||||
AlignedProperties(aProperties, aNumProperties, propertiesArray),
|
||||
aNumProperties));
|
||||
}
|
||||
|
||||
static void
|
||||
RemoteDeviceProperties(bt_status_t aStatus, bt_bdaddr_t* aBdAddress,
|
||||
int aNumProperties, bt_property_t* aProperties)
|
||||
{
|
||||
nsAutoArrayPtr<bt_property_t> propertiesArray;
|
||||
|
||||
RemoteDevicePropertiesNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::RemoteDevicePropertiesNotification,
|
||||
ConvertDefault(aStatus, STATUS_FAIL), aBdAddress, aNumProperties,
|
||||
ConvertArray<bt_property_t>(
|
||||
AlignedProperties(aProperties, aNumProperties, propertiesArray),
|
||||
aNumProperties));
|
||||
}
|
||||
|
||||
static void
|
||||
DeviceFound(int aNumProperties, bt_property_t* aProperties)
|
||||
{
|
||||
nsAutoArrayPtr<bt_property_t> propertiesArray;
|
||||
|
||||
DeviceFoundNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::DeviceFoundNotification,
|
||||
aNumProperties,
|
||||
ConvertArray<bt_property_t>(
|
||||
AlignedProperties(aProperties, aNumProperties, propertiesArray),
|
||||
aNumProperties));
|
||||
}
|
||||
|
||||
static void
|
||||
DiscoveryStateChanged(bt_discovery_state_t aState)
|
||||
{
|
||||
DiscoveryStateChangedNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::DiscoveryStateChangedNotification,
|
||||
aState);
|
||||
}
|
||||
|
||||
static void
|
||||
PinRequest(bt_bdaddr_t* aRemoteBdAddress,
|
||||
bt_bdname_t* aRemoteBdName, uint32_t aRemoteClass)
|
||||
{
|
||||
PinRequestNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::PinRequestNotification,
|
||||
aRemoteBdAddress, aRemoteBdName, aRemoteClass);
|
||||
}
|
||||
|
||||
static void
|
||||
SspRequest(bt_bdaddr_t* aRemoteBdAddress, bt_bdname_t* aRemoteBdName,
|
||||
uint32_t aRemoteClass, bt_ssp_variant_t aPairingVariant,
|
||||
uint32_t aPasskey)
|
||||
{
|
||||
SspRequestNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::SspRequestNotification,
|
||||
aRemoteBdAddress, aRemoteBdName, aRemoteClass,
|
||||
aPairingVariant, aPasskey);
|
||||
}
|
||||
|
||||
static void
|
||||
BondStateChanged(bt_status_t aStatus, bt_bdaddr_t* aRemoteBdAddress,
|
||||
bt_bond_state_t aState)
|
||||
{
|
||||
BondStateChangedNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::BondStateChangedNotification,
|
||||
aStatus, aRemoteBdAddress, aState);
|
||||
}
|
||||
|
||||
static void
|
||||
AclStateChanged(bt_status_t aStatus, bt_bdaddr_t* aRemoteBdAddress,
|
||||
bt_acl_state_t aState)
|
||||
{
|
||||
AclStateChangedNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::AclStateChangedNotification,
|
||||
aStatus, aRemoteBdAddress, aState);
|
||||
}
|
||||
|
||||
static void
|
||||
ThreadEvt(bt_cb_thread_evt evt)
|
||||
{
|
||||
// This callback maintains internal state and is not exported.
|
||||
}
|
||||
|
||||
static void
|
||||
DutModeRecv(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen)
|
||||
{
|
||||
DutModeRecvNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::DutModeRecvNotification,
|
||||
aOpcode, ConvertArray<uint8_t>(aBuf, aLen), aLen);
|
||||
}
|
||||
|
||||
#if ANDROID_VERSION >= 18
|
||||
static void
|
||||
LeTestMode(bt_status_t aStatus, uint16_t aNumPackets)
|
||||
{
|
||||
LeTestModeNotification::Dispatch(
|
||||
&BluetoothNotificationHandler::LeTestModeNotification,
|
||||
aStatus, aNumPackets);
|
||||
}
|
||||
#endif // ANDROID_VERSION >= 18
|
||||
};
|
||||
|
||||
// Interface
|
||||
//
|
||||
|
||||
/* returns the container structure of a variable; _t is the container's
|
||||
* type, _v the name of the variable, and _m is _v's field within _t
|
||||
*/
|
||||
#define container(_t, _v, _m) \
|
||||
( (_t*)( ((const unsigned char*)(_v)) - offsetof(_t, _m) ) )
|
||||
|
||||
BluetoothHALInterface*
|
||||
BluetoothHALInterface::GetInstance()
|
||||
{
|
||||
static BluetoothHALInterface* sBluetoothInterface;
|
||||
|
||||
if (sBluetoothInterface) {
|
||||
return sBluetoothInterface;
|
||||
}
|
||||
|
||||
/* get driver module */
|
||||
|
||||
const hw_module_t* module;
|
||||
int err = hw_get_module(BT_HARDWARE_MODULE_ID, &module);
|
||||
if (err) {
|
||||
BT_WARNING("hw_get_module failed: %s", strerror(err));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* get device */
|
||||
|
||||
hw_device_t* device;
|
||||
err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device);
|
||||
if (err) {
|
||||
BT_WARNING("open failed: %s", strerror(err));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const bluetooth_device_t* bt_device =
|
||||
container(bluetooth_device_t, device, common);
|
||||
|
||||
/* get interface */
|
||||
|
||||
const bt_interface_t* bt_interface = bt_device->get_bluetooth_interface();
|
||||
if (!bt_interface) {
|
||||
BT_WARNING("get_bluetooth_interface failed");
|
||||
goto err_get_bluetooth_interface;
|
||||
}
|
||||
|
||||
if (bt_interface->size != sizeof(*bt_interface)) {
|
||||
BT_WARNING("interface of incorrect size");
|
||||
goto err_bt_interface_size;
|
||||
}
|
||||
|
||||
sBluetoothInterface = new BluetoothHALInterface(bt_interface);
|
||||
|
||||
return sBluetoothInterface;
|
||||
|
||||
err_bt_interface_size:
|
||||
err_get_bluetooth_interface:
|
||||
err = device->close(device);
|
||||
if (err) {
|
||||
BT_WARNING("close failed: %s", strerror(err));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BluetoothHALInterface::BluetoothHALInterface(
|
||||
const bt_interface_t* aInterface)
|
||||
: mInterface(aInterface)
|
||||
{
|
||||
MOZ_ASSERT(mInterface);
|
||||
}
|
||||
|
||||
BluetoothHALInterface::~BluetoothHALInterface()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothHALInterface::Init(
|
||||
BluetoothNotificationHandler* aNotificationHandler,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
static bt_callbacks_t sBluetoothCallbacks = {
|
||||
sizeof(sBluetoothCallbacks),
|
||||
BluetoothCallback::AdapterStateChanged,
|
||||
BluetoothCallback::AdapterProperties,
|
||||
BluetoothCallback::RemoteDeviceProperties,
|
||||
BluetoothCallback::DeviceFound,
|
||||
BluetoothCallback::DiscoveryStateChanged,
|
||||
BluetoothCallback::PinRequest,
|
||||
BluetoothCallback::SspRequest,
|
||||
BluetoothCallback::BondStateChanged,
|
||||
BluetoothCallback::AclStateChanged,
|
||||
BluetoothCallback::ThreadEvt,
|
||||
BluetoothCallback::DutModeRecv
|
||||
#if ANDROID_VERSION >= 18
|
||||
,
|
||||
BluetoothCallback::LeTestMode
|
||||
#endif
|
||||
};
|
||||
|
||||
sNotificationHandler = aNotificationHandler;
|
||||
|
||||
int status = mInterface->init(&sBluetoothCallbacks);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Init,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::Cleanup(BluetoothResultHandler* aRes)
|
||||
{
|
||||
mInterface->cleanup();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Cleanup,
|
||||
STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
sNotificationHandler = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::Enable(BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status = mInterface->enable();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Enable,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::Disable(BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status = mInterface->disable();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes, &BluetoothResultHandler::Disable,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Adapter Properties */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::GetAdapterProperties(BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status = mInterface->get_adapter_properties();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::GetAdapterProperties,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::GetAdapterProperty(const nsAString& aName,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_property_type_t type;
|
||||
|
||||
/* FIXME: you need to implement the missing conversion functions */
|
||||
NS_NOTREACHED("Conversion function missing");
|
||||
|
||||
if (false /* TODO: we don't support any values for aName currently */) {
|
||||
status = mInterface->get_adapter_property(type);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::GetAdapterProperties,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::SetAdapterProperty(
|
||||
const BluetoothNamedValue& aProperty, BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
ConvertNamedValue convertProperty(aProperty);
|
||||
bt_property_t property;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(convertProperty, property))) {
|
||||
status = mInterface->set_adapter_property(&property);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::SetAdapterProperty,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Remote Device Properties */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::GetRemoteDeviceProperties(
|
||||
const nsAString& aRemoteAddr, BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_bdaddr_t addr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aRemoteAddr, addr))) {
|
||||
status = mInterface->get_remote_device_properties(&addr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::GetRemoteDeviceProperties,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::GetRemoteDeviceProperty(
|
||||
const nsAString& aRemoteAddr, const nsAString& aName,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_bdaddr_t remoteAddr;
|
||||
bt_property_type_t name;
|
||||
|
||||
/* FIXME: you need to implement the missing conversion functions */
|
||||
NS_NOTREACHED("Conversion function missing");
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr)) &&
|
||||
false /* TODO: we don't support any values for aName currently */) {
|
||||
status = mInterface->get_remote_device_property(&remoteAddr, name);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::GetRemoteDeviceProperty,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::SetRemoteDeviceProperty(
|
||||
const nsAString& aRemoteAddr, const BluetoothNamedValue& aProperty,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_bdaddr_t remoteAddr;
|
||||
bt_property_t property;
|
||||
|
||||
/* FIXME: you need to implement the missing conversion functions */
|
||||
NS_NOTREACHED("Conversion function missing");
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr)) &&
|
||||
false /* TODO: we don't support any values for aProperty currently */) {
|
||||
status = mInterface->set_remote_device_property(&remoteAddr, &property);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::SetRemoteDeviceProperty,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Remote Services */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::GetRemoteServiceRecord(const nsAString& aRemoteAddr,
|
||||
const uint8_t aUuid[16],
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_bdaddr_t remoteAddr;
|
||||
bt_uuid_t uuid;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr)) &&
|
||||
NS_SUCCEEDED(Convert(aUuid, uuid))) {
|
||||
status = mInterface->get_remote_service_record(&remoteAddr, &uuid);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::GetRemoteServiceRecord,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::GetRemoteServices(const nsAString& aRemoteAddr,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_bdaddr_t remoteAddr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aRemoteAddr, remoteAddr))) {
|
||||
status = mInterface->get_remote_services(&remoteAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::GetRemoteServices,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Discovery */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::StartDiscovery(BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status = mInterface->start_discovery();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::StartDiscovery,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::CancelDiscovery(BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status = mInterface->cancel_discovery();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::CancelDiscovery,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Bonds */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::CreateBond(const nsAString& aBdAddr,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
bt_bdaddr_t bdAddr;
|
||||
int status;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->create_bond(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::CreateBond,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::RemoveBond(const nsAString& aBdAddr,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
bt_bdaddr_t bdAddr;
|
||||
int status;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->remove_bond(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::RemoveBond,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::CancelBond(const nsAString& aBdAddr,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
bt_bdaddr_t bdAddr;
|
||||
int status;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->cancel_bond(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::CancelBond,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Authentication */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::PinReply(const nsAString& aBdAddr, bool aAccept,
|
||||
const nsAString& aPinCode,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
uint8_t accept;
|
||||
bt_pin_code_t pinCode;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
|
||||
NS_SUCCEEDED(Convert(aAccept, accept)) &&
|
||||
NS_SUCCEEDED(Convert(aPinCode, pinCode))) {
|
||||
status = mInterface->pin_reply(&bdAddr, accept, aPinCode.Length(),
|
||||
&pinCode);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::PinReply,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::SspReply(const nsAString& aBdAddr,
|
||||
BluetoothSspVariant aVariant,
|
||||
bool aAccept, uint32_t aPasskey,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
bt_ssp_variant_t variant;
|
||||
uint8_t accept;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
|
||||
NS_SUCCEEDED(Convert(aVariant, variant)) &&
|
||||
NS_SUCCEEDED(Convert(aAccept, accept))) {
|
||||
status = mInterface->ssp_reply(&bdAddr, variant, accept, aPasskey);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::SspReply,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* DUT Mode */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::DutModeConfigure(bool aEnable,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status;
|
||||
uint8_t enable;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aEnable, enable))) {
|
||||
status = mInterface->dut_mode_configure(enable);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::DutModeConfigure,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHALInterface::DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
int status = mInterface->dut_mode_send(aOpcode, aBuf, aLen);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::DutModeSend,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* LE Mode */
|
||||
|
||||
void
|
||||
BluetoothHALInterface::LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
#if ANDROID_VERSION >= 18
|
||||
int status = mInterface->le_test_mode(aOpcode, aBuf, aLen);
|
||||
#else
|
||||
int status = BT_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHALResult(aRes,
|
||||
&BluetoothResultHandler::LeTestMode,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Profile Interfaces */
|
||||
|
||||
template <class T>
|
||||
T*
|
||||
BluetoothHALInterface::CreateProfileInterface()
|
||||
{
|
||||
typename interface_traits<T>::const_interface_type* interface =
|
||||
reinterpret_cast<typename interface_traits<T>::const_interface_type*>(
|
||||
mInterface->get_profile_interface(interface_traits<T>::profile_id()));
|
||||
|
||||
if (!interface) {
|
||||
BT_WARNING("Bluetooth profile '%s' is not supported",
|
||||
interface_traits<T>::profile_id());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (interface->size != sizeof(*interface)) {
|
||||
BT_WARNING("interface of incorrect size");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new T(interface);
|
||||
}
|
||||
|
||||
#if ANDROID_VERSION < 18
|
||||
/*
|
||||
* Bluedroid versions that don't support AVRCP will call this function
|
||||
* to create an AVRCP interface. All interface methods will fail with
|
||||
* the error constant STATUS_UNSUPPORTED.
|
||||
*/
|
||||
template <>
|
||||
BluetoothAvrcpHALInterface*
|
||||
BluetoothHALInterface::CreateProfileInterface<BluetoothAvrcpHALInterface>()
|
||||
{
|
||||
BT_WARNING("Bluetooth profile 'avrcp' is not supported");
|
||||
|
||||
return new BluetoothAvrcpHALInterface();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ANDROID_VERSION < 19
|
||||
/*
|
||||
* Versions that we don't support GATT will call this function
|
||||
* to create an GATT interface. All interface methods will fail with
|
||||
* the error constant STATUS_UNSUPPORTED.
|
||||
*/
|
||||
template <>
|
||||
BluetoothGattHALInterface*
|
||||
BluetoothHALInterface::CreateProfileInterface<BluetoothGattHALInterface>()
|
||||
{
|
||||
BT_WARNING("Bluetooth profile 'gatt' is not supported");
|
||||
|
||||
return new BluetoothGattHALInterface();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
T*
|
||||
BluetoothHALInterface::GetProfileInterface()
|
||||
{
|
||||
static T* sBluetoothProfileInterface;
|
||||
|
||||
if (sBluetoothProfileInterface) {
|
||||
return sBluetoothProfileInterface;
|
||||
}
|
||||
|
||||
sBluetoothProfileInterface = CreateProfileInterface<T>();
|
||||
|
||||
return sBluetoothProfileInterface;
|
||||
}
|
||||
|
||||
BluetoothSocketInterface*
|
||||
BluetoothHALInterface::GetBluetoothSocketInterface()
|
||||
{
|
||||
return GetProfileInterface<BluetoothSocketHALInterface>();
|
||||
}
|
||||
|
||||
BluetoothHandsfreeInterface*
|
||||
BluetoothHALInterface::GetBluetoothHandsfreeInterface()
|
||||
{
|
||||
return GetProfileInterface<BluetoothHandsfreeHALInterface>();
|
||||
}
|
||||
|
||||
BluetoothA2dpInterface*
|
||||
BluetoothHALInterface::GetBluetoothA2dpInterface()
|
||||
{
|
||||
return GetProfileInterface<BluetoothA2dpHALInterface>();
|
||||
}
|
||||
|
||||
BluetoothAvrcpInterface*
|
||||
BluetoothHALInterface::GetBluetoothAvrcpInterface()
|
||||
{
|
||||
return GetProfileInterface<BluetoothAvrcpHALInterface>();
|
||||
}
|
||||
|
||||
BluetoothGattInterface*
|
||||
BluetoothHALInterface::GetBluetoothGattInterface()
|
||||
{
|
||||
return GetProfileInterface<BluetoothGattHALInterface>();
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,111 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothhalinterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetoothhalinterface_h__
|
||||
|
||||
#include <hardware/bluetooth.h>
|
||||
#include "BluetoothInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothHALInterface final : public BluetoothInterface
|
||||
{
|
||||
public:
|
||||
static BluetoothHALInterface* GetInstance();
|
||||
|
||||
void Init(BluetoothNotificationHandler* aNotificationHandler,
|
||||
BluetoothResultHandler* aRes);
|
||||
void Cleanup(BluetoothResultHandler* aRes);
|
||||
|
||||
void Enable(BluetoothResultHandler* aRes);
|
||||
void Disable(BluetoothResultHandler* aRes);
|
||||
|
||||
|
||||
/* Adapter Properties */
|
||||
|
||||
void GetAdapterProperties(BluetoothResultHandler* aRes);
|
||||
void GetAdapterProperty(const nsAString& aName,
|
||||
BluetoothResultHandler* aRes);
|
||||
void SetAdapterProperty(const BluetoothNamedValue& aProperty,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Remote Device Properties */
|
||||
|
||||
void GetRemoteDeviceProperties(const nsAString& aRemoteAddr,
|
||||
BluetoothResultHandler* aRes);
|
||||
void GetRemoteDeviceProperty(const nsAString& aRemoteAddr,
|
||||
const nsAString& aName,
|
||||
BluetoothResultHandler* aRes);
|
||||
void SetRemoteDeviceProperty(const nsAString& aRemoteAddr,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Remote Services */
|
||||
|
||||
void GetRemoteServiceRecord(const nsAString& aRemoteAddr,
|
||||
const uint8_t aUuid[16],
|
||||
BluetoothResultHandler* aRes);
|
||||
void GetRemoteServices(const nsAString& aRemoteAddr,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Discovery */
|
||||
|
||||
void StartDiscovery(BluetoothResultHandler* aRes);
|
||||
void CancelDiscovery(BluetoothResultHandler* aRes);
|
||||
|
||||
/* Bonds */
|
||||
|
||||
void CreateBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
|
||||
void RemoveBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
|
||||
void CancelBond(const nsAString& aBdAddr, BluetoothResultHandler* aRes);
|
||||
|
||||
/* Authentication */
|
||||
|
||||
void PinReply(const nsAString& aBdAddr, bool aAccept,
|
||||
const nsAString& aPinCode,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
|
||||
bool aAccept, uint32_t aPasskey,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* DUT Mode */
|
||||
|
||||
void DutModeConfigure(bool aEnable, BluetoothResultHandler* aRes);
|
||||
void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* LE Mode */
|
||||
|
||||
void LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Profile Interfaces */
|
||||
|
||||
BluetoothSocketInterface* GetBluetoothSocketInterface();
|
||||
BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface();
|
||||
BluetoothA2dpInterface* GetBluetoothA2dpInterface();
|
||||
BluetoothAvrcpInterface* GetBluetoothAvrcpInterface();
|
||||
BluetoothGattInterface* GetBluetoothGattInterface();
|
||||
|
||||
protected:
|
||||
BluetoothHALInterface(const bt_interface_t* aInterface);
|
||||
~BluetoothHALInterface();
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
T* CreateProfileInterface();
|
||||
|
||||
template <class T>
|
||||
T* GetProfileInterface();
|
||||
|
||||
const bt_interface_t* mInterface;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,616 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothHandsfreeHALInterface.h"
|
||||
#include "BluetoothHALHelpers.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable0<BluetoothHandsfreeResultHandler, void>
|
||||
BluetoothHandsfreeHALResultRunnable;
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable1<BluetoothHandsfreeResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
BluetoothHandsfreeHALErrorRunnable;
|
||||
|
||||
static nsresult
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
BluetoothHandsfreeResultHandler* aRes,
|
||||
void (BluetoothHandsfreeResultHandler::*aMethod)(),
|
||||
BluetoothStatus aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
nsRunnable* runnable;
|
||||
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
runnable = new BluetoothHandsfreeHALResultRunnable(aRes, aMethod);
|
||||
} else {
|
||||
runnable = new BluetoothHandsfreeHALErrorRunnable(aRes,
|
||||
&BluetoothHandsfreeResultHandler::OnError, aStatus);
|
||||
}
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_FAILED(rv)) {
|
||||
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Notification handling
|
||||
//
|
||||
|
||||
static BluetoothHandsfreeNotificationHandler* sHandsfreeNotificationHandler;
|
||||
|
||||
struct BluetoothHandsfreeHALCallback
|
||||
{
|
||||
class HandsfreeNotificationHandlerWrapper
|
||||
{
|
||||
public:
|
||||
typedef BluetoothHandsfreeNotificationHandler ObjectType;
|
||||
|
||||
static ObjectType* GetInstance()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return sHandsfreeNotificationHandler;
|
||||
}
|
||||
};
|
||||
|
||||
// Notifications
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<
|
||||
HandsfreeNotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeConnectionState, nsString,
|
||||
BluetoothHandsfreeConnectionState, const nsAString&>
|
||||
ConnectionStateNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<
|
||||
HandsfreeNotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeAudioState, nsString,
|
||||
BluetoothHandsfreeAudioState, const nsAString&>
|
||||
AudioStateNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<
|
||||
HandsfreeNotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeVoiceRecognitionState>
|
||||
VoiceRecognitionNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<
|
||||
HandsfreeNotificationHandlerWrapper, void>
|
||||
AnswerCallNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<
|
||||
HandsfreeNotificationHandlerWrapper, void>
|
||||
HangupCallNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable2<
|
||||
HandsfreeNotificationHandlerWrapper, void,
|
||||
BluetoothHandsfreeVolumeType, int>
|
||||
VolumeNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<
|
||||
HandsfreeNotificationHandlerWrapper, void, nsString, const nsAString&>
|
||||
DialCallNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<
|
||||
HandsfreeNotificationHandlerWrapper, void, char>
|
||||
DtmfNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<
|
||||
HandsfreeNotificationHandlerWrapper, void, BluetoothHandsfreeNRECState>
|
||||
NRECNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<
|
||||
HandsfreeNotificationHandlerWrapper, void, BluetoothHandsfreeCallHoldType>
|
||||
CallHoldNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<
|
||||
HandsfreeNotificationHandlerWrapper, void>
|
||||
CnumNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<
|
||||
HandsfreeNotificationHandlerWrapper, void>
|
||||
CindNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<
|
||||
HandsfreeNotificationHandlerWrapper, void>
|
||||
CopsNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<
|
||||
HandsfreeNotificationHandlerWrapper, void>
|
||||
ClccNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable1<
|
||||
HandsfreeNotificationHandlerWrapper, void, nsCString, const nsACString&>
|
||||
UnknownAtNotification;
|
||||
|
||||
typedef BluetoothNotificationHALRunnable0<
|
||||
HandsfreeNotificationHandlerWrapper, void>
|
||||
KeyPressedNotification;
|
||||
|
||||
// Bluedroid Handsfree callbacks
|
||||
|
||||
static void
|
||||
ConnectionState(bthf_connection_state_t aState, bt_bdaddr_t* aBdAddr)
|
||||
{
|
||||
ConnectionStateNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::ConnectionStateNotification,
|
||||
aState, aBdAddr);
|
||||
}
|
||||
|
||||
static void
|
||||
AudioState(bthf_audio_state_t aState, bt_bdaddr_t* aBdAddr)
|
||||
{
|
||||
AudioStateNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::AudioStateNotification,
|
||||
aState, aBdAddr);
|
||||
}
|
||||
|
||||
static void
|
||||
VoiceRecognition(bthf_vr_state_t aState)
|
||||
{
|
||||
VoiceRecognitionNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::VoiceRecognitionNotification,
|
||||
aState);
|
||||
}
|
||||
|
||||
static void
|
||||
AnswerCall()
|
||||
{
|
||||
AnswerCallNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::AnswerCallNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
HangupCall()
|
||||
{
|
||||
HangupCallNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::HangupCallNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
Volume(bthf_volume_type_t aType, int aVolume)
|
||||
{
|
||||
VolumeNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::VolumeNotification,
|
||||
aType, aVolume);
|
||||
}
|
||||
|
||||
static void
|
||||
DialCall(char* aNumber)
|
||||
{
|
||||
DialCallNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::DialCallNotification, aNumber);
|
||||
}
|
||||
|
||||
static void
|
||||
Dtmf(char aDtmf)
|
||||
{
|
||||
DtmfNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::DtmfNotification, aDtmf);
|
||||
}
|
||||
|
||||
static void
|
||||
NoiseReductionEchoCancellation(bthf_nrec_t aNrec)
|
||||
{
|
||||
NRECNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::NRECNotification, aNrec);
|
||||
}
|
||||
|
||||
static void
|
||||
CallHold(bthf_chld_type_t aChld)
|
||||
{
|
||||
CallHoldNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::CallHoldNotification, aChld);
|
||||
}
|
||||
|
||||
static void
|
||||
Cnum()
|
||||
{
|
||||
CnumNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::CnumNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
Cind()
|
||||
{
|
||||
CindNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::CindNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
Cops()
|
||||
{
|
||||
CopsNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::CopsNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
Clcc()
|
||||
{
|
||||
ClccNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::ClccNotification);
|
||||
}
|
||||
|
||||
static void
|
||||
UnknownAt(char* aAtString)
|
||||
{
|
||||
UnknownAtNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::UnknownAtNotification,
|
||||
aAtString);
|
||||
}
|
||||
|
||||
static void
|
||||
KeyPressed()
|
||||
{
|
||||
KeyPressedNotification::Dispatch(
|
||||
&BluetoothHandsfreeNotificationHandler::KeyPressedNotification);
|
||||
}
|
||||
};
|
||||
|
||||
// Interface
|
||||
//
|
||||
|
||||
BluetoothHandsfreeHALInterface::BluetoothHandsfreeHALInterface(
|
||||
const bthf_interface_t* aInterface)
|
||||
: mInterface(aInterface)
|
||||
{
|
||||
MOZ_ASSERT(mInterface);
|
||||
}
|
||||
|
||||
BluetoothHandsfreeHALInterface::~BluetoothHandsfreeHALInterface()
|
||||
{ }
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::Init(
|
||||
BluetoothHandsfreeNotificationHandler* aNotificationHandler,
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
static bthf_callbacks_t sCallbacks = {
|
||||
sizeof(sCallbacks),
|
||||
BluetoothHandsfreeHALCallback::ConnectionState,
|
||||
BluetoothHandsfreeHALCallback::AudioState,
|
||||
BluetoothHandsfreeHALCallback::VoiceRecognition,
|
||||
BluetoothHandsfreeHALCallback::AnswerCall,
|
||||
BluetoothHandsfreeHALCallback::HangupCall,
|
||||
BluetoothHandsfreeHALCallback::Volume,
|
||||
BluetoothHandsfreeHALCallback::DialCall,
|
||||
BluetoothHandsfreeHALCallback::Dtmf,
|
||||
BluetoothHandsfreeHALCallback::NoiseReductionEchoCancellation,
|
||||
BluetoothHandsfreeHALCallback::CallHold,
|
||||
BluetoothHandsfreeHALCallback::Cnum,
|
||||
BluetoothHandsfreeHALCallback::Cind,
|
||||
BluetoothHandsfreeHALCallback::Cops,
|
||||
BluetoothHandsfreeHALCallback::Clcc,
|
||||
BluetoothHandsfreeHALCallback::UnknownAt,
|
||||
BluetoothHandsfreeHALCallback::KeyPressed
|
||||
};
|
||||
|
||||
sHandsfreeNotificationHandler = aNotificationHandler;
|
||||
|
||||
bt_status_t status = mInterface->init(&sCallbacks);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::Init,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::Cleanup(
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
mInterface->cleanup();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::Cleanup, STATUS_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/* Connect / Disconnect */
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::Connect(
|
||||
const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->connect(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::Connect,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::Disconnect(
|
||||
const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->disconnect(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::Disconnect,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::ConnectAudio(
|
||||
const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->connect_audio(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::ConnectAudio,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::DisconnectAudio(
|
||||
const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
|
||||
status = mInterface->disconnect_audio(&bdAddr);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::DisconnectAudio,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Voice Recognition */
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::StartVoiceRecognition(
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status = mInterface->start_voice_recognition();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::StartVoiceRecognition,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::StopVoiceRecognition(
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status = mInterface->stop_voice_recognition();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::StopVoiceRecognition,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Volume */
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::VolumeControl(
|
||||
BluetoothHandsfreeVolumeType aType, int aVolume,
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bthf_volume_type_t type = BTHF_VOLUME_TYPE_SPK;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aType, type))) {
|
||||
status = mInterface->volume_control(type, aVolume);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::VolumeControl,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Device status */
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::DeviceStatusNotification(
|
||||
BluetoothHandsfreeNetworkState aNtkState,
|
||||
BluetoothHandsfreeServiceType aSvcType, int aSignal,
|
||||
int aBattChg, BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bthf_network_state_t ntkState = BTHF_NETWORK_STATE_NOT_AVAILABLE;
|
||||
bthf_service_type_t svcType = BTHF_SERVICE_TYPE_HOME;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aNtkState, ntkState)) &&
|
||||
NS_SUCCEEDED(Convert(aSvcType, svcType))) {
|
||||
status = mInterface->device_status_notification(ntkState, svcType,
|
||||
aSignal, aBattChg);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::DeviceStatusNotification,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Responses */
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::CopsResponse(
|
||||
const char* aCops, BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status = mInterface->cops_response(aCops);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::CopsResponse,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::CindResponse(
|
||||
int aSvc, int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState,
|
||||
int aSignal, int aRoam, int aBattChg,
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bthf_call_state_t callSetupState = BTHF_CALL_STATE_ACTIVE;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aCallSetupState, callSetupState))) {
|
||||
status = mInterface->cind_response(aSvc, aNumActive, aNumHeld,
|
||||
callSetupState, aSignal,
|
||||
aRoam, aBattChg);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::CindResponse,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::FormattedAtResponse(
|
||||
const char* aRsp, BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status = mInterface->formatted_at_response(aRsp);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::FormattedAtResponse,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::AtResponse(
|
||||
BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bthf_at_response_t responseCode = BTHF_AT_RESPONSE_ERROR;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aResponseCode, responseCode))) {
|
||||
status = mInterface->at_response(responseCode, aErrorCode);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::AtResponse,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::ClccResponse(
|
||||
int aIndex,
|
||||
BluetoothHandsfreeCallDirection aDir,
|
||||
BluetoothHandsfreeCallState aState,
|
||||
BluetoothHandsfreeCallMode aMode,
|
||||
BluetoothHandsfreeCallMptyType aMpty,
|
||||
const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bthf_call_direction_t dir = BTHF_CALL_DIRECTION_OUTGOING;
|
||||
bthf_call_state_t state = BTHF_CALL_STATE_ACTIVE;
|
||||
bthf_call_mode_t mode = BTHF_CALL_TYPE_VOICE;
|
||||
bthf_call_mpty_type_t mpty = BTHF_CALL_MPTY_TYPE_SINGLE;
|
||||
bthf_call_addrtype_t type = BTHF_CALL_ADDRTYPE_UNKNOWN;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aDir, dir)) &&
|
||||
NS_SUCCEEDED(Convert(aState, state)) &&
|
||||
NS_SUCCEEDED(Convert(aMode, mode)) &&
|
||||
NS_SUCCEEDED(Convert(aMpty, mpty)) &&
|
||||
NS_SUCCEEDED(Convert(aType, type))) {
|
||||
status = mInterface->clcc_response(aIndex, dir, state, mode, mpty,
|
||||
NS_ConvertUTF16toUTF8(aNumber).get(),
|
||||
type);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::ClccResponse,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* Phone State */
|
||||
|
||||
void
|
||||
BluetoothHandsfreeHALInterface::PhoneStateChange(int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState, const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
bt_status_t status;
|
||||
bthf_call_state_t callSetupState = BTHF_CALL_STATE_ACTIVE;
|
||||
bthf_call_addrtype_t type = BTHF_CALL_ADDRTYPE_UNKNOWN;
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aCallSetupState, callSetupState)) &&
|
||||
NS_SUCCEEDED(Convert(aType, type))) {
|
||||
status = mInterface->phone_state_change(
|
||||
aNumActive, aNumHeld, callSetupState,
|
||||
NS_ConvertUTF16toUTF8(aNumber).get(), type);
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothHandsfreeHALResult(
|
||||
aRes, &BluetoothHandsfreeResultHandler::PhoneStateChange,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,95 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothhandsfreehalinterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetoothhandsfreehalinterface_h__
|
||||
|
||||
#include <hardware/bluetooth.h>
|
||||
#include <hardware/bt_hf.h>
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothHALInterface;
|
||||
|
||||
class BluetoothHandsfreeHALInterface final
|
||||
: public BluetoothHandsfreeInterface
|
||||
{
|
||||
public:
|
||||
friend class BluetoothHALInterface;
|
||||
|
||||
void Init(BluetoothHandsfreeNotificationHandler* aNotificationHandler,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void Cleanup(BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Connect / Disconnect */
|
||||
|
||||
void Connect(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void Disconnect(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void ConnectAudio(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void DisconnectAudio(const nsAString& aBdAddr,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Voice Recognition */
|
||||
|
||||
void StartVoiceRecognition(BluetoothHandsfreeResultHandler* aRes);
|
||||
void StopVoiceRecognition(BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Volume */
|
||||
|
||||
void VolumeControl(BluetoothHandsfreeVolumeType aType, int aVolume,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Device status */
|
||||
|
||||
void DeviceStatusNotification(BluetoothHandsfreeNetworkState aNtkState,
|
||||
BluetoothHandsfreeServiceType aSvcType,
|
||||
int aSignal, int aBattChg,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Responses */
|
||||
|
||||
void CopsResponse(const char* aCops,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void CindResponse(int aSvc, int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState, int aSignal,
|
||||
int aRoam, int aBattChg,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void FormattedAtResponse(const char* aRsp,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void AtResponse(BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
void ClccResponse(int aIndex, BluetoothHandsfreeCallDirection aDir,
|
||||
BluetoothHandsfreeCallState aState,
|
||||
BluetoothHandsfreeCallMode aMode,
|
||||
BluetoothHandsfreeCallMptyType aMpty,
|
||||
const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
/* Phone State */
|
||||
|
||||
void PhoneStateChange(int aNumActive, int aNumHeld,
|
||||
BluetoothHandsfreeCallState aCallSetupState,
|
||||
const nsAString& aNumber,
|
||||
BluetoothHandsfreeCallAddressType aType,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
BluetoothHandsfreeHALInterface(const bthf_interface_t* aInterface);
|
||||
~BluetoothHandsfreeHALInterface();
|
||||
|
||||
private:
|
||||
const bthf_interface_t* mInterface;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,232 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothoppmanager_h__
|
||||
#define mozilla_dom_bluetooth_bluetoothoppmanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothProfileManagerBase.h"
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "DeviceStorage.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
class nsIDOMBlob;
|
||||
class nsIOutputStream;
|
||||
class nsIInputStream;
|
||||
class nsIVolumeMountLock;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class BlobParent;
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocket;
|
||||
class ObexHeaderSet;
|
||||
class SendFileBatch;
|
||||
|
||||
class BluetoothOppManager : public BluetoothSocketObserver
|
||||
, public BluetoothProfileManagerBase
|
||||
{
|
||||
public:
|
||||
BT_DECL_PROFILE_MGR_BASE
|
||||
virtual void GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("OPP");
|
||||
}
|
||||
|
||||
static const int MAX_PACKET_LENGTH = 0xFFFE;
|
||||
|
||||
virtual ~BluetoothOppManager();
|
||||
static BluetoothOppManager* Get();
|
||||
void ClientDataHandler(mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
void ServerDataHandler(mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
|
||||
bool Listen();
|
||||
|
||||
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
|
||||
bool SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
bool StopSendingFile();
|
||||
bool ConfirmReceivingFile(bool aConfirm);
|
||||
|
||||
void SendConnectRequest();
|
||||
void SendPutHeaderRequest(const nsAString& aFileName, int aFileSize);
|
||||
void SendPutRequest(uint8_t* aFileBody, int aFileBodyLength);
|
||||
void SendPutFinalRequest();
|
||||
void SendDisconnectRequest();
|
||||
|
||||
void ExtractPacketHeaders(const ObexHeaderSet& aHeader);
|
||||
bool ExtractBlobHeaders();
|
||||
void CheckPutFinal(uint32_t aNumRead);
|
||||
|
||||
// The following functions are inherited from BluetoothSocketObserver
|
||||
void ReceiveSocketData(
|
||||
BluetoothSocket* aSocket,
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) override;
|
||||
virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) override;
|
||||
virtual void OnSocketConnectError(BluetoothSocket* aSocket) override;
|
||||
virtual void OnSocketDisconnect(BluetoothSocket* aSocket) override;
|
||||
|
||||
private:
|
||||
class CloseSocketTask;
|
||||
class ReadFileTask;
|
||||
class SendSocketDataTask;
|
||||
|
||||
BluetoothOppManager();
|
||||
bool Init();
|
||||
void HandleShutdown();
|
||||
|
||||
void StartFileTransfer();
|
||||
void StartSendingNextFile();
|
||||
void FileTransferComplete();
|
||||
void UpdateProgress();
|
||||
void ReceivingFileConfirmation();
|
||||
bool CreateFile();
|
||||
bool WriteToFile(const uint8_t* aData, int aDataLength);
|
||||
void RestoreReceivedFileAndNotify();
|
||||
void DeleteReceivedFile();
|
||||
void ReplyToConnect();
|
||||
void ReplyToDisconnectOrAbort();
|
||||
void ReplyToPut(bool aFinal, bool aContinue);
|
||||
void ReplyError(uint8_t aError);
|
||||
void AfterOppConnected();
|
||||
void AfterFirstPut();
|
||||
void AfterOppDisconnected();
|
||||
void ValidateFileName();
|
||||
bool IsReservedChar(char16_t c);
|
||||
void ClearQueue();
|
||||
void RetrieveSentFileName();
|
||||
void NotifyAboutFileChange();
|
||||
bool AcquireSdcardMountLock();
|
||||
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
|
||||
void AppendBlobToSend(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
void DiscardBlobsToSend();
|
||||
bool ProcessNextBatch();
|
||||
void ConnectInternal(const nsAString& aDeviceAddress);
|
||||
|
||||
/**
|
||||
* Usually we won't get a full PUT packet in one operation, which means that
|
||||
* a packet may be devided into several parts and BluetoothOppManager should
|
||||
* be in charge of assembling.
|
||||
*
|
||||
* @return true if a packet has been fully received.
|
||||
* false if the received length exceeds/not reaches the expected
|
||||
* length.
|
||||
*/
|
||||
bool ComposePacket(uint8_t aOpCode,
|
||||
mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
|
||||
/**
|
||||
* OBEX session status.
|
||||
* Set when OBEX session is established.
|
||||
*/
|
||||
bool mConnected;
|
||||
nsString mDeviceAddress;
|
||||
|
||||
/**
|
||||
* Remote information
|
||||
*/
|
||||
uint8_t mRemoteObexVersion;
|
||||
uint8_t mRemoteConnectionFlags;
|
||||
int mRemoteMaxPacketLength;
|
||||
|
||||
/**
|
||||
* For sending files, we decide our next action based on current command and
|
||||
* previous one.
|
||||
* For receiving files, we don't need previous command and it is set to 0
|
||||
* as a default value.
|
||||
*/
|
||||
int mLastCommand;
|
||||
|
||||
int mPacketLength;
|
||||
int mPutPacketReceivedLength;
|
||||
int mBodySegmentLength;
|
||||
int mUpdateProgressCounter;
|
||||
|
||||
/**
|
||||
* When it is true and the target service on target device couldn't be found,
|
||||
* refreshing SDP records is necessary.
|
||||
*/
|
||||
bool mNeedsUpdatingSdpRecords;
|
||||
|
||||
/**
|
||||
* Set when StopSendingFile() is called.
|
||||
*/
|
||||
bool mAbortFlag;
|
||||
|
||||
/**
|
||||
* Set when receiving the first PUT packet of a new file
|
||||
*/
|
||||
bool mNewFileFlag;
|
||||
|
||||
/**
|
||||
* Set when receiving a PutFinal packet
|
||||
*/
|
||||
bool mPutFinalFlag;
|
||||
|
||||
/**
|
||||
* Set when FileTransferComplete() is called
|
||||
*/
|
||||
bool mSendTransferCompleteFlag;
|
||||
|
||||
/**
|
||||
* Set when a transfer is successfully completed.
|
||||
*/
|
||||
bool mSuccessFlag;
|
||||
|
||||
/**
|
||||
* True: Receive file (Server)
|
||||
* False: Send file (Client)
|
||||
*/
|
||||
bool mIsServer;
|
||||
|
||||
/**
|
||||
* Set when receiving the first PUT packet and wait for
|
||||
* ConfirmReceivingFile() to be called.
|
||||
*/
|
||||
bool mWaitingForConfirmationFlag;
|
||||
|
||||
nsString mFileName;
|
||||
nsString mContentType;
|
||||
uint32_t mFileLength;
|
||||
uint32_t mSentFileLength;
|
||||
bool mWaitingToSendPutFinal;
|
||||
|
||||
nsAutoArrayPtr<uint8_t> mBodySegment;
|
||||
nsAutoArrayPtr<uint8_t> mReceivedDataBuffer;
|
||||
|
||||
int mCurrentBlobIndex;
|
||||
nsCOMPtr<nsIDOMBlob> mBlob;
|
||||
nsTArray<SendFileBatch> mBatches;
|
||||
|
||||
/**
|
||||
* A seperate member thread is required because our read calls can block
|
||||
* execution, which is not allowed to happen on the IOThread.
|
||||
*/
|
||||
nsCOMPtr<nsIThread> mReadFileThread;
|
||||
nsCOMPtr<nsIOutputStream> mOutputStream;
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
nsCOMPtr<nsIVolumeMountLock> mMountLock;
|
||||
nsRefPtr<DeviceStorageFile> mDsFile;
|
||||
nsRefPtr<DeviceStorageFile> mDummyDsFile;
|
||||
|
||||
// If a connection has been established, mSocket will be the socket
|
||||
// communicating with the remote socket. We maintain the invariant that if
|
||||
// mSocket is non-null, mServerSocket must be null (and vice versa).
|
||||
nsRefPtr<BluetoothSocket> mSocket;
|
||||
|
||||
// Server sockets. Once an inbound connection is established, it will hand
|
||||
// over the ownership to mSocket, and get a new server socket while Listen()
|
||||
// is called.
|
||||
nsRefPtr<BluetoothSocket> mServerSocket;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,286 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothservicebluedroid_h__
|
||||
#define mozilla_dom_bluetooth_bluetoothservicebluedroid_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothService.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothServiceBluedroid : public BluetoothService
|
||||
, public BluetoothNotificationHandler
|
||||
{
|
||||
class CancelDiscoveryResultHandler;
|
||||
class CreateBondResultHandler;
|
||||
class DisableResultHandler;
|
||||
class EnableResultHandler;
|
||||
class GetRemoteDevicePropertiesResultHandler;
|
||||
class GetRemoteServicesResultHandler;
|
||||
class InitResultHandler;
|
||||
class PinReplyResultHandler;
|
||||
class ProfileDeinitResultHandler;
|
||||
class ProfileInitResultHandler;
|
||||
class RemoveBondResultHandler;
|
||||
class SetAdapterPropertyDiscoverableResultHandler;
|
||||
class SetAdapterPropertyResultHandler;
|
||||
class SspReplyResultHandler;
|
||||
class StartDiscoveryResultHandler;
|
||||
|
||||
public:
|
||||
BluetoothServiceBluedroid();
|
||||
~BluetoothServiceBluedroid();
|
||||
|
||||
virtual nsresult StartInternal(BluetoothReplyRunnable* aRunnable);
|
||||
virtual nsresult StopInternal(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
FetchUuidsInternal(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
|
||||
virtual nsresult StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
SetProperty(BluetoothObjectType aType,
|
||||
const BluetoothNamedValue& aValue,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
GetServiceChannel(const nsAString& aDeviceAddress,
|
||||
const nsAString& aServiceUuid,
|
||||
BluetoothProfileManagerBase* aManager);
|
||||
|
||||
virtual bool
|
||||
UpdateSdpRecords(const nsAString& aDeviceAddress,
|
||||
BluetoothProfileManagerBase* aManager);
|
||||
|
||||
virtual nsresult
|
||||
CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
|
||||
int aTimeout,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
PinReplyInternal(const nsAString& aDeviceAddress,
|
||||
bool aAccept,
|
||||
const nsAString& aPinCode,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SspReplyInternal(const nsAString& aDeviceAddress,
|
||||
BluetoothSspVariant aVariant,
|
||||
bool aAccept,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SetPinCodeInternal(const nsAString& aDeviceAddress,
|
||||
const nsAString& aPinCode,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SetPasskeyInternal(const nsAString& aDeviceAddress,
|
||||
uint32_t aPasskey,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
|
||||
bool aConfirm,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
Connect(const nsAString& aDeviceAddress,
|
||||
uint32_t aCod,
|
||||
uint16_t aServiceUuid,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual bool
|
||||
IsConnected(uint16_t aProfileId);
|
||||
|
||||
virtual void
|
||||
Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
BlobParent* aBlobParent,
|
||||
BlobChild* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
ConnectSco(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
DisconnectSco(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
IsScoConnected(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
AnswerWaitingCall(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
ToggleCalls(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
SendMetaData(const nsAString& aTitle,
|
||||
const nsAString& aArtist,
|
||||
const nsAString& aAlbum,
|
||||
int64_t aMediaNumber,
|
||||
int64_t aTotalMediaCount,
|
||||
int64_t aDuration,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
SendPlayStatus(int64_t aDuration,
|
||||
int64_t aPosition,
|
||||
const nsAString& aPlayStatus,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
UpdatePlayStatus(uint32_t aDuration,
|
||||
uint32_t aPosition,
|
||||
ControlPlayStatus aPlayStatus) override;
|
||||
|
||||
virtual nsresult
|
||||
SendSinkMessage(const nsAString& aDeviceAddresses,
|
||||
const nsAString& aMessage) override;
|
||||
|
||||
virtual nsresult
|
||||
SendInputMessage(const nsAString& aDeviceAddresses,
|
||||
const nsAString& aMessage) override;
|
||||
|
||||
//
|
||||
// GATT Client
|
||||
//
|
||||
|
||||
virtual void
|
||||
ConnectGattClientInternal(const nsAString& aAppUuid,
|
||||
const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
DisconnectGattClientInternal(const nsAString& aAppUuid,
|
||||
const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
DiscoverGattServicesInternal(const nsAString& aAppUuid,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
GattClientStartNotificationsInternal(
|
||||
const nsAString& aAppUuid,
|
||||
const BluetoothGattServiceId& aServId,
|
||||
const BluetoothGattId& aCharId,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
GattClientStopNotificationsInternal(
|
||||
const nsAString& aAppUuid,
|
||||
const BluetoothGattServiceId& aServId,
|
||||
const BluetoothGattId& aCharId,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
UnregisterGattClientInternal(int aClientIf,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
GattClientReadRemoteRssiInternal(
|
||||
int aClientIf, const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
//
|
||||
// Bluetooth notifications
|
||||
//
|
||||
|
||||
virtual void AdapterStateChangedNotification(bool aState) override;
|
||||
virtual void AdapterPropertiesNotification(
|
||||
BluetoothStatus aStatus, int aNumProperties,
|
||||
const BluetoothProperty* aProperties) override;
|
||||
|
||||
virtual void RemoteDevicePropertiesNotification(
|
||||
BluetoothStatus aStatus, const nsAString& aBdAddr,
|
||||
int aNumProperties, const BluetoothProperty* aProperties) override;
|
||||
|
||||
virtual void DeviceFoundNotification(
|
||||
int aNumProperties, const BluetoothProperty* aProperties) override;
|
||||
|
||||
virtual void DiscoveryStateChangedNotification(bool aState) override;
|
||||
|
||||
virtual void PinRequestNotification(const nsAString& aRemoteBdAddr,
|
||||
const nsAString& aBdName,
|
||||
uint32_t aCod) override;
|
||||
virtual void SspRequestNotification(const nsAString& aRemoteBdAddr,
|
||||
const nsAString& aBdName,
|
||||
uint32_t aCod,
|
||||
BluetoothSspVariant aPairingVariant,
|
||||
uint32_t aPasskey) override;
|
||||
|
||||
virtual void BondStateChangedNotification(
|
||||
BluetoothStatus aStatus, const nsAString& aRemoteBdAddr,
|
||||
BluetoothBondState aState) override;
|
||||
virtual void AclStateChangedNotification(BluetoothStatus aStatus,
|
||||
const nsAString& aRemoteBdAddr,
|
||||
bool aState) override;
|
||||
|
||||
virtual void DutModeRecvNotification(uint16_t aOpcode,
|
||||
const uint8_t* aBuf,
|
||||
uint8_t aLen) override;
|
||||
virtual void LeTestModeNotification(BluetoothStatus aStatus,
|
||||
uint16_t aNumPackets) override;
|
||||
|
||||
protected:
|
||||
static nsresult StartGonkBluetooth();
|
||||
static nsresult StopGonkBluetooth();
|
||||
static bool EnsureBluetoothHalLoad();
|
||||
|
||||
static void ConnectDisconnect(bool aConnect,
|
||||
const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable,
|
||||
uint16_t aServiceUuid, uint32_t aCod = 0);
|
||||
static void NextBluetoothProfileController();
|
||||
static ControlPlayStatus PlayStatusStringToControlPlayStatus(
|
||||
const nsAString& aPlayStatus);
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -1,708 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothSocket.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "base/message_loop.h"
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "BluetoothUtils.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
static const size_t MAX_READ_SIZE = 1 << 16;
|
||||
static const uint8_t UUID_OBEX_OBJECT_PUSH[] = {
|
||||
0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
|
||||
};
|
||||
static BluetoothSocketInterface* sBluetoothSocketInterface;
|
||||
|
||||
// helper functions
|
||||
static bool
|
||||
EnsureBluetoothSocketHalLoad()
|
||||
{
|
||||
if (sBluetoothSocketInterface) {
|
||||
return true;
|
||||
}
|
||||
|
||||
BluetoothInterface* btInf = BluetoothInterface::GetInstance();
|
||||
NS_ENSURE_TRUE(btInf, false);
|
||||
|
||||
sBluetoothSocketInterface = btInf->GetBluetoothSocketInterface();
|
||||
NS_ENSURE_TRUE(sBluetoothSocketInterface, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class mozilla::dom::bluetooth::DroidSocketImpl : public ipc::UnixFdWatcher
|
||||
, protected SocketIOBase
|
||||
{
|
||||
public:
|
||||
/* The connection status in DroidSocketImpl indicates the current
|
||||
* phase of the socket connection. The initial settign should always
|
||||
* be DISCONNECTED, when no connection is present.
|
||||
*
|
||||
* To establish a connection on the server, DroidSocketImpl moves
|
||||
* to LISTENING. It now waits for incoming connection attempts by
|
||||
* installing a read watcher on the I/O thread. When its socket file
|
||||
* descriptor becomes readable, DroidSocketImpl accepts the connection
|
||||
* and finally moves DroidSocketImpl to CONNECTED. DroidSocketImpl now
|
||||
* uses read and write watchers during data transfers. Any socket setup
|
||||
* is handled internally by the accept method.
|
||||
*
|
||||
* On the client side, DroidSocketImpl moves to CONNECTING and installs
|
||||
* a write watcher on the I/O thread to wait until the connection is
|
||||
* ready. The socket setup is handled internally by the connect method.
|
||||
* Installing the write handler makes the code compatible with POSIX
|
||||
* semantics for non-blocking connects and gives a clear signal when the
|
||||
* conncetion is ready. DroidSocketImpl then moves to CONNECTED and uses
|
||||
* read and write watchers during data transfers.
|
||||
*/
|
||||
enum ConnectionStatus {
|
||||
SOCKET_IS_DISCONNECTED = 0,
|
||||
SOCKET_IS_LISTENING,
|
||||
SOCKET_IS_CONNECTING,
|
||||
SOCKET_IS_CONNECTED
|
||||
};
|
||||
|
||||
DroidSocketImpl(MessageLoop* aIOLoop, BluetoothSocket* aConsumer)
|
||||
: ipc::UnixFdWatcher(aIOLoop)
|
||||
, SocketIOBase(MAX_READ_SIZE)
|
||||
, mConsumer(aConsumer)
|
||||
, mShuttingDownOnIOThread(false)
|
||||
, mConnectionStatus(SOCKET_IS_DISCONNECTED)
|
||||
{ }
|
||||
|
||||
~DroidSocketImpl()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
|
||||
void Send(UnixSocketRawData* aData)
|
||||
{
|
||||
EnqueueData(aData);
|
||||
AddWatchers(WRITE_WATCHER, false);
|
||||
}
|
||||
|
||||
bool IsShutdownOnMainThread()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return mConsumer == nullptr;
|
||||
}
|
||||
|
||||
bool IsShutdownOnIOThread()
|
||||
{
|
||||
return mShuttingDownOnIOThread;
|
||||
}
|
||||
|
||||
void ShutdownOnMainThread()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsShutdownOnMainThread());
|
||||
mConsumer = nullptr;
|
||||
}
|
||||
|
||||
void ShutdownOnIOThread()
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!mShuttingDownOnIOThread);
|
||||
|
||||
Close(); // will also remove fd from I/O loop
|
||||
mShuttingDownOnIOThread = true;
|
||||
}
|
||||
|
||||
void Connect(int aFd);
|
||||
void Listen(int aFd);
|
||||
void Accept(int aFd);
|
||||
|
||||
void ConnectClientFd()
|
||||
{
|
||||
// Stop current read watch
|
||||
RemoveWatchers(READ_WATCHER);
|
||||
|
||||
mConnectionStatus = SOCKET_IS_CONNECTED;
|
||||
|
||||
// Restart read & write watch on client fd
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
AddWatchers(WRITE_WATCHER, false);
|
||||
}
|
||||
|
||||
SocketConsumerBase* GetConsumer()
|
||||
{
|
||||
return mConsumer.get();
|
||||
}
|
||||
|
||||
SocketBase* GetSocketBase()
|
||||
{
|
||||
return GetConsumer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
|
||||
* directly from main thread. All non-main-thread accesses should happen with
|
||||
* mImpl as container.
|
||||
*/
|
||||
RefPtr<BluetoothSocket> mConsumer;
|
||||
|
||||
private:
|
||||
/**
|
||||
* libevent triggered functions that reads data from socket when available and
|
||||
* guarenteed non-blocking. Only to be called on IO thread.
|
||||
*
|
||||
* @param aFd [in] File descriptor to read from
|
||||
*/
|
||||
virtual void OnFileCanReadWithoutBlocking(int aFd);
|
||||
|
||||
/**
|
||||
* libevent or developer triggered functions that writes data to socket when
|
||||
* available and guarenteed non-blocking. Only to be called on IO thread.
|
||||
*
|
||||
* @param aFd [in] File descriptor to read from
|
||||
*/
|
||||
virtual void OnFileCanWriteWithoutBlocking(int aFd);
|
||||
|
||||
void OnSocketCanReceiveWithoutBlocking(int aFd);
|
||||
void OnSocketCanAcceptWithoutBlocking(int aFd);
|
||||
void OnSocketCanSendWithoutBlocking(int aFd);
|
||||
void OnSocketCanConnectWithoutBlocking(int aFd);
|
||||
|
||||
/**
|
||||
* If true, do not requeue whatever task we're running
|
||||
*/
|
||||
bool mShuttingDownOnIOThread;
|
||||
|
||||
ConnectionStatus mConnectionStatus;
|
||||
};
|
||||
|
||||
class SocketConnectTask final : public SocketIOTask<DroidSocketImpl>
|
||||
{
|
||||
public:
|
||||
SocketConnectTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
|
||||
: SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
|
||||
, mFd(aFd)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsCanceled());
|
||||
|
||||
GetIO()->Connect(mFd);
|
||||
}
|
||||
|
||||
private:
|
||||
int mFd;
|
||||
};
|
||||
|
||||
class SocketListenTask final : public SocketIOTask<DroidSocketImpl>
|
||||
{
|
||||
public:
|
||||
SocketListenTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
|
||||
: SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
|
||||
, mFd(aFd)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
if (!IsCanceled()) {
|
||||
GetIO()->Listen(mFd);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int mFd;
|
||||
};
|
||||
|
||||
class SocketConnectClientFdTask final
|
||||
: public SocketIOTask<DroidSocketImpl>
|
||||
{
|
||||
SocketConnectClientFdTask(DroidSocketImpl* aImpl)
|
||||
: SocketIOTask<DroidSocketImpl>(aImpl)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
GetIO()->ConnectClientFd();
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
DroidSocketImpl::Connect(int aFd)
|
||||
{
|
||||
MOZ_ASSERT(aFd >= 0);
|
||||
|
||||
int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
|
||||
NS_ENSURE_TRUE_VOID(flags >= 0);
|
||||
|
||||
if (!(flags & O_NONBLOCK)) {
|
||||
int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags | O_NONBLOCK));
|
||||
NS_ENSURE_TRUE_VOID(!res);
|
||||
}
|
||||
|
||||
SetFd(aFd);
|
||||
mConnectionStatus = SOCKET_IS_CONNECTING;
|
||||
|
||||
AddWatchers(WRITE_WATCHER, false);
|
||||
}
|
||||
|
||||
void
|
||||
DroidSocketImpl::Listen(int aFd)
|
||||
{
|
||||
MOZ_ASSERT(aFd >= 0);
|
||||
|
||||
int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
|
||||
NS_ENSURE_TRUE_VOID(flags >= 0);
|
||||
|
||||
if (!(flags & O_NONBLOCK)) {
|
||||
int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags | O_NONBLOCK));
|
||||
NS_ENSURE_TRUE_VOID(!res);
|
||||
}
|
||||
|
||||
SetFd(aFd);
|
||||
mConnectionStatus = SOCKET_IS_LISTENING;
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
}
|
||||
|
||||
void
|
||||
DroidSocketImpl::Accept(int aFd)
|
||||
{
|
||||
Close();
|
||||
|
||||
int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
|
||||
NS_ENSURE_TRUE_VOID(flags >= 0);
|
||||
|
||||
if (!(flags & O_NONBLOCK)) {
|
||||
int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags | O_NONBLOCK));
|
||||
NS_ENSURE_TRUE_VOID(!res);
|
||||
}
|
||||
|
||||
SetFd(aFd);
|
||||
mConnectionStatus = SOCKET_IS_CONNECTED;
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<DroidSocketImpl>(
|
||||
this, SocketIOEventRunnable<DroidSocketImpl>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
AddWatchers(WRITE_WATCHER, false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DroidSocketImpl::OnFileCanReadWithoutBlocking(int aFd)
|
||||
{
|
||||
if (mConnectionStatus == SOCKET_IS_CONNECTED) {
|
||||
OnSocketCanReceiveWithoutBlocking(aFd);
|
||||
} else if (mConnectionStatus == SOCKET_IS_LISTENING) {
|
||||
OnSocketCanAcceptWithoutBlocking(aFd);
|
||||
} else {
|
||||
NS_NOTREACHED("invalid connection state for reading");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DroidSocketImpl::OnSocketCanReceiveWithoutBlocking(int aFd)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!mShuttingDownOnIOThread);
|
||||
|
||||
ssize_t res = ReceiveData(aFd, this);
|
||||
if (res < 0) {
|
||||
/* I/O error */
|
||||
RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
|
||||
} else if (!res) {
|
||||
/* EOF or peer shutdown */
|
||||
RemoveWatchers(READ_WATCHER);
|
||||
}
|
||||
}
|
||||
|
||||
class AcceptTask final : public SocketIOTask<DroidSocketImpl>
|
||||
{
|
||||
public:
|
||||
AcceptTask(DroidSocketImpl* aDroidSocketImpl, int aFd)
|
||||
: SocketIOTask<DroidSocketImpl>(aDroidSocketImpl)
|
||||
, mFd(aFd)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsCanceled());
|
||||
|
||||
GetIO()->Accept(mFd);
|
||||
}
|
||||
|
||||
private:
|
||||
int mFd;
|
||||
};
|
||||
|
||||
class AcceptResultHandler final : public BluetoothSocketResultHandler
|
||||
{
|
||||
public:
|
||||
AcceptResultHandler(DroidSocketImpl* aImpl)
|
||||
: mImpl(aImpl)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
}
|
||||
|
||||
void Accept(int aFd, const nsAString& aBdAddress,
|
||||
int aConnectionStatus) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mozilla::ScopedClose fd(aFd); // Close received socket fd on error
|
||||
|
||||
if (mImpl->IsShutdownOnMainThread()) {
|
||||
BT_LOGD("mConsumer is null, aborting receive!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (aConnectionStatus != 0) {
|
||||
mImpl->mConsumer->NotifyError();
|
||||
return;
|
||||
}
|
||||
|
||||
mImpl->mConsumer->SetAddress(aBdAddress);
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
||||
new AcceptTask(mImpl, fd.forget()));
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
BT_LOGR("BluetoothSocketInterface::Accept failed: %d", (int)aStatus);
|
||||
|
||||
if (!mImpl->IsShutdownOnMainThread()) {
|
||||
// Instead of NotifyError(), call NotifyDisconnect() to trigger
|
||||
// BluetoothOppManager::OnSocketDisconnect() as
|
||||
// DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
|
||||
// order to keep the same behavior and reduce regression risk.
|
||||
mImpl->mConsumer->NotifyDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
DroidSocketImpl* mImpl;
|
||||
};
|
||||
|
||||
class AcceptRunnable final : public SocketIORunnable<DroidSocketImpl>
|
||||
{
|
||||
public:
|
||||
AcceptRunnable(DroidSocketImpl* aImpl, int aFd)
|
||||
: SocketIORunnable<DroidSocketImpl>(aImpl)
|
||||
, mFd(aFd)
|
||||
{ }
|
||||
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(sBluetoothSocketInterface);
|
||||
|
||||
BluetoothSocketResultHandler* res = new AcceptResultHandler(GetIO());
|
||||
GetIO()->mConsumer->SetCurrentResultHandler(res);
|
||||
|
||||
sBluetoothSocketInterface->Accept(mFd, res);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
int mFd;
|
||||
};
|
||||
|
||||
void
|
||||
DroidSocketImpl::OnSocketCanAcceptWithoutBlocking(int aFd)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!mShuttingDownOnIOThread);
|
||||
|
||||
/* When a listening socket is ready for receiving data,
|
||||
* we can call |Accept| on it.
|
||||
*/
|
||||
|
||||
RemoveWatchers(READ_WATCHER);
|
||||
nsRefPtr<AcceptRunnable> t = new AcceptRunnable(this, aFd);
|
||||
NS_DispatchToMainThread(t);
|
||||
}
|
||||
|
||||
void
|
||||
DroidSocketImpl::OnFileCanWriteWithoutBlocking(int aFd)
|
||||
{
|
||||
if (mConnectionStatus == SOCKET_IS_CONNECTED) {
|
||||
OnSocketCanSendWithoutBlocking(aFd);
|
||||
} else if (mConnectionStatus == SOCKET_IS_CONNECTING) {
|
||||
OnSocketCanConnectWithoutBlocking(aFd);
|
||||
} else {
|
||||
NS_NOTREACHED("invalid connection state for writing");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DroidSocketImpl::OnSocketCanSendWithoutBlocking(int aFd)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!mShuttingDownOnIOThread);
|
||||
MOZ_ASSERT(aFd >= 0);
|
||||
|
||||
nsresult rv = SendPendingData(aFd, this);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasPendingData()) {
|
||||
AddWatchers(WRITE_WATCHER, false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DroidSocketImpl::OnSocketCanConnectWithoutBlocking(int aFd)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!mShuttingDownOnIOThread);
|
||||
|
||||
/* We follow Posix behaviour here: Connect operations are
|
||||
* complete once we can write to the connecting socket.
|
||||
*/
|
||||
|
||||
mConnectionStatus = SOCKET_IS_CONNECTED;
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<DroidSocketImpl>(
|
||||
this, SocketIOEventRunnable<DroidSocketImpl>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
AddWatchers(WRITE_WATCHER, false);
|
||||
}
|
||||
}
|
||||
|
||||
BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt)
|
||||
: mObserver(aObserver)
|
||||
, mCurrentRes(nullptr)
|
||||
, mImpl(nullptr)
|
||||
, mAuth(aAuth)
|
||||
, mEncrypt(aEncrypt)
|
||||
{
|
||||
MOZ_ASSERT(aObserver);
|
||||
|
||||
EnsureBluetoothSocketHalLoad();
|
||||
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
}
|
||||
|
||||
class ConnectSocketResultHandler final : public BluetoothSocketResultHandler
|
||||
{
|
||||
public:
|
||||
ConnectSocketResultHandler(DroidSocketImpl* aImpl)
|
||||
: mImpl(aImpl)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
}
|
||||
|
||||
void Connect(int aFd, const nsAString& aBdAddress,
|
||||
int aConnectionStatus) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mImpl->IsShutdownOnMainThread()) {
|
||||
BT_LOGD("mConsumer is null, aborting send!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (aConnectionStatus != 0) {
|
||||
mImpl->mConsumer->NotifyError();
|
||||
return;
|
||||
}
|
||||
|
||||
mImpl->mConsumer->SetAddress(aBdAddress);
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
||||
new SocketConnectTask(mImpl, aFd));
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
BT_WARNING("Connect failed: %d", (int)aStatus);
|
||||
|
||||
if (!mImpl->IsShutdownOnMainThread()) {
|
||||
// Instead of NotifyError(), call NotifyDisconnect() to trigger
|
||||
// BluetoothOppManager::OnSocketDisconnect() as
|
||||
// DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
|
||||
// order to keep the same behavior and reduce regression risk.
|
||||
mImpl->mConsumer->NotifyDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
DroidSocketImpl* mImpl;
|
||||
};
|
||||
|
||||
bool
|
||||
BluetoothSocket::ConnectSocket(const nsAString& aDeviceAddress, int aChannel)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
NS_ENSURE_FALSE(mImpl, false);
|
||||
|
||||
SetConnectionStatus(SOCKET_CONNECTING);
|
||||
|
||||
mImpl = new DroidSocketImpl(XRE_GetIOMessageLoop(), this);
|
||||
|
||||
BluetoothSocketResultHandler* res = new ConnectSocketResultHandler(mImpl);
|
||||
SetCurrentResultHandler(res);
|
||||
|
||||
// TODO: uuid as argument
|
||||
sBluetoothSocketInterface->Connect(
|
||||
aDeviceAddress,
|
||||
BluetoothSocketType::RFCOMM,
|
||||
UUID_OBEX_OBJECT_PUSH,
|
||||
aChannel, mEncrypt, mAuth, res);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class ListenResultHandler final : public BluetoothSocketResultHandler
|
||||
{
|
||||
public:
|
||||
ListenResultHandler(DroidSocketImpl* aImpl)
|
||||
: mImpl(aImpl)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
}
|
||||
|
||||
void Listen(int aFd) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
||||
new SocketListenTask(mImpl, aFd));
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
BT_WARNING("Listen failed: %d", (int)aStatus);
|
||||
}
|
||||
|
||||
private:
|
||||
DroidSocketImpl* mImpl;
|
||||
};
|
||||
|
||||
bool
|
||||
BluetoothSocket::ListenSocket(int aChannel)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
NS_ENSURE_FALSE(mImpl, false);
|
||||
|
||||
SetConnectionStatus(SOCKET_LISTENING);
|
||||
|
||||
mImpl = new DroidSocketImpl(XRE_GetIOMessageLoop(), this);
|
||||
|
||||
BluetoothSocketResultHandler* res = new ListenResultHandler(mImpl);
|
||||
SetCurrentResultHandler(res);
|
||||
|
||||
sBluetoothSocketInterface->Listen(
|
||||
BluetoothSocketType::RFCOMM,
|
||||
NS_LITERAL_STRING("OBEX Object Push"),
|
||||
UUID_OBEX_OBJECT_PUSH,
|
||||
aChannel, mEncrypt, mAuth, res);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::CloseSocket()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(sBluetoothSocketInterface);
|
||||
if (!mImpl) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop any watching |SocketMessageWatcher|
|
||||
if (mCurrentRes) {
|
||||
sBluetoothSocketInterface->Close(mCurrentRes);
|
||||
}
|
||||
|
||||
// From this point on, we consider mImpl as being deleted.
|
||||
// We sever the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
mImpl->ShutdownOnMainThread();
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
FROM_HERE, new SocketIOShutdownTask<DroidSocketImpl>(mImpl));
|
||||
|
||||
mImpl = nullptr;
|
||||
|
||||
NotifyDisconnect();
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothSocket::SendSocketData(UnixSocketRawData* aData)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
NS_ENSURE_TRUE(mImpl, false);
|
||||
|
||||
MOZ_ASSERT(!mImpl->IsShutdownOnMainThread());
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
FROM_HERE, new SocketIOSendTask<DroidSocketImpl, UnixSocketRawData>(mImpl, aData));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->ReceiveSocketData(this, aMessage);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnConnectSuccess()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
|
||||
SetCurrentResultHandler(nullptr);
|
||||
mObserver->OnSocketConnectSuccess(this);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnConnectError()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
|
||||
SetCurrentResultHandler(nullptr);
|
||||
mObserver->OnSocketConnectError(this);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnDisconnect()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->OnSocketDisconnect(this);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_BluetoothSocket_h
|
||||
#define mozilla_dom_bluetooth_BluetoothSocket_h
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "mozilla/ipc/SocketBase.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocketObserver;
|
||||
class BluetoothSocketResultHandler;
|
||||
class DroidSocketImpl;
|
||||
|
||||
class BluetoothSocket : public mozilla::ipc::SocketConsumerBase
|
||||
{
|
||||
public:
|
||||
BluetoothSocket(BluetoothSocketObserver* aObserver,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt);
|
||||
|
||||
bool ConnectSocket(const nsAString& aDeviceAddress, int aChannel);
|
||||
|
||||
bool ListenSocket(int aChannel);
|
||||
|
||||
void CloseSocket();
|
||||
|
||||
bool SendSocketData(mozilla::ipc::UnixSocketRawData* aData);
|
||||
|
||||
virtual void OnConnectSuccess() override;
|
||||
virtual void OnConnectError() override;
|
||||
virtual void OnDisconnect() override;
|
||||
virtual void ReceiveSocketData(
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) override;
|
||||
|
||||
inline void GetAddress(nsAString& aDeviceAddress)
|
||||
{
|
||||
aDeviceAddress = mDeviceAddress;
|
||||
}
|
||||
|
||||
inline void SetAddress(const nsAString& aDeviceAddress)
|
||||
{
|
||||
mDeviceAddress = aDeviceAddress;
|
||||
}
|
||||
|
||||
inline void SetCurrentResultHandler(BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
mCurrentRes = aRes;
|
||||
}
|
||||
|
||||
private:
|
||||
BluetoothSocketObserver* mObserver;
|
||||
BluetoothSocketResultHandler* mCurrentRes;
|
||||
DroidSocketImpl* mImpl;
|
||||
nsString mDeviceAddress;
|
||||
bool mAuth;
|
||||
bool mEncrypt;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,243 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothSocketHALInterface.h"
|
||||
#include "BluetoothHALHelpers.h"
|
||||
#include "BluetoothSocketMessageWatcher.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable1<BluetoothSocketResultHandler, void,
|
||||
int, int>
|
||||
BluetoothSocketHALIntResultRunnable;
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable3<BluetoothSocketResultHandler, void,
|
||||
int, const nsString, int,
|
||||
int, const nsAString_internal&, int>
|
||||
BluetoothSocketHALIntStringIntResultRunnable;
|
||||
|
||||
typedef
|
||||
BluetoothHALInterfaceRunnable1<BluetoothSocketResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>
|
||||
BluetoothSocketHALErrorRunnable;
|
||||
|
||||
static nsresult
|
||||
DispatchBluetoothSocketHALResult(
|
||||
BluetoothSocketResultHandler* aRes,
|
||||
void (BluetoothSocketResultHandler::*aMethod)(int), int aArg,
|
||||
BluetoothStatus aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
nsRunnable* runnable;
|
||||
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
runnable = new BluetoothSocketHALIntResultRunnable(aRes, aMethod, aArg);
|
||||
} else {
|
||||
runnable = new BluetoothSocketHALErrorRunnable(aRes,
|
||||
&BluetoothSocketResultHandler::OnError, aStatus);
|
||||
}
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_FAILED(rv)) {
|
||||
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
DispatchBluetoothSocketHALResult(
|
||||
BluetoothSocketResultHandler* aRes,
|
||||
void (BluetoothSocketResultHandler::*aMethod)(int, const nsAString&, int),
|
||||
int aArg1, const nsAString& aArg2, int aArg3, BluetoothStatus aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
nsRunnable* runnable;
|
||||
|
||||
if (aStatus == STATUS_SUCCESS) {
|
||||
runnable = new BluetoothSocketHALIntStringIntResultRunnable(
|
||||
aRes, aMethod, aArg1, aArg2, aArg3);
|
||||
} else {
|
||||
runnable = new BluetoothSocketHALErrorRunnable(aRes,
|
||||
&BluetoothSocketResultHandler::OnError, aStatus);
|
||||
}
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_FAILED(rv)) {
|
||||
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocketHALInterface::Listen(BluetoothSocketType aType,
|
||||
const nsAString& aServiceName,
|
||||
const uint8_t aServiceUuid[16],
|
||||
int aChannel, bool aEncrypt,
|
||||
bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
int fd;
|
||||
bt_status_t status;
|
||||
btsock_type_t type = BTSOCK_RFCOMM; // silences compiler warning
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aType, type))) {
|
||||
status = mInterface->listen(type,
|
||||
NS_ConvertUTF16toUTF8(aServiceName).get(),
|
||||
aServiceUuid, aChannel, &fd,
|
||||
(BTSOCK_FLAG_ENCRYPT * aEncrypt) |
|
||||
(BTSOCK_FLAG_AUTH * aAuth));
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothSocketHALResult(
|
||||
aRes, &BluetoothSocketResultHandler::Listen, fd,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* |DeleteTask| deletes a class instance on the I/O thread
|
||||
*/
|
||||
template <typename T>
|
||||
class DeleteTask final : public Task
|
||||
{
|
||||
public:
|
||||
DeleteTask(T* aPtr)
|
||||
: mPtr(aPtr)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
{
|
||||
mPtr = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
nsAutoPtr<T> mPtr;
|
||||
};
|
||||
|
||||
/* |ConnectWatcher| specializes SocketMessageWatcher for
|
||||
* connect operations by reading the socket messages from
|
||||
* Bluedroid and forwarding the connected socket to the
|
||||
* resource handler.
|
||||
*/
|
||||
class BluetoothSocketHALInterface::ConnectWatcher final
|
||||
: public SocketMessageWatcher
|
||||
{
|
||||
public:
|
||||
ConnectWatcher(int aFd, BluetoothSocketResultHandler* aRes)
|
||||
: SocketMessageWatcher(aFd, aRes)
|
||||
{ }
|
||||
|
||||
void Proceed(BluetoothStatus aStatus) override
|
||||
{
|
||||
DispatchBluetoothSocketHALResult(
|
||||
GetResultHandler(), &BluetoothSocketResultHandler::Connect,
|
||||
GetFd(), GetBdAddress(), GetConnectionStatus(), aStatus);
|
||||
|
||||
MessageLoopForIO::current()->PostTask(
|
||||
FROM_HERE, new DeleteTask<ConnectWatcher>(this));
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothSocketHALInterface::Connect(const nsAString& aBdAddr,
|
||||
BluetoothSocketType aType,
|
||||
const uint8_t aUuid[16],
|
||||
int aChannel, bool aEncrypt,
|
||||
bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
int fd;
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t bdAddr;
|
||||
btsock_type_t type = BTSOCK_RFCOMM; // silences compiler warning
|
||||
|
||||
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
|
||||
NS_SUCCEEDED(Convert(aType, type))) {
|
||||
status = mInterface->connect(&bdAddr, type, aUuid, aChannel, &fd,
|
||||
(BTSOCK_FLAG_ENCRYPT * aEncrypt) |
|
||||
(BTSOCK_FLAG_AUTH * aAuth));
|
||||
} else {
|
||||
status = BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (status == BT_STATUS_SUCCESS) {
|
||||
/* receive Bluedroid's socket-setup messages */
|
||||
Task* t = new SocketMessageWatcherTask(new ConnectWatcher(fd, aRes));
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
|
||||
} else if (aRes) {
|
||||
DispatchBluetoothSocketHALResult(
|
||||
aRes, &BluetoothSocketResultHandler::Connect, -1, EmptyString(), 0,
|
||||
ConvertDefault(status, STATUS_FAIL));
|
||||
}
|
||||
}
|
||||
|
||||
/* |AcceptWatcher| specializes |SocketMessageWatcher| for accept
|
||||
* operations by reading the socket messages from Bluedroid and
|
||||
* forwarding the received client socket to the resource handler.
|
||||
* The first message is received immediately. When there's a new
|
||||
* connection, Bluedroid sends the 2nd message with the socket
|
||||
* info and socket file descriptor.
|
||||
*/
|
||||
class BluetoothSocketHALInterface::AcceptWatcher final
|
||||
: public SocketMessageWatcher
|
||||
{
|
||||
public:
|
||||
AcceptWatcher(int aFd, BluetoothSocketResultHandler* aRes)
|
||||
: SocketMessageWatcher(aFd, aRes)
|
||||
{ }
|
||||
|
||||
void Proceed(BluetoothStatus aStatus) override
|
||||
{
|
||||
if ((aStatus != STATUS_SUCCESS) && (GetClientFd() != -1)) {
|
||||
mozilla::ScopedClose(GetClientFd()); // Close received socket fd on error
|
||||
}
|
||||
|
||||
DispatchBluetoothSocketHALResult(
|
||||
GetResultHandler(), &BluetoothSocketResultHandler::Accept,
|
||||
GetClientFd(), GetBdAddress(), GetConnectionStatus(), aStatus);
|
||||
|
||||
MessageLoopForIO::current()->PostTask(
|
||||
FROM_HERE, new DeleteTask<AcceptWatcher>(this));
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothSocketHALInterface::Accept(int aFd,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
/* receive Bluedroid's socket-setup messages and client fd */
|
||||
Task* t = new SocketMessageWatcherTask(new AcceptWatcher(aFd, aRes));
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocketHALInterface::Close(BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
/* stop the watcher corresponding to |aRes| */
|
||||
Task* t = new DeleteSocketMessageWatcherTask(aRes);
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, t);
|
||||
}
|
||||
|
||||
BluetoothSocketHALInterface::BluetoothSocketHALInterface(
|
||||
const btsock_interface_t* aInterface)
|
||||
: mInterface(aInterface)
|
||||
{
|
||||
MOZ_ASSERT(mInterface);
|
||||
}
|
||||
|
||||
BluetoothSocketHALInterface::~BluetoothSocketHALInterface()
|
||||
{ }
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,54 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothsockethalinterface_h__
|
||||
#define mozilla_dom_bluetooth_bluedroid_bluetoothsockethalinterface_h__
|
||||
|
||||
#include <hardware/bluetooth.h>
|
||||
#include <hardware/bt_sock.h>
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothInterface.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothHALInterface;
|
||||
|
||||
class BluetoothSocketHALInterface final
|
||||
: public BluetoothSocketInterface
|
||||
{
|
||||
public:
|
||||
class ConnectWatcher;
|
||||
class AcceptWatcher;
|
||||
|
||||
friend class BluetoothHALInterface;
|
||||
|
||||
void Listen(BluetoothSocketType aType,
|
||||
const nsAString& aServiceName,
|
||||
const uint8_t aServiceUuid[16],
|
||||
int aChannel, bool aEncrypt, bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void Connect(const nsAString& aBdAddr,
|
||||
BluetoothSocketType aType,
|
||||
const uint8_t aUuid[16],
|
||||
int aChannel, bool aEncrypt, bool aAuth,
|
||||
BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void Accept(int aFd, BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void Close(BluetoothSocketResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
BluetoothSocketHALInterface(const btsock_interface_t* aInterface);
|
||||
~BluetoothSocketHALInterface();
|
||||
|
||||
private:
|
||||
const btsock_interface_t* mInterface;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,325 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothSocketMessageWatcher.h"
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include "BluetoothInterface.h"
|
||||
#include "nsClassHashtable.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
//
|
||||
// SocketMessageWatcherWrapper
|
||||
//
|
||||
|
||||
/* |SocketMessageWatcherWrapper| wraps SocketMessageWatcher to keep it from
|
||||
* being released by hash table's Remove() method.
|
||||
*/
|
||||
class SocketMessageWatcherWrapper
|
||||
{
|
||||
public:
|
||||
SocketMessageWatcherWrapper(SocketMessageWatcher* aSocketMessageWatcher)
|
||||
: mSocketMessageWatcher(aSocketMessageWatcher)
|
||||
{
|
||||
MOZ_ASSERT(mSocketMessageWatcher);
|
||||
}
|
||||
|
||||
SocketMessageWatcher* GetSocketMessageWatcher()
|
||||
{
|
||||
return mSocketMessageWatcher;
|
||||
}
|
||||
|
||||
private:
|
||||
SocketMessageWatcher* mSocketMessageWatcher;
|
||||
};
|
||||
|
||||
/* |sWatcherHashTable| maps result handlers to corresponding watchers */
|
||||
static nsClassHashtable<nsRefPtrHashKey<BluetoothSocketResultHandler>,
|
||||
SocketMessageWatcherWrapper>
|
||||
sWatcherHashtable;
|
||||
|
||||
//
|
||||
// SocketMessageWatcher
|
||||
//
|
||||
|
||||
SocketMessageWatcher::SocketMessageWatcher(
|
||||
int aFd, BluetoothSocketResultHandler* aRes)
|
||||
: mFd(aFd)
|
||||
, mClientFd(-1)
|
||||
, mLen(0)
|
||||
, mRes(aRes)
|
||||
{
|
||||
MOZ_ASSERT(mRes);
|
||||
}
|
||||
|
||||
SocketMessageWatcher::~SocketMessageWatcher()
|
||||
{ }
|
||||
|
||||
void
|
||||
SocketMessageWatcher::OnFileCanReadWithoutBlocking(int aFd)
|
||||
{
|
||||
BluetoothStatus status;
|
||||
|
||||
switch (mLen) {
|
||||
case 0:
|
||||
status = RecvMsg1();
|
||||
break;
|
||||
case MSG1_SIZE:
|
||||
status = RecvMsg2();
|
||||
break;
|
||||
default:
|
||||
/* message-size error */
|
||||
status = STATUS_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (IsComplete() || status != STATUS_SUCCESS) {
|
||||
StopWatching();
|
||||
Proceed(status);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SocketMessageWatcher::OnFileCanWriteWithoutBlocking(int aFd)
|
||||
{ }
|
||||
|
||||
void
|
||||
SocketMessageWatcher::Watch()
|
||||
{
|
||||
// add this watcher and its result handler to hash table
|
||||
sWatcherHashtable.Put(mRes, new SocketMessageWatcherWrapper(this));
|
||||
|
||||
MessageLoopForIO::current()->WatchFileDescriptor(
|
||||
mFd,
|
||||
true,
|
||||
MessageLoopForIO::WATCH_READ,
|
||||
&mWatcher,
|
||||
this);
|
||||
}
|
||||
|
||||
void
|
||||
SocketMessageWatcher::StopWatching()
|
||||
{
|
||||
mWatcher.StopWatchingFileDescriptor();
|
||||
|
||||
// remove this watcher and its result handler from hash table
|
||||
sWatcherHashtable.Remove(mRes);
|
||||
}
|
||||
|
||||
bool
|
||||
SocketMessageWatcher::IsComplete() const
|
||||
{
|
||||
return mLen == (MSG1_SIZE + MSG2_SIZE);
|
||||
}
|
||||
|
||||
int
|
||||
SocketMessageWatcher::GetFd() const
|
||||
{
|
||||
return mFd;
|
||||
}
|
||||
|
||||
int32_t
|
||||
SocketMessageWatcher::GetChannel1() const
|
||||
{
|
||||
return ReadInt32(OFF_CHANNEL1);
|
||||
}
|
||||
|
||||
int32_t
|
||||
SocketMessageWatcher::GetSize() const
|
||||
{
|
||||
return ReadInt16(OFF_SIZE);
|
||||
}
|
||||
|
||||
nsString
|
||||
SocketMessageWatcher::GetBdAddress() const
|
||||
{
|
||||
nsString bdAddress;
|
||||
ReadBdAddress(OFF_BDADDRESS, bdAddress);
|
||||
return bdAddress;
|
||||
}
|
||||
|
||||
int32_t
|
||||
SocketMessageWatcher::GetChannel2() const
|
||||
{
|
||||
return ReadInt32(OFF_CHANNEL2);
|
||||
}
|
||||
|
||||
int32_t
|
||||
SocketMessageWatcher::GetConnectionStatus() const
|
||||
{
|
||||
return ReadInt32(OFF_STATUS);
|
||||
}
|
||||
|
||||
int
|
||||
SocketMessageWatcher::GetClientFd() const
|
||||
{
|
||||
return mClientFd;
|
||||
}
|
||||
|
||||
BluetoothSocketResultHandler*
|
||||
SocketMessageWatcher::GetResultHandler() const
|
||||
{
|
||||
return mRes;
|
||||
}
|
||||
|
||||
BluetoothStatus
|
||||
SocketMessageWatcher::RecvMsg1()
|
||||
{
|
||||
struct iovec iv;
|
||||
memset(&iv, 0, sizeof(iv));
|
||||
iv.iov_base = mBuf;
|
||||
iv.iov_len = MSG1_SIZE;
|
||||
|
||||
struct msghdr msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.msg_iov = &iv;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
ssize_t res = TEMP_FAILURE_RETRY(recvmsg(mFd, &msg, MSG_NOSIGNAL));
|
||||
if (res <= 0) {
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
|
||||
mLen += res;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
#define CMSGHDR_CONTAINS_FD(_cmsghdr) \
|
||||
( ((_cmsghdr)->cmsg_level == SOL_SOCKET) && \
|
||||
((_cmsghdr)->cmsg_type == SCM_RIGHTS) )
|
||||
|
||||
BluetoothStatus
|
||||
SocketMessageWatcher::RecvMsg2()
|
||||
{
|
||||
struct iovec iv;
|
||||
memset(&iv, 0, sizeof(iv));
|
||||
iv.iov_base = mBuf + MSG1_SIZE;
|
||||
iv.iov_len = MSG2_SIZE;
|
||||
|
||||
struct msghdr msg;
|
||||
struct cmsghdr cmsgbuf[CMSG_SPACE(sizeof(int))];
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.msg_iov = &iv;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = cmsgbuf;
|
||||
msg.msg_controllen = sizeof(cmsgbuf);
|
||||
|
||||
ssize_t res = TEMP_FAILURE_RETRY(recvmsg(mFd, &msg, MSG_NOSIGNAL));
|
||||
if (res <= 0) {
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
|
||||
mLen += res;
|
||||
|
||||
if (msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) {
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
|
||||
struct cmsghdr *cmsgptr = CMSG_FIRSTHDR(&msg);
|
||||
|
||||
// Extract client fd from message header
|
||||
for (; cmsgptr; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
|
||||
if (CMSGHDR_CONTAINS_FD(cmsgptr)) {
|
||||
// if multiple file descriptors have been sent, we close
|
||||
// all but the final one.
|
||||
if (mClientFd != -1) {
|
||||
TEMP_FAILURE_RETRY(close(mClientFd));
|
||||
}
|
||||
// retrieve sent client fd
|
||||
memcpy(&mClientFd, CMSG_DATA(cmsgptr), sizeof(mClientFd));
|
||||
}
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int16_t
|
||||
SocketMessageWatcher::ReadInt16(unsigned long aOffset) const
|
||||
{
|
||||
/* little-endian buffer */
|
||||
return (static_cast<int16_t>(mBuf[aOffset + 1]) << 8) |
|
||||
static_cast<int16_t>(mBuf[aOffset]);
|
||||
}
|
||||
|
||||
int32_t
|
||||
SocketMessageWatcher::ReadInt32(unsigned long aOffset) const
|
||||
{
|
||||
/* little-endian buffer */
|
||||
return (static_cast<int32_t>(mBuf[aOffset + 3]) << 24) |
|
||||
(static_cast<int32_t>(mBuf[aOffset + 2]) << 16) |
|
||||
(static_cast<int32_t>(mBuf[aOffset + 1]) << 8) |
|
||||
static_cast<int32_t>(mBuf[aOffset]);
|
||||
}
|
||||
|
||||
void
|
||||
SocketMessageWatcher::ReadBdAddress(unsigned long aOffset,
|
||||
nsAString& aBdAddress) const
|
||||
{
|
||||
char str[BLUETOOTH_ADDRESS_LENGTH + 1];
|
||||
|
||||
int res = snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
static_cast<int>(mBuf[aOffset + 0]),
|
||||
static_cast<int>(mBuf[aOffset + 1]),
|
||||
static_cast<int>(mBuf[aOffset + 2]),
|
||||
static_cast<int>(mBuf[aOffset + 3]),
|
||||
static_cast<int>(mBuf[aOffset + 4]),
|
||||
static_cast<int>(mBuf[aOffset + 5]));
|
||||
if (res < 0) {
|
||||
aBdAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
} else if ((size_t)res >= sizeof(str)) { /* string buffer too small */
|
||||
aBdAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
} else {
|
||||
aBdAddress = NS_ConvertUTF8toUTF16(str);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// SocketMessageWatcherTask
|
||||
//
|
||||
|
||||
SocketMessageWatcherTask::SocketMessageWatcherTask(
|
||||
SocketMessageWatcher* aWatcher)
|
||||
: mWatcher(aWatcher)
|
||||
{
|
||||
MOZ_ASSERT(mWatcher);
|
||||
}
|
||||
|
||||
void
|
||||
SocketMessageWatcherTask::Run()
|
||||
{
|
||||
mWatcher->Watch();
|
||||
}
|
||||
|
||||
//
|
||||
// DeleteSocketMessageWatcherTask
|
||||
//
|
||||
|
||||
DeleteSocketMessageWatcherTask::DeleteSocketMessageWatcherTask(
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
: mRes(aRes)
|
||||
{
|
||||
MOZ_ASSERT(mRes);
|
||||
}
|
||||
|
||||
void
|
||||
DeleteSocketMessageWatcherTask::Run()
|
||||
{
|
||||
// look up hash table for the watcher corresponding to |mRes|
|
||||
SocketMessageWatcherWrapper* wrapper = sWatcherHashtable.Get(mRes);
|
||||
if (!wrapper) {
|
||||
return;
|
||||
}
|
||||
|
||||
// stop the watcher if it exists
|
||||
SocketMessageWatcher* watcher = wrapper->GetSocketMessageWatcher();
|
||||
watcher->StopWatching();
|
||||
watcher->Proceed(STATUS_DONE);
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,109 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/message_loop.h"
|
||||
#include "BluetoothCommon.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocketResultHandler;
|
||||
|
||||
/* |SocketMessageWatcher| receives Bluedroid's socket setup
|
||||
* messages on the I/O thread. You need to inherit from this
|
||||
* class to make use of it.
|
||||
*
|
||||
* Bluedroid sends two socket info messages (20 bytes) at
|
||||
* the beginning of a connection to both peers.
|
||||
*
|
||||
* - 1st message: [channel:4]
|
||||
* - 2nd message: [size:2][bd address:6][channel:4][connection status:4]
|
||||
*
|
||||
* On the server side, the second message will contain a
|
||||
* socket file descriptor for the connection. The client
|
||||
* uses the original file descriptor.
|
||||
*/
|
||||
class SocketMessageWatcher : public MessageLoopForIO::Watcher
|
||||
{
|
||||
public:
|
||||
static const unsigned char MSG1_SIZE = 4;
|
||||
static const unsigned char MSG2_SIZE = 16;
|
||||
|
||||
static const unsigned char OFF_CHANNEL1 = 0;
|
||||
static const unsigned char OFF_SIZE = 4;
|
||||
static const unsigned char OFF_BDADDRESS = 6;
|
||||
static const unsigned char OFF_CHANNEL2 = 12;
|
||||
static const unsigned char OFF_STATUS = 16;
|
||||
|
||||
virtual ~SocketMessageWatcher();
|
||||
|
||||
virtual void Proceed(BluetoothStatus aStatus) = 0;
|
||||
|
||||
void OnFileCanReadWithoutBlocking(int aFd) override;
|
||||
void OnFileCanWriteWithoutBlocking(int aFd) override;
|
||||
|
||||
void Watch();
|
||||
void StopWatching();
|
||||
|
||||
bool IsComplete() const;
|
||||
|
||||
int GetFd() const;
|
||||
int32_t GetChannel1() const;
|
||||
int32_t GetSize() const;
|
||||
nsString GetBdAddress() const;
|
||||
int32_t GetChannel2() const;
|
||||
int32_t GetConnectionStatus() const;
|
||||
int GetClientFd() const;
|
||||
|
||||
BluetoothSocketResultHandler* GetResultHandler() const;
|
||||
|
||||
protected:
|
||||
SocketMessageWatcher(int aFd, BluetoothSocketResultHandler* aRes);
|
||||
|
||||
private:
|
||||
BluetoothStatus RecvMsg1();
|
||||
BluetoothStatus RecvMsg2();
|
||||
|
||||
int16_t ReadInt16(unsigned long aOffset) const;
|
||||
int32_t ReadInt32(unsigned long aOffset) const;
|
||||
void ReadBdAddress(unsigned long aOffset, nsAString& aBdAddress) const;
|
||||
|
||||
MessageLoopForIO::FileDescriptorWatcher mWatcher;
|
||||
int mFd;
|
||||
int mClientFd;
|
||||
unsigned char mLen;
|
||||
uint8_t mBuf[MSG1_SIZE + MSG2_SIZE];
|
||||
nsRefPtr<BluetoothSocketResultHandler> mRes;
|
||||
};
|
||||
|
||||
/* |SocketMessageWatcherTask| starts a SocketMessageWatcher
|
||||
* on the I/O task
|
||||
*/
|
||||
class SocketMessageWatcherTask final : public Task
|
||||
{
|
||||
public:
|
||||
SocketMessageWatcherTask(SocketMessageWatcher* aWatcher);
|
||||
|
||||
void Run() override;
|
||||
|
||||
private:
|
||||
SocketMessageWatcher* mWatcher;
|
||||
};
|
||||
|
||||
/* |DeleteSocketMessageWatcherTask| deletes a watching SocketMessageWatcher
|
||||
* on the I/O task
|
||||
*/
|
||||
class DeleteSocketMessageWatcherTask final : public Task
|
||||
{
|
||||
public:
|
||||
DeleteSocketMessageWatcherTask(BluetoothSocketResultHandler* aRes);
|
||||
|
||||
void Run() override;
|
||||
|
||||
private:
|
||||
BluetoothSocketResultHandler* mRes;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef B2G_BDROID_BUILDCFG_H
|
||||
#define B2G_BDROID_BUILDCFG_H
|
||||
|
||||
/**
|
||||
* This header defines B2G common bluedroid build configuration.
|
||||
*
|
||||
* This header is included by
|
||||
* $(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR)/bdroid_buildcfg.h,
|
||||
* which applies external configuration onto bluedroid.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
**
|
||||
** HSP, HFP
|
||||
**
|
||||
******************************************************************************/
|
||||
/* AG feature masks */
|
||||
#define BTIF_HF_FEATURES ( BTA_AG_FEAT_3WAY | \
|
||||
BTA_AG_FEAT_REJECT | \
|
||||
BTA_AG_FEAT_ECS | \
|
||||
BTA_AG_FEAT_EXTERR)
|
||||
|
||||
/* CHLD values */
|
||||
#define BTA_AG_CHLD_VAL "(0,1,2,3)"
|
||||
|
||||
/* BLE Feature */
|
||||
#define BTA_GATT_INCLUDED TRUE
|
||||
#define BLE_INCLUDED TRUE
|
||||
#define SMP_INCLUDED TRUE
|
||||
|
||||
#endif /* B2G_BDROID_BUILDCFG_H */
|
|
@ -1,223 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothHfpManager.h"
|
||||
#include "BluetoothProfileController.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
namespace {
|
||||
StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
|
||||
bool sInShutdown = false;
|
||||
} // anonymous namespace
|
||||
|
||||
/**
|
||||
* nsIObserver function
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
BluetoothHfpManager::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
HandleShutdown();
|
||||
} else {
|
||||
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* BluetoothProfileManagerBase functions
|
||||
*/
|
||||
void
|
||||
BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||
BluetoothProfileController* aController)
|
||||
{
|
||||
MOZ_ASSERT(aController);
|
||||
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
|
||||
{
|
||||
MOZ_ASSERT(aController);
|
||||
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::IsConnected()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
|
||||
{
|
||||
aDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
|
||||
const nsAString& aServiceUuid,
|
||||
int aChannel)
|
||||
{
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
|
||||
{
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* BluetoothHfpManagerBase function
|
||||
*/
|
||||
bool
|
||||
BluetoothHfpManager::IsScoConnected()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-inherited functions
|
||||
*/
|
||||
// static
|
||||
BluetoothHfpManager*
|
||||
BluetoothHfpManager::Get()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// If sBluetoothHfpManager already exists, exit early
|
||||
if (sBluetoothHfpManager) {
|
||||
return sBluetoothHfpManager;
|
||||
}
|
||||
|
||||
// If we're in shutdown, don't create a new instance
|
||||
NS_ENSURE_FALSE(sInShutdown, nullptr);
|
||||
|
||||
// Create a new instance and return
|
||||
BluetoothHfpManager* manager = new BluetoothHfpManager();
|
||||
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||
|
||||
sBluetoothHfpManager = manager;
|
||||
return sBluetoothHfpManager;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::Init()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE(obs, false);
|
||||
|
||||
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
||||
BT_WARNING("Failed to add observers!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
BluetoothHfpManager::InitHfpInterface(BluetoothProfileResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* Implement InitHfpInterface() for applications that want to create SCO
|
||||
* link without a HFP connection (e.g., VoIP).
|
||||
*/
|
||||
|
||||
if (aRes) {
|
||||
aRes->Init();
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
BluetoothHfpManager::DeinitHfpInterface(BluetoothProfileResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* Implement DeinitHfpInterface() for applications that want to create SCO
|
||||
* link without a HFP connection (e.g., VoIP).
|
||||
*/
|
||||
|
||||
if (aRes) {
|
||||
aRes->Deinit();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::HandleShutdown()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
sInShutdown = true;
|
||||
sBluetoothHfpManager = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::ConnectSco()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* Implement ConnectSco() for applications that want to create SCO link
|
||||
* without a HFP connection (e.g., VoIP).
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::DisconnectSco()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* Implement DisconnectSco() for applications that want to destroy SCO link
|
||||
* without a HFP connection (e.g., VoIP).
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::Reset()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)
|
|
@ -1,47 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||
#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||
|
||||
#include "BluetoothHfpManagerBase.h"
|
||||
|
||||
/**
|
||||
* Fallback BluetoothHfpManager is built for non-phone devices (e.g., tablets).
|
||||
* These devices has no radio interface and the build flag MOZ_B2G_RIL is
|
||||
* disabled. To prevent build breaks of accessing radio interface, we implement
|
||||
* fallback BluetoothHfpManager with empty functions to keep original
|
||||
* BluetoothHfpManager away from numerous #ifdef/#endif statements.
|
||||
*/
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothHfpManager : public BluetoothHfpManagerBase
|
||||
{
|
||||
public:
|
||||
BT_DECL_HFP_MGR_BASE
|
||||
virtual void GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("Fallback HFP/HSP");
|
||||
}
|
||||
|
||||
static BluetoothHfpManager* Get();
|
||||
virtual ~BluetoothHfpManager() { }
|
||||
static void InitHfpInterface(BluetoothProfileResultHandler* aRes);
|
||||
static void DeinitHfpInterface(BluetoothProfileResultHandler* aRes);
|
||||
|
||||
bool ConnectSco();
|
||||
bool DisconnectSco();
|
||||
|
||||
private:
|
||||
BluetoothHfpManager() { }
|
||||
bool Init();
|
||||
void HandleShutdown();
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,216 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||
#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||
|
||||
#include "BluetoothInterface.h"
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothHfpManagerBase.h"
|
||||
#include "BluetoothRilListener.h"
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
#include "mozilla/Hal.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothSocket;
|
||||
class Call;
|
||||
|
||||
/**
|
||||
* These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
|
||||
* and 3GPP 27.007" in Bluetooth hands-free profile 1.6
|
||||
*/
|
||||
enum BluetoothCmeError {
|
||||
AG_FAILURE = 0,
|
||||
NO_CONNECTION_TO_PHONE = 1,
|
||||
OPERATION_NOT_ALLOWED = 3,
|
||||
OPERATION_NOT_SUPPORTED = 4,
|
||||
PIN_REQUIRED = 5,
|
||||
SIM_NOT_INSERTED = 10,
|
||||
SIM_PIN_REQUIRED = 11,
|
||||
SIM_PUK_REQUIRED = 12,
|
||||
SIM_FAILURE = 13,
|
||||
SIM_BUSY = 14,
|
||||
INCORRECT_PASSWORD = 16,
|
||||
SIM_PIN2_REQUIRED = 17,
|
||||
SIM_PUK2_REQUIRED = 18,
|
||||
MEMORY_FULL = 20,
|
||||
INVALID_INDEX = 21,
|
||||
MEMORY_FAILURE = 23,
|
||||
TEXT_STRING_TOO_LONG = 24,
|
||||
INVALID_CHARACTERS_IN_TEXT_STRING = 25,
|
||||
DIAL_STRING_TOO_LONG = 26,
|
||||
INVALID_CHARACTERS_IN_DIAL_STRING = 27,
|
||||
NO_NETWORK_SERVICE = 30,
|
||||
NETWORK_TIMEOUT = 31,
|
||||
NETWORK_NOT_ALLOWED = 32
|
||||
};
|
||||
|
||||
enum PhoneType {
|
||||
NONE, // no connection
|
||||
GSM,
|
||||
CDMA
|
||||
};
|
||||
|
||||
class Call {
|
||||
public:
|
||||
Call();
|
||||
void Set(const nsAString& aNumber, const bool aIsOutgoing);
|
||||
void Reset();
|
||||
bool IsActive();
|
||||
|
||||
uint16_t mState;
|
||||
nsString mNumber;
|
||||
BluetoothHandsfreeCallDirection mDirection;
|
||||
BluetoothHandsfreeCallAddressType mType;
|
||||
};
|
||||
|
||||
class BluetoothHfpManager : public BluetoothHfpManagerBase
|
||||
, public BluetoothHandsfreeNotificationHandler
|
||||
, public BatteryObserver
|
||||
{
|
||||
public:
|
||||
BT_DECL_HFP_MGR_BASE
|
||||
|
||||
void OnConnectError();
|
||||
void OnDisconnectError();
|
||||
|
||||
virtual void GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("HFP/HSP");
|
||||
}
|
||||
|
||||
static BluetoothHfpManager* Get();
|
||||
virtual ~BluetoothHfpManager();
|
||||
static void InitHfpInterface(BluetoothProfileResultHandler* aRes);
|
||||
static void DeinitHfpInterface(BluetoothProfileResultHandler* aRes);
|
||||
|
||||
bool ConnectSco();
|
||||
bool DisconnectSco();
|
||||
|
||||
/**
|
||||
* @param aSend A boolean indicates whether we need to notify headset or not
|
||||
*/
|
||||
void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
|
||||
const nsAString& aError, const nsAString& aNumber,
|
||||
const bool aIsOutgoing, const bool aIsConference,
|
||||
bool aSend);
|
||||
void HandleIccInfoChanged(uint32_t aClientId);
|
||||
void HandleVoiceConnectionChanged(uint32_t aClientId);
|
||||
|
||||
// CDMA-specific functions
|
||||
void UpdateSecondNumber(const nsAString& aNumber);
|
||||
void AnswerWaitingCall();
|
||||
void IgnoreWaitingCall();
|
||||
void ToggleCalls();
|
||||
|
||||
//
|
||||
// Bluetooth notifications
|
||||
//
|
||||
|
||||
void ConnectionStateNotification(BluetoothHandsfreeConnectionState aState,
|
||||
const nsAString& aBdAddress) override;
|
||||
void AudioStateNotification(BluetoothHandsfreeAudioState aState,
|
||||
const nsAString& aBdAddress) override;
|
||||
void AnswerCallNotification() override;
|
||||
void HangupCallNotification() override;
|
||||
void VolumeNotification(BluetoothHandsfreeVolumeType aType,
|
||||
int aVolume) override;
|
||||
void DtmfNotification(char aDtmf) override;
|
||||
void CallHoldNotification(BluetoothHandsfreeCallHoldType aChld) override;
|
||||
void DialCallNotification(const nsAString& aNumber) override;
|
||||
void CnumNotification() override;
|
||||
void CindNotification() override;
|
||||
void CopsNotification() override;
|
||||
void ClccNotification() override;
|
||||
void UnknownAtNotification(const nsACString& aAtString) override;
|
||||
void KeyPressedNotification() override;
|
||||
|
||||
private:
|
||||
class AtResponseResultHandler;
|
||||
class GetVolumeTask;
|
||||
class CindResponseResultHandler;
|
||||
class ClccResponseResultHandler;
|
||||
class CleanupResultHandler;
|
||||
class CleanupInitResultHandler;
|
||||
class CloseScoTask;
|
||||
class CloseScoRunnable;
|
||||
class ConnectAudioResultHandler;
|
||||
class ConnectResultHandler;
|
||||
class CopsResponseResultHandler;
|
||||
class DeinitResultHandlerRunnable;
|
||||
class DeviceStatusNotificationResultHandler;
|
||||
class DisconnectAudioResultHandler;
|
||||
class DisconnectResultHandler;
|
||||
class FormattedAtResponseResultHandler;
|
||||
class InitResultHandlerRunnable;
|
||||
class OnErrorProfileResultHandlerRunnable;
|
||||
class PhoneStateChangeResultHandler;
|
||||
class RespondToBLDNTask;
|
||||
class VolumeControlResultHandler;
|
||||
|
||||
friend class BluetoothHfpManagerObserver;
|
||||
friend class GetVolumeTask;
|
||||
friend class CloseScoTask;
|
||||
friend class RespondToBLDNTask;
|
||||
friend class MainThreadTask;
|
||||
|
||||
BluetoothHfpManager();
|
||||
bool Init();
|
||||
|
||||
void HandleShutdown();
|
||||
void HandleVolumeChanged(nsISupports* aSubject);
|
||||
void Notify(const hal::BatteryInformation& aBatteryInfo);
|
||||
|
||||
void NotifyConnectionStateChanged(const nsAString& aType);
|
||||
void NotifyDialer(const nsAString& aCommand);
|
||||
|
||||
PhoneType GetPhoneType(const nsAString& aType);
|
||||
void ResetCallArray();
|
||||
uint32_t FindFirstCall(uint16_t aState);
|
||||
uint32_t GetNumberOfCalls(uint16_t aState);
|
||||
uint16_t GetCallSetupState();
|
||||
bool IsTransitionState(uint16_t aCallState, bool aIsConference);
|
||||
BluetoothHandsfreeCallState
|
||||
ConvertToBluetoothHandsfreeCallState(int aCallState) const;
|
||||
|
||||
void UpdatePhoneCIND(uint32_t aCallIndex);
|
||||
void UpdateDeviceCIND();
|
||||
void SendCLCC(Call& aCall, int aIndex);
|
||||
void SendLine(const char* aMessage);
|
||||
void SendResponse(BluetoothHandsfreeAtResponse aResponseCode);
|
||||
|
||||
BluetoothHandsfreeConnectionState mConnectionState;
|
||||
BluetoothHandsfreeConnectionState mPrevConnectionState;
|
||||
BluetoothHandsfreeAudioState mAudioState;
|
||||
// Device CIND
|
||||
int mBattChg;
|
||||
BluetoothHandsfreeNetworkState mService;
|
||||
BluetoothHandsfreeServiceType mRoam;
|
||||
int mSignal;
|
||||
|
||||
int mCurrentVgs;
|
||||
int mCurrentVgm;
|
||||
bool mReceiveVgsFlag;
|
||||
bool mDialingRequestProcessed;
|
||||
PhoneType mPhoneType;
|
||||
nsString mDeviceAddress;
|
||||
nsString mMsisdn;
|
||||
nsString mOperatorName;
|
||||
|
||||
nsTArray<Call> mCurrentCallArray;
|
||||
nsAutoPtr<BluetoothRilListener> mListener;
|
||||
nsRefPtr<BluetoothProfileController> mController;
|
||||
|
||||
// CDMA-specific variable
|
||||
Call mCdmaSecondCall;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,477 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothA2dpManager.h"
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothSocket.h"
|
||||
#include "BluetoothUtils.h"
|
||||
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "MainThreadUtils.h"
|
||||
|
||||
|
||||
using namespace mozilla;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
namespace {
|
||||
StaticRefPtr<BluetoothA2dpManager> sBluetoothA2dpManager;
|
||||
bool sInShutdown = false;
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothA2dpManager::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
MOZ_ASSERT(sBluetoothA2dpManager);
|
||||
|
||||
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
HandleShutdown();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false, "BluetoothA2dpManager got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
BluetoothA2dpManager::BluetoothA2dpManager()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::Reset()
|
||||
{
|
||||
ResetA2dp();
|
||||
ResetAvrcp();
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothA2dpManager::Init()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE(obs, false);
|
||||
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
||||
BT_WARNING("Failed to add shutdown observer!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BluetoothA2dpManager::~BluetoothA2dpManager()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE_VOID(obs);
|
||||
if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
|
||||
BT_WARNING("Failed to remove shutdown observer!");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::ResetA2dp()
|
||||
{
|
||||
mA2dpConnected = false;
|
||||
mSinkState = SinkState::SINK_DISCONNECTED;
|
||||
mController = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::ResetAvrcp()
|
||||
{
|
||||
mAvrcpConnected = false;
|
||||
mDuration = 0;
|
||||
mMediaNumber = 0;
|
||||
mTotalMediaCount = 0;
|
||||
mPosition = 0;
|
||||
mPlayStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
|
||||
}
|
||||
|
||||
static BluetoothA2dpManager::SinkState
|
||||
StatusStringToSinkState(const nsAString& aStatus)
|
||||
{
|
||||
BluetoothA2dpManager::SinkState state =
|
||||
BluetoothA2dpManager::SinkState::SINK_UNKNOWN;
|
||||
if (aStatus.EqualsLiteral("disconnected")) {
|
||||
state = BluetoothA2dpManager::SinkState::SINK_DISCONNECTED;
|
||||
} else if (aStatus.EqualsLiteral("connecting")) {
|
||||
state = BluetoothA2dpManager::SinkState::SINK_CONNECTING;
|
||||
} else if (aStatus.EqualsLiteral("connected")) {
|
||||
state = BluetoothA2dpManager::SinkState::SINK_CONNECTED;
|
||||
} else if (aStatus.EqualsLiteral("playing")) {
|
||||
state = BluetoothA2dpManager::SinkState::SINK_PLAYING;
|
||||
} else {
|
||||
BT_WARNING("Unknown sink state");
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
//static
|
||||
BluetoothA2dpManager*
|
||||
BluetoothA2dpManager::Get()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// If sBluetoothA2dpManager already exists, exit early
|
||||
if (sBluetoothA2dpManager) {
|
||||
return sBluetoothA2dpManager;
|
||||
}
|
||||
|
||||
// If we're in shutdown, don't create a new instance
|
||||
NS_ENSURE_FALSE(sInShutdown, nullptr);
|
||||
|
||||
// Create a new instance, register, and return
|
||||
BluetoothA2dpManager* manager = new BluetoothA2dpManager();
|
||||
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||
|
||||
sBluetoothA2dpManager = manager;
|
||||
return sBluetoothA2dpManager;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::HandleShutdown()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
sInShutdown = true;
|
||||
Disconnect(nullptr);
|
||||
sBluetoothA2dpManager = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
|
||||
BluetoothProfileController* aController)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
|
||||
MOZ_ASSERT(aController && !mController);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs || sInShutdown) {
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mA2dpConnected) {
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
return;
|
||||
}
|
||||
|
||||
mDeviceAddress = aDeviceAddress;
|
||||
mController = aController;
|
||||
|
||||
if (NS_FAILED(bs->SendSinkMessage(aDeviceAddress,
|
||||
NS_LITERAL_STRING("Connect")))) {
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
|
||||
{
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
if (aController) {
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mA2dpConnected) {
|
||||
if (aController) {
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!mDeviceAddress.IsEmpty());
|
||||
MOZ_ASSERT(!mController);
|
||||
|
||||
mController = aController;
|
||||
|
||||
if (NS_FAILED(bs->SendSinkMessage(mDeviceAddress,
|
||||
NS_LITERAL_STRING("Disconnect")))) {
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::OnConnect(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/**
|
||||
* On the one hand, notify the controller that we've done for outbound
|
||||
* connections. On the other hand, we do nothing for inbound connections.
|
||||
*/
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
/**
|
||||
* On the one hand, notify the controller that we've done for outbound
|
||||
* connections. On the other hand, we do nothing for inbound connections.
|
||||
*/
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
/* HandleSinkPropertyChanged update sink state in A2dp
|
||||
*
|
||||
* Possible values: "disconnected", "connecting", "connected", "playing"
|
||||
*
|
||||
* 1. "disconnected" -> "connecting"
|
||||
* Either an incoming or outgoing connection attempt ongoing
|
||||
* 2. "connecting" -> "disconnected"
|
||||
* Connection attempt failed
|
||||
* 3. "connecting" -> "connected"
|
||||
* Successfully connected
|
||||
* 4. "connected" -> "playing"
|
||||
* Audio stream active
|
||||
* 5. "playing" -> "connected"
|
||||
* Audio stream suspended
|
||||
* 6. "connected" -> "disconnected"
|
||||
* "playing" -> "disconnected"
|
||||
* Disconnected from local or the remote device
|
||||
*/
|
||||
void
|
||||
BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aSignal.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue);
|
||||
|
||||
const nsString& address = aSignal.path();
|
||||
/**
|
||||
* Update sink property only if
|
||||
* - mDeviceAddress is empty (A2dp is disconnected), or
|
||||
* - this property change is from the connected sink.
|
||||
*/
|
||||
NS_ENSURE_TRUE_VOID(mDeviceAddress.IsEmpty() ||
|
||||
mDeviceAddress.Equals(address));
|
||||
|
||||
const InfallibleTArray<BluetoothNamedValue>& arr =
|
||||
aSignal.value().get_ArrayOfBluetoothNamedValue();
|
||||
MOZ_ASSERT(arr.Length() == 1);
|
||||
|
||||
/**
|
||||
* There are three properties:
|
||||
* - "State": a string
|
||||
* - "Connected": a boolean value
|
||||
* - "Playing": a boolean value
|
||||
*
|
||||
* Note that only "State" is handled in this function.
|
||||
*/
|
||||
|
||||
const nsString& name = arr[0].name();
|
||||
NS_ENSURE_TRUE_VOID(name.EqualsLiteral("State"));
|
||||
|
||||
const BluetoothValue& value = arr[0].value();
|
||||
MOZ_ASSERT(value.type() == BluetoothValue::TnsString);
|
||||
SinkState newState = StatusStringToSinkState(value.get_nsString());
|
||||
NS_ENSURE_TRUE_VOID((newState != SinkState::SINK_UNKNOWN) &&
|
||||
(newState != mSinkState));
|
||||
|
||||
/**
|
||||
* Reject 'connected' state change if bluetooth is already disabled.
|
||||
* Sink state would be reset to 'disconnected' when bluetooth is disabled.
|
||||
*
|
||||
* See bug 984284 for more information about the edge case.
|
||||
*/
|
||||
NS_ENSURE_FALSE_VOID(newState == SinkState::SINK_CONNECTED &&
|
||||
mSinkState == SinkState::SINK_DISCONNECTED);
|
||||
|
||||
SinkState prevState = mSinkState;
|
||||
mSinkState = newState;
|
||||
|
||||
switch(mSinkState) {
|
||||
case SinkState::SINK_CONNECTING:
|
||||
// case 1: Either an incoming or outgoing connection attempt ongoing
|
||||
MOZ_ASSERT(prevState == SinkState::SINK_DISCONNECTED);
|
||||
break;
|
||||
case SinkState::SINK_PLAYING:
|
||||
// case 4: Audio stream active
|
||||
MOZ_ASSERT(prevState == SinkState::SINK_CONNECTED);
|
||||
break;
|
||||
case SinkState::SINK_CONNECTED:
|
||||
// case 5: Audio stream suspended
|
||||
if (prevState == SinkState::SINK_PLAYING) {
|
||||
break;
|
||||
}
|
||||
|
||||
// case 3: Successfully connected
|
||||
MOZ_ASSERT(prevState == SinkState::SINK_CONNECTING);
|
||||
|
||||
mA2dpConnected = true;
|
||||
mDeviceAddress = address;
|
||||
NotifyConnectionStatusChanged();
|
||||
|
||||
OnConnect(EmptyString());
|
||||
break;
|
||||
case SinkState::SINK_DISCONNECTED:
|
||||
// case 2: Connection attempt failed
|
||||
if (prevState == SinkState::SINK_CONNECTING) {
|
||||
OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
|
||||
break;
|
||||
}
|
||||
|
||||
// case 6: Disconnected from the remote device
|
||||
MOZ_ASSERT(prevState == SinkState::SINK_CONNECTED ||
|
||||
prevState == SinkState::SINK_PLAYING);
|
||||
|
||||
mA2dpConnected = false;
|
||||
NotifyConnectionStatusChanged();
|
||||
mDeviceAddress.Truncate();
|
||||
OnDisconnect(EmptyString());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::NotifyConnectionStatusChanged()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Notify Gecko observers
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE_VOID(obs);
|
||||
|
||||
if (NS_FAILED(obs->NotifyObservers(this,
|
||||
BLUETOOTH_A2DP_STATUS_CHANGED_ID,
|
||||
mDeviceAddress.get()))) {
|
||||
BT_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
|
||||
}
|
||||
|
||||
// Dispatch an event of status change
|
||||
DispatchStatusChangedEvent(
|
||||
NS_LITERAL_STRING(A2DP_STATUS_CHANGED_ID), mDeviceAddress, mA2dpConnected);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
|
||||
const nsAString& aServiceUuid,
|
||||
int aChannel)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::GetAddress(nsAString& aDeviceAddress)
|
||||
{
|
||||
aDeviceAddress = mDeviceAddress;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothA2dpManager::IsConnected()
|
||||
{
|
||||
return mA2dpConnected;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::SetAvrcpConnected(bool aConnected)
|
||||
{
|
||||
mAvrcpConnected = aConnected;
|
||||
if (!aConnected) {
|
||||
ResetAvrcp();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothA2dpManager::IsAvrcpConnected()
|
||||
{
|
||||
return mAvrcpConnected;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::UpdateMetaData(const nsAString& aTitle,
|
||||
const nsAString& aArtist,
|
||||
const nsAString& aAlbum,
|
||||
uint64_t aMediaNumber,
|
||||
uint64_t aTotalMediaCount,
|
||||
uint32_t aDuration)
|
||||
{
|
||||
mTitle.Assign(aTitle);
|
||||
mArtist.Assign(aArtist);
|
||||
mAlbum.Assign(aAlbum);
|
||||
mMediaNumber = aMediaNumber;
|
||||
mTotalMediaCount = aTotalMediaCount;
|
||||
mDuration = aDuration;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::UpdatePlayStatus(uint32_t aDuration,
|
||||
uint32_t aPosition,
|
||||
ControlPlayStatus aPlayStatus)
|
||||
{
|
||||
mDuration = aDuration;
|
||||
mPosition = aPosition;
|
||||
mPlayStatus = aPlayStatus;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::GetAlbum(nsAString& aAlbum)
|
||||
{
|
||||
aAlbum.Assign(mAlbum);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
BluetoothA2dpManager::GetDuration()
|
||||
{
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
ControlPlayStatus
|
||||
BluetoothA2dpManager::GetPlayStatus()
|
||||
{
|
||||
return mPlayStatus;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
BluetoothA2dpManager::GetPosition()
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
BluetoothA2dpManager::GetMediaNumber()
|
||||
{
|
||||
return mMediaNumber;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothA2dpManager::GetTitle(nsAString& aTitle)
|
||||
{
|
||||
aTitle.Assign(mTitle);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(BluetoothA2dpManager, nsIObserver)
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetootha2dpmanager_h__
|
||||
#define mozilla_dom_bluetooth_bluetootha2dpmanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothProfileController.h"
|
||||
#include "BluetoothProfileManagerBase.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothA2dpManager : public BluetoothProfileManagerBase
|
||||
{
|
||||
public:
|
||||
BT_DECL_PROFILE_MGR_BASE
|
||||
virtual void GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("A2DP");
|
||||
}
|
||||
|
||||
enum SinkState {
|
||||
SINK_UNKNOWN,
|
||||
SINK_DISCONNECTED,
|
||||
SINK_CONNECTING,
|
||||
SINK_CONNECTED,
|
||||
SINK_PLAYING,
|
||||
};
|
||||
|
||||
static BluetoothA2dpManager* Get();
|
||||
virtual ~BluetoothA2dpManager();
|
||||
|
||||
// A2DP-specific functions
|
||||
void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
|
||||
|
||||
// AVRCP-specific functions
|
||||
void SetAvrcpConnected(bool aConnected);
|
||||
bool IsAvrcpConnected();
|
||||
void UpdateMetaData(const nsAString& aTitle,
|
||||
const nsAString& aArtist,
|
||||
const nsAString& aAlbum,
|
||||
uint64_t aMediaNumber,
|
||||
uint64_t aTotalMediaCount,
|
||||
uint32_t aDuration);
|
||||
void UpdatePlayStatus(uint32_t aDuration,
|
||||
uint32_t aPosition,
|
||||
ControlPlayStatus aPlayStatus);
|
||||
void GetAlbum(nsAString& aAlbum);
|
||||
uint32_t GetDuration();
|
||||
ControlPlayStatus GetPlayStatus();
|
||||
uint32_t GetPosition();
|
||||
uint64_t GetMediaNumber();
|
||||
void GetTitle(nsAString& aTitle);
|
||||
|
||||
private:
|
||||
BluetoothA2dpManager();
|
||||
bool Init();
|
||||
void ResetA2dp();
|
||||
void ResetAvrcp();
|
||||
|
||||
void HandleShutdown();
|
||||
void NotifyConnectionStatusChanged();
|
||||
|
||||
nsString mDeviceAddress;
|
||||
nsRefPtr<BluetoothProfileController> mController;
|
||||
|
||||
// A2DP data member
|
||||
bool mA2dpConnected;
|
||||
SinkState mSinkState;
|
||||
|
||||
// AVRCP data member
|
||||
bool mAvrcpConnected;
|
||||
nsString mAlbum;
|
||||
nsString mArtist;
|
||||
nsString mTitle;
|
||||
uint32_t mDuration;
|
||||
uint64_t mMediaNumber;
|
||||
uint64_t mTotalMediaCount;
|
||||
uint32_t mPosition;
|
||||
ControlPlayStatus mPlayStatus;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,262 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothdbusservice_h__
|
||||
#define mozilla_dom_bluetooth_bluetoothdbusservice_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ipc/RawDBusConnection.h"
|
||||
#include "nsIThread.h"
|
||||
|
||||
class DBusMessage;
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
/**
|
||||
* BluetoothDBusService is the implementation of BluetoothService for DBus on
|
||||
* linux/android/B2G. Function comments are in BluetoothService.h
|
||||
*/
|
||||
|
||||
class BluetoothDBusService : public BluetoothService
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* For DBus Control method of "UpdateNotification", event id should be
|
||||
* specified as following:
|
||||
* (Please see specification of AVRCP 1.3, Table 5.28 for more details.)
|
||||
*/
|
||||
enum ControlEventId {
|
||||
EVENT_PLAYBACK_STATUS_CHANGED = 0x01,
|
||||
EVENT_TRACK_CHANGED = 0x02,
|
||||
EVENT_TRACK_REACHED_END = 0x03,
|
||||
EVENT_TRACK_REACHED_START = 0x04,
|
||||
EVENT_PLAYBACK_POS_CHANGED = 0x05,
|
||||
EVENT_BATT_STATUS_CHANGED = 0x06,
|
||||
EVENT_SYSTEM_STATUS_CHANGED = 0x07,
|
||||
EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08,
|
||||
EVENT_UNKNOWN
|
||||
};
|
||||
|
||||
BluetoothDBusService();
|
||||
~BluetoothDBusService();
|
||||
|
||||
bool IsReady();
|
||||
|
||||
virtual nsresult StartInternal(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult StopInternal(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult
|
||||
GetAdaptersInternal(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult
|
||||
GetConnectedDevicePropertiesInternal(uint16_t aServiceUuid,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult
|
||||
GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult
|
||||
FetchUuidsInternal(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult
|
||||
SetProperty(BluetoothObjectType aType,
|
||||
const BluetoothNamedValue& aValue,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult
|
||||
GetServiceChannel(const nsAString& aDeviceAddress,
|
||||
const nsAString& aServiceUuid,
|
||||
BluetoothProfileManagerBase* aManager) override;
|
||||
|
||||
virtual bool
|
||||
UpdateSdpRecords(const nsAString& aDeviceAddress,
|
||||
BluetoothProfileManagerBase* aManager) override;
|
||||
|
||||
virtual nsresult
|
||||
CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
|
||||
int aTimeout,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual nsresult
|
||||
RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
PinReplyInternal(const nsAString& aDeviceAddress,
|
||||
bool aAccept,
|
||||
const nsAString& aPinCode,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
|
||||
virtual void
|
||||
SspReplyInternal(const nsAString& aDeviceAddress,
|
||||
BluetoothSspVariant aVariant,
|
||||
bool aAccept,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
|
||||
virtual void
|
||||
SetPinCodeInternal(const nsAString& aDeviceAddress,
|
||||
const nsAString& aPinCode,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
|
||||
bool aConfirm,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
Connect(const nsAString& aDeviceAddress,
|
||||
uint32_t aCod,
|
||||
uint16_t aServiceUuid,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual bool
|
||||
IsConnected(uint16_t aServiceUuid) override;
|
||||
|
||||
virtual void
|
||||
Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
BlobParent* aBlobParent,
|
||||
BlobChild* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
ConnectSco(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
DisconnectSco(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
IsScoConnected(BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
#ifdef MOZ_B2G_RIL
|
||||
virtual void
|
||||
AnswerWaitingCall(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual void
|
||||
ToggleCalls(BluetoothReplyRunnable* aRunnable);
|
||||
#endif
|
||||
|
||||
virtual void
|
||||
SendMetaData(const nsAString& aTitle,
|
||||
const nsAString& aArtist,
|
||||
const nsAString& aAlbum,
|
||||
int64_t aMediaNumber,
|
||||
int64_t aTotalMediaCount,
|
||||
int64_t aDuration,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
SendPlayStatus(int64_t aDuration,
|
||||
int64_t aPosition,
|
||||
const nsAString& aPlayStatus,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
UpdatePlayStatus(uint32_t aDuration,
|
||||
uint32_t aPosition,
|
||||
ControlPlayStatus aPlayStatus) override;
|
||||
|
||||
virtual nsresult
|
||||
SendSinkMessage(const nsAString& aDeviceAddresses,
|
||||
const nsAString& aMessage) override;
|
||||
|
||||
virtual nsresult
|
||||
SendInputMessage(const nsAString& aDeviceAddresses,
|
||||
const nsAString& aMessage) override;
|
||||
|
||||
virtual void
|
||||
ConnectGattClientInternal(const nsAString& aAppUuid,
|
||||
const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
DisconnectGattClientInternal(const nsAString& aAppUuid,
|
||||
const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
DiscoverGattServicesInternal(const nsAString& aAppUuid,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
GattClientStartNotificationsInternal(
|
||||
const nsAString& aAppUuid,
|
||||
const BluetoothGattServiceId& aServId,
|
||||
const BluetoothGattId& aCharId,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
GattClientStopNotificationsInternal(
|
||||
const nsAString& aAppUuid,
|
||||
const BluetoothGattServiceId& aServId,
|
||||
const BluetoothGattId& aCharId,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
UnregisterGattClientInternal(int aClientIf,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
virtual void
|
||||
GattClientReadRemoteRssiInternal(
|
||||
int aClientIf, const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) override;
|
||||
|
||||
private:
|
||||
nsresult SendGetPropertyMessage(const nsAString& aPath,
|
||||
const char* aInterface,
|
||||
void (*aCB)(DBusMessage *, void *),
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
nsresult SendDiscoveryMessage(const char* aMessageName,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
nsresult SendSetPropertyMessage(const char* aInterface,
|
||||
const BluetoothNamedValue& aValue,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
void UpdateNotification(ControlEventId aEventId, uint64_t aData);
|
||||
|
||||
nsresult SendAsyncDBusMessage(const nsAString& aObjectPath,
|
||||
const char* aInterface,
|
||||
const nsAString& aMessage,
|
||||
mozilla::ipc::DBusReplyCallback aCallback);
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,238 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||
#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothHfpManagerBase.h"
|
||||
#ifdef MOZ_B2G_RIL
|
||||
#include "BluetoothRilListener.h"
|
||||
#endif
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
#include "mozilla/Hal.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothSocket;
|
||||
|
||||
#ifdef MOZ_B2G_RIL
|
||||
class Call;
|
||||
|
||||
/**
|
||||
* These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
|
||||
* and 3GPP 27.007" in Bluetooth hands-free profile 1.6
|
||||
*/
|
||||
enum BluetoothCmeError {
|
||||
AG_FAILURE = 0,
|
||||
NO_CONNECTION_TO_PHONE = 1,
|
||||
OPERATION_NOT_ALLOWED = 3,
|
||||
OPERATION_NOT_SUPPORTED = 4,
|
||||
PIN_REQUIRED = 5,
|
||||
SIM_NOT_INSERTED = 10,
|
||||
SIM_PIN_REQUIRED = 11,
|
||||
SIM_PUK_REQUIRED = 12,
|
||||
SIM_FAILURE = 13,
|
||||
SIM_BUSY = 14,
|
||||
INCORRECT_PASSWORD = 16,
|
||||
SIM_PIN2_REQUIRED = 17,
|
||||
SIM_PUK2_REQUIRED = 18,
|
||||
MEMORY_FULL = 20,
|
||||
INVALID_INDEX = 21,
|
||||
MEMORY_FAILURE = 23,
|
||||
TEXT_STRING_TOO_LONG = 24,
|
||||
INVALID_CHARACTERS_IN_TEXT_STRING = 25,
|
||||
DIAL_STRING_TOO_LONG = 26,
|
||||
INVALID_CHARACTERS_IN_DIAL_STRING = 27,
|
||||
NO_NETWORK_SERVICE = 30,
|
||||
NETWORK_TIMEOUT = 31,
|
||||
NETWORK_NOT_ALLOWED = 32
|
||||
};
|
||||
|
||||
enum PhoneType {
|
||||
NONE, // no connection
|
||||
GSM,
|
||||
CDMA
|
||||
};
|
||||
|
||||
class Call {
|
||||
public:
|
||||
Call();
|
||||
void Reset();
|
||||
bool IsActive();
|
||||
|
||||
uint16_t mState;
|
||||
bool mDirection; // true: incoming call; false: outgoing call
|
||||
bool mIsConference;
|
||||
nsString mNumber;
|
||||
int mType;
|
||||
};
|
||||
#endif // MOZ_B2G_RIL
|
||||
|
||||
class BluetoothHfpManager : public BluetoothSocketObserver
|
||||
, public BluetoothHfpManagerBase
|
||||
, public BatteryObserver
|
||||
{
|
||||
public:
|
||||
BT_DECL_HFP_MGR_BASE
|
||||
virtual void GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("HFP/HSP");
|
||||
}
|
||||
|
||||
static BluetoothHfpManager* Get();
|
||||
~BluetoothHfpManager();
|
||||
|
||||
// The following functions are inherited from BluetoothSocketObserver
|
||||
virtual void ReceiveSocketData(
|
||||
BluetoothSocket* aSocket,
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) override;
|
||||
virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) override;
|
||||
virtual void OnSocketConnectError(BluetoothSocket* aSocket) override;
|
||||
virtual void OnSocketDisconnect(BluetoothSocket* aSocket) override;
|
||||
|
||||
bool Listen();
|
||||
/**
|
||||
* This function set up a Synchronous Connection (SCO) link for HFP.
|
||||
* Service Level Connection (SLC) should be established before SCO setup
|
||||
* process.
|
||||
* If SLC haven't been established, this function will return false and
|
||||
* send a request to set up SCO ater HfpManager receive AT+CMER, unless we are
|
||||
* connecting HSP socket rather than HFP socket.
|
||||
*
|
||||
* @param aRunnable Indicate a BluetoothReplyRunnable to execute this
|
||||
* function. The default value is nullpter
|
||||
* @return <code>true</code> if SCO established successfully
|
||||
*/
|
||||
bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
|
||||
bool DisconnectSco();
|
||||
bool ListenSco();
|
||||
|
||||
#ifdef MOZ_B2G_RIL
|
||||
/**
|
||||
* @param aSend A boolean indicates whether we need to notify headset or not
|
||||
*/
|
||||
void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
|
||||
const nsAString& aError, const nsAString& aNumber,
|
||||
const bool aIsOutgoing, const bool aIsConference,
|
||||
bool aSend);
|
||||
void HandleIccInfoChanged(uint32_t aClientId);
|
||||
void HandleVoiceConnectionChanged(uint32_t aClientId);
|
||||
|
||||
// CDMA-specific functions
|
||||
void UpdateSecondNumber(const nsAString& aNumber);
|
||||
void AnswerWaitingCall();
|
||||
void IgnoreWaitingCall();
|
||||
void ToggleCalls();
|
||||
#endif
|
||||
|
||||
private:
|
||||
void ParseAtCommand(const nsACString& aAtCommand, const int aStart,
|
||||
nsTArray<nsCString>& aRetValues);
|
||||
|
||||
class CloseScoTask;
|
||||
class GetVolumeTask;
|
||||
#ifdef MOZ_B2G_RIL
|
||||
class RespondToBLDNTask;
|
||||
class SendRingIndicatorTask;
|
||||
#endif
|
||||
|
||||
friend class CloseScoTask;
|
||||
friend class GetVolumeTask;
|
||||
#ifdef MOZ_B2G_RIL
|
||||
friend class RespondToBLDNTask;
|
||||
friend class SendRingIndicatorTask;
|
||||
#endif
|
||||
friend class BluetoothHfpManagerObserver;
|
||||
|
||||
BluetoothHfpManager();
|
||||
void HandleShutdown();
|
||||
void HandleVolumeChanged(nsISupports* aSubject);
|
||||
|
||||
bool Init();
|
||||
void Notify(const hal::BatteryInformation& aBatteryInfo);
|
||||
#ifdef MOZ_B2G_RIL
|
||||
void ResetCallArray();
|
||||
uint32_t FindFirstCall(uint16_t aState);
|
||||
uint32_t GetNumberOfCalls(uint16_t aState);
|
||||
uint32_t GetNumberOfConCalls();
|
||||
uint32_t GetNumberOfConCalls(uint16_t aState);
|
||||
PhoneType GetPhoneType(const nsAString& aType);
|
||||
#endif
|
||||
|
||||
void NotifyConnectionStatusChanged(const nsAString& aType);
|
||||
void NotifyDialer(const nsAString& aCommand);
|
||||
|
||||
#ifdef MOZ_B2G_RIL
|
||||
void SendCCWA(const nsAString& aNumber, int aType);
|
||||
bool SendCLCC(const Call& aCall, int aIndex);
|
||||
#endif
|
||||
bool SendCommand(const char* aCommand, uint32_t aValue = 0);
|
||||
bool SendLine(const char* aMessage);
|
||||
#ifdef MOZ_B2G_RIL
|
||||
void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend = true);
|
||||
#endif
|
||||
void OnScoConnectSuccess();
|
||||
void OnScoConnectError();
|
||||
void OnScoDisconnect();
|
||||
|
||||
int mCurrentVgs;
|
||||
int mCurrentVgm;
|
||||
#ifdef MOZ_B2G_RIL
|
||||
bool mBSIR;
|
||||
bool mCCWA;
|
||||
bool mCLIP;
|
||||
#endif
|
||||
bool mCMEE;
|
||||
bool mCMER;
|
||||
bool mConnectScoRequest;
|
||||
bool mSlcConnected;
|
||||
bool mIsHsp;
|
||||
#ifdef MOZ_B2G_RIL
|
||||
bool mFirstCKPD;
|
||||
int mNetworkSelectionMode;
|
||||
PhoneType mPhoneType;
|
||||
#endif
|
||||
bool mReceiveVgsFlag;
|
||||
#ifdef MOZ_B2G_RIL
|
||||
bool mDialingRequestProcessed;
|
||||
#endif
|
||||
nsString mDeviceAddress;
|
||||
#ifdef MOZ_B2G_RIL
|
||||
nsString mMsisdn;
|
||||
nsString mOperatorName;
|
||||
|
||||
nsTArray<Call> mCurrentCallArray;
|
||||
nsAutoPtr<BluetoothRilListener> mListener;
|
||||
#endif
|
||||
nsRefPtr<BluetoothProfileController> mController;
|
||||
nsRefPtr<BluetoothReplyRunnable> mScoRunnable;
|
||||
|
||||
// If a connection has been established, mSocket will be the socket
|
||||
// communicating with the remote socket. We maintain the invariant that if
|
||||
// mSocket is non-null, mHandsfreeSocket and mHeadsetSocket must be null (and
|
||||
// vice versa).
|
||||
nsRefPtr<BluetoothSocket> mSocket;
|
||||
|
||||
// Server sockets. Once an inbound connection is established, it will hand
|
||||
// over the ownership to mSocket, and get a new server socket while Listen()
|
||||
// is called.
|
||||
nsRefPtr<BluetoothSocket> mHandsfreeSocket;
|
||||
nsRefPtr<BluetoothSocket> mHeadsetSocket;
|
||||
nsRefPtr<BluetoothSocket> mScoSocket;
|
||||
mozilla::ipc::SocketConnectionStatus mScoSocketStatus;
|
||||
|
||||
#ifdef MOZ_B2G_RIL
|
||||
// CDMA-specific variable
|
||||
Call mCdmaSecondCall;
|
||||
#endif
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,234 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_bluetoothoppmanager_h__
|
||||
#define mozilla_dom_bluetooth_bluetoothoppmanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothProfileManagerBase.h"
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "DeviceStorage.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
class nsIDOMBlob;
|
||||
class nsIOutputStream;
|
||||
class nsIInputStream;
|
||||
class nsIVolumeMountLock;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class BlobParent;
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocket;
|
||||
class ObexHeaderSet;
|
||||
class SendFileBatch;
|
||||
|
||||
class BluetoothOppManager : public BluetoothSocketObserver
|
||||
, public BluetoothProfileManagerBase
|
||||
{
|
||||
public:
|
||||
BT_DECL_PROFILE_MGR_BASE
|
||||
virtual void GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("OPP");
|
||||
}
|
||||
|
||||
static const int MAX_PACKET_LENGTH = 0xFFFE;
|
||||
|
||||
virtual ~BluetoothOppManager();
|
||||
static BluetoothOppManager* Get();
|
||||
void ClientDataHandler(mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
void ServerDataHandler(mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
|
||||
bool Listen();
|
||||
|
||||
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
|
||||
bool SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
bool StopSendingFile();
|
||||
bool ConfirmReceivingFile(bool aConfirm);
|
||||
|
||||
void SendConnectRequest();
|
||||
void SendPutHeaderRequest(const nsAString& aFileName, int aFileSize);
|
||||
void SendPutRequest(uint8_t* aFileBody, int aFileBodyLength);
|
||||
void SendPutFinalRequest();
|
||||
void SendDisconnectRequest();
|
||||
|
||||
void ExtractPacketHeaders(const ObexHeaderSet& aHeader);
|
||||
bool ExtractBlobHeaders();
|
||||
void CheckPutFinal(uint32_t aNumRead);
|
||||
|
||||
// The following functions are inherited from BluetoothSocketObserver
|
||||
void ReceiveSocketData(
|
||||
BluetoothSocket* aSocket,
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) override;
|
||||
virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) override;
|
||||
virtual void OnSocketConnectError(BluetoothSocket* aSocket) override;
|
||||
virtual void OnSocketDisconnect(BluetoothSocket* aSocket) override;
|
||||
|
||||
private:
|
||||
BluetoothOppManager();
|
||||
bool Init();
|
||||
void HandleShutdown();
|
||||
|
||||
void StartFileTransfer();
|
||||
void StartSendingNextFile();
|
||||
void FileTransferComplete();
|
||||
void UpdateProgress();
|
||||
void ReceivingFileConfirmation();
|
||||
bool CreateFile();
|
||||
bool WriteToFile(const uint8_t* aData, int aDataLength);
|
||||
void RestoreReceivedFileAndNotify();
|
||||
void DeleteReceivedFile();
|
||||
void ReplyToConnect();
|
||||
void ReplyToDisconnectOrAbort();
|
||||
void ReplyToPut(bool aFinal, bool aContinue);
|
||||
void ReplyError(uint8_t aError);
|
||||
void AfterOppConnected();
|
||||
void AfterFirstPut();
|
||||
void AfterOppDisconnected();
|
||||
void ValidateFileName();
|
||||
bool IsReservedChar(char16_t c);
|
||||
void ClearQueue();
|
||||
void RetrieveSentFileName();
|
||||
void NotifyAboutFileChange();
|
||||
bool AcquireSdcardMountLock();
|
||||
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
|
||||
void AppendBlobToSend(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
|
||||
void DiscardBlobsToSend();
|
||||
bool ProcessNextBatch();
|
||||
void ConnectInternal(const nsAString& aDeviceAddress);
|
||||
|
||||
/**
|
||||
* Usually we won't get a full PUT packet in one operation, which means that
|
||||
* a packet may be devided into several parts and BluetoothOppManager should
|
||||
* be in charge of assembling.
|
||||
*
|
||||
* @return true if a packet has been fully received.
|
||||
* false if the received length exceeds/not reaches the expected
|
||||
* length.
|
||||
*/
|
||||
bool ComposePacket(uint8_t aOpCode,
|
||||
mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
|
||||
/**
|
||||
* OBEX session status.
|
||||
* Set when OBEX session is established.
|
||||
*/
|
||||
bool mConnected;
|
||||
nsString mConnectedDeviceAddress;
|
||||
|
||||
/**
|
||||
* Remote information
|
||||
*/
|
||||
uint8_t mRemoteObexVersion;
|
||||
uint8_t mRemoteConnectionFlags;
|
||||
int mRemoteMaxPacketLength;
|
||||
|
||||
/**
|
||||
* For sending files, we decide our next action based on current command and
|
||||
* previous one.
|
||||
* For receiving files, we don't need previous command and it is set to 0
|
||||
* as a default value.
|
||||
*/
|
||||
int mLastCommand;
|
||||
|
||||
int mPacketLength;
|
||||
int mPutPacketReceivedLength;
|
||||
int mBodySegmentLength;
|
||||
int mUpdateProgressCounter;
|
||||
|
||||
/**
|
||||
* When it is true and the target service on target device couldn't be found,
|
||||
* refreshing SDP records is necessary.
|
||||
*/
|
||||
bool mNeedsUpdatingSdpRecords;
|
||||
|
||||
/**
|
||||
* Set when StopSendingFile() is called.
|
||||
*/
|
||||
bool mAbortFlag;
|
||||
|
||||
/**
|
||||
* Set when receiving the first PUT packet of a new file
|
||||
*/
|
||||
bool mNewFileFlag;
|
||||
|
||||
/**
|
||||
* Set when receiving a PutFinal packet
|
||||
*/
|
||||
bool mPutFinalFlag;
|
||||
|
||||
/**
|
||||
* Set when FileTransferComplete() is called
|
||||
*/
|
||||
bool mSendTransferCompleteFlag;
|
||||
|
||||
/**
|
||||
* Set when a transfer is successfully completed.
|
||||
*/
|
||||
bool mSuccessFlag;
|
||||
|
||||
/**
|
||||
* True: Receive file (Server)
|
||||
* False: Send file (Client)
|
||||
*/
|
||||
bool mIsServer;
|
||||
|
||||
/**
|
||||
* Set when receiving the first PUT packet and wait for
|
||||
* ConfirmReceivingFile() to be called.
|
||||
*/
|
||||
bool mWaitingForConfirmationFlag;
|
||||
|
||||
nsString mFileName;
|
||||
nsString mContentType;
|
||||
uint32_t mFileLength;
|
||||
uint32_t mSentFileLength;
|
||||
bool mWaitingToSendPutFinal;
|
||||
|
||||
nsAutoArrayPtr<uint8_t> mBodySegment;
|
||||
nsAutoArrayPtr<uint8_t> mReceivedDataBuffer;
|
||||
|
||||
int mCurrentBlobIndex;
|
||||
nsCOMPtr<nsIDOMBlob> mBlob;
|
||||
nsTArray<SendFileBatch> mBatches;
|
||||
|
||||
/**
|
||||
* A seperate member thread is required because our read calls can block
|
||||
* execution, which is not allowed to happen on the IOThread.
|
||||
*/
|
||||
nsCOMPtr<nsIThread> mReadFileThread;
|
||||
nsCOMPtr<nsIOutputStream> mOutputStream;
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
nsCOMPtr<nsIVolumeMountLock> mMountLock;
|
||||
nsRefPtr<DeviceStorageFile> mDsFile;
|
||||
nsRefPtr<DeviceStorageFile> mDummyDsFile;
|
||||
|
||||
// If a connection has been established, mSocket will be the socket
|
||||
// communicating with the remote socket. We maintain the invariant that if
|
||||
// mSocket is non-null, mRfcommSocket and mL2capSocket must be null (and vice
|
||||
// versa).
|
||||
nsRefPtr<BluetoothSocket> mSocket;
|
||||
|
||||
// Server sockets. Once an inbound connection is established, it will hand
|
||||
// over the ownership to mSocket, and get a new server socket while Listen()
|
||||
// is called.
|
||||
nsRefPtr<BluetoothSocket> mRfcommSocket;
|
||||
nsRefPtr<BluetoothSocket> mL2capSocket;
|
||||
|
||||
// This holds the time when OPP manager fail to get service channel and
|
||||
// prepare to refresh SDP records.
|
||||
mozilla::TimeStamp mLastServiceChannelCheck;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,98 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "BluetoothSocket.h"
|
||||
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "BluetoothUnixSocketConnector.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt)
|
||||
: mObserver(aObserver)
|
||||
, mType(aType)
|
||||
, mAuth(aAuth)
|
||||
, mEncrypt(aEncrypt)
|
||||
{
|
||||
MOZ_ASSERT(aObserver);
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothSocket::Connect(const nsACString& aDeviceAddress, int aChannel)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
|
||||
|
||||
nsAutoPtr<BluetoothUnixSocketConnector> c(
|
||||
new BluetoothUnixSocketConnector(mType, aChannel, mAuth, mEncrypt));
|
||||
|
||||
if (!ConnectSocket(c.forget(), aDeviceAddress.BeginReading())) {
|
||||
nsAutoString addr;
|
||||
GetAddress(addr);
|
||||
BT_LOGD("%s failed. Current connected device address: %s",
|
||||
__FUNCTION__, NS_ConvertUTF16toUTF8(addr).get());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothSocket::Listen(int aChannel)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsAutoPtr<BluetoothUnixSocketConnector> c(
|
||||
new BluetoothUnixSocketConnector(mType, aChannel, mAuth, mEncrypt));
|
||||
|
||||
if (!ListenSocket(c.forget())) {
|
||||
nsAutoString addr;
|
||||
GetAddress(addr);
|
||||
BT_LOGD("%s failed. Current connected device address: %s",
|
||||
__FUNCTION__, NS_ConvertUTF16toUTF8(addr).get());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->ReceiveSocketData(this, aMessage);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnConnectSuccess()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->OnSocketConnectSuccess(this);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnConnectError()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->OnSocketConnectError(this);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnDisconnect()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->OnSocketDisconnect(this);
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_BluetoothSocket_h
|
||||
#define mozilla_dom_bluetooth_BluetoothSocket_h
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocketObserver;
|
||||
|
||||
class BluetoothSocket : public mozilla::ipc::UnixSocketConsumer
|
||||
{
|
||||
public:
|
||||
BluetoothSocket(BluetoothSocketObserver* aObserver,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt);
|
||||
|
||||
bool Connect(const nsACString& aDeviceAddress, int aChannel);
|
||||
bool Listen(int aChannel);
|
||||
inline void Disconnect()
|
||||
{
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
virtual void OnConnectSuccess() override;
|
||||
virtual void OnConnectError() override;
|
||||
virtual void OnDisconnect() override;
|
||||
virtual void ReceiveSocketData(
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) override;
|
||||
|
||||
inline void GetAddress(nsAString& aDeviceAddress)
|
||||
{
|
||||
GetSocketAddr(aDeviceAddress);
|
||||
}
|
||||
|
||||
private:
|
||||
BluetoothSocketObserver* mObserver;
|
||||
BluetoothSocketType mType;
|
||||
bool mAuth;
|
||||
bool mEncrypt;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,285 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/*
|
||||
* Copyright 2009, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NOTE: Due to being based on the dbus compatibility layer for
|
||||
* android's bluetooth implementation, this file is licensed under the
|
||||
* apache license instead of MPL.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#ifdef MOZ_B2G_BT_BLUEZ
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/l2cap.h>
|
||||
#include <bluetooth/rfcomm.h>
|
||||
#include <bluetooth/sco.h>
|
||||
#endif
|
||||
#include "BluetoothUnixSocketConnector.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
static const int RFCOMM_SO_SNDBUF = 70 * 1024; // 70 KB send buffer
|
||||
static const int L2CAP_SO_SNDBUF = 400 * 1024; // 400 KB send buffer
|
||||
static const int L2CAP_SO_RCVBUF = 400 * 1024; // 400 KB receive buffer
|
||||
static const int L2CAP_MAX_MTU = 65000;
|
||||
|
||||
#ifdef MOZ_B2G_BT_BLUEZ
|
||||
static
|
||||
int get_bdaddr(const char *str, bdaddr_t *ba)
|
||||
{
|
||||
char *d = ((char*)ba) + 5, *endp;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
*d-- = strtol(str, &endp, 16);
|
||||
MOZ_ASSERT(!(*endp != ':' && i != 5));
|
||||
str = endp + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void get_bdaddr_as_string(const bdaddr_t *ba, char *str) {
|
||||
const uint8_t *b = (const uint8_t *)ba;
|
||||
sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
|
||||
b[5], b[4], b[3], b[2], b[1], b[0]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
BluetoothUnixSocketConnector::BluetoothUnixSocketConnector(
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth,
|
||||
bool aEncrypt) : mType(aType)
|
||||
, mChannel(aChannel)
|
||||
, mAuth(aAuth)
|
||||
, mEncrypt(aEncrypt)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothUnixSocketConnector::SetUp(int aFd)
|
||||
{
|
||||
#ifdef MOZ_B2G_BT_BLUEZ
|
||||
int lm = 0;
|
||||
int sndbuf, rcvbuf;
|
||||
|
||||
/* kernel does not yet support LM for SCO */
|
||||
switch (mType) {
|
||||
case BluetoothSocketType::RFCOMM:
|
||||
lm |= mAuth ? RFCOMM_LM_AUTH : 0;
|
||||
lm |= mEncrypt ? RFCOMM_LM_ENCRYPT : 0;
|
||||
break;
|
||||
case BluetoothSocketType::L2CAP:
|
||||
case BluetoothSocketType::EL2CAP:
|
||||
lm |= mAuth ? L2CAP_LM_AUTH : 0;
|
||||
lm |= mEncrypt ? L2CAP_LM_ENCRYPT : 0;
|
||||
break;
|
||||
case BluetoothSocketType::SCO:
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Unknown socket type!");
|
||||
}
|
||||
|
||||
if (lm) {
|
||||
if (mType == BluetoothSocketType::RFCOMM) {
|
||||
if (setsockopt(aFd, SOL_RFCOMM, RFCOMM_LM, &lm, sizeof(lm))) {
|
||||
BT_WARNING("setsockopt(RFCOMM_LM) failed, throwing");
|
||||
return false;
|
||||
}
|
||||
} else if (mType == BluetoothSocketType::L2CAP ||
|
||||
mType == BluetoothSocketType::EL2CAP) {
|
||||
if (setsockopt(aFd, SOL_L2CAP, L2CAP_LM, &lm, sizeof(lm))) {
|
||||
BT_WARNING("setsockopt(L2CAP_LM) failed, throwing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mType == BluetoothSocketType::RFCOMM) {
|
||||
sndbuf = RFCOMM_SO_SNDBUF;
|
||||
if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf))) {
|
||||
BT_WARNING("setsockopt(SO_SNDBUF) failed, throwing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Setting L2CAP socket options */
|
||||
if (mType == BluetoothSocketType::L2CAP ||
|
||||
mType == BluetoothSocketType::EL2CAP) {
|
||||
struct l2cap_options opts;
|
||||
socklen_t optlen = sizeof(opts);
|
||||
int err;
|
||||
err = getsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, &optlen);
|
||||
if (!err) {
|
||||
/* setting MTU for [E]L2CAP */
|
||||
opts.omtu = opts.imtu = L2CAP_MAX_MTU;
|
||||
|
||||
/* Enable ERTM for [E]L2CAP */
|
||||
if (mType == BluetoothSocketType::EL2CAP) {
|
||||
opts.flush_to = 0xffff; /* infinite */
|
||||
opts.mode = L2CAP_MODE_ERTM;
|
||||
opts.fcs = 1;
|
||||
opts.txwin_size = 64;
|
||||
opts.max_tx = 10;
|
||||
}
|
||||
|
||||
err = setsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, optlen);
|
||||
}
|
||||
|
||||
/* Set larger SNDBUF & RCVBUF for EL2CAP connections */
|
||||
if (mType == BluetoothSocketType::EL2CAP) {
|
||||
sndbuf = L2CAP_SO_SNDBUF;
|
||||
if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf))) {
|
||||
BT_WARNING("setsockopt(SO_SNDBUF) failed, throwing");
|
||||
return false;
|
||||
}
|
||||
|
||||
rcvbuf = L2CAP_SO_RCVBUF;
|
||||
if (setsockopt(aFd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf))) {
|
||||
BT_WARNING("setsockopt(SO_RCVBUF) failed, throwing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothUnixSocketConnector::SetUpListenSocket(int aFd)
|
||||
{
|
||||
// Nothing to do here.
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
BluetoothUnixSocketConnector::Create()
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
int fd = -1;
|
||||
|
||||
#ifdef MOZ_B2G_BT_BLUEZ
|
||||
switch (mType) {
|
||||
case BluetoothSocketType::RFCOMM:
|
||||
fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
|
||||
break;
|
||||
case BluetoothSocketType::SCO:
|
||||
fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
|
||||
break;
|
||||
case BluetoothSocketType::L2CAP:
|
||||
fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
||||
break;
|
||||
case BluetoothSocketType::EL2CAP:
|
||||
fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_L2CAP);
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH();
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
BT_WARNING("Could not open bluetooth socket!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!SetUp(fd)) {
|
||||
BT_WARNING("Could not set up socket!");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return fd;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothUnixSocketConnector::CreateAddr(bool aIsServer,
|
||||
socklen_t& aAddrSize,
|
||||
sockaddr_any& aAddr,
|
||||
const char* aAddress)
|
||||
{
|
||||
#ifdef MOZ_B2G_BT_BLUEZ
|
||||
// Set to BDADDR_ANY, if it's not a server, we'll reset.
|
||||
bdaddr_t bd_address_obj = {{0, 0, 0, 0, 0, 0}};
|
||||
|
||||
if (!aIsServer && aAddress && strlen(aAddress) > 0) {
|
||||
if (get_bdaddr(aAddress, &bd_address_obj)) {
|
||||
BT_WARNING("Can't get bluetooth address!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize
|
||||
memset(&aAddr, 0, sizeof(aAddr));
|
||||
|
||||
switch (mType) {
|
||||
case BluetoothSocketType::RFCOMM:
|
||||
struct sockaddr_rc addr_rc;
|
||||
aAddrSize = sizeof(addr_rc);
|
||||
aAddr.rc.rc_family = AF_BLUETOOTH;
|
||||
aAddr.rc.rc_channel = mChannel;
|
||||
memcpy(&aAddr.rc.rc_bdaddr, &bd_address_obj, sizeof(bd_address_obj));
|
||||
break;
|
||||
case BluetoothSocketType::L2CAP:
|
||||
case BluetoothSocketType::EL2CAP:
|
||||
struct sockaddr_l2 addr_l2;
|
||||
aAddrSize = sizeof(addr_l2);
|
||||
aAddr.l2.l2_family = AF_BLUETOOTH;
|
||||
aAddr.l2.l2_psm = mChannel;
|
||||
memcpy(&aAddr.l2.l2_bdaddr, &bd_address_obj, sizeof(bdaddr_t));
|
||||
break;
|
||||
case BluetoothSocketType::SCO:
|
||||
struct sockaddr_sco addr_sco;
|
||||
aAddrSize = sizeof(addr_sco);
|
||||
aAddr.sco.sco_family = AF_BLUETOOTH;
|
||||
memcpy(&aAddr.sco.sco_bdaddr, &bd_address_obj, sizeof(bd_address_obj));
|
||||
break;
|
||||
default:
|
||||
BT_WARNING("Socket type unknown!");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothUnixSocketConnector::GetSocketAddr(const sockaddr_any& aAddr,
|
||||
nsAString& aAddrStr)
|
||||
{
|
||||
#ifdef MOZ_B2G_BT_BLUEZ
|
||||
char addr[18];
|
||||
switch (mType) {
|
||||
case BluetoothSocketType::RFCOMM:
|
||||
get_bdaddr_as_string((bdaddr_t*)(&aAddr.rc.rc_bdaddr), addr);
|
||||
break;
|
||||
case BluetoothSocketType::SCO:
|
||||
get_bdaddr_as_string((bdaddr_t*)(&aAddr.sco.sco_bdaddr), addr);
|
||||
break;
|
||||
case BluetoothSocketType::L2CAP:
|
||||
case BluetoothSocketType::EL2CAP:
|
||||
get_bdaddr_as_string((bdaddr_t*)(&aAddr.l2.l2_bdaddr), addr);
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Socket should be either RFCOMM or SCO!");
|
||||
}
|
||||
aAddrStr.AssignASCII(addr);
|
||||
#endif
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_BluetoothUnixSocketConnector_h
|
||||
#define mozilla_dom_bluetooth_BluetoothUnixSocketConnector_h
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include <sys/socket.h>
|
||||
#include <mozilla/ipc/UnixSocket.h>
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothUnixSocketConnector : public mozilla::ipc::UnixSocketConnector
|
||||
{
|
||||
public:
|
||||
BluetoothUnixSocketConnector(BluetoothSocketType aType, int aChannel,
|
||||
bool aAuth, bool aEncrypt);
|
||||
virtual ~BluetoothUnixSocketConnector()
|
||||
{}
|
||||
virtual int Create() override;
|
||||
virtual bool CreateAddr(bool aIsServer,
|
||||
socklen_t& aAddrSize,
|
||||
mozilla::ipc::sockaddr_any& aAddr,
|
||||
const char* aAddress) override;
|
||||
virtual bool SetUp(int aFd) override;
|
||||
virtual bool SetUpListenSocket(int aFd) override;
|
||||
virtual void GetSocketAddr(const mozilla::ipc::sockaddr_any& aAddr,
|
||||
nsAString& aAddrStr) override;
|
||||
|
||||
private:
|
||||
BluetoothSocketType mType;
|
||||
int mChannel;
|
||||
bool mAuth;
|
||||
bool mEncrypt;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,152 +0,0 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# 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/.
|
||||
|
||||
if CONFIG['MOZ_B2G_BT']:
|
||||
SOURCES += [
|
||||
'BluetoothAdapter.cpp',
|
||||
'BluetoothClassOfDevice.cpp',
|
||||
'BluetoothDevice.cpp',
|
||||
'BluetoothDiscoveryHandle.cpp',
|
||||
'BluetoothGatt.cpp',
|
||||
'BluetoothGattCharacteristic.cpp',
|
||||
'BluetoothGattDescriptor.cpp',
|
||||
'BluetoothGattService.cpp',
|
||||
'BluetoothHidManager.cpp',
|
||||
'BluetoothInterface.cpp',
|
||||
'BluetoothManager.cpp',
|
||||
'BluetoothPairingHandle.cpp',
|
||||
'BluetoothPairingListener.cpp',
|
||||
'BluetoothProfileController.cpp',
|
||||
'BluetoothReplyRunnable.cpp',
|
||||
'BluetoothService.cpp',
|
||||
'BluetoothUtils.cpp',
|
||||
'BluetoothUuid.cpp',
|
||||
'ipc/BluetoothChild.cpp',
|
||||
'ipc/BluetoothParent.cpp',
|
||||
'ipc/BluetoothServiceChildProcess.cpp',
|
||||
'ObexBase.cpp'
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_RIL']:
|
||||
SOURCES += [
|
||||
'BluetoothRilListener.cpp',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
||||
if CONFIG['MOZ_B2G_BT_BLUEZ']:
|
||||
CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
|
||||
SOURCES += [
|
||||
'bluez/BluetoothA2dpManager.cpp',
|
||||
'bluez/BluetoothDBusService.cpp',
|
||||
'bluez/BluetoothHfpManager.cpp',
|
||||
'bluez/BluetoothOppManager.cpp',
|
||||
'bluez/BluetoothSocket.cpp',
|
||||
'bluez/BluetoothUnixSocketConnector.cpp'
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'bluez',
|
||||
]
|
||||
DEFINES['MOZ_B2G_BT_BLUEZ'] = True
|
||||
elif CONFIG['MOZ_B2G_BT_BLUEDROID']:
|
||||
SOURCES += [
|
||||
'bluedroid/BluetoothA2dpHALInterface.cpp',
|
||||
'bluedroid/BluetoothA2dpManager.cpp',
|
||||
'bluedroid/BluetoothAvrcpHALInterface.cpp',
|
||||
'bluedroid/BluetoothDaemonA2dpInterface.cpp',
|
||||
'bluedroid/BluetoothDaemonAvrcpInterface.cpp',
|
||||
'bluedroid/BluetoothDaemonHandsfreeInterface.cpp',
|
||||
'bluedroid/BluetoothDaemonHelpers.cpp',
|
||||
'bluedroid/BluetoothDaemonInterface.cpp',
|
||||
'bluedroid/BluetoothDaemonSetupInterface.cpp',
|
||||
'bluedroid/BluetoothDaemonSocketInterface.cpp',
|
||||
'bluedroid/BluetoothGattHALInterface.cpp',
|
||||
'bluedroid/BluetoothGattManager.cpp',
|
||||
'bluedroid/BluetoothHALHelpers.cpp',
|
||||
'bluedroid/BluetoothHALInterface.cpp',
|
||||
'bluedroid/BluetoothHandsfreeHALInterface.cpp',
|
||||
'bluedroid/BluetoothOppManager.cpp',
|
||||
'bluedroid/BluetoothServiceBluedroid.cpp',
|
||||
'bluedroid/BluetoothSocket.cpp',
|
||||
'bluedroid/BluetoothSocketHALInterface.cpp',
|
||||
'bluedroid/BluetoothSocketMessageWatcher.cpp'
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'bluedroid',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_RIL']:
|
||||
SOURCES += [
|
||||
'bluedroid/hfp/BluetoothHfpManager.cpp',
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'bluedroid/hfp',
|
||||
]
|
||||
else:
|
||||
SOURCES += [
|
||||
'bluedroid/hfp-fallback/BluetoothHfpManager.cpp',
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'bluedroid/hfp-fallback',
|
||||
]
|
||||
|
||||
DEFINES['MOZ_B2G_BT_BLUEDROID'] = True
|
||||
if CONFIG['MOZ_B2G_BT_DAEMON']:
|
||||
DEFINES['MOZ_B2G_BT_DAEMON'] = True
|
||||
elif CONFIG['MOZ_ENABLE_DBUS']:
|
||||
CFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
|
||||
CFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
|
||||
CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
|
||||
CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
|
||||
SOURCES += [
|
||||
'bluez/BluetoothDBusService.cpp',
|
||||
'bluez/BluetoothHfpManager.cpp',
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'bluez',
|
||||
]
|
||||
DEFINES['MOZ_BLUETOOTH_DBUS'] = True
|
||||
DEFINES['HAVE_PTHREADS'] = True
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'ipc',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.dom.bluetooth.ipc += [
|
||||
'ipc/BluetoothMessageUtils.h',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.dom.bluetooth += [
|
||||
'BluetoothAdapter.h',
|
||||
'BluetoothClassOfDevice.h',
|
||||
'BluetoothCommon.h',
|
||||
'BluetoothDevice.h',
|
||||
'BluetoothDiscoveryHandle.h',
|
||||
'BluetoothGatt.h',
|
||||
'BluetoothGattCharacteristic.h',
|
||||
'BluetoothGattDescriptor.h',
|
||||
'BluetoothGattService.h',
|
||||
'BluetoothManager.h',
|
||||
'BluetoothPairingHandle.h',
|
||||
'BluetoothPairingListener.h',
|
||||
]
|
||||
|
||||
IPDL_SOURCES += [
|
||||
'ipc/BluetoothTypes.ipdlh',
|
||||
'ipc/PBluetooth.ipdl',
|
||||
'ipc/PBluetoothRequest.ipdl',
|
||||
]
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'../base',
|
||||
'../network',
|
||||
'../system/gonk',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
Загрузка…
Ссылка в новой задаче