зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 9 changesets (bug 851046) for B2G bustage on a CLOSED TREE.
This commit is contained in:
Родитель
c25fe283e7
Коммит
e3283fe2b4
|
@ -53,7 +53,6 @@ extern bool gBluetoothDebugFlag;
|
|||
|
||||
// Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx)
|
||||
#define BLUETOOTH_ADDRESS_LENGTH 17
|
||||
#define BLUETOOTH_ADDRESS_NONE "00:00:00:00:00:00"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothScoManager.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothSocket.h"
|
||||
#include "BluetoothUtils.h"
|
||||
#include "BluetoothUuid.h"
|
||||
|
||||
|
@ -40,19 +39,17 @@
|
|||
#define TOA_UNKNOWN 0x81
|
||||
#define TOA_INTERNATIONAL 0x91
|
||||
|
||||
#define CR_LF "\xd\xa";
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
namespace {
|
||||
StaticAutoPtr<BluetoothHfpManager> gBluetoothHfpManager;
|
||||
StaticRefPtr<BluetoothHfpManager> gBluetoothHfpManager;
|
||||
StaticRefPtr<BluetoothHfpManagerObserver> sHfpObserver;
|
||||
bool gInShutdown = false;
|
||||
static bool sStopSendingRingFlag = true;
|
||||
|
||||
static int sRingInterval = 3000; //unit: ms
|
||||
static const char kHfpCrlf[] = "\xd\xa";
|
||||
} // anonymous namespace
|
||||
|
||||
/* CallState for sCINDItems[CINDType::CALL].value
|
||||
|
@ -263,7 +260,7 @@ BluetoothHfpManagerObserver::Observe(nsISupports* aSubject,
|
|||
|
||||
NS_IMPL_ISUPPORTS1(BluetoothHfpManagerObserver, nsIObserver)
|
||||
|
||||
class BluetoothHfpManager::SendRingIndicatorTask : public Task
|
||||
class SendRingIndicatorTask : public Task
|
||||
{
|
||||
public:
|
||||
SendRingIndicatorTask(const nsAString& aNumber, int aType)
|
||||
|
@ -287,19 +284,20 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
const char* kHfpCrlf = "\xd\xa";
|
||||
nsAutoCString ringMsg(kHfpCrlf);
|
||||
ringMsg.AppendLiteral("RING");
|
||||
ringMsg.AppendLiteral(kHfpCrlf);
|
||||
gBluetoothHfpManager->SendLine(ringMsg.get());
|
||||
ringMsg += "RING";
|
||||
ringMsg += kHfpCrlf;
|
||||
gBluetoothHfpManager->SendSocketData(ringMsg);
|
||||
|
||||
if (!mNumber.IsEmpty()) {
|
||||
nsAutoCString clipMsg(kHfpCrlf);
|
||||
clipMsg.AppendLiteral("+CLIP: \"");
|
||||
clipMsg.Append(NS_ConvertUTF16toUTF8(mNumber).get());
|
||||
clipMsg.AppendLiteral("\",");
|
||||
clipMsg += "+CLIP: \"";
|
||||
clipMsg += NS_ConvertUTF16toUTF8(mNumber).get();
|
||||
clipMsg += "\",";
|
||||
clipMsg.AppendInt(mType);
|
||||
clipMsg.AppendLiteral(kHfpCrlf);
|
||||
gBluetoothHfpManager->SendLine(clipMsg.get());
|
||||
clipMsg += kHfpCrlf;
|
||||
gBluetoothHfpManager->SendSocketData(clipMsg);
|
||||
}
|
||||
|
||||
MessageLoop::current()->
|
||||
|
@ -393,11 +391,7 @@ BluetoothHfpManager::Init()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mSocket = new BluetoothSocket(this,
|
||||
BluetoothSocketType::RFCOMM,
|
||||
true,
|
||||
true);
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
|
||||
sHfpObserver = new BluetoothHfpManagerObserver();
|
||||
if (!sHfpObserver->Init()) {
|
||||
|
@ -460,8 +454,12 @@ BluetoothHfpManager::Get()
|
|||
}
|
||||
|
||||
// Create new instance, register, return
|
||||
BluetoothHfpManager* manager = new BluetoothHfpManager();
|
||||
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||
nsRefPtr<BluetoothHfpManager> manager = new BluetoothHfpManager();
|
||||
NS_ENSURE_TRUE(manager, nullptr);
|
||||
|
||||
if (!manager->Init()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gBluetoothHfpManager = manager;
|
||||
return gBluetoothHfpManager;
|
||||
|
@ -476,8 +474,8 @@ BluetoothHfpManager::NotifySettings()
|
|||
type.AssignLiteral("bluetooth-hfp-status-changed");
|
||||
|
||||
name.AssignLiteral("connected");
|
||||
v = (mSocket->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_CONNECTED);
|
||||
v = (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED)
|
||||
? true : false ;
|
||||
parameters.AppendElement(BluetoothNamedValue(name, v));
|
||||
|
||||
name.AssignLiteral("address");
|
||||
|
@ -573,7 +571,7 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
|
|||
}
|
||||
|
||||
// Only send volume back when there's a connected headset
|
||||
if (mSocket->GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
SendCommand("+VGS: ", mCurrentVgs);
|
||||
}
|
||||
|
||||
|
@ -665,15 +663,14 @@ BluetoothHfpManager::HandleShutdown()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
gInShutdown = true;
|
||||
Disconnect();
|
||||
CloseSocket();
|
||||
gBluetoothHfpManager = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Virtual function of class SocketConsumer
|
||||
void
|
||||
BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,
|
||||
nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
BluetoothHfpManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -745,9 +742,9 @@ BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,
|
|||
} else if (msg.Find("AT+COPS?") != -1) {
|
||||
nsAutoCString message("+COPS: ");
|
||||
message.AppendInt(mNetworkSelectionMode);
|
||||
message.AppendLiteral(",0,\"");
|
||||
message.Append(NS_ConvertUTF16toUTF8(mOperatorName));
|
||||
message.AppendLiteral("\"");
|
||||
message += ",0,\"";
|
||||
message += NS_ConvertUTF16toUTF8(mOperatorName);
|
||||
message += "\"";
|
||||
SendLine(message.get());
|
||||
return;
|
||||
} else if (msg.Find("AT+VTS=") != -1) {
|
||||
|
@ -911,10 +908,10 @@ BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,
|
|||
} else if (msg.Find("AT+CNUM") != -1) {
|
||||
if (!mMsisdn.IsEmpty()) {
|
||||
nsAutoCString message("+CNUM: ,\"");
|
||||
message.Append(NS_ConvertUTF16toUTF8(mMsisdn).get());
|
||||
message.AppendLiteral("\",");
|
||||
message += NS_ConvertUTF16toUTF8(mMsisdn).get();
|
||||
message += "\",";
|
||||
message.AppendInt(TOA_UNKNOWN);
|
||||
message.AppendLiteral(",,4");
|
||||
message += ",,4";
|
||||
SendLine(message.get());
|
||||
}
|
||||
} else {
|
||||
|
@ -945,15 +942,13 @@ BluetoothHfpManager::Connect(const nsAString& aDevicePath,
|
|||
return false;
|
||||
}
|
||||
|
||||
SocketConnectionStatus s = mSocket->GetConnectionStatus();
|
||||
|
||||
if (s == SocketConnectionStatus::SOCKET_CONNECTED ||
|
||||
s == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
NS_WARNING("BluetoothHfpManager has been already connected");
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED ||
|
||||
GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
NS_WARNING("BluetoothHfpManager has connected/is connecting to a headset!");
|
||||
return false;
|
||||
}
|
||||
|
||||
mSocket->Disconnect();
|
||||
CloseSocket();
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
NS_ENSURE_TRUE(bs, false);
|
||||
|
@ -972,7 +967,7 @@ BluetoothHfpManager::Connect(const nsAString& aDevicePath,
|
|||
BluetoothSocketType::RFCOMM,
|
||||
true,
|
||||
true,
|
||||
mSocket,
|
||||
this,
|
||||
mRunnable);
|
||||
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
|
@ -988,45 +983,56 @@ BluetoothHfpManager::Listen()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (mSocket->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_LISTENING) {
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_LISTENING) {
|
||||
NS_WARNING("BluetoothHfpManager has been already listening");
|
||||
return true;
|
||||
}
|
||||
|
||||
mSocket->Disconnect();
|
||||
CloseSocket();
|
||||
|
||||
if (!mSocket->Listen(BluetoothReservedChannels::CHANNEL_HANDSFREE_AG)) {
|
||||
NS_WARNING("[HFP] Can't listen on socket!");
|
||||
return false;
|
||||
}
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
NS_ENSURE_TRUE(bs, false);
|
||||
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
return true;
|
||||
nsresult rv =
|
||||
bs->ListenSocketViaService(BluetoothReservedChannels::CHANNEL_HANDSFREE_AG,
|
||||
BluetoothSocketType::RFCOMM,
|
||||
true,
|
||||
true,
|
||||
this);
|
||||
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::Disconnect()
|
||||
{
|
||||
mSocket->Disconnect();
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_DISCONNECTED) {
|
||||
NS_WARNING("BluetoothHfpManager has been disconnected!");
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::SendLine(const char* aMessage)
|
||||
{
|
||||
const char* kHfpCrlf = "\xd\xa";
|
||||
nsAutoCString msg;
|
||||
|
||||
msg.AppendLiteral(kHfpCrlf);
|
||||
msg.Append(aMessage);
|
||||
msg.AppendLiteral(kHfpCrlf);
|
||||
msg += kHfpCrlf;
|
||||
msg += aMessage;
|
||||
msg += kHfpCrlf;
|
||||
|
||||
return mSocket->SendSocketData(msg);
|
||||
return SendSocketData(msg);
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
|
||||
{
|
||||
if (mPrevSocketStatus != SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (mSocketStatus != SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1046,22 +1052,22 @@ BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
|
|||
}
|
||||
|
||||
message.AppendInt(aValue);
|
||||
message.AppendLiteral(",");
|
||||
message += ",";
|
||||
message.AppendInt(sCINDItems[aValue].value);
|
||||
} else if (!strcmp(aCommand, "+CIND: ")) {
|
||||
if (!aValue) {
|
||||
// Query for range
|
||||
for (uint8_t i = 1; i < ArrayLength(sCINDItems); i++) {
|
||||
message.AppendLiteral("(\"");
|
||||
message.Append(sCINDItems[i].name);
|
||||
message.AppendLiteral("\",(");
|
||||
message.Append(sCINDItems[i].range);
|
||||
message.AppendLiteral(")");
|
||||
message += "(\"";
|
||||
message += sCINDItems[i].name;
|
||||
message += "\",(";
|
||||
message += sCINDItems[i].range;
|
||||
message += ")";
|
||||
if (i == (ArrayLength(sCINDItems) - 1)) {
|
||||
message.AppendLiteral(")");
|
||||
message +=")";
|
||||
break;
|
||||
}
|
||||
message.AppendLiteral("),");
|
||||
message += "),";
|
||||
}
|
||||
} else {
|
||||
// Query for value
|
||||
|
@ -1070,7 +1076,7 @@ BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
|
|||
if (i == (ArrayLength(sCINDItems) - 1)) {
|
||||
break;
|
||||
}
|
||||
message.AppendLiteral(",");
|
||||
message += ",";
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(aCommand, "+CLCC: ")) {
|
||||
|
@ -1084,9 +1090,9 @@ BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
|
|||
|
||||
message.AssignLiteral("+CLCC: ");
|
||||
message.AppendInt(i);
|
||||
message.AppendLiteral(",");
|
||||
message += ",";
|
||||
message.AppendInt(call.mDirection);
|
||||
message.AppendLiteral(",");
|
||||
message += ",";
|
||||
|
||||
switch (call.mState) {
|
||||
case nsITelephonyProvider::CALL_STATE_CONNECTED:
|
||||
|
@ -1108,9 +1114,9 @@ BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
|
|||
NS_WARNING("Not handling call status for CLCC");
|
||||
break;
|
||||
}
|
||||
message.AppendLiteral(",0,0,\"");
|
||||
message.Append(NS_ConvertUTF16toUTF8(call.mNumber));
|
||||
message.AppendLiteral("\",");
|
||||
message += ",0,0,\"";
|
||||
message += NS_ConvertUTF16toUTF8(call.mNumber).get();
|
||||
message += "\",";
|
||||
message.AppendInt(call.mType);
|
||||
|
||||
rv &= SendLine(message.get());
|
||||
|
@ -1141,8 +1147,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|||
const nsAString& aNumber,
|
||||
bool aSend)
|
||||
{
|
||||
if (mSocket->GetConnectionStatus() !=
|
||||
SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (GetConnectionStatus() != SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1176,8 +1181,8 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|||
if (mCurrentCallIndex) {
|
||||
if (mCCWA) {
|
||||
nsAutoCString ccwaMsg("+CCWA: \"");
|
||||
ccwaMsg.Append(NS_ConvertUTF16toUTF8(aNumber));
|
||||
ccwaMsg.AppendLiteral("\",");
|
||||
ccwaMsg += NS_ConvertUTF16toUTF8(aNumber).get();
|
||||
ccwaMsg += "\",";
|
||||
ccwaMsg.AppendInt(mCurrentCallArray[aCallIndex].mType);
|
||||
SendLine(ccwaMsg.get());
|
||||
}
|
||||
|
@ -1201,7 +1206,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|||
mCurrentCallArray[aCallIndex].mDirection = false;
|
||||
UpdateCIND(CINDType::CALLSETUP, CallSetupState::OUTGOING, aSend);
|
||||
|
||||
mSocket->GetAddress(address);
|
||||
GetSocketAddr(address);
|
||||
OpenScoSocket(address);
|
||||
break;
|
||||
case nsITelephonyProvider::CALL_STATE_ALERTING:
|
||||
|
@ -1210,7 +1215,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|||
|
||||
// If there's an ongoing call when the headset is just connected, we have
|
||||
// to open a sco socket here.
|
||||
mSocket->GetAddress(address);
|
||||
GetSocketAddr(address);
|
||||
OpenScoSocket(address);
|
||||
break;
|
||||
case nsITelephonyProvider::CALL_STATE_CONNECTED:
|
||||
|
@ -1221,7 +1226,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|||
// Incoming call, no break
|
||||
sStopSendingRingFlag = true;
|
||||
|
||||
mSocket->GetAddress(address);
|
||||
GetSocketAddr(address);
|
||||
OpenScoSocket(address);
|
||||
case nsITelephonyProvider::CALL_STATE_ALERTING:
|
||||
// Outgoing call
|
||||
|
@ -1305,10 +1310,8 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::OnConnectSuccess(BluetoothSocket* aSocket)
|
||||
BluetoothHfpManager::OnConnectSuccess()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
nsCOMPtr<nsITelephonyProvider> provider =
|
||||
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
||||
NS_ENSURE_TRUE_VOID(provider);
|
||||
|
@ -1325,17 +1328,15 @@ BluetoothHfpManager::OnConnectSuccess(BluetoothSocket* aSocket)
|
|||
|
||||
// Cache device path for NotifySettings() since we can't get socket address
|
||||
// when a headset disconnect with us
|
||||
mSocket->GetAddress(mDevicePath);
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
GetSocketAddr(mDevicePath);
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
|
||||
NotifySettings();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::OnConnectError(BluetoothSocket* aSocket)
|
||||
BluetoothHfpManager::OnConnectError()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
// For active connection request, we need to reply the DOMRequest
|
||||
if (mRunnable) {
|
||||
BluetoothValue v;
|
||||
|
@ -1347,30 +1348,23 @@ BluetoothHfpManager::OnConnectError(BluetoothSocket* aSocket)
|
|||
}
|
||||
|
||||
// If connecting for some reason didn't work, restart listening
|
||||
CloseSocket();
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
Listen();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::OnDisconnect(BluetoothSocket* aSocket)
|
||||
BluetoothHfpManager::OnDisconnect()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
// When we close a connected socket, then restart listening again and
|
||||
// notify Settings app.
|
||||
if (mPrevSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
Listen();
|
||||
NotifySettings();
|
||||
} else if (mPrevSocketStatus == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
} else if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
NS_WARNING("BluetoothHfpManager got unexpected socket status!");
|
||||
}
|
||||
|
||||
CloseScoSocket();
|
||||
Reset();
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::IsConnected()
|
||||
{
|
||||
return mSocket->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_CONNECTED;
|
||||
}
|
||||
|
|
|
@ -8,16 +8,14 @@
|
|||
#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "BluetoothTelephonyListener.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothHfpManagerObserver;
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothSocket;
|
||||
class BluetoothHfpManagerObserver;
|
||||
class Call;
|
||||
|
||||
/**
|
||||
|
@ -50,18 +48,12 @@ enum BluetoothCmeError {
|
|||
NETWORK_NOT_ALLOWED = 32
|
||||
};
|
||||
|
||||
class BluetoothHfpManager : public BluetoothSocketObserver
|
||||
class BluetoothHfpManager : public mozilla::ipc::UnixSocketConsumer
|
||||
{
|
||||
public:
|
||||
static BluetoothHfpManager* Get();
|
||||
~BluetoothHfpManager();
|
||||
|
||||
virtual void ReceiveSocketData(
|
||||
BluetoothSocket* aSocket,
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
|
||||
virtual void OnConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
virtual void OnConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
virtual void OnDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
virtual void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage)
|
||||
MOZ_OVERRIDE;
|
||||
|
||||
bool Connect(const nsAString& aDeviceObjectPath,
|
||||
const bool aIsHandsfree,
|
||||
|
@ -74,17 +66,14 @@ public:
|
|||
*/
|
||||
void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
|
||||
const nsAString& aNumber, bool aSend);
|
||||
bool IsConnected();
|
||||
|
||||
private:
|
||||
class GetVolumeTask;
|
||||
class SendRingIndicatorTask;
|
||||
|
||||
friend class GetVolumeTask;
|
||||
friend class SendRingIndicatorTask;
|
||||
friend class BluetoothHfpManagerObserver;
|
||||
|
||||
BluetoothHfpManager();
|
||||
~BluetoothHfpManager();
|
||||
nsresult HandleIccInfoChanged();
|
||||
nsresult HandleShutdown();
|
||||
nsresult HandleVolumeChanged(const nsAString& aData);
|
||||
|
@ -102,6 +91,10 @@ private:
|
|||
bool SendLine(const char* aMessage);
|
||||
void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend);
|
||||
|
||||
virtual void OnConnectSuccess() MOZ_OVERRIDE;
|
||||
virtual void OnConnectError() MOZ_OVERRIDE;
|
||||
virtual void OnDisconnect() MOZ_OVERRIDE;
|
||||
|
||||
int mCurrentVgs;
|
||||
int mCurrentVgm;
|
||||
uint32_t mCurrentCallIndex;
|
||||
|
@ -114,12 +107,11 @@ private:
|
|||
nsString mDevicePath;
|
||||
nsString mMsisdn;
|
||||
nsString mOperatorName;
|
||||
SocketConnectionStatus mPrevSocketStatus;
|
||||
enum mozilla::ipc::SocketConnectionStatus mSocketStatus;
|
||||
|
||||
nsTArray<Call> mCurrentCallArray;
|
||||
nsAutoPtr<BluetoothTelephonyListener> mListener;
|
||||
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
||||
nsRefPtr<BluetoothSocket> mSocket;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothSocket.h"
|
||||
#include "BluetoothUtils.h"
|
||||
#include "BluetoothUuid.h"
|
||||
#include "ObexBase.h"
|
||||
|
@ -85,7 +84,7 @@ static const uint32_t kUpdateProgressBase = 50 * 1024;
|
|||
*/
|
||||
static const uint32_t kPutRequestHeaderSize = 6;
|
||||
|
||||
StaticAutoPtr<BluetoothOppManager> sInstance;
|
||||
StaticRefPtr<BluetoothOppManager> sInstance;
|
||||
StaticRefPtr<BluetoothOppManagerObserver> sOppObserver;
|
||||
|
||||
/*
|
||||
|
@ -195,23 +194,18 @@ private:
|
|||
class CloseSocketTask : public Task
|
||||
{
|
||||
public:
|
||||
CloseSocketTask(BluetoothSocket* aSocket) : mSocket(aSocket)
|
||||
{
|
||||
MOZ_ASSERT(aSocket);
|
||||
}
|
||||
|
||||
void Run() MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (!sInstance) {
|
||||
NS_WARNING("BluetoothOppManager no longer exists, cannot close socket!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSocket->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
mSocket->Disconnect();
|
||||
if (sInstance->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
sInstance->CloseSocket();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<BluetoothSocket> mSocket;
|
||||
};
|
||||
|
||||
BluetoothOppManager::BluetoothOppManager() : mConnected(false)
|
||||
|
@ -229,13 +223,8 @@ BluetoothOppManager::BluetoothOppManager() : mConnected(false)
|
|||
, mSuccessFlag(false)
|
||||
, mWaitingForConfirmationFlag(false)
|
||||
{
|
||||
mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
|
||||
mSocket = new BluetoothSocket(this,
|
||||
BluetoothSocketType::RFCOMM,
|
||||
true,
|
||||
true);
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
mConnectedDeviceAddress.AssignLiteral("00:00:00:00:00:00");
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
}
|
||||
|
||||
BluetoothOppManager::~BluetoothOppManager()
|
||||
|
@ -248,7 +237,7 @@ BluetoothOppManager::Get()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!sInstance) {
|
||||
if (sInstance == nullptr) {
|
||||
sInstance = new BluetoothOppManager();
|
||||
}
|
||||
|
||||
|
@ -261,15 +250,13 @@ BluetoothOppManager::Connect(const nsAString& aDeviceObjectPath,
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
SocketConnectionStatus s = mSocket->GetConnectionStatus();
|
||||
|
||||
if (s == SocketConnectionStatus::SOCKET_CONNECTED ||
|
||||
s == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED ||
|
||||
GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
NS_WARNING("BluetoothOppManager has been already connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
Disconnect();
|
||||
CloseSocket();
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
|
@ -287,7 +274,7 @@ BluetoothOppManager::Connect(const nsAString& aDeviceObjectPath,
|
|||
BluetoothSocketType::RFCOMM,
|
||||
true,
|
||||
true,
|
||||
mSocket,
|
||||
this,
|
||||
mRunnable);
|
||||
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
|
@ -296,7 +283,12 @@ BluetoothOppManager::Connect(const nsAString& aDeviceObjectPath,
|
|||
void
|
||||
BluetoothOppManager::Disconnect()
|
||||
{
|
||||
mSocket->Disconnect();
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_DISCONNECTED) {
|
||||
NS_WARNING("BluetoothOppManager has been disconnected!");
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -304,7 +296,7 @@ BluetoothOppManager::HandleShutdown()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
sInShutdown = true;
|
||||
Disconnect();
|
||||
CloseSocket();
|
||||
sInstance = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -314,21 +306,28 @@ BluetoothOppManager::Listen()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mSocket->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_LISTENING) {
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_LISTENING) {
|
||||
NS_WARNING("BluetoothOppManager has been already listening");
|
||||
return true;
|
||||
}
|
||||
|
||||
Disconnect();
|
||||
CloseSocket();
|
||||
|
||||
if (!mSocket->Listen(BluetoothReservedChannels::CHANNEL_OPUSH)) {
|
||||
NS_WARNING("[OPP] Can't listen on socket!");
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
NS_WARNING("BluetoothService not available!");
|
||||
return false;
|
||||
}
|
||||
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
return true;
|
||||
nsresult rv =
|
||||
bs->ListenSocketViaService(BluetoothReservedChannels::CHANNEL_OPUSH,
|
||||
BluetoothSocketType::RFCOMM,
|
||||
true,
|
||||
true,
|
||||
this);
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -692,8 +691,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
|
|||
// When there's a Put packet right after a PutFinal packet,
|
||||
// which means it's the start point of a new file.
|
||||
if (mPutFinalFlag &&
|
||||
(opCode == ObexRequestCode::Put ||
|
||||
opCode == ObexRequestCode::PutFinal)) {
|
||||
(opCode == ObexRequestCode::Put || opCode == ObexRequestCode::PutFinal)) {
|
||||
mNewFileFlag = true;
|
||||
AfterFirstPut();
|
||||
}
|
||||
|
@ -866,7 +864,7 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
|
|||
// Disconnect request, so we make a delay here. If the socket hasn't been
|
||||
// disconnected, we will close it.
|
||||
MessageLoop::current()->
|
||||
PostDelayedTask(FROM_HERE, new CloseSocketTask(mSocket), 1000);
|
||||
PostDelayedTask(FROM_HERE, new CloseSocketTask(), 1000);
|
||||
} else if (mLastCommand == ObexRequestCode::Connect) {
|
||||
MOZ_ASSERT(!sFileName.IsEmpty());
|
||||
MOZ_ASSERT(mBlob);
|
||||
|
@ -928,8 +926,7 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
|
|||
|
||||
// Virtual function of class SocketConsumer
|
||||
void
|
||||
BluetoothOppManager::ReceiveSocketData(BluetoothSocket* aSocket,
|
||||
nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
BluetoothOppManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
{
|
||||
if (mLastCommand) {
|
||||
ClientDataHandler(aMessage);
|
||||
|
@ -960,7 +957,7 @@ BluetoothOppManager::SendConnectRequest()
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -990,7 +987,7 @@ BluetoothOppManager::SendPutHeaderRequest(const nsAString& aFileName,
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
|
||||
delete [] fileName;
|
||||
delete [] req;
|
||||
|
@ -1020,7 +1017,7 @@ BluetoothOppManager::SendPutRequest(uint8_t* aFileBody,
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
|
||||
delete [] req;
|
||||
}
|
||||
|
@ -1046,7 +1043,7 @@ BluetoothOppManager::SendPutFinalRequest()
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
|
||||
sWaitingToSendPutFinal = false;
|
||||
|
||||
|
@ -1066,7 +1063,7 @@ BluetoothOppManager::SendDisconnectRequest()
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1082,7 +1079,7 @@ BluetoothOppManager::SendAbortRequest()
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1112,7 +1109,7 @@ BluetoothOppManager::ReplyToConnect()
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1130,7 +1127,7 @@ BluetoothOppManager::ReplyToDisconnect()
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1161,7 +1158,7 @@ BluetoothOppManager::ReplyToPut(bool aFinal, bool aContinue)
|
|||
|
||||
UnixSocketRawData* s = new UnixSocketRawData(index);
|
||||
memcpy(s->mData, req, s->mSize);
|
||||
mSocket->SendSocketData(s);
|
||||
SendSocketData(s);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1303,10 +1300,8 @@ BluetoothOppManager::ReceivingFileConfirmation()
|
|||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::OnConnectSuccess(BluetoothSocket* aSocket)
|
||||
BluetoothOppManager::OnConnectSuccess()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
if (mRunnable) {
|
||||
BluetoothReply* reply = new BluetoothReply(BluetoothReplySuccess(true));
|
||||
mRunnable->SetReply(reply);
|
||||
|
@ -1318,15 +1313,14 @@ BluetoothOppManager::OnConnectSuccess(BluetoothSocket* aSocket)
|
|||
|
||||
// Cache device address since we can't get socket address when a remote
|
||||
// device disconnect with us.
|
||||
mSocket->GetAddress(mConnectedDeviceAddress);
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
GetSocketAddr(mConnectedDeviceAddress);
|
||||
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::OnConnectError(BluetoothSocket* aSocket)
|
||||
BluetoothOppManager::OnConnectError()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
if (mRunnable) {
|
||||
nsString errorStr;
|
||||
errorStr.AssignLiteral("Failed to connect with a bluetooth opp manager!");
|
||||
|
@ -1338,16 +1332,14 @@ BluetoothOppManager::OnConnectError(BluetoothSocket* aSocket)
|
|||
mRunnable.forget();
|
||||
}
|
||||
|
||||
mSocket->Disconnect();
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
CloseSocket();
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
Listen();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothOppManager::OnDisconnect(BluetoothSocket* aSocket)
|
||||
BluetoothOppManager::OnDisconnect()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
/**
|
||||
* It is valid for a bluetooth device which is transfering file via OPP
|
||||
* closing socket without sending OBEX disconnect request first. So we
|
||||
|
@ -1355,7 +1347,7 @@ BluetoothOppManager::OnDisconnect(BluetoothSocket* aSocket)
|
|||
* and notify the transfer has been completed (but failed). We also call
|
||||
* AfterOppDisconnected here to ensure all variables will be cleaned.
|
||||
*/
|
||||
if (mPrevSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (mTransferMode) {
|
||||
if (!mSuccessFlag) {
|
||||
DeleteReceivedFile();
|
||||
|
@ -1363,8 +1355,7 @@ BluetoothOppManager::OnDisconnect(BluetoothSocket* aSocket)
|
|||
nsString data;
|
||||
CopyASCIItoUTF16("modified", data);
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs =
|
||||
mozilla::services::GetObserverService();
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->NotifyObservers(mDsFile, "file-watcher-notify", data.get());
|
||||
}
|
||||
|
@ -1376,11 +1367,11 @@ BluetoothOppManager::OnDisconnect(BluetoothSocket* aSocket)
|
|||
}
|
||||
|
||||
Listen();
|
||||
} else if (mPrevSocketStatus == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
} else if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTING) {
|
||||
NS_WARNING("BluetoothOppManager got unexpected socket status!");
|
||||
}
|
||||
|
||||
AfterOppDisconnected();
|
||||
mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||
mConnectedDeviceAddress.AssignLiteral("00:00:00:00:00:00");
|
||||
mSuccessFlag = false;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#define mozilla_dom_bluetooth_bluetoothoppmanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "mozilla/dom/ipc/Blob.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
#include "DeviceStorage.h"
|
||||
|
@ -19,10 +18,9 @@ class nsIInputStream;
|
|||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothSocket;
|
||||
class ObexHeaderSet;
|
||||
|
||||
class BluetoothOppManager : public BluetoothSocketObserver
|
||||
class BluetoothOppManager : public mozilla::ipc::UnixSocketConsumer
|
||||
{
|
||||
public:
|
||||
/*
|
||||
|
@ -35,6 +33,8 @@ public:
|
|||
|
||||
~BluetoothOppManager();
|
||||
static BluetoothOppManager* Get();
|
||||
void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage)
|
||||
MOZ_OVERRIDE;
|
||||
void ClientDataHandler(mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
void ServerDataHandler(mozilla::ipc::UnixSocketRawData* aMessage);
|
||||
|
||||
|
@ -72,15 +72,6 @@ public:
|
|||
// Return true if there is an ongoing file-transfer session, please see
|
||||
// Bug 827267 for more information.
|
||||
bool IsTransferring();
|
||||
|
||||
// Implement interface BluetoothSocketObserver
|
||||
void ReceiveSocketData(
|
||||
BluetoothSocket* aSocket,
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
|
||||
void OnConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
void OnConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
void OnDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
BluetoothOppManager();
|
||||
void StartFileTransfer();
|
||||
|
@ -99,10 +90,14 @@ private:
|
|||
void ValidateFileName();
|
||||
bool IsReservedChar(PRUnichar c);
|
||||
|
||||
virtual void OnConnectSuccess() MOZ_OVERRIDE;
|
||||
virtual void OnConnectError() MOZ_OVERRIDE;
|
||||
virtual void OnDisconnect() MOZ_OVERRIDE;
|
||||
|
||||
/**
|
||||
* RFCOMM socket status.
|
||||
*/
|
||||
mozilla::ipc::SocketConnectionStatus mPrevSocketStatus;
|
||||
enum mozilla::ipc::SocketConnectionStatus mSocketStatus;
|
||||
|
||||
/**
|
||||
* OBEX session status.
|
||||
|
@ -178,7 +173,6 @@ private:
|
|||
|
||||
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
||||
nsRefPtr<DeviceStorageFile> mDsFile;
|
||||
nsRefPtr<BluetoothSocket> mSocket;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothSocket.h"
|
||||
#include "BluetoothUtils.h"
|
||||
|
||||
#include "mozilla/Services.h"
|
||||
|
@ -94,7 +93,7 @@ BluetoothScoManager::NotifyAudioManager(const nsAString& aAddress) {
|
|||
NS_IMPL_ISUPPORTS1(BluetoothScoManagerObserver, nsIObserver)
|
||||
|
||||
namespace {
|
||||
StaticAutoPtr<BluetoothScoManager> gBluetoothScoManager;
|
||||
StaticRefPtr<BluetoothScoManager> gBluetoothScoManager;
|
||||
StaticRefPtr<BluetoothScoManagerObserver> sScoObserver;
|
||||
bool gInShutdown = false;
|
||||
} // anonymous namespace
|
||||
|
@ -120,11 +119,7 @@ BluetoothScoManager::BluetoothScoManager()
|
|||
bool
|
||||
BluetoothScoManager::Init()
|
||||
{
|
||||
mSocket = new BluetoothSocket(this,
|
||||
BluetoothSocketType::SCO,
|
||||
true,
|
||||
false);
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
|
||||
sScoObserver = new BluetoothScoManagerObserver();
|
||||
if (!sScoObserver->Init()) {
|
||||
|
@ -163,8 +158,12 @@ BluetoothScoManager::Get()
|
|||
}
|
||||
|
||||
// Create new instance, register, return
|
||||
BluetoothScoManager* manager = new BluetoothScoManager();
|
||||
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||
nsRefPtr<BluetoothScoManager> manager = new BluetoothScoManager();
|
||||
NS_ENSURE_TRUE(manager, nullptr);
|
||||
|
||||
if (!manager->Init()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gBluetoothScoManager = manager;
|
||||
return gBluetoothScoManager;
|
||||
|
@ -172,8 +171,7 @@ BluetoothScoManager::Get()
|
|||
|
||||
// Virtual function of class SocketConsumer
|
||||
void
|
||||
BluetoothScoManager::ReceiveSocketData(BluetoothSocket* aSocket,
|
||||
nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
BluetoothScoManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
|
||||
{
|
||||
// SCO socket do nothing here
|
||||
MOZ_NOT_REACHED("This should never be called!");
|
||||
|
@ -184,7 +182,7 @@ BluetoothScoManager::HandleShutdown()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
gInShutdown = true;
|
||||
mSocket->Disconnect();
|
||||
CloseSocket();
|
||||
gBluetoothScoManager = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -199,13 +197,12 @@ BluetoothScoManager::Connect(const nsAString& aDeviceAddress)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (mSocket->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
NS_WARNING("Sco socket has been connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
mSocket->Disconnect();
|
||||
CloseSocket();
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
|
@ -216,7 +213,7 @@ BluetoothScoManager::Connect(const nsAString& aDeviceAddress)
|
|||
nsresult rv = bs->GetScoSocket(aDeviceAddress,
|
||||
true,
|
||||
false,
|
||||
mSocket);
|
||||
this);
|
||||
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
}
|
||||
|
@ -231,57 +228,57 @@ BluetoothScoManager::Listen()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (mSocket->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_LISTENING) {
|
||||
NS_WARNING("BluetoothScoManager has been already listening");
|
||||
return true;
|
||||
}
|
||||
CloseSocket();
|
||||
|
||||
mSocket->Disconnect();
|
||||
|
||||
if (!mSocket->Listen(-1)) {
|
||||
NS_WARNING("[SCO] Can't listen on socket!");
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
NS_WARNING("BluetoothService not available!");
|
||||
return false;
|
||||
}
|
||||
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
return true;
|
||||
nsresult rv = bs->ListenSocketViaService(-1,
|
||||
BluetoothSocketType::SCO,
|
||||
true,
|
||||
true,
|
||||
this);
|
||||
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothScoManager::Disconnect()
|
||||
{
|
||||
mSocket->Disconnect();
|
||||
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_DISCONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothScoManager::OnConnectSuccess(BluetoothSocket* aSocket)
|
||||
BluetoothScoManager::OnConnectSuccess()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
nsString address;
|
||||
mSocket->GetAddress(address);
|
||||
GetSocketAddr(address);
|
||||
NotifyAudioManager(address);
|
||||
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothScoManager::OnConnectError(BluetoothSocket* aSocket)
|
||||
BluetoothScoManager::OnConnectError()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
mSocket->Disconnect();
|
||||
mPrevSocketStatus = mSocket->GetConnectionStatus();
|
||||
CloseSocket();
|
||||
mSocketStatus = GetConnectionStatus();
|
||||
Listen();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothScoManager::OnDisconnect(BluetoothSocket* aSocket)
|
||||
BluetoothScoManager::OnDisconnect()
|
||||
{
|
||||
MOZ_ASSERT(aSocket == mSocket);
|
||||
|
||||
if (mPrevSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
||||
Listen();
|
||||
|
||||
nsString address = NS_LITERAL_STRING("");
|
||||
|
|
|
@ -8,27 +8,22 @@
|
|||
#define mozilla_dom_bluetooth_bluetoothscomanager_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "BluetoothSocketObserver.h"
|
||||
#include "mozilla/ipc/UnixSocket.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothReplyRunnable;
|
||||
class BluetoothScoManagerObserver;
|
||||
class BluetoothSocket;
|
||||
|
||||
class BluetoothScoManager : public BluetoothSocketObserver
|
||||
class BluetoothScoManager : public mozilla::ipc::UnixSocketConsumer
|
||||
{
|
||||
public:
|
||||
static BluetoothScoManager* Get();
|
||||
~BluetoothScoManager();
|
||||
|
||||
virtual void ReceiveSocketData(
|
||||
BluetoothSocket* aSocket,
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
|
||||
virtual void OnConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
virtual void OnConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
virtual void OnDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
||||
static BluetoothScoManager* Get();
|
||||
void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage)
|
||||
MOZ_OVERRIDE;
|
||||
|
||||
bool Connect(const nsAString& aDeviceObjectPath);
|
||||
void Disconnect();
|
||||
|
@ -41,9 +36,11 @@ private:
|
|||
void Cleanup();
|
||||
nsresult HandleShutdown();
|
||||
void NotifyAudioManager(const nsAString& aAddress);
|
||||
virtual void OnConnectSuccess() MOZ_OVERRIDE;
|
||||
virtual void OnConnectError() MOZ_OVERRIDE;
|
||||
virtual void OnDisconnect() MOZ_OVERRIDE;
|
||||
|
||||
SocketConnectionStatus mPrevSocketStatus;
|
||||
nsRefPtr<BluetoothSocket> mSocket;
|
||||
int mSocketStatus;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
|
|
@ -249,6 +249,13 @@ public:
|
|||
StopSendingFile(const nsAString& aDeviceAddress,
|
||||
BluetoothReplyRunnable* aRunnable) = 0;
|
||||
|
||||
virtual nsresult
|
||||
ListenSocketViaService(int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer) = 0;
|
||||
|
||||
virtual void
|
||||
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
|
||||
BluetoothReplyRunnable* aRunnable) = 0;
|
||||
|
|
|
@ -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_LOG("%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_LOG("%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->OnConnectSuccess(this);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnConnectError()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->OnConnectError(this);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::OnDisconnect()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mObserver);
|
||||
mObserver->OnDisconnect(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() MOZ_OVERRIDE;
|
||||
virtual void OnConnectError() MOZ_OVERRIDE;
|
||||
virtual void OnDisconnect() MOZ_OVERRIDE;
|
||||
virtual void ReceiveSocketData(
|
||||
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
|
||||
|
||||
inline void GetAddress(nsAString& aDeviceAddress)
|
||||
{
|
||||
GetSocketAddr(aDeviceAddress);
|
||||
}
|
||||
|
||||
private:
|
||||
BluetoothSocketObserver* mObserver;
|
||||
BluetoothSocketType mType;
|
||||
bool mAuth;
|
||||
bool mEncrypt;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -1,30 +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_BluetoothSocketObserver_h
|
||||
#define mozilla_dom_bluetooth_BluetoothSocketObserver_h
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include <mozilla/ipc/UnixSocket.h>
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocket;
|
||||
|
||||
class BluetoothSocketObserver
|
||||
{
|
||||
public:
|
||||
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage) = 0;
|
||||
virtual void OnConnectSuccess() = 0;
|
||||
virtual void OnConnectError() = 0;
|
||||
virtual void OnDisconnect() = 0;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
|
@ -54,7 +54,6 @@ CPPSRCS += \
|
|||
ObexBase.cpp \
|
||||
BluetoothScoManager.cpp \
|
||||
BluetoothUuid.cpp \
|
||||
BluetoothSocket.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_B2G_RIL
|
||||
|
|
|
@ -212,6 +212,19 @@ BluetoothServiceChildProcess::GetSocketViaService(
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
BluetoothServiceChildProcess::ListenSocketViaService(
|
||||
int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer)
|
||||
{
|
||||
MOZ_NOT_REACHED("This should never be called!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothServiceChildProcess::SetPinCodeInternal(
|
||||
const nsAString& aDeviceAddress,
|
||||
|
|
|
@ -91,6 +91,13 @@ public:
|
|||
mozilla::ipc::UnixSocketConsumer* aConsumer,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
||||
virtual nsresult
|
||||
ListenSocketViaService(int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
SetPinCodeInternal(const nsAString& aDeviceAddress,
|
||||
const nsAString& aPinCode,
|
||||
|
|
|
@ -833,17 +833,17 @@ public:
|
|||
{
|
||||
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
|
||||
if (hfp) {
|
||||
hfp->Disconnect();
|
||||
hfp->CloseSocket();
|
||||
}
|
||||
|
||||
BluetoothOppManager* opp = BluetoothOppManager::Get();
|
||||
if (opp) {
|
||||
opp->Disconnect();
|
||||
opp->CloseSocket();
|
||||
}
|
||||
|
||||
BluetoothScoManager* sco = BluetoothScoManager::Get();
|
||||
if (sco) {
|
||||
sco->Disconnect();
|
||||
sco->CloseSocket();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -2547,7 +2547,8 @@ BluetoothDBusService::IsConnected(const uint16_t aProfileId)
|
|||
if (aProfileId == BluetoothServiceClass::HANDSFREE ||
|
||||
aProfileId == BluetoothServiceClass::HEADSET) {
|
||||
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
|
||||
return hfp->IsConnected();
|
||||
return (hfp->GetConnectionStatus() ==
|
||||
SocketConnectionStatus::SOCKET_CONNECTED);
|
||||
} else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
|
||||
BluetoothOppManager* opp = BluetoothOppManager::Get();
|
||||
return opp->IsTransferring();
|
||||
|
@ -2793,3 +2794,22 @@ BluetoothDBusService::ConfirmReceivingFile(const nsAString& aDeviceAddress,
|
|||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDBusService::ListenSocketViaService(
|
||||
int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
||||
|
||||
BluetoothUnixSocketConnector* c =
|
||||
new BluetoothUnixSocketConnector(aType, aChannel, aAuth, aEncrypt);
|
||||
if (!aConsumer->ListenSocket(c)) {
|
||||
NS_WARNING("Can't listen on socket!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -86,6 +86,13 @@ public:
|
|||
mozilla::ipc::UnixSocketConsumer* aConsumer,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
ListenSocketViaService(int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer);
|
||||
|
||||
virtual nsresult
|
||||
CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
|
||||
int aTimeout,
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
|
||||
virtual ~UnixSocketConsumer();
|
||||
|
||||
SocketConnectionStatus GetConnectionStatus() const
|
||||
SocketConnectionStatus GetConnectionStatus()
|
||||
{
|
||||
return mConnectionStatus;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче