2012-09-26 06:34:55 -07: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/. */
|
|
|
|
|
2012-09-29 02:39:05 -07:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
#include "BluetoothHfpManager.h"
|
|
|
|
|
|
|
|
#include "BluetoothReplyRunnable.h"
|
2012-09-29 02:39:05 -07:00
|
|
|
#include "BluetoothScoManager.h"
|
2012-09-26 06:34:55 -07:00
|
|
|
#include "BluetoothService.h"
|
|
|
|
#include "BluetoothServiceUuid.h"
|
2012-10-03 02:06:40 -07:00
|
|
|
#include "BluetoothUtils.h"
|
2012-09-26 06:34:55 -07:00
|
|
|
|
2012-09-25 03:18:38 -07:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2012-09-26 19:24:39 -07:00
|
|
|
#include "mozilla/Services.h"
|
2012-10-02 22:53:39 -07:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-09-25 03:18:38 -07:00
|
|
|
#include "nsContentUtils.h"
|
2012-10-02 19:55:28 -07:00
|
|
|
#include "nsIAudioManager.h"
|
2012-09-26 19:24:39 -07:00
|
|
|
#include "nsIObserverService.h"
|
2012-09-26 22:15:33 -07:00
|
|
|
#include "nsIRadioInterfaceLayer.h"
|
|
|
|
|
|
|
|
#include <unistd.h> /* usleep() */
|
2012-09-26 19:24:39 -07:00
|
|
|
|
2012-09-25 03:18:38 -07:00
|
|
|
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
|
|
|
|
#define AUDIO_VOLUME_MASTER "audio.volume.master"
|
2012-10-09 04:19:29 -07:00
|
|
|
#define HANDSFREE_UUID mozilla::dom::bluetooth::BluetoothServiceUuidStr::Handsfree
|
|
|
|
#define HEADSET_UUID mozilla::dom::bluetooth::BluetoothServiceUuidStr::Headset
|
2012-09-25 03:18:38 -07:00
|
|
|
|
2012-10-02 22:53:39 -07:00
|
|
|
using namespace mozilla;
|
2012-09-26 06:34:55 -07:00
|
|
|
using namespace mozilla::ipc;
|
2012-10-02 22:53:39 -07:00
|
|
|
USING_BLUETOOTH_NAMESPACE
|
2012-09-26 06:34:55 -07:00
|
|
|
|
2012-10-22 03:34:15 -07: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,
|
|
|
|
SIGNAL,
|
|
|
|
SERVICE,
|
|
|
|
CALL,
|
|
|
|
CALLSETUP,
|
|
|
|
CALLHELD,
|
|
|
|
ROAM,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CINDItem sCINDItems[] = {
|
|
|
|
{},
|
|
|
|
{"battchg", "0-5", 5},
|
|
|
|
{"signal", "0-5", 5},
|
|
|
|
{"service", "0,1", 1},
|
|
|
|
{"call", "0,1", CallState::NO_CALL},
|
|
|
|
{"callsetup", "0-3", CallSetupState::NO_CALLSETUP},
|
|
|
|
{"callheld", "0-2", CallHeldState::NO_CALLHELD},
|
|
|
|
{"roam", "0,1", 0}
|
|
|
|
};
|
|
|
|
|
2012-10-05 17:11:24 -07:00
|
|
|
class mozilla::dom::bluetooth::BluetoothHfpManagerObserver : public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
BluetoothHfpManagerObserver()
|
2012-10-08 21:59:33 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Init()
|
2012-10-05 17:11:24 -07: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-08 21:59:33 -07:00
|
|
|
return false;
|
2012-10-05 17:11:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
|
|
|
NS_WARNING("Failed to add shutdown observer!");
|
2012-10-08 21:59:33 -07:00
|
|
|
return false;
|
2012-10-05 17:11:24 -07:00
|
|
|
}
|
2012-10-08 21:59:33 -07:00
|
|
|
|
|
|
|
return true;
|
2012-10-05 17:11:24 -07:00
|
|
|
}
|
|
|
|
|
2012-10-08 21:59:33 -07:00
|
|
|
bool Shutdown()
|
2012-10-05 17:11:24 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
2012-10-08 21:59:33 -07:00
|
|
|
if (!obs ||
|
2012-10-05 17:11:24 -07:00
|
|
|
(NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
|
|
|
|
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)))) {
|
2012-10-08 21:59:33 -07:00
|
|
|
NS_WARNING("Can't unregister observers, or already unregistered!");
|
|
|
|
return false;
|
2012-10-05 17:11:24 -07:00
|
|
|
}
|
2012-10-08 21:59:33 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
~BluetoothHfpManagerObserver()
|
|
|
|
{
|
|
|
|
Shutdown();
|
2012-10-05 17:11:24 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-02 22:53:39 -07:00
|
|
|
namespace {
|
|
|
|
StaticRefPtr<BluetoothHfpManager> gBluetoothHfpManager;
|
2012-10-08 21:59:33 -07:00
|
|
|
StaticRefPtr<BluetoothHfpManagerObserver> sHfpObserver;
|
2012-10-02 22:53:39 -07:00
|
|
|
bool gInShutdown = false;
|
|
|
|
static bool sStopSendingRingFlag = true;
|
2012-09-26 22:15:33 -07:00
|
|
|
|
2012-10-25 18:25:15 -07:00
|
|
|
static int sRingInterval = 3000; //unit: ms
|
2012-10-02 22:53:39 -07:00
|
|
|
} // anonymous namespace
|
2012-09-26 22:15:33 -07:00
|
|
|
|
2012-10-05 17:11:24 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(BluetoothHfpManagerObserver, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BluetoothHfpManagerObserver::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(gBluetoothHfpManager);
|
2012-10-22 03:34:15 -07:00
|
|
|
|
2012-10-05 17:11:24 -07:00
|
|
|
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
|
|
|
|
return gBluetoothHfpManager->HandleVolumeChanged(nsDependentString(aData));
|
|
|
|
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
|
|
|
return gBluetoothHfpManager->HandleShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2012-09-25 03:18:38 -07:00
|
|
|
|
2012-10-25 18:25:15 -07:00
|
|
|
class SendRingIndicatorTask : public Task
|
2012-09-26 22:15:33 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SendRingIndicatorTask()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2012-10-25 18:25:15 -07:00
|
|
|
void Run() MOZ_OVERRIDE
|
2012-09-26 22:15:33 -07:00
|
|
|
{
|
2012-10-25 18:25:15 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-26 22:15:33 -07:00
|
|
|
|
2012-10-25 18:25:15 -07:00
|
|
|
if (sStopSendingRingFlag) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-26 22:15:33 -07:00
|
|
|
|
2012-10-25 18:25:15 -07:00
|
|
|
if (!gBluetoothHfpManager) {
|
|
|
|
NS_WARNING("BluetoothHfpManager no longer exists, cannot send ring!");
|
|
|
|
return;
|
2012-09-26 22:15:33 -07:00
|
|
|
}
|
|
|
|
|
2012-10-25 18:25:15 -07:00
|
|
|
gBluetoothHfpManager->SendLine("RING");
|
|
|
|
|
|
|
|
MessageLoop::current()->
|
|
|
|
PostDelayedTask(FROM_HERE,
|
|
|
|
new SendRingIndicatorTask(),
|
|
|
|
sRingInterval);
|
|
|
|
|
|
|
|
return;
|
2012-09-26 22:15:33 -07:00
|
|
|
}
|
|
|
|
};
|
2012-09-26 06:34:55 -07:00
|
|
|
|
2012-09-29 02:39:05 -07:00
|
|
|
void
|
2012-10-22 03:34:15 -07:00
|
|
|
OpenScoSocket(const nsAString& aDeviceAddress)
|
2012-09-29 02:39:05 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
BluetoothScoManager* sco = BluetoothScoManager::Get();
|
|
|
|
if (!sco) {
|
|
|
|
NS_WARNING("BluetoothScoManager is not available!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
if (!sco->Connect(aDeviceAddress)) {
|
2012-09-29 02:39:05 -07: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 03:34:15 -07:00
|
|
|
sco->Disconnect();
|
2012-09-29 02:39:05 -07:00
|
|
|
}
|
|
|
|
|
2012-09-26 22:15:33 -07:00
|
|
|
BluetoothHfpManager::BluetoothHfpManager()
|
2012-10-25 03:50:41 -07:00
|
|
|
: mCurrentCallIndex(0)
|
2012-09-26 22:15:33 -07:00
|
|
|
, mCurrentCallState(nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED)
|
2012-10-25 03:50:41 -07:00
|
|
|
, mReceiveVgsFlag(false)
|
2012-10-02 22:53:39 -07:00
|
|
|
{
|
2012-10-22 03:34:15 -07:00
|
|
|
sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
|
|
|
sCINDItems[CINDType::CALLHELD].value = CallHeldState::NO_CALLHELD;
|
2012-10-02 22:53:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BluetoothHfpManager::Init()
|
2012-09-26 06:34:55 -07:00
|
|
|
{
|
2012-10-26 02:28:39 -07:00
|
|
|
mSocketStatus = GetConnectionStatus();
|
|
|
|
|
2012-10-05 17:11:24 -07:00
|
|
|
sHfpObserver = new BluetoothHfpManagerObserver();
|
2012-10-08 21:59:33 -07:00
|
|
|
if (!sHfpObserver->Init()) {
|
|
|
|
NS_WARNING("Cannot set up Hfp Observers!");
|
|
|
|
}
|
2012-10-02 22:53:39 -07:00
|
|
|
|
2012-09-27 05:24:06 -07:00
|
|
|
mListener = new BluetoothRilListener();
|
|
|
|
if (!mListener->StartListening()) {
|
|
|
|
NS_WARNING("Failed to start listening RIL");
|
2012-10-02 22:53:39 -07:00
|
|
|
return false;
|
2012-09-27 05:24:06 -07:00
|
|
|
}
|
|
|
|
|
2012-10-25 03:50:41 -07:00
|
|
|
float volume;
|
|
|
|
nsCOMPtr<nsIAudioManager> am = do_GetService("@mozilla.org/telephony/audiomanager;1");
|
|
|
|
if (!am) {
|
|
|
|
NS_WARNING("Failed to get AudioManager Service!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
am->GetMasterVolume(&volume);
|
|
|
|
|
|
|
|
// AG volume range: [0.0, 1.0]
|
|
|
|
// HS volume range: [0, 15]
|
|
|
|
mCurrentVgs = floor(volume * 15);
|
|
|
|
|
2012-10-02 22:53:39 -07:00
|
|
|
return true;
|
2012-09-26 06:34:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
BluetoothHfpManager::~BluetoothHfpManager()
|
2012-10-02 22:53:39 -07:00
|
|
|
{
|
|
|
|
Cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::Cleanup()
|
2012-09-26 06:34:55 -07:00
|
|
|
{
|
2012-09-27 05:24:06 -07:00
|
|
|
if (!mListener->StopListening()) {
|
|
|
|
NS_WARNING("Failed to stop listening RIL");
|
|
|
|
}
|
|
|
|
mListener = nullptr;
|
|
|
|
|
2012-10-08 21:59:33 -07:00
|
|
|
sHfpObserver->Shutdown();
|
2012-10-05 17:11:24 -07:00
|
|
|
sHfpObserver = nullptr;
|
2012-09-26 06:34:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
BluetoothHfpManager*
|
|
|
|
BluetoothHfpManager::Get()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-02 22:53:39 -07:00
|
|
|
// If we already exist, exit early
|
|
|
|
if (gBluetoothHfpManager) {
|
|
|
|
return gBluetoothHfpManager;
|
2012-09-26 06:34:55 -07:00
|
|
|
}
|
|
|
|
|
2012-10-02 22:53:39 -07: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 06:34:55 -07:00
|
|
|
}
|
|
|
|
|
2012-10-01 00:44:48 -07:00
|
|
|
void
|
2012-10-22 03:34:15 -07:00
|
|
|
BluetoothHfpManager::NotifySettings()
|
2012-10-01 00:44:48 -07:00
|
|
|
{
|
|
|
|
nsString type, name;
|
|
|
|
BluetoothValue v;
|
|
|
|
InfallibleTArray<BluetoothNamedValue> parameters;
|
|
|
|
type.AssignLiteral("bluetooth-hfp-status-changed");
|
|
|
|
|
|
|
|
name.AssignLiteral("connected");
|
2012-10-26 02:21:32 -07:00
|
|
|
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
v = true;
|
|
|
|
} else {
|
|
|
|
v = false;
|
|
|
|
}
|
2012-10-01 00:44:48 -07:00
|
|
|
parameters.AppendElement(BluetoothNamedValue(name, v));
|
|
|
|
|
|
|
|
name.AssignLiteral("address");
|
2012-10-26 02:21:32 -07:00
|
|
|
GetSocketAddr(mDevicePath);
|
|
|
|
v = mDevicePath;
|
2012-10-01 00:44:48 -07:00
|
|
|
parameters.AppendElement(BluetoothNamedValue(name, v));
|
|
|
|
|
|
|
|
if (!BroadcastSystemMessage(type, parameters)) {
|
|
|
|
NS_WARNING("Failed to broadcast system message to dialer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
|
|
|
|
{
|
|
|
|
nsString type, name, command;
|
|
|
|
command = aCommand;
|
|
|
|
InfallibleTArray<BluetoothNamedValue> parameters;
|
|
|
|
type.AssignLiteral("bluetooth-dialer-command");
|
|
|
|
|
|
|
|
BluetoothValue v(command);
|
|
|
|
parameters.AppendElement(BluetoothNamedValue(type, v));
|
|
|
|
|
|
|
|
if (!BroadcastSystemMessage(type, parameters)) {
|
|
|
|
NS_WARNING("Failed to broadcast system message to dialer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 03:18:38 -07: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:
|
|
|
|
// {"key":"volumeup", "value":1.0}
|
|
|
|
// {"key":"volumedown", "value":0.2}
|
|
|
|
|
|
|
|
JSContext* cx = nsContentUtils::GetSafeJSContext();
|
|
|
|
if (!cx) {
|
|
|
|
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;
|
|
|
|
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_MASTER, &match)) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// AG volume range: [0.0, 1.0]
|
|
|
|
// HS volume range: [0, 15]
|
2012-10-22 03:34:15 -07:00
|
|
|
float volume = value.toNumber();
|
2012-10-25 03:50:41 -07:00
|
|
|
mCurrentVgs = floor(volume * 15);
|
|
|
|
|
|
|
|
if (mReceiveVgsFlag) {
|
|
|
|
mReceiveVgsFlag = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetConnectionStatus() != SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-09-25 03:18:38 -07:00
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
SendCommand("+VGS: ", mCurrentVgs);
|
2012-09-25 03:18:38 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-02 22:53:39 -07:00
|
|
|
nsresult
|
|
|
|
BluetoothHfpManager::HandleShutdown()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
gInShutdown = true;
|
2012-10-05 16:05:35 -07:00
|
|
|
CloseSocket();
|
2012-10-02 22:53:39 -07:00
|
|
|
gBluetoothHfpManager = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
// Virtual function of class SocketConsumer
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ReceiveSocketData(UnixSocketRawData* aMessage)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-26 19:24:39 -07:00
|
|
|
|
|
|
|
const char* msg = (const char*)aMessage->mData;
|
|
|
|
|
|
|
|
// For more information, please refer to 4.34.1 "Bluetooth Defined AT
|
|
|
|
// Capabilities" in Bluetooth hands-free profile 1.6
|
|
|
|
if (!strncmp(msg, "AT+BRSF=", 8)) {
|
2012-10-22 03:34:15 -07:00
|
|
|
SendCommand("+BRSF: ", 23);
|
2012-09-26 19:24:39 -07:00
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "AT+CIND=?", 9)) {
|
2012-10-22 03:34:15 -07:00
|
|
|
// Asking for CIND range
|
|
|
|
SendCommand("+CIND: ", 0);
|
2012-09-26 19:24:39 -07:00
|
|
|
SendLine("OK");
|
2012-10-09 04:19:29 -07:00
|
|
|
} else if (!strncmp(msg, "AT+CIND?", 8)) {
|
2012-10-22 03:34:15 -07:00
|
|
|
// Asking for CIND value
|
|
|
|
SendCommand("+CIND: ", 1);
|
2012-09-26 19:24:39 -07:00
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "AT+CMER=", 8)) {
|
2012-10-01 00:44:48 -07:00
|
|
|
// SLC establishment
|
2012-09-26 19:24:39 -07:00
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "AT+CHLD=?", 9)) {
|
|
|
|
SendLine("+CHLD: (0,1,2,3)");
|
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "AT+CHLD=", 8)) {
|
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "AT+VGS=", 7)) {
|
2012-10-25 03:50:41 -07:00
|
|
|
mReceiveVgsFlag = true;
|
2012-09-26 19:24:39 -07:00
|
|
|
|
2012-10-25 03:50:41 -07:00
|
|
|
int length = strlen(msg) - 8;
|
|
|
|
nsAutoCString vgsString(nsDependentCSubstring(msg+7, length));
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
int newVgs = vgsString.ToInteger(&rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to extract volume value from bluetooth headset!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newVgs == mCurrentVgs) {
|
|
|
|
SendLine("OK");
|
|
|
|
return;
|
2012-09-26 19:24:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(newVgs >= 0 && newVgs <= 15, "Received invalid VGS value");
|
|
|
|
#endif
|
|
|
|
|
2012-10-25 03:50:41 -07:00
|
|
|
// HS volume range: [0, 15]
|
|
|
|
// sound_manager volume range: [0, 10]
|
|
|
|
nsString data;
|
|
|
|
int volume;
|
2012-09-26 19:24:39 -07:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2012-10-25 03:50:41 -07:00
|
|
|
volume = ceil((float)newVgs / 15.0 * 10.0);
|
|
|
|
data.AppendInt(volume);
|
|
|
|
os->NotifyObservers(nullptr, "bluetooth-volume-change", data.get());
|
2012-09-26 19:24:39 -07:00
|
|
|
|
2012-09-27 05:24:06 -07:00
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "AT+BLDN", 7)) {
|
2012-10-01 00:44:48 -07:00
|
|
|
NotifyDialer(NS_LITERAL_STRING("BLDN"));
|
2012-09-27 05:24:06 -07:00
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "ATA", 3)) {
|
2012-10-01 00:44:48 -07:00
|
|
|
NotifyDialer(NS_LITERAL_STRING("ATA"));
|
2012-09-27 05:24:06 -07:00
|
|
|
SendLine("OK");
|
|
|
|
} else if (!strncmp(msg, "AT+CHUP", 7)) {
|
2012-10-01 00:44:48 -07:00
|
|
|
NotifyDialer(NS_LITERAL_STRING("CHUP"));
|
2012-09-26 19:24:39 -07:00
|
|
|
SendLine("OK");
|
2012-10-05 03:48:05 -07:00
|
|
|
} else if (!strncmp(msg, "AT+CKPD", 7)) {
|
|
|
|
// For Headset
|
|
|
|
switch (mCurrentCallState) {
|
|
|
|
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:
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_WARNING("Not handling state changed");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SendLine("OK");
|
2012-09-26 19:24:39 -07:00
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCString warningMsg;
|
|
|
|
warningMsg.AssignLiteral("Not handling HFP message, reply ok: ");
|
|
|
|
warningMsg.Append(msg);
|
|
|
|
NS_WARNING(warningMsg.get());
|
|
|
|
#endif
|
|
|
|
SendLine("OK");
|
|
|
|
}
|
2012-09-26 06:34:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-10-22 03:34:15 -07:00
|
|
|
BluetoothHfpManager::Connect(const nsAString& aDevicePath,
|
2012-10-05 03:48:05 -07:00
|
|
|
const bool aIsHandsfree,
|
2012-09-26 06:34:55 -07:00
|
|
|
BluetoothReplyRunnable* aRunnable)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-02 22:53:39 -07:00
|
|
|
if (gInShutdown) {
|
|
|
|
MOZ_ASSERT(false, "Connect called while in shutdown!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
NS_WARNING("BluetoothHfpManager has connected to a headset/handsfree!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-10 22:49:11 -07:00
|
|
|
CloseSocket();
|
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
if (!bs) {
|
|
|
|
NS_WARNING("BluetoothService not available!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-05 03:48:05 -07:00
|
|
|
nsString serviceUuidStr;
|
|
|
|
if (aIsHandsfree) {
|
2012-10-09 04:19:29 -07:00
|
|
|
serviceUuidStr = NS_ConvertUTF8toUTF16(HANDSFREE_UUID);
|
2012-10-05 03:48:05 -07:00
|
|
|
} else {
|
2012-10-09 04:19:29 -07:00
|
|
|
serviceUuidStr = NS_ConvertUTF8toUTF16(HEADSET_UUID);
|
2012-10-05 03:48:05 -07:00
|
|
|
}
|
2012-09-26 06:34:55 -07:00
|
|
|
|
2012-10-09 04:19:29 -07:00
|
|
|
nsCOMPtr<nsIRILContentHelper> ril =
|
|
|
|
do_GetService("@mozilla.org/ril/content-helper;1");
|
2012-10-22 03:34:15 -07:00
|
|
|
if (!ril) {
|
|
|
|
MOZ_ASSERT("Failed to get RIL Content Helper");
|
|
|
|
}
|
2012-10-09 04:19:29 -07:00
|
|
|
ril->EnumerateCalls(mListener->GetCallback());
|
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
nsresult rv = bs->GetSocketViaService(aDevicePath,
|
2012-09-26 06:34:55 -07:00
|
|
|
serviceUuidStr,
|
|
|
|
BluetoothSocketType::RFCOMM,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
this,
|
|
|
|
runnable);
|
|
|
|
|
|
|
|
runnable.forget();
|
|
|
|
return NS_FAILED(rv) ? false : true;
|
|
|
|
}
|
|
|
|
|
2012-10-01 00:04:01 -07:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::Listen()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-10-02 22:53:39 -07:00
|
|
|
if (gInShutdown) {
|
|
|
|
MOZ_ASSERT(false, "Listen called while in shutdown!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-10 22:49:11 -07:00
|
|
|
CloseSocket();
|
|
|
|
|
2012-10-01 00:04:01 -07:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
if (!bs) {
|
|
|
|
NS_WARNING("BluetoothService not available!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::HANDSFREE_AG,
|
|
|
|
BluetoothSocketType::RFCOMM,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
this);
|
2012-10-26 02:28:39 -07:00
|
|
|
|
|
|
|
mSocketStatus = GetConnectionStatus();
|
|
|
|
|
2012-10-01 00:04:01 -07:00
|
|
|
return NS_FAILED(rv) ? false : true;
|
|
|
|
}
|
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::Disconnect()
|
|
|
|
{
|
2012-10-22 03:34:15 -07:00
|
|
|
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_DISCONNECTED) {
|
|
|
|
NS_WARNING("BluetoothHfpManager has disconnected!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
CloseSocket();
|
|
|
|
}
|
|
|
|
|
2012-09-26 19:24:39 -07: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 03:34:15 -07:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::SendCommand(const char* aCommand, const int aValue)
|
2012-10-09 04:19:29 -07:00
|
|
|
{
|
2012-10-22 03:34:15 -07:00
|
|
|
nsAutoCString message;
|
|
|
|
int value = aValue;
|
|
|
|
message += aCommand;
|
|
|
|
|
|
|
|
if (!strcmp(aCommand, "+CIEV: ")) {
|
|
|
|
message.AppendInt(aValue);
|
|
|
|
message += ",";
|
|
|
|
switch (aValue) {
|
|
|
|
case CINDType::CALL:
|
|
|
|
message.AppendInt(sCINDItems[CINDType::CALL].value);
|
|
|
|
break;
|
|
|
|
case CINDType::CALLSETUP:
|
|
|
|
message.AppendInt(sCINDItems[CINDType::CALLSETUP].value);
|
|
|
|
break;
|
|
|
|
case CINDType::CALLHELD:
|
|
|
|
message.AppendInt(sCINDItems[CINDType::CALLHELD].value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_WARNING("unexpected CINDType for CIEV command");
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!strcmp(aCommand, "+CIND: ")) {
|
|
|
|
if (!aValue) {
|
|
|
|
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 {
|
|
|
|
for (uint8_t i = 1; i < ArrayLength(sCINDItems); i++) {
|
|
|
|
message.AppendInt(sCINDItems[i].value);
|
|
|
|
if (i == (ArrayLength(sCINDItems) - 1)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
message += ",";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message.AppendInt(value);
|
2012-10-09 04:19:29 -07:00
|
|
|
}
|
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
return SendLine(message.get());
|
2012-10-09 04:19:29 -07:00
|
|
|
}
|
|
|
|
|
2012-09-26 22:15:22 -07:00
|
|
|
void
|
2012-10-22 03:34:15 -07:00
|
|
|
BluetoothHfpManager::SetupCIND(int aCallIndex, int aCallState, bool aInitial)
|
2012-09-26 22:15:22 -07:00
|
|
|
{
|
2012-09-26 22:15:33 -07:00
|
|
|
nsRefPtr<nsRunnable> sendRingTask;
|
2012-10-22 03:34:15 -07:00
|
|
|
nsString address;
|
2012-09-26 22:15:33 -07:00
|
|
|
|
|
|
|
switch (aCallState) {
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
2012-10-22 03:34:15 -07:00
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::INCOMING;
|
|
|
|
if (!aInitial) {
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALLSETUP);
|
|
|
|
}
|
2012-09-26 22:15:33 -07:00
|
|
|
|
|
|
|
// Start sending RING indicator to HF
|
|
|
|
sStopSendingRingFlag = false;
|
2012-10-25 18:25:15 -07:00
|
|
|
MessageLoop::current()->PostTask(FROM_HERE,
|
|
|
|
new SendRingIndicatorTask());
|
2012-09-26 22:15:33 -07:00
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
|
2012-10-22 03:34:15 -07:00
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::OUTGOING;
|
|
|
|
if (!aInitial) {
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALLSETUP);
|
|
|
|
|
|
|
|
GetSocketAddr(address);
|
|
|
|
OpenScoSocket(address);
|
|
|
|
}
|
2012-09-26 22:15:33 -07:00
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
2012-10-22 03:34:15 -07:00
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::OUTGOING_ALERTING;
|
|
|
|
if (!aInitial) {
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALLSETUP);
|
2012-09-26 22:15:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
|
2012-10-22 03:34:15 -07:00
|
|
|
if (aInitial) {
|
|
|
|
sCINDItems[CINDType::CALL].value = CallState::IN_PROGRESS;
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
|
|
|
} else {
|
|
|
|
switch (mCurrentCallState) {
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
|
|
|
// Incoming call, no break
|
|
|
|
sStopSendingRingFlag = true;
|
|
|
|
|
|
|
|
GetSocketAddr(address);
|
|
|
|
OpenScoSocket(address);
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
|
|
|
// Outgoing call
|
|
|
|
sCINDItems[CINDType::CALL].value = CallState::IN_PROGRESS;
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALL);
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALLSETUP);
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-26 22:15:33 -07:00
|
|
|
#ifdef DEBUG
|
2012-10-22 03:34:15 -07:00
|
|
|
NS_WARNING("Not handling state changed");
|
2012-09-26 22:15:33 -07:00
|
|
|
#endif
|
2012-10-22 03:34:15 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-09-26 22:15:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
|
2012-10-22 03:34:15 -07:00
|
|
|
if (!aInitial) {
|
|
|
|
switch (mCurrentCallState) {
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
|
|
|
|
// Incoming call, no break
|
|
|
|
sStopSendingRingFlag = true;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
|
|
|
|
// Outgoing call
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALLSETUP);
|
|
|
|
break;
|
|
|
|
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
|
|
|
|
sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
|
|
|
|
SendCommand("+CIEV: ", CINDType::CALL);
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-26 22:15:33 -07:00
|
|
|
#ifdef DEBUG
|
2012-10-22 03:34:15 -07:00
|
|
|
NS_WARNING("Not handling state changed");
|
2012-09-26 22:15:33 -07:00
|
|
|
#endif
|
2012-10-22 03:34:15 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
CloseScoSocket();
|
2012-09-26 22:15:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_WARNING("Not handling state changed");
|
2012-10-22 03:34:15 -07:00
|
|
|
sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
2012-09-26 22:15:33 -07:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2012-09-26 22:15:22 -07:00
|
|
|
|
2012-09-26 22:15:33 -07:00
|
|
|
mCurrentCallIndex = aCallIndex;
|
|
|
|
mCurrentCallState = aCallState;
|
2012-09-26 22:15:22 -07:00
|
|
|
}
|
2012-10-10 22:49:11 -07:00
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
/*
|
|
|
|
* EnumerateCallState will be called for each call
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::EnumerateCallState(int aCallIndex, int aCallState,
|
|
|
|
const char* aNumber, bool aIsActive)
|
|
|
|
{
|
|
|
|
if (aIsActive &&
|
|
|
|
(sCINDItems[CINDType::CALLHELD].value == CallHeldState::ONHOLD_NOACTIVE)) {
|
|
|
|
sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sCINDItems[CINDType::CALL].value || sCINDItems[CINDType::CALLSETUP].value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupCIND(aCallIndex, aCallState, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CallStateChanged will be called whenever call status is changed, and it
|
|
|
|
* also means we need to notify HS about the change. For more information,
|
|
|
|
* please refer to 4.13 ~ 4.15 in Bluetooth hands-free profile 1.6.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::CallStateChanged(int aCallIndex, int aCallState,
|
|
|
|
const char* aNumber, bool aIsActive)
|
|
|
|
{
|
|
|
|
if (GetConnectionStatus() != SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupCIND(aCallIndex, aCallState, false);
|
|
|
|
}
|
|
|
|
|
2012-10-10 22:49:11 -07:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnConnectSuccess()
|
|
|
|
{
|
2012-10-26 02:21:32 -07:00
|
|
|
// Cache device path for NotifySettings() since we can't get socket address
|
|
|
|
// when a headset disconnect with us
|
|
|
|
GetSocketAddr(mDevicePath);
|
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
if (mCurrentCallState == nsIRadioInterfaceLayer::CALL_STATE_CONNECTED ||
|
|
|
|
mCurrentCallState == nsIRadioInterfaceLayer::CALL_STATE_DIALING ||
|
|
|
|
mCurrentCallState == nsIRadioInterfaceLayer::CALL_STATE_ALERTING) {
|
2012-10-26 02:21:32 -07:00
|
|
|
OpenScoSocket(mDevicePath);
|
2012-10-22 03:34:15 -07:00
|
|
|
}
|
|
|
|
|
2012-10-26 02:28:39 -07:00
|
|
|
mSocketStatus = GetConnectionStatus();
|
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
NotifySettings();
|
2012-10-10 22:49:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnConnectError()
|
|
|
|
{
|
|
|
|
CloseSocket();
|
2012-10-26 02:28:39 -07:00
|
|
|
mSocketStatus = GetConnectionStatus();
|
2012-10-10 22:49:11 -07:00
|
|
|
// If connecting for some reason didn't work, restart listening
|
|
|
|
Listen();
|
|
|
|
}
|
2012-10-12 11:38:14 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnDisconnect()
|
|
|
|
{
|
2012-10-26 02:28:39 -07:00
|
|
|
if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
|
|
|
|
Listen();
|
|
|
|
NotifySettings();
|
|
|
|
}
|
|
|
|
|
2012-10-22 03:34:15 -07:00
|
|
|
sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
|
|
|
|
sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
|
|
|
|
sCINDItems[CINDType::CALLHELD].value = CallHeldState::NO_CALLHELD;
|
2012-10-12 11:38:14 -07:00
|
|
|
}
|