2012-09-26 13:34:55 +00:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2013-01-08 09:21:00 +00:00
|
|
|
#include "base/basictypes.h"
|
2012-09-29 09:39:05 +00:00
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
#include "BluetoothHfpManager.h"
|
|
|
|
|
|
|
|
#include "BluetoothReplyRunnable.h"
|
2012-09-29 09:39:05 +00:00
|
|
|
#include "BluetoothScoManager.h"
|
2012-09-26 13:34:55 +00:00
|
|
|
#include "BluetoothService.h"
|
2012-10-03 09:06:40 +00:00
|
|
|
#include "BluetoothUtils.h"
|
2012-11-27 06:12:19 +00:00
|
|
|
#include "BluetoothUuid.h"
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2012-12-17 09:44:32 +00:00
|
|
|
#include "MobileConnection.h"
|
2012-09-25 10:18:38 +00:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2013-01-22 05:53:28 +00:00
|
|
|
#include "mozilla/Hal.h"
|
2012-09-27 02:24:39 +00:00
|
|
|
#include "mozilla/Services.h"
|
2012-10-03 05:53:39 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-09-25 10:18:38 +00:00
|
|
|
#include "nsContentUtils.h"
|
2012-10-03 02:55:28 +00:00
|
|
|
#include "nsIAudioManager.h"
|
2012-09-27 02:24:39 +00:00
|
|
|
#include "nsIObserverService.h"
|
2012-11-19 07:10:38 +00:00
|
|
|
#include "nsISettingsService.h"
|
2012-09-27 05:15:33 +00:00
|
|
|
#include "nsIRadioInterfaceLayer.h"
|
2012-12-20 07:28:51 +00:00
|
|
|
#include "nsRadioInterfaceLayer.h"
|
2012-09-27 05:15:33 +00:00
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
#define AUDIO_VOLUME_BT_SCO "audio.volume.bt_sco"
|
2012-12-17 09:44:32 +00:00
|
|
|
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
|
|
|
|
#define MOBILE_CONNECTION_ICCINFO_CHANGED "mobile-connection-iccinfo-changed"
|
2012-12-20 07:28:51 +00:00
|
|
|
#define MOBILE_CONNECTION_VOICE_CHANGED "mobile-connection-voice-changed"
|
2012-12-17 09:44:32 +00:00
|
|
|
|
2012-12-17 15:24:35 +00:00
|
|
|
/**
|
|
|
|
* These constants are used in result code such as +CLIP and +CCWA. The value
|
|
|
|
* of these constants is the same as TOA_INTERNATIONAL/TOA_UNKNOWN defined in
|
|
|
|
* ril_consts.js
|
|
|
|
*/
|
|
|
|
#define TOA_UNKNOWN 0x81
|
|
|
|
#define TOA_INTERNATIONAL 0x91
|
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
using namespace mozilla;
|
2012-09-26 13:34:55 +00:00
|
|
|
using namespace mozilla::ipc;
|
2012-10-03 05:53:39 +00:00
|
|
|
USING_BLUETOOTH_NAMESPACE
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2012-12-20 07:28:51 +00:00
|
|
|
namespace {
|
|
|
|
StaticRefPtr<BluetoothHfpManager> gBluetoothHfpManager;
|
|
|
|
StaticRefPtr<BluetoothHfpManagerObserver> sHfpObserver;
|
|
|
|
bool gInShutdown = false;
|
|
|
|
static bool sStopSendingRingFlag = true;
|
|
|
|
|
|
|
|
static int sRingInterval = 3000; //unit: ms
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
/* CallState for sCINDItems[CINDType::CALL].value
|
|
|
|
* - NO_CALL: there are no calls in progress
|
|
|
|
* - IN_PROGRESS: at least one call is in progress
|
|
|
|
*/
|
|
|
|
enum CallState {
|
|
|
|
NO_CALL,
|
|
|
|
IN_PROGRESS
|
|
|
|
};
|
|
|
|
|
|
|
|
/* CallSetupState for sCINDItems[CINDType::CALLSETUP].value
|
|
|
|
* - NO_CALLSETUP: not currently in call set up
|
|
|
|
* - INCOMING: an incoming call process ongoing
|
|
|
|
* - OUTGOING: an outgoing call set up is ongoing
|
|
|
|
* - OUTGOING_ALERTING: remote party being alerted in an outgoing call
|
|
|
|
*/
|
|
|
|
enum CallSetupState {
|
|
|
|
NO_CALLSETUP,
|
|
|
|
INCOMING,
|
|
|
|
OUTGOING,
|
|
|
|
OUTGOING_ALERTING
|
|
|
|
};
|
|
|
|
|
|
|
|
/* CallHeldState for sCINDItems[CINDType::CALLHELD].value
|
|
|
|
* - NO_CALLHELD: no calls held
|
|
|
|
* - ONHOLD_ACTIVE: both an active and a held call
|
|
|
|
* - ONHOLD_NOACTIVE: call on hold, no active call
|
|
|
|
*/
|
|
|
|
enum CallHeldState {
|
|
|
|
NO_CALLHELD,
|
|
|
|
ONHOLD_ACTIVE,
|
|
|
|
ONHOLD_NOACTIVE
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char* name;
|
|
|
|
const char* range;
|
|
|
|
int value;
|
|
|
|
} CINDItem;
|
|
|
|
|
|
|
|
enum CINDType {
|
|
|
|
BATTCHG = 1,
|
|
|
|
CALL,
|
|
|
|
CALLHELD,
|
2012-12-20 07:28:51 +00:00
|
|
|
CALLSETUP,
|
|
|
|
SERVICE,
|
|
|
|
SIGNAL,
|
|
|
|
ROAM
|
2012-10-22 10:34:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static CINDItem sCINDItems[] = {
|
|
|
|
{},
|
|
|
|
{"battchg", "0-5", 5},
|
|
|
|
{"call", "0,1", CallState::NO_CALL},
|
|
|
|
{"callheld", "0-2", CallHeldState::NO_CALLHELD},
|
2012-12-20 07:28:51 +00:00
|
|
|
{"callsetup", "0-3", CallSetupState::NO_CALLSETUP},
|
|
|
|
{"service", "0,1", 0},
|
|
|
|
{"signal", "0-5", 0},
|
2012-10-22 10:34:15 +00:00
|
|
|
{"roam", "0,1", 0}
|
|
|
|
};
|
|
|
|
|
2013-01-16 06:13:58 +00:00
|
|
|
class mozilla::dom::bluetooth::Call {
|
|
|
|
public:
|
|
|
|
Call(uint16_t aState = nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED,
|
|
|
|
bool aDirection = false,
|
|
|
|
const nsAString& aNumber = NS_LITERAL_STRING(""),
|
|
|
|
int aType = TOA_UNKNOWN)
|
|
|
|
: mState(aState), mDirection(aDirection), mNumber(aNumber), mType(aType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t mState;
|
|
|
|
bool mDirection; // true: incoming call; false: outgoing call
|
|
|
|
nsString mNumber;
|
|
|
|
int mType;
|
|
|
|
};
|
|
|
|
|
2012-10-06 00:11:24 +00:00
|
|
|
class mozilla::dom::bluetooth::BluetoothHfpManagerObserver : public nsIObserver
|
2013-01-22 05:53:28 +00:00
|
|
|
, public BatteryObserver
|
2012-10-06 00:11:24 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
BluetoothHfpManagerObserver()
|
2012-10-09 04:59:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Init()
|
2012-10-06 00:11:24 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
MOZ_ASSERT(obs);
|
|
|
|
if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false))) {
|
|
|
|
NS_WARNING("Failed to add settings change observer!");
|
2012-10-09 04:59:33 +00:00
|
|
|
return false;
|
2012-10-06 00:11:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
|
|
|
NS_WARNING("Failed to add shutdown observer!");
|
2012-10-09 04:59:33 +00:00
|
|
|
return false;
|
2012-10-06 00:11:24 +00:00
|
|
|
}
|
2012-10-09 04:59:33 +00:00
|
|
|
|
2012-12-17 09:44:32 +00:00
|
|
|
if (NS_FAILED(obs->AddObserver(this, MOBILE_CONNECTION_ICCINFO_CHANGED, false))) {
|
|
|
|
NS_WARNING("Failed to add mobile connection iccinfo change observer!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-20 07:28:51 +00:00
|
|
|
if (NS_FAILED(obs->AddObserver(this, MOBILE_CONNECTION_VOICE_CHANGED, false))) {
|
|
|
|
NS_WARNING("Failed to add mobile connection voice change observer!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-22 05:53:28 +00:00
|
|
|
hal::RegisterBatteryObserver(this);
|
|
|
|
|
2012-10-09 04:59:33 +00:00
|
|
|
return true;
|
2012-10-06 00:11:24 +00:00
|
|
|
}
|
|
|
|
|
2012-10-09 04:59:33 +00:00
|
|
|
bool Shutdown()
|
2012-10-06 00:11:24 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
2012-10-09 04:59:33 +00:00
|
|
|
if (!obs ||
|
2012-12-17 09:44:32 +00:00
|
|
|
NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
|
|
|
|
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)) ||
|
2012-12-20 07:28:51 +00:00
|
|
|
NS_FAILED(obs->RemoveObserver(this, MOBILE_CONNECTION_ICCINFO_CHANGED)) ||
|
|
|
|
NS_FAILED(obs->RemoveObserver(this, MOBILE_CONNECTION_VOICE_CHANGED))) {
|
2012-10-09 04:59:33 +00:00
|
|
|
NS_WARNING("Can't unregister observers, or already unregistered!");
|
|
|
|
return false;
|
2012-10-06 00:11:24 +00:00
|
|
|
}
|
2013-01-22 05:53:28 +00:00
|
|
|
|
|
|
|
hal::UnregisterBatteryObserver(this);
|
|
|
|
|
2012-10-09 04:59:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
~BluetoothHfpManagerObserver()
|
|
|
|
{
|
|
|
|
Shutdown();
|
2012-10-06 00:11:24 +00:00
|
|
|
}
|
2013-01-22 05:53:28 +00:00
|
|
|
|
|
|
|
void Notify(const hal::BatteryInformation& aBatteryInfo)
|
|
|
|
{
|
|
|
|
// Range of battery level: [0, 1], double
|
|
|
|
// Range of CIND::BATTCHG: [0, 5], int
|
|
|
|
int level = ceil(aBatteryInfo.level() * 5.0);
|
|
|
|
if (level != sCINDItems[CINDType::BATTCHG].value) {
|
|
|
|
sCINDItems[CINDType::BATTCHG].value = level;
|
|
|
|
gBluetoothHfpManager->SendCommand("+CIEV: ", CINDType::BATTCHG);
|
|
|
|
}
|
|
|
|
}
|
2012-10-06 00:11:24 +00:00
|
|
|
};
|
|
|
|
|
2013-01-16 06:13:41 +00:00
|
|
|
class BluetoothHfpManager::GetVolumeTask : public nsISettingsServiceCallback
|
2012-11-19 07:10:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Handle(const nsAString& aName, const jsval& aResult)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
NS_ENSURE_TRUE(cx, NS_OK);
|
|
|
|
|
|
|
|
if (!aResult.isNumber()) {
|
|
|
|
NS_WARNING("'" AUDIO_VOLUME_BT_SCO "' is not a number!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
|
2013-01-16 06:13:41 +00:00
|
|
|
hfp->mCurrentVgs = aResult.toNumber();
|
2012-11-19 07:10:38 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
HandleError(const nsAString& aName)
|
|
|
|
{
|
|
|
|
NS_WARNING("Unable to get value for '" AUDIO_VOLUME_BT_SCO "'");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-16 06:13:41 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(BluetoothHfpManager::GetVolumeTask,
|
|
|
|
nsISettingsServiceCallback);
|
2012-11-19 07:10:38 +00:00
|
|
|
|
2012-10-06 00:11:24 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BluetoothHfpManagerObserver::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(gBluetoothHfpManager);
|
2012-10-22 10:34:15 +00:00
|
|
|
|
2012-10-06 00:11:24 +00:00
|
|
|
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
|
|
|
|
return gBluetoothHfpManager->HandleVolumeChanged(nsDependentString(aData));
|
|
|
|
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
|
|
|
return gBluetoothHfpManager->HandleShutdown();
|
2012-12-17 09:44:32 +00:00
|
|
|
} else if (!strcmp(aTopic, MOBILE_CONNECTION_ICCINFO_CHANGED)) {
|
|
|
|
return gBluetoothHfpManager->HandleIccInfoChanged();
|
2012-12-20 07:28:51 +00:00
|
|
|
} else if (!strcmp(aTopic, MOBILE_CONNECTION_VOICE_CHANGED)) {
|
|
|
|
return gBluetoothHfpManager->HandleVoiceConnectionChanged();
|
2012-10-06 00:11:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2012-09-25 10:18:38 +00:00
|
|
|
|
2012-12-20 07:28:51 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(BluetoothHfpManagerObserver, nsIObserver)
|
|
|
|
|
2012-10-26 01:25:15 +00:00
|
|
|
class SendRingIndicatorTask : public Task
|
2012-09-27 05:15:33 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-01-16 06:13:58 +00:00
|
|
|
SendRingIndicatorTask(const nsAString& aNumber, int aType)
|
2012-12-17 15:24:35 +00:00
|
|
|
: mNumber(aNumber)
|
|
|
|
, mType(aType)
|
2012-09-27 05:15:33 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2012-10-26 01:25:15 +00:00
|
|
|
void Run() MOZ_OVERRIDE
|
2012-09-27 05:15:33 +00:00
|
|
|
{
|
2012-10-26 01:25:15 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-27 05:15:33 +00:00
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_ENSURE_FALSE_VOID(sStopSendingRingFlag);
|
2012-09-27 05:15:33 +00:00
|
|
|
|
2012-10-26 01:25:15 +00:00
|
|
|
if (!gBluetoothHfpManager) {
|
|
|
|
NS_WARNING("BluetoothHfpManager no longer exists, cannot send ring!");
|
|
|
|
return;
|
2012-09-27 05:15:33 +00:00
|
|
|
}
|
2012-12-17 15:24:35 +00:00
|
|
|
|
2013-01-16 06:13:41 +00:00
|
|
|
const char* kHfpCrlf = "\xd\xa";
|
|
|
|
nsAutoCString ringMsg(kHfpCrlf);
|
|
|
|
ringMsg += "RING";
|
|
|
|
ringMsg += kHfpCrlf;
|
|
|
|
gBluetoothHfpManager->SendSocketData(ringMsg);
|
2012-10-26 01:25:15 +00:00
|
|
|
|
2012-12-17 15:24:35 +00:00
|
|
|
if (!mNumber.IsEmpty()) {
|
2013-01-16 06:13:41 +00:00
|
|
|
nsAutoCString clipMsg(kHfpCrlf);
|
|
|
|
clipMsg += "+CLIP: \"";
|
2013-01-16 06:13:58 +00:00
|
|
|
clipMsg += NS_ConvertUTF16toUTF8(mNumber).get();
|
2013-01-16 06:13:41 +00:00
|
|
|
clipMsg += "\",";
|
|
|
|
clipMsg.AppendInt(mType);
|
|
|
|
clipMsg += kHfpCrlf;
|
|
|
|
gBluetoothHfpManager->SendSocketData(clipMsg);
|
2012-12-17 15:24:35 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 01:25:15 +00:00
|
|
|
MessageLoop::current()->
|
|
|
|
PostDelayedTask(FROM_HERE,
|
2013-01-16 06:13:58 +00:00
|
|
|
new SendRingIndicatorTask(mNumber, mType),
|
2012-10-26 01:25:15 +00:00
|
|
|
sRingInterval);
|
2012-09-27 05:15:33 +00:00
|
|
|
}
|
2012-12-17 15:24:35 +00:00
|
|
|
|
|
|
|
private:
|
2013-01-16 06:13:58 +00:00
|
|
|
nsString mNumber;
|
2012-12-17 15:24:35 +00:00
|
|
|
int mType;
|
2012-09-27 05:15:33 +00:00
|
|
|
};
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2012-09-29 09:39:05 +00:00
|
|
|
void
|
2012-10-22 10:34:15 +00:00
|
|
|
OpenScoSocket(const nsAString& aDeviceAddress)
|
2012-09-29 09:39:05 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
BluetoothScoManager* sco = BluetoothScoManager::Get();
|
|
|
|
if (!sco) {
|
|
|
|
NS_WARNING("BluetoothScoManager is not available!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
if (!sco->Connect(aDeviceAddress)) {
|
2012-09-29 09:39:05 +00:00
|
|
|
NS_WARNING("Failed to create a sco socket!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CloseScoSocket()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
BluetoothScoManager* sco = BluetoothScoManager::Get();
|
|
|
|
if (!sco) {
|
|
|
|
NS_WARNING("BluetoothScoManager is not available!");
|
|
|
|
return;
|
|
|
|
}
|
2012-10-22 10:34:15 +00:00
|
|
|
sco->Disconnect();
|
2012-09-29 09:39:05 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 06:13:41 +00:00
|
|
|
static bool
|
2013-01-08 09:21:00 +00:00
|
|
|
IsValidDtmf(const char aChar) {
|
|
|
|
// Valid DTMF: [*#0-9ABCD]
|
|
|
|
if (aChar == '*' || aChar == '#') {
|
|
|
|
return true;
|
|
|
|
} else if (aChar >= '0' && aChar <= '9') {
|
|
|
|
return true;
|
|
|
|
} else if (aChar >= 'A' && aChar <= 'D') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:15:33 +00:00
|
|
|
BluetoothHfpManager::BluetoothHfpManager()
|
2012-10-03 05:53:39 +00:00
|
|
|
{
|
2013-01-16 06:13:58 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ResetCallArray()
|
|
|
|
{
|
|
|
|
mCurrentCallIndex = 0;
|
|
|
|
mCurrentCallArray.Clear();
|
|
|
|
// Append a call object at the beginning of mCurrentCallArray since call
|
|
|
|
// index from RIL starts at 1.
|
|
|
|
Call call;
|
|
|
|
mCurrentCallArray.AppendElement(call);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::Reset()
|
|
|
|
{
|
|
|
|
sStopSendingRingFlag = true;
|
2012-10-22 10:34:15 +00:00
|
|
|
sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
|
|
|
sCINDItems[CINDType::CALLHELD].value = CallHeldState::NO_CALLHELD;
|
2012-10-31 03:53:36 +00:00
|
|
|
|
2013-01-16 06:17:41 +00:00
|
|
|
mCCWA = false;
|
2013-01-16 06:13:58 +00:00
|
|
|
mCLIP = false;
|
|
|
|
mCMEE = false;
|
|
|
|
mCMER = false;
|
|
|
|
mReceiveVgsFlag = false;
|
|
|
|
|
|
|
|
ResetCallArray();
|
2012-10-03 05:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BluetoothHfpManager::Init()
|
2012-09-26 13:34:55 +00:00
|
|
|
{
|
2012-11-19 07:10:38 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-26 09:28:39 +00:00
|
|
|
mSocketStatus = GetConnectionStatus();
|
|
|
|
|
2012-10-06 00:11:24 +00:00
|
|
|
sHfpObserver = new BluetoothHfpManagerObserver();
|
2012-10-09 04:59:33 +00:00
|
|
|
if (!sHfpObserver->Init()) {
|
|
|
|
NS_WARNING("Cannot set up Hfp Observers!");
|
|
|
|
}
|
2012-10-03 05:53:39 +00:00
|
|
|
|
2012-09-27 12:24:06 +00:00
|
|
|
mListener = new BluetoothRilListener();
|
|
|
|
if (!mListener->StartListening()) {
|
|
|
|
NS_WARNING("Failed to start listening RIL");
|
2012-10-03 05:53:39 +00:00
|
|
|
return false;
|
2012-09-27 12:24:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
nsCOMPtr<nsISettingsService> settings =
|
|
|
|
do_GetService("@mozilla.org/settingsService;1");
|
|
|
|
NS_ENSURE_TRUE(settings, false);
|
2012-10-25 10:50:41 +00:00
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
nsCOMPtr<nsISettingsServiceLock> settingsLock;
|
|
|
|
nsresult rv = settings->CreateLock(getter_AddRefs(settingsLock));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
nsRefPtr<GetVolumeTask> callback = new GetVolumeTask();
|
|
|
|
rv = settingsLock->Get(AUDIO_VOLUME_BT_SCO, callback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2012-10-25 10:50:41 +00:00
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
return true;
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BluetoothHfpManager::~BluetoothHfpManager()
|
2012-10-03 05:53:39 +00:00
|
|
|
{
|
|
|
|
Cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::Cleanup()
|
2012-09-26 13:34:55 +00:00
|
|
|
{
|
2012-09-27 12:24:06 +00:00
|
|
|
if (!mListener->StopListening()) {
|
|
|
|
NS_WARNING("Failed to stop listening RIL");
|
|
|
|
}
|
|
|
|
mListener = nullptr;
|
|
|
|
|
2012-10-09 04:59:33 +00:00
|
|
|
sHfpObserver->Shutdown();
|
2012-10-06 00:11:24 +00:00
|
|
|
sHfpObserver = nullptr;
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
BluetoothHfpManager*
|
|
|
|
BluetoothHfpManager::Get()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
// If we already exist, exit early
|
|
|
|
if (gBluetoothHfpManager) {
|
|
|
|
return gBluetoothHfpManager;
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
// If we're in shutdown, don't create a new instance
|
|
|
|
if (gInShutdown) {
|
|
|
|
NS_WARNING("BluetoothHfpManager can't be created during shutdown");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new instance, register, return
|
|
|
|
nsRefPtr<BluetoothHfpManager> manager = new BluetoothHfpManager();
|
|
|
|
NS_ENSURE_TRUE(manager, nullptr);
|
|
|
|
|
|
|
|
if (!manager->Init()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBluetoothHfpManager = manager;
|
|
|
|
return gBluetoothHfpManager;
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-01 07:44:48 +00:00
|
|
|
void
|
2012-10-22 10:34:15 +00:00
|
|
|
BluetoothHfpManager::NotifySettings()
|
2012-10-01 07:44:48 +00:00
|
|
|
{
|
|
|
|
nsString type, name;
|
|
|
|
BluetoothValue v;
|
|
|
|
InfallibleTArray<BluetoothNamedValue> parameters;
|
|
|
|
type.AssignLiteral("bluetooth-hfp-status-changed");
|
|
|
|
|
|
|
|
name.AssignLiteral("connected");
|
2012-11-19 07:10:38 +00:00
|
|
|
v = (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED)
|
|
|
|
? true : false ;
|
2012-10-01 07:44:48 +00:00
|
|
|
parameters.AppendElement(BluetoothNamedValue(name, v));
|
|
|
|
|
|
|
|
name.AssignLiteral("address");
|
2012-10-26 09:21:32 +00:00
|
|
|
v = mDevicePath;
|
2012-10-01 07:44:48 +00:00
|
|
|
parameters.AppendElement(BluetoothNamedValue(name, v));
|
|
|
|
|
|
|
|
if (!BroadcastSystemMessage(type, parameters)) {
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_WARNING("Failed to broadcast system message to settings");
|
2012-10-01 07:44:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
|
|
|
|
{
|
2012-12-17 09:51:38 +00:00
|
|
|
nsString type, name;
|
|
|
|
BluetoothValue v;
|
2012-10-01 07:44:48 +00:00
|
|
|
InfallibleTArray<BluetoothNamedValue> parameters;
|
|
|
|
type.AssignLiteral("bluetooth-dialer-command");
|
|
|
|
|
2012-12-17 09:51:38 +00:00
|
|
|
name.AssignLiteral("command");
|
|
|
|
v = nsString(aCommand);
|
|
|
|
parameters.AppendElement(BluetoothNamedValue(name, v));
|
2012-10-01 07:44:48 +00:00
|
|
|
|
|
|
|
if (!BroadcastSystemMessage(type, parameters)) {
|
|
|
|
NS_WARNING("Failed to broadcast system message to dialer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 10:18:38 +00:00
|
|
|
nsresult
|
|
|
|
BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// The string that we're interested in will be a JSON string that looks like:
|
2012-11-19 07:10:38 +00:00
|
|
|
// {"key":"volumeup", "value":10}
|
|
|
|
// {"key":"volumedown", "value":2}
|
2012-09-25 10:18:38 +00:00
|
|
|
|
|
|
|
JSContext* cx = nsContentUtils::GetSafeJSContext();
|
|
|
|
if (!cx) {
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_WARNING("Failed to get JSContext");
|
2012-09-25 10:18:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value val;
|
|
|
|
if (!JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val)) {
|
|
|
|
return JS_ReportPendingException(cx) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!val.isObject()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject& obj(val.toObject());
|
|
|
|
|
|
|
|
JS::Value key;
|
|
|
|
if (!JS_GetProperty(cx, &obj, "key", &key)) {
|
|
|
|
MOZ_ASSERT(!JS_IsExceptionPending(cx));
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!key.isString()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool match;
|
2012-11-19 07:10:38 +00:00
|
|
|
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO, &match)) {
|
2012-09-25 10:18:38 +00:00
|
|
|
MOZ_ASSERT(!JS_IsExceptionPending(cx));
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value value;
|
|
|
|
if (!JS_GetProperty(cx, &obj, "value", &value)) {
|
|
|
|
MOZ_ASSERT(!JS_IsExceptionPending(cx));
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value.isNumber()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
mCurrentVgs = value.toNumber();
|
2012-10-25 10:50:41 +00:00
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
// Adjust volume by headset and we don't have to send volume back to headset
|
2012-10-25 10:50:41 +00:00
|
|
|
if (mReceiveVgsFlag) {
|
|
|
|
mReceiveVgsFlag = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
// Only send volume back when there's a connected headset
|
|
|
|
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
SendCommand("+VGS: ", mCurrentVgs);
|
2012-10-25 10:50:41 +00:00
|
|
|
}
|
2012-09-25 10:18:38 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-20 07:28:51 +00:00
|
|
|
nsresult
|
|
|
|
BluetoothHfpManager::HandleVoiceConnectionChanged()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMobileConnectionProvider> connection =
|
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(connection, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsIDOMMozMobileConnectionInfo* voiceInfo;
|
|
|
|
connection->GetVoiceConnectionInfo(&voiceInfo);
|
|
|
|
NS_ENSURE_TRUE(voiceInfo, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
bool roaming;
|
|
|
|
voiceInfo->GetRoaming(&roaming);
|
|
|
|
if (roaming != sCINDItems[CINDType::ROAM].value) {
|
|
|
|
sCINDItems[CINDType::ROAM].value = roaming;
|
|
|
|
SendCommand("+CIEV: ", CINDType::ROAM);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool service = false;
|
|
|
|
nsString regState;
|
|
|
|
voiceInfo->GetState(regState);
|
|
|
|
if (regState.EqualsLiteral("registered")) {
|
|
|
|
service = true;
|
|
|
|
}
|
|
|
|
if (service != sCINDItems[CINDType::SERVICE].value) {
|
|
|
|
sCINDItems[CINDType::SERVICE].value = service;
|
|
|
|
SendCommand("+CIEV: ", CINDType::SERVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t signal;
|
|
|
|
JS::Value value;
|
|
|
|
voiceInfo->GetRelSignalStrength(&value);
|
|
|
|
if (!value.isNumber()) {
|
|
|
|
NS_WARNING("Failed to get relSignalStrength in BluetoothHfpManager");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
signal = ceil(value.toNumber() / 20.0);
|
|
|
|
|
|
|
|
if (signal != sCINDItems[CINDType::SIGNAL].value) {
|
|
|
|
sCINDItems[CINDType::SIGNAL].value = signal;
|
|
|
|
SendCommand("+CIEV: ", CINDType::SIGNAL);
|
|
|
|
}
|
|
|
|
|
2013-01-23 01:22:08 +00:00
|
|
|
/**
|
|
|
|
* Possible return values for mode are:
|
|
|
|
* - null (unknown): set mNetworkSelectionMode to 0 (auto)
|
|
|
|
* - automatic: set mNetworkSelectionMode to 0 (auto)
|
|
|
|
* - manual: set mNetworkSelectionMode to 1 (manual)
|
|
|
|
*/
|
|
|
|
nsString mode;
|
|
|
|
connection->GetNetworkSelectionMode(mode);
|
|
|
|
if (mode.EqualsLiteral("manual")) {
|
|
|
|
mNetworkSelectionMode = 1;
|
|
|
|
} else {
|
|
|
|
mNetworkSelectionMode = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMMozMobileNetworkInfo* network;
|
|
|
|
voiceInfo->GetNetwork(&network);
|
|
|
|
NS_ENSURE_TRUE(network, NS_ERROR_FAILURE);
|
|
|
|
network->GetLongName(mOperatorName);
|
|
|
|
|
2012-12-20 07:28:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-17 09:44:32 +00:00
|
|
|
nsresult
|
|
|
|
BluetoothHfpManager::HandleIccInfoChanged()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMobileConnectionProvider> connection =
|
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(connection, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsIDOMMozMobileICCInfo* iccInfo;
|
|
|
|
connection->GetIccInfo(&iccInfo);
|
|
|
|
NS_ENSURE_TRUE(iccInfo, NS_ERROR_FAILURE);
|
2013-01-23 01:22:08 +00:00
|
|
|
iccInfo->GetMsisdn(mMsisdn);
|
2012-12-17 09:44:32 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
nsresult
|
|
|
|
BluetoothHfpManager::HandleShutdown()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
gInShutdown = true;
|
2012-10-05 23:05:35 +00:00
|
|
|
CloseSocket();
|
2012-10-03 05:53:39 +00:00
|
|
|
gBluetoothHfpManager = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
// Virtual function of class SocketConsumer
|
|
|
|
void
|
2013-02-01 12:28:15 +00:00
|
|
|
BluetoothHfpManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
|
2012-09-26 13:34:55 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-27 02:24:39 +00:00
|
|
|
|
2013-01-30 04:58:40 +00:00
|
|
|
nsAutoCString msg((const char*)aMessage->mData.get(), aMessage->mSize);
|
2012-12-17 15:24:35 +00:00
|
|
|
msg.StripWhitespace();
|
|
|
|
|
|
|
|
nsTArray<nsCString> atCommandValues;
|
|
|
|
|
2012-09-27 02:24:39 +00:00
|
|
|
// For more information, please refer to 4.34.1 "Bluetooth Defined AT
|
|
|
|
// Capabilities" in Bluetooth hands-free profile 1.6
|
2012-12-17 15:24:35 +00:00
|
|
|
if (msg.Find("AT+BRSF=") != -1) {
|
2013-01-30 04:33:23 +00:00
|
|
|
SendCommand("+BRSF: ", 97);
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CIND=?") != -1) {
|
2012-10-22 10:34:15 +00:00
|
|
|
// Asking for CIND range
|
|
|
|
SendCommand("+CIND: ", 0);
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CIND?") != -1) {
|
2012-10-22 10:34:15 +00:00
|
|
|
// Asking for CIND value
|
|
|
|
SendCommand("+CIND: ", 1);
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CMER=") != -1) {
|
|
|
|
/**
|
|
|
|
* SLC establishment is done when AT+CMER has been received.
|
|
|
|
* Do nothing but respond with "OK".
|
|
|
|
*/
|
2013-01-09 06:05:34 +00:00
|
|
|
ParseAtCommand(msg, 8, atCommandValues);
|
|
|
|
|
2013-01-11 09:45:28 +00:00
|
|
|
if (atCommandValues.Length() < 4) {
|
2013-01-09 06:05:34 +00:00
|
|
|
NS_WARNING("Could't get the value of command [AT+CMER=]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!atCommandValues[0].EqualsLiteral("3") ||
|
|
|
|
!atCommandValues[1].EqualsLiteral("0") ||
|
|
|
|
!atCommandValues[2].EqualsLiteral("0")) {
|
|
|
|
NS_WARNING("Wrong value of CMER");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
2013-01-11 06:00:04 +00:00
|
|
|
mCMER = atCommandValues[3].EqualsLiteral("1");
|
|
|
|
} else if (msg.Find("AT+CMEE=") != -1) {
|
|
|
|
ParseAtCommand(msg, 8, atCommandValues);
|
|
|
|
|
|
|
|
if (atCommandValues.IsEmpty()) {
|
|
|
|
NS_WARNING("Could't get the value of command [AT+CMEE=]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
// AT+CMEE = 0: +CME ERROR shall not be used
|
|
|
|
// AT+CMEE = 1: use numeric <err>
|
|
|
|
// AT+CMEE = 2: use verbose <err>
|
|
|
|
mCMEE = !atCommandValues[0].EqualsLiteral("0");
|
2013-01-23 01:22:08 +00:00
|
|
|
} else if (msg.Find("AT+COPS=") != -1) {
|
|
|
|
ParseAtCommand(msg, 8, atCommandValues);
|
|
|
|
|
|
|
|
if (atCommandValues.Length() != 2) {
|
|
|
|
NS_WARNING("Could't get the value of command [AT+COPS=]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handsfree only support AT+COPS=3,0
|
|
|
|
if (!atCommandValues[0].EqualsLiteral("3") ||
|
|
|
|
!atCommandValues[1].EqualsLiteral("0")) {
|
|
|
|
if (mCMEE) {
|
|
|
|
SendCommand("+CME ERROR: ", BluetoothCmeError::OPERATION_NOT_SUPPORTED);
|
|
|
|
} else {
|
|
|
|
SendLine("ERROR");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (msg.Find("AT+COPS?") != -1) {
|
|
|
|
nsAutoCString message("+COPS: ");
|
|
|
|
message.AppendInt(mNetworkSelectionMode);
|
|
|
|
message += ",0,\"";
|
|
|
|
message += NS_ConvertUTF16toUTF8(mOperatorName);
|
|
|
|
message += "\"";
|
|
|
|
SendLine(message.get());
|
|
|
|
return;
|
2013-01-08 09:21:00 +00:00
|
|
|
} else if (msg.Find("AT+VTS=") != -1) {
|
|
|
|
ParseAtCommand(msg, 7, atCommandValues);
|
2013-01-23 01:22:08 +00:00
|
|
|
|
2013-01-08 09:21:00 +00:00
|
|
|
if (atCommandValues.Length() != 1) {
|
|
|
|
NS_WARNING("Couldn't get the value of command [AT+VTS=]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsValidDtmf(atCommandValues[0].get()[0])) {
|
|
|
|
nsAutoCString message("VTS=");
|
|
|
|
message += atCommandValues[0].get()[0];
|
|
|
|
NotifyDialer(NS_ConvertUTF8toUTF16(message));
|
|
|
|
}
|
2013-01-07 08:58:59 +00:00
|
|
|
} else if (msg.Find("AT+VGM=") != -1) {
|
|
|
|
ParseAtCommand(msg, 7, atCommandValues);
|
|
|
|
|
|
|
|
if (atCommandValues.IsEmpty()) {
|
|
|
|
NS_WARNING("Couldn't get the value of command [AT+VGM]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
int vgm = atCommandValues[0].ToInteger(&rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to extract microphone volume from bluetooth headset!");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(vgm >= 0 && vgm <= 15, "Received invalid VGM value");
|
|
|
|
mCurrentVgm = vgm;
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CHLD=?") != -1) {
|
2012-10-31 03:53:36 +00:00
|
|
|
SendLine("+CHLD: (1,2)");
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CHLD=") != -1) {
|
|
|
|
ParseAtCommand(msg, 8, atCommandValues);
|
|
|
|
|
|
|
|
if (atCommandValues.IsEmpty()) {
|
2013-01-18 10:53:00 +00:00
|
|
|
NS_WARNING("Could't get the value of command [AT+CHLD=]");
|
2012-12-17 15:24:35 +00:00
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
2012-10-31 03:53:36 +00:00
|
|
|
|
2013-01-18 10:53:00 +00:00
|
|
|
char chld = atCommandValues[0][0];
|
|
|
|
if (chld < '0' || chld > '4') {
|
|
|
|
NS_WARNING("Wrong value of command [AT+CHLD]");
|
|
|
|
SendLine("ERROR");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The following two cases are supported:
|
|
|
|
* AT+CHLD=1 - Releases active calls and accepts the other (held or
|
|
|
|
* waiting) call
|
|
|
|
* AT+CHLD=2 - Places active calls on hold and accepts the other (held
|
|
|
|
* or waiting) call
|
|
|
|
*
|
|
|
|
* The following cases are NOT supported yet:
|
|
|
|
* AT+CHLD=0, AT+CHLD=1<idx>, AT+CHLD=2<idx>, AT+CHLD=3, AT+CHLD=4
|
|
|
|
* Please see 4.33.2 in Bluetooth hands-free profile 1.6 for more
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// No idx shall be included
|
|
|
|
if (atCommandValues[0].Length() > 1) {
|
|
|
|
SendLine("ERROR");
|
|
|
|
return;
|
2012-10-31 03:53:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 10:53:00 +00:00
|
|
|
if (chld == '1') {
|
|
|
|
NotifyDialer(NS_LITERAL_STRING("CHUP+ATA"));
|
|
|
|
} else if (chld == '2') {
|
|
|
|
NotifyDialer(NS_LITERAL_STRING("CHLD+ATA"));
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Not handling chld value");
|
2012-10-31 03:53:36 +00:00
|
|
|
}
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+VGS=") != -1) {
|
2012-11-19 07:10:38 +00:00
|
|
|
// Adjust volume by headset
|
2012-10-25 10:50:41 +00:00
|
|
|
mReceiveVgsFlag = true;
|
2012-12-17 15:24:35 +00:00
|
|
|
ParseAtCommand(msg, 7, atCommandValues);
|
2012-09-27 02:24:39 +00:00
|
|
|
|
2012-12-17 15:24:35 +00:00
|
|
|
if (atCommandValues.IsEmpty()) {
|
|
|
|
NS_WARNING("Could't get the value of command [AT+VGS=]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
2012-10-25 10:50:41 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
2012-12-17 15:24:35 +00:00
|
|
|
int newVgs = atCommandValues[0].ToInteger(&rv);
|
2012-10-25 10:50:41 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to extract volume value from bluetooth headset!");
|
2012-12-17 15:24:35 +00:00
|
|
|
goto respond_with_ok;
|
2012-10-25 10:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newVgs == mCurrentVgs) {
|
2012-12-17 15:24:35 +00:00
|
|
|
goto respond_with_ok;
|
2012-09-27 02:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(newVgs >= 0 && newVgs <= 15, "Received invalid VGS value");
|
|
|
|
|
2012-10-25 10:50:41 +00:00
|
|
|
nsString data;
|
2012-09-27 02:24:39 +00:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2012-11-19 07:10:38 +00:00
|
|
|
data.AppendInt(newVgs);
|
2012-10-25 10:50:41 +00:00
|
|
|
os->NotifyObservers(nullptr, "bluetooth-volume-change", data.get());
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+BLDN") != -1) {
|
2012-10-01 07:44:48 +00:00
|
|
|
NotifyDialer(NS_LITERAL_STRING("BLDN"));
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("ATA") != -1) {
|
2012-10-01 07:44:48 +00:00
|
|
|
NotifyDialer(NS_LITERAL_STRING("ATA"));
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CHUP") != -1) {
|
2012-10-01 07:44:48 +00:00
|
|
|
NotifyDialer(NS_LITERAL_STRING("CHUP"));
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("ATD>") != -1) {
|
2012-12-17 09:51:38 +00:00
|
|
|
// Currently, we don't support memory dialing in Dialer app
|
|
|
|
SendLine("ERROR");
|
2013-01-11 06:00:04 +00:00
|
|
|
return;
|
2013-02-05 11:19:15 +00:00
|
|
|
} else if ((msg.Find("AT+XAPL=") != -1) ||
|
|
|
|
(msg.Find("AT+XEVENT=") != -1)) {
|
|
|
|
// FIXME: Bug 838089
|
|
|
|
// These are vendor commands used on some special headsets. Eventually we
|
|
|
|
// should reply with ERROR to all unknown incoming commands. However,
|
|
|
|
// in order not to cause interoperability issues for b2g18 branch, only
|
|
|
|
// filtering these two commands should be fine for now.
|
|
|
|
SendLine("ERROR");
|
|
|
|
return;
|
2013-01-18 10:53:00 +00:00
|
|
|
} else if (msg.Find("AT+CLCC") != -1) {
|
|
|
|
SendCommand("+CLCC: ");
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("ATD") != -1) {
|
2012-12-17 09:51:38 +00:00
|
|
|
nsAutoCString message(msg), newMsg;
|
|
|
|
int end = message.FindChar(';');
|
|
|
|
if (end < 0) {
|
|
|
|
NS_WARNING("Could't get the value of command [ATD]");
|
2012-12-17 15:24:35 +00:00
|
|
|
goto respond_with_ok;
|
2012-12-17 09:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newMsg += nsDependentCSubstring(message, 0, end);
|
|
|
|
NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CLIP=") != -1) {
|
|
|
|
ParseAtCommand(msg, 8, atCommandValues);
|
|
|
|
|
|
|
|
if (atCommandValues.IsEmpty()) {
|
|
|
|
NS_WARNING("Could't get the value of command [AT+CLIP=]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
2013-01-16 06:17:41 +00:00
|
|
|
mCLIP = atCommandValues[0].EqualsLiteral("1");
|
|
|
|
} else if (msg.Find("AT+CCWA=") != -1) {
|
|
|
|
ParseAtCommand(msg, 8, atCommandValues);
|
|
|
|
|
|
|
|
if (atCommandValues.IsEmpty()) {
|
|
|
|
NS_WARNING("Could't get the value of command [AT+CCWA=]");
|
|
|
|
goto respond_with_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCCWA = atCommandValues[0].EqualsLiteral("1");
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CKPD") != -1) {
|
|
|
|
// For Headset Profile (HSP)
|
2013-01-28 11:28:51 +00:00
|
|
|
switch (mCurrentCallArray[mCurrentCallIndex].mState) {
|
2012-10-05 10:48:05 +00:00
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
|
|
|
NotifyDialer(NS_LITERAL_STRING("ATA"));
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
|
|
|
NotifyDialer(NS_LITERAL_STRING("CHUP"));
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
|
|
|
|
NotifyDialer(NS_LITERAL_STRING("BLDN"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Not handling state changed");
|
|
|
|
break;
|
|
|
|
}
|
2012-12-17 15:24:35 +00:00
|
|
|
} else if (msg.Find("AT+CNUM") != -1) {
|
2012-12-17 09:44:32 +00:00
|
|
|
if (!mMsisdn.IsEmpty()) {
|
|
|
|
nsAutoCString message("+CNUM: ,\"");
|
|
|
|
message += NS_ConvertUTF16toUTF8(mMsisdn).get();
|
|
|
|
message += "\",";
|
|
|
|
message.AppendInt(TOA_UNKNOWN);
|
|
|
|
message += ",,4";
|
|
|
|
SendLine(message.get());
|
|
|
|
}
|
2012-09-27 02:24:39 +00:00
|
|
|
} else {
|
|
|
|
nsCString warningMsg;
|
|
|
|
warningMsg.AssignLiteral("Not handling HFP message, reply ok: ");
|
|
|
|
warningMsg.Append(msg);
|
|
|
|
NS_WARNING(warningMsg.get());
|
|
|
|
}
|
2012-12-17 15:24:35 +00:00
|
|
|
|
|
|
|
respond_with_ok:
|
|
|
|
// We always respond to remote device with "OK" in general cases.
|
|
|
|
SendLine("OK");
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-10-22 10:34:15 +00:00
|
|
|
BluetoothHfpManager::Connect(const nsAString& aDevicePath,
|
2012-10-05 10:48:05 +00:00
|
|
|
const bool aIsHandsfree,
|
2012-09-26 13:34:55 +00:00
|
|
|
BluetoothReplyRunnable* aRunnable)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
if (gInShutdown) {
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_WARNING("Connect called while in shutdown!");
|
2012-10-03 05:53:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-16 10:46:08 +00:00
|
|
|
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED ||
|
|
|
|
GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTING) {
|
|
|
|
NS_WARNING("BluetoothHfpManager has connected/is connecting to a headset!");
|
2012-10-22 10:34:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-11 05:49:11 +00:00
|
|
|
CloseSocket();
|
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_ENSURE_TRUE(bs, false);
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2012-11-27 06:12:19 +00:00
|
|
|
nsString uuid;
|
2012-10-05 10:48:05 +00:00
|
|
|
if (aIsHandsfree) {
|
2012-11-27 06:12:19 +00:00
|
|
|
BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
|
2012-10-05 10:48:05 +00:00
|
|
|
} else {
|
2012-11-27 06:12:19 +00:00
|
|
|
BluetoothUuidHelper::GetString(BluetoothServiceClass::HEADSET, uuid);
|
2012-10-05 10:48:05 +00:00
|
|
|
}
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2012-11-07 23:48:39 +00:00
|
|
|
mRunnable = aRunnable;
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
nsresult rv = bs->GetSocketViaService(aDevicePath,
|
2012-11-27 06:12:19 +00:00
|
|
|
uuid,
|
2012-09-26 13:34:55 +00:00
|
|
|
BluetoothSocketType::RFCOMM,
|
|
|
|
true,
|
2012-10-31 09:33:50 +00:00
|
|
|
true,
|
2012-09-26 13:34:55 +00:00
|
|
|
this,
|
2012-11-07 23:48:39 +00:00
|
|
|
mRunnable);
|
2012-09-26 13:34:55 +00:00
|
|
|
|
|
|
|
return NS_FAILED(rv) ? false : true;
|
|
|
|
}
|
|
|
|
|
2012-10-01 07:04:01 +00:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::Listen()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
if (gInShutdown) {
|
|
|
|
MOZ_ASSERT(false, "Listen called while in shutdown!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-28 07:59:20 +00:00
|
|
|
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_LISTENING) {
|
|
|
|
NS_WARNING("BluetoothHfpManager has been already listening");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-11 05:49:11 +00:00
|
|
|
CloseSocket();
|
|
|
|
|
2012-10-01 07:04:01 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_ENSURE_TRUE(bs, false);
|
2012-10-01 07:04:01 +00:00
|
|
|
|
2012-11-27 06:12:19 +00:00
|
|
|
nsresult rv =
|
|
|
|
bs->ListenSocketViaService(BluetoothReservedChannels::CHANNEL_HANDSFREE_AG,
|
|
|
|
BluetoothSocketType::RFCOMM,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
this);
|
2012-10-26 09:28:39 +00:00
|
|
|
|
|
|
|
mSocketStatus = GetConnectionStatus();
|
|
|
|
|
2012-10-01 07:04:01 +00:00
|
|
|
return NS_FAILED(rv) ? false : true;
|
|
|
|
}
|
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::Disconnect()
|
|
|
|
{
|
2012-10-22 10:34:15 +00:00
|
|
|
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_DISCONNECTED) {
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_WARNING("BluetoothHfpManager has been disconnected!");
|
2012-10-22 10:34:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
CloseSocket();
|
|
|
|
}
|
|
|
|
|
2012-09-27 02:24:39 +00:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::SendLine(const char* aMessage)
|
|
|
|
{
|
|
|
|
const char* kHfpCrlf = "\xd\xa";
|
|
|
|
nsAutoCString msg;
|
|
|
|
|
|
|
|
msg += kHfpCrlf;
|
|
|
|
msg += aMessage;
|
|
|
|
msg += kHfpCrlf;
|
|
|
|
|
|
|
|
return SendSocketData(msg);
|
|
|
|
}
|
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
bool
|
2013-01-28 11:28:51 +00:00
|
|
|
BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
|
2012-10-09 11:19:29 +00:00
|
|
|
{
|
2012-12-20 07:28:51 +00:00
|
|
|
if (mSocketStatus != SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
nsAutoCString message;
|
|
|
|
int value = aValue;
|
|
|
|
message += aCommand;
|
|
|
|
|
|
|
|
if (!strcmp(aCommand, "+CIEV: ")) {
|
2013-01-09 06:05:34 +00:00
|
|
|
if (!mCMER) {
|
|
|
|
// Indicator status update is disabled
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-20 07:28:51 +00:00
|
|
|
if ((aValue < 1) || (aValue > ArrayLength(sCINDItems) - 1)) {
|
|
|
|
NS_WARNING("unexpected CINDType for CIEV command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
message.AppendInt(aValue);
|
|
|
|
message += ",";
|
2012-12-20 07:28:51 +00:00
|
|
|
message.AppendInt(sCINDItems[aValue].value);
|
2012-10-22 10:34:15 +00:00
|
|
|
} else if (!strcmp(aCommand, "+CIND: ")) {
|
|
|
|
if (!aValue) {
|
2013-01-16 06:13:58 +00:00
|
|
|
// Query for range
|
2012-10-22 10:34:15 +00:00
|
|
|
for (uint8_t i = 1; i < ArrayLength(sCINDItems); i++) {
|
|
|
|
message += "(\"";
|
|
|
|
message += sCINDItems[i].name;
|
|
|
|
message += "\",(";
|
|
|
|
message += sCINDItems[i].range;
|
|
|
|
message += ")";
|
|
|
|
if (i == (ArrayLength(sCINDItems) - 1)) {
|
|
|
|
message +=")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
message += "),";
|
|
|
|
}
|
|
|
|
} else {
|
2013-01-16 06:13:58 +00:00
|
|
|
// Query for value
|
2012-10-22 10:34:15 +00:00
|
|
|
for (uint8_t i = 1; i < ArrayLength(sCINDItems); i++) {
|
|
|
|
message.AppendInt(sCINDItems[i].value);
|
|
|
|
if (i == (ArrayLength(sCINDItems) - 1)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
message += ",";
|
|
|
|
}
|
|
|
|
}
|
2013-01-16 06:13:58 +00:00
|
|
|
} else if (!strcmp(aCommand, "+CLCC: ")) {
|
|
|
|
bool rv = true;
|
|
|
|
uint32_t callNumbers = mCurrentCallArray.Length();
|
|
|
|
for (uint32_t i = 1; i < callNumbers; i++) {
|
|
|
|
Call& call = mCurrentCallArray[i];
|
|
|
|
if (call.mState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
message.AssignLiteral("+CLCC: ");
|
|
|
|
message.AppendInt(i);
|
|
|
|
message += ",";
|
|
|
|
message.AppendInt(call.mDirection);
|
|
|
|
message += ",";
|
|
|
|
|
|
|
|
switch (call.mState) {
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
|
|
|
|
message.AppendInt(0);
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
|
|
|
|
message.AppendInt(1);
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
|
|
|
|
message.AppendInt(2);
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
|
|
|
message.AppendInt(3);
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
|
|
|
message.AppendInt((i == mCurrentCallIndex) ? 4 : 5);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Not handling call status for CLCC");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
message += ",0,0,\"";
|
|
|
|
message += NS_ConvertUTF16toUTF8(call.mNumber).get();
|
|
|
|
message += "\",";
|
|
|
|
message.AppendInt(call.mType);
|
|
|
|
|
|
|
|
rv &= SendLine(message.get());
|
|
|
|
}
|
|
|
|
return rv;
|
2012-10-22 10:34:15 +00:00
|
|
|
} else {
|
|
|
|
message.AppendInt(value);
|
2012-10-09 11:19:29 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
return SendLine(message.get());
|
2012-10-09 11:19:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:15:22 +00:00
|
|
|
void
|
2013-01-28 11:28:51 +00:00
|
|
|
BluetoothHfpManager::UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend)
|
2012-09-27 05:15:22 +00:00
|
|
|
{
|
2013-01-28 11:28:51 +00:00
|
|
|
if (sCINDItems[aType].value != aValue) {
|
|
|
|
sCINDItems[aType].value = aValue;
|
|
|
|
// Indicator status update is enabled
|
|
|
|
if (aSend && mCMER) {
|
|
|
|
SendCommand("+CIEV: ", aType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|
|
|
uint16_t aCallState,
|
|
|
|
const nsAString& aNumber,
|
|
|
|
bool aSend)
|
|
|
|
{
|
|
|
|
if (GetConnectionStatus() != SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-27 05:15:33 +00:00
|
|
|
|
2013-01-16 06:13:58 +00:00
|
|
|
while (aCallIndex >= mCurrentCallArray.Length()) {
|
|
|
|
Call call;
|
|
|
|
mCurrentCallArray.AppendElement(call);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same logic as implementation in ril_worker.js
|
|
|
|
if (aNumber.Length() && aNumber[0] == '+') {
|
|
|
|
mCurrentCallArray[aCallIndex].mType = TOA_INTERNATIONAL;
|
2012-10-31 03:53:36 +00:00
|
|
|
}
|
2013-01-16 06:13:58 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mNumber = aNumber;
|
2012-10-31 03:53:36 +00:00
|
|
|
|
2013-01-28 11:28:51 +00:00
|
|
|
nsRefPtr<nsRunnable> sendRingTask;
|
|
|
|
nsString address;
|
|
|
|
uint16_t prevCallState = mCurrentCallArray[aCallIndex].mState;
|
|
|
|
uint32_t callArrayLength = mCurrentCallArray.Length();
|
|
|
|
uint32_t index = 1;
|
2012-10-31 03:53:36 +00:00
|
|
|
|
2012-09-27 05:15:33 +00:00
|
|
|
switch (aCallState) {
|
2013-01-28 11:28:51 +00:00
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
|
|
|
|
sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALLHELD);
|
|
|
|
break;
|
2012-09-27 05:15:33 +00:00
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
2013-01-16 06:13:58 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mDirection = true;
|
2012-09-27 05:15:33 +00:00
|
|
|
|
2013-01-16 06:17:41 +00:00
|
|
|
if (mCurrentCallIndex) {
|
|
|
|
if (mCCWA) {
|
|
|
|
nsAutoCString ccwaMsg("+CCWA: \"");
|
|
|
|
ccwaMsg += NS_ConvertUTF16toUTF8(aNumber).get();
|
|
|
|
ccwaMsg += "\",";
|
|
|
|
ccwaMsg.AppendInt(mCurrentCallArray[aCallIndex].mType);
|
|
|
|
SendLine(ccwaMsg.get());
|
|
|
|
}
|
2013-01-28 11:28:51 +00:00
|
|
|
UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, aSend);
|
2013-01-16 06:17:41 +00:00
|
|
|
} else {
|
2012-10-31 03:53:36 +00:00
|
|
|
// Start sending RING indicator to HF
|
|
|
|
sStopSendingRingFlag = false;
|
2013-01-28 11:28:51 +00:00
|
|
|
UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, aSend);
|
2013-01-16 06:17:41 +00:00
|
|
|
|
2013-01-16 06:13:58 +00:00
|
|
|
nsAutoString number(aNumber);
|
2012-12-17 15:24:35 +00:00
|
|
|
if (!mCLIP) {
|
2013-01-16 06:13:58 +00:00
|
|
|
number.AssignLiteral("");
|
2012-12-17 15:24:35 +00:00
|
|
|
}
|
2013-01-16 06:13:58 +00:00
|
|
|
|
|
|
|
MessageLoop::current()->PostDelayedTask(FROM_HERE,
|
|
|
|
new SendRingIndicatorTask(number, mCurrentCallArray[aCallIndex].mType),
|
|
|
|
sRingInterval);
|
2012-10-31 03:53:36 +00:00
|
|
|
}
|
2012-09-27 05:15:33 +00:00
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
|
2013-01-16 06:13:58 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mDirection = false;
|
2013-01-28 11:28:51 +00:00
|
|
|
UpdateCIND(CINDType::CALLSETUP, CallSetupState::OUTGOING, aSend);
|
2012-10-22 10:34:15 +00:00
|
|
|
|
2013-01-28 11:28:51 +00:00
|
|
|
GetSocketAddr(address);
|
|
|
|
OpenScoSocket(address);
|
2012-09-27 05:15:33 +00:00
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
2013-01-16 06:13:58 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mDirection = false;
|
2013-01-28 11:28:51 +00:00
|
|
|
UpdateCIND(CINDType::CALLSETUP, CallSetupState::OUTGOING_ALERTING, aSend);
|
|
|
|
|
|
|
|
// If there's an ongoing call when the headset is just connected, we have
|
|
|
|
// to open a sco socket here.
|
|
|
|
GetSocketAddr(address);
|
|
|
|
OpenScoSocket(address);
|
2012-09-27 05:15:33 +00:00
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
|
2012-10-31 03:53:36 +00:00
|
|
|
mCurrentCallIndex = aCallIndex;
|
2013-01-28 11:28:51 +00:00
|
|
|
switch (prevCallState) {
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
|
|
|
|
// Incoming call, no break
|
|
|
|
sStopSendingRingFlag = true;
|
2012-10-31 03:53:36 +00:00
|
|
|
|
2013-01-28 11:28:51 +00:00
|
|
|
GetSocketAddr(address);
|
|
|
|
OpenScoSocket(address);
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
|
|
|
// Outgoing call
|
|
|
|
UpdateCIND(CINDType::CALL, CallState::IN_PROGRESS, aSend);
|
|
|
|
UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, aSend);
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
|
|
|
|
// Check whether to update CINDType::CALLHELD or not
|
|
|
|
while (index < callArrayLength) {
|
|
|
|
if (index == mCurrentCallIndex) {
|
|
|
|
index++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t state = mCurrentCallArray[index].mState;
|
|
|
|
// If there's another call on hold or other calls exist, no need to
|
|
|
|
// update CINDType::CALLHELD
|
|
|
|
if (state != nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
|
2012-10-31 03:53:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-01-28 11:28:51 +00:00
|
|
|
index++;
|
2012-10-31 03:53:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-28 11:28:51 +00:00
|
|
|
if (index == callArrayLength) {
|
|
|
|
UpdateCIND(CINDType::CALLHELD, CallHeldState::NO_CALLHELD, aSend);
|
2012-12-17 15:24:35 +00:00
|
|
|
}
|
2013-01-28 11:28:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Not handling state changed");
|
2012-09-27 05:15:33 +00:00
|
|
|
}
|
2012-10-31 03:53:36 +00:00
|
|
|
break;
|
2013-01-28 11:28:51 +00:00
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
|
|
|
|
switch (prevCallState) {
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_BUSY:
|
|
|
|
// Incoming call, no break
|
|
|
|
sStopSendingRingFlag = true;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
|
|
|
// Outgoing call
|
|
|
|
UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, aSend);
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
|
|
|
|
// No call is ongoing
|
|
|
|
if (sCINDItems[CINDType::CALLHELD].value == CallHeldState::NO_CALLHELD) {
|
|
|
|
UpdateCIND(CINDType::CALL, CallState::NO_CALL, aSend);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
|
|
|
|
UpdateCIND(CINDType::CALLHELD, CallHeldState::NO_CALLHELD, aSend);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Not handling state changed");
|
2012-10-31 03:53:36 +00:00
|
|
|
}
|
2013-01-09 06:05:34 +00:00
|
|
|
|
2013-01-28 11:28:51 +00:00
|
|
|
if (aCallIndex == mCurrentCallIndex) {
|
|
|
|
NS_ASSERTION(mCurrentCallArray.Length() > aCallIndex,
|
|
|
|
"Call index out of bounds!");
|
|
|
|
mCurrentCallArray[aCallIndex].mState = aCallState;
|
|
|
|
|
|
|
|
// Find the first non-disconnected call (like connected, held),
|
|
|
|
// and update mCurrentCallIndex
|
|
|
|
while (index < callArrayLength) {
|
|
|
|
if (mCurrentCallArray[index].mState !=
|
|
|
|
nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
|
|
|
|
mCurrentCallIndex = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is no call, close Sco and clear mCurrentCallArray
|
|
|
|
if (index == callArrayLength) {
|
|
|
|
CloseScoSocket();
|
|
|
|
ResetCallArray();
|
|
|
|
}
|
|
|
|
}
|
2012-09-27 05:15:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Not handling state changed");
|
2012-10-22 10:34:15 +00:00
|
|
|
sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
2012-10-31 03:53:36 +00:00
|
|
|
sCINDItems[CINDType::CALLHELD].value = CallHeldState::NO_CALLHELD;
|
2012-09-27 05:15:33 +00:00
|
|
|
}
|
2012-09-27 05:15:22 +00:00
|
|
|
|
2013-01-16 06:13:58 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mState = aCallState;
|
2012-09-27 05:15:22 +00:00
|
|
|
}
|
2012-10-11 05:49:11 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnConnectSuccess()
|
|
|
|
{
|
2013-01-28 11:28:51 +00:00
|
|
|
nsCOMPtr<nsIRILContentHelper> ril =
|
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE_VOID(ril);
|
|
|
|
ril->EnumerateCalls(mListener->GetCallback());
|
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
// For active connection request, we need to reply the DOMRequest
|
2012-11-07 23:48:39 +00:00
|
|
|
if (mRunnable) {
|
2012-11-19 07:10:38 +00:00
|
|
|
BluetoothValue v = true;
|
|
|
|
nsString errorStr;
|
|
|
|
DispatchBluetoothReply(mRunnable, v, errorStr);
|
|
|
|
|
2012-11-07 23:48:39 +00:00
|
|
|
mRunnable.forget();
|
|
|
|
}
|
2012-11-19 07:10:38 +00:00
|
|
|
|
2012-10-26 09:21:32 +00:00
|
|
|
// Cache device path for NotifySettings() since we can't get socket address
|
|
|
|
// when a headset disconnect with us
|
|
|
|
GetSocketAddr(mDevicePath);
|
2012-10-31 03:53:36 +00:00
|
|
|
mSocketStatus = GetConnectionStatus();
|
2012-10-26 09:21:32 +00:00
|
|
|
|
2012-10-22 10:34:15 +00:00
|
|
|
NotifySettings();
|
2012-10-11 05:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnConnectError()
|
|
|
|
{
|
2012-11-19 07:10:38 +00:00
|
|
|
// For active connection request, we need to reply the DOMRequest
|
2012-11-07 23:48:39 +00:00
|
|
|
if (mRunnable) {
|
2012-11-19 07:10:38 +00:00
|
|
|
BluetoothValue v;
|
2012-11-07 23:48:39 +00:00
|
|
|
nsString errorStr;
|
|
|
|
errorStr.AssignLiteral("Failed to connect with a bluetooth headset!");
|
2012-11-19 07:10:38 +00:00
|
|
|
DispatchBluetoothReply(mRunnable, v, errorStr);
|
|
|
|
|
2012-11-07 23:48:39 +00:00
|
|
|
mRunnable.forget();
|
|
|
|
}
|
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
// If connecting for some reason didn't work, restart listening
|
2012-10-11 05:49:11 +00:00
|
|
|
CloseSocket();
|
2012-10-26 09:28:39 +00:00
|
|
|
mSocketStatus = GetConnectionStatus();
|
2012-10-11 05:49:11 +00:00
|
|
|
Listen();
|
|
|
|
}
|
2012-10-12 18:38:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnDisconnect()
|
|
|
|
{
|
2012-11-19 07:10:38 +00:00
|
|
|
// When we close a connected socket, then restart listening again and
|
|
|
|
// notify Settings app.
|
2012-10-26 09:28:39 +00:00
|
|
|
if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
Listen();
|
|
|
|
NotifySettings();
|
2012-11-28 07:59:20 +00:00
|
|
|
} else if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTING) {
|
|
|
|
NS_WARNING("BluetoothHfpManager got unexpected socket status!");
|
2012-10-26 09:28:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-28 11:28:51 +00:00
|
|
|
CloseScoSocket();
|
2013-01-16 06:13:58 +00:00
|
|
|
Reset();
|
2012-10-12 18:38:14 +00:00
|
|
|
}
|