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"
|
2013-09-06 11:20:43 +00:00
|
|
|
#include "BluetoothProfileController.h"
|
2013-11-18 07:41:16 +00:00
|
|
|
#include "BluetoothServiceBluedroid.h"
|
2012-10-03 09:06:40 +00:00
|
|
|
#include "BluetoothUtils.h"
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2013-10-29 08:12:46 +00:00
|
|
|
#include "jsapi.h"
|
2012-09-25 10:18:38 +00:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.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"
|
2013-11-18 07:41:16 +00:00
|
|
|
#include "nsIAudioManager.h"
|
2013-10-29 08:12:46 +00:00
|
|
|
#include "nsIDOMIccInfo.h"
|
|
|
|
#include "nsIDOMMobileConnection.h"
|
|
|
|
#include "nsIIccProvider.h"
|
|
|
|
#include "nsIMobileConnectionProvider.h"
|
2013-11-18 07:41:16 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsISettingsService.h"
|
2013-03-06 09:53:23 +00:00
|
|
|
#include "nsITelephonyProvider.h"
|
2012-12-20 07:28:51 +00:00
|
|
|
#include "nsRadioInterfaceLayer.h"
|
2013-11-18 07:41:16 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
|
|
|
|
#define AUDIO_VOLUME_BT_SCO_ID "audio.volume.bt_sco"
|
2012-09-27 05:15:33 +00:00
|
|
|
|
2013-06-05 08:53:22 +00:00
|
|
|
/**
|
2013-11-18 07:41:16 +00:00
|
|
|
* Dispatch task with arguments to main thread.
|
2013-06-05 08:53:22 +00:00
|
|
|
*/
|
2013-11-18 07:41:16 +00:00
|
|
|
#define BT_HF_DISPATCH_MAIN(args...) \
|
|
|
|
NS_DispatchToMainThread(new MainThreadTask(args))
|
|
|
|
|
2012-12-17 15:24:35 +00:00
|
|
|
/**
|
2013-11-18 07:41:16 +00:00
|
|
|
* Process bluedroid callbacks with corresponding handlers.
|
2012-12-17 15:24:35 +00:00
|
|
|
*/
|
2013-11-18 07:41:16 +00:00
|
|
|
#define BT_HF_PROCESS_CB(func, args...) \
|
|
|
|
do { \
|
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpManager); \
|
|
|
|
sBluetoothHfpManager->func(args); \
|
|
|
|
} while(0)
|
2013-06-20 01:20:16 +00:00
|
|
|
|
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 {
|
2013-07-19 02:27:07 +00:00
|
|
|
StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
|
2013-11-18 07:41:16 +00:00
|
|
|
static const bthf_interface_t* sBluetoothHfpInterface = nullptr;
|
2013-05-09 14:10:28 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bool sInShutdown = false;
|
2013-05-09 14:10:28 +00:00
|
|
|
|
|
|
|
// Wait for 2 seconds for Dialer processing event 'BLDN'. '2' seconds is a
|
|
|
|
// magic number. The mechanism should be revised once we can get call history.
|
2013-05-31 12:43:18 +00:00
|
|
|
static int sWaitingForDialingInterval = 2000; //unit: ms
|
2013-06-24 04:10:07 +00:00
|
|
|
|
|
|
|
// Wait 3.7 seconds until Dialer stops playing busy tone. '3' seconds is the
|
|
|
|
// time window set in Dialer and the extra '0.7' second is a magic number.
|
|
|
|
// The mechanism should be revised once we know the exact time at which
|
|
|
|
// Dialer stops playing.
|
|
|
|
static int sBusyToneInterval = 3700; //unit: ms
|
2012-12-20 07:28:51 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
// Main thread task commands
|
|
|
|
enum MainThreadTaskCmd {
|
|
|
|
NOTIFY_CONN_STATE_CHANGED,
|
|
|
|
NOTIFY_DIALER,
|
|
|
|
POST_TASK_RESPOND_TO_BLDN,
|
|
|
|
POST_TASK_CLOSE_SCO
|
2012-10-22 10:34:15 +00:00
|
|
|
};
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
static void
|
|
|
|
ConnectionStateCallback(bthf_connection_state_t state, bt_bdaddr_t* bd_addr)
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessConnectionState, state, bd_addr);
|
|
|
|
}
|
2012-10-22 10:34:15 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
static void
|
|
|
|
AudioStateCallback(bthf_audio_state_t state, bt_bdaddr_t* bd_addr)
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessAudioState, state, bd_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VoiceRecognitionCallback(bthf_vr_state_t state)
|
|
|
|
{
|
|
|
|
// No support
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AnswerCallCallback()
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessAnswerCall);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
HangupCallCallback()
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessHangupCall);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VolumeControlCallback(bthf_volume_type_t type, int volume)
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessVolumeControl, type, volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DialCallCallback(char *number)
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessDialCall, number);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DtmfCmdCallback(char dtmf)
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessDtmfCmd, dtmf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
NoiceReductionCallback(bthf_nrec_t nrec)
|
|
|
|
{
|
|
|
|
// No support
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AtChldCallback(bthf_chld_type_t chld)
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessAtChld, chld);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AtCnumCallback()
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessAtCnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AtCindCallback()
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessAtCind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AtCopsCallback()
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessAtCops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AtClccCallback()
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessAtClcc);
|
|
|
|
}
|
2012-10-22 10:34:15 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
static void
|
|
|
|
UnknownAtCallback(char *at_string)
|
|
|
|
{
|
|
|
|
BT_HF_PROCESS_CB(ProcessUnknownAt, at_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
KeyPressedCallback()
|
|
|
|
{
|
|
|
|
// No support
|
|
|
|
}
|
|
|
|
|
|
|
|
static bthf_callbacks_t sBluetoothHfpCallbacks = {
|
|
|
|
sizeof(sBluetoothHfpCallbacks),
|
|
|
|
ConnectionStateCallback,
|
|
|
|
AudioStateCallback,
|
|
|
|
VoiceRecognitionCallback,
|
|
|
|
AnswerCallCallback,
|
|
|
|
HangupCallCallback,
|
|
|
|
VolumeControlCallback,
|
|
|
|
DialCallCallback,
|
|
|
|
DtmfCmdCallback,
|
|
|
|
NoiceReductionCallback,
|
|
|
|
AtChldCallback,
|
|
|
|
AtCnumCallback,
|
|
|
|
AtCindCallback,
|
|
|
|
AtCopsCallback,
|
|
|
|
AtClccCallback,
|
|
|
|
UnknownAtCallback,
|
|
|
|
KeyPressedCallback
|
2012-10-22 10:34:15 +00:00
|
|
|
};
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
static bool
|
|
|
|
IsValidDtmf(const char aChar) {
|
|
|
|
// Valid DTMF: [*#0-9ABCD]
|
|
|
|
return (aChar == '*' || aChar == '#') ||
|
|
|
|
(aChar >= '0' && aChar <= '9') ||
|
|
|
|
(aChar >= 'A' && aChar <= 'D');
|
|
|
|
}
|
|
|
|
|
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
|
2013-04-02 23:06:14 +00:00
|
|
|
Handle(const nsAString& aName, const JS::Value& aResult)
|
2012-11-19 07:10:38 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
NS_ENSURE_TRUE(cx, NS_OK);
|
|
|
|
|
|
|
|
if (!aResult.isNumber()) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("'" AUDIO_VOLUME_BT_SCO_ID "' is not a number!");
|
2012-11-19 07:10:38 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Unable to get value for '" AUDIO_VOLUME_BT_SCO_ID "'");
|
2012-11-19 07:10:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
class BluetoothHfpManager::CloseScoTask : public Task
|
2013-06-20 01:19:31 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
private:
|
|
|
|
void Run() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sBluetoothHfpManager);
|
|
|
|
sBluetoothHfpManager->DisconnectSco();
|
2013-06-20 01:19:31 +00:00
|
|
|
}
|
2013-11-18 07:41:16 +00:00
|
|
|
};
|
2012-12-20 07:28:51 +00:00
|
|
|
|
2013-05-09 14:10:28 +00:00
|
|
|
class BluetoothHfpManager::RespondToBLDNTask : public Task
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
void Run() MOZ_OVERRIDE
|
|
|
|
{
|
2013-07-19 02:27:07 +00:00
|
|
|
MOZ_ASSERT(sBluetoothHfpManager);
|
2013-05-09 14:10:28 +00:00
|
|
|
|
2013-07-19 02:27:07 +00:00
|
|
|
if (!sBluetoothHfpManager->mDialingRequestProcessed) {
|
|
|
|
sBluetoothHfpManager->mDialingRequestProcessed = true;
|
2013-11-18 07:41:16 +00:00
|
|
|
sBluetoothHfpManager->SendResponse(BTHF_AT_RESPONSE_ERROR);
|
2013-05-09 14:10:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
class BluetoothHfpManager::MainThreadTask : public nsRunnable
|
2012-09-27 05:15:33 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-11-18 07:41:16 +00:00
|
|
|
MainThreadTask(const int aCommand,
|
|
|
|
const nsAString& aParameter = EmptyString())
|
|
|
|
: mCommand(aCommand), mParameter(aParameter)
|
2012-09-27 05:15:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
nsresult Run()
|
2012-09-27 05:15:33 +00:00
|
|
|
{
|
2012-10-26 01:25:15 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-11-18 07:41:16 +00:00
|
|
|
MOZ_ASSERT(sBluetoothHfpManager);
|
2012-09-27 05:15:33 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
switch (mCommand) {
|
|
|
|
case MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED:
|
|
|
|
sBluetoothHfpManager->NotifyConnectionStateChanged(mParameter);
|
|
|
|
break;
|
|
|
|
case MainThreadTaskCmd::NOTIFY_DIALER:
|
|
|
|
sBluetoothHfpManager->NotifyDialer(mParameter);
|
|
|
|
break;
|
|
|
|
case MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN:
|
|
|
|
MessageLoop::current()->
|
|
|
|
PostDelayedTask(FROM_HERE, new RespondToBLDNTask(),
|
|
|
|
sWaitingForDialingInterval);
|
|
|
|
break;
|
|
|
|
case MainThreadTaskCmd::POST_TASK_CLOSE_SCO:
|
|
|
|
MessageLoop::current()->
|
|
|
|
PostDelayedTask(FROM_HERE, new CloseScoTask(),
|
|
|
|
sBusyToneInterval);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BT_WARNING("MainThreadTask: Unknown command %d", mCommand);
|
|
|
|
break;
|
2012-12-17 15:24:35 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
return NS_OK;
|
2012-09-27 05:15:33 +00:00
|
|
|
}
|
2012-12-17 15:24:35 +00:00
|
|
|
|
|
|
|
private:
|
2013-11-18 07:41:16 +00:00
|
|
|
int mCommand;
|
|
|
|
nsString mParameter;
|
2013-06-24 04:10:07 +00:00
|
|
|
};
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(BluetoothHfpManager::GetVolumeTask,
|
|
|
|
nsISettingsServiceCallback);
|
2013-06-07 08:54:13 +00:00
|
|
|
|
2013-10-17 04:40:17 +00:00
|
|
|
/**
|
|
|
|
* Call
|
|
|
|
*/
|
|
|
|
Call::Call()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Call::Reset()
|
|
|
|
{
|
|
|
|
mState = nsITelephonyProvider::CALL_STATE_DISCONNECTED;
|
2013-11-18 07:41:16 +00:00
|
|
|
mDirection = BTHF_CALL_DIRECTION_OUTGOING;
|
2013-10-17 04:40:17 +00:00
|
|
|
mNumber.Truncate();
|
2013-11-18 07:41:16 +00:00
|
|
|
mType = BTHF_CALL_ADDRTYPE_UNKNOWN;
|
2013-10-17 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Call::IsActive()
|
|
|
|
{
|
|
|
|
return (mState == nsITelephonyProvider::CALL_STATE_CONNECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BluetoothHfpManager
|
|
|
|
*/
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::BluetoothHfpManager()
|
2012-10-03 05:53:39 +00:00
|
|
|
{
|
2013-01-16 06:13:58 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ResetCallArray()
|
|
|
|
{
|
|
|
|
mCurrentCallArray.Clear();
|
|
|
|
// Append a call object at the beginning of mCurrentCallArray since call
|
|
|
|
// index from RIL starts at 1.
|
|
|
|
Call call;
|
|
|
|
mCurrentCallArray.AppendElement(call);
|
2013-10-17 04:40:17 +00:00
|
|
|
|
|
|
|
if (mPhoneType == PhoneType::CDMA) {
|
|
|
|
mCdmaSecondCall.Reset();
|
|
|
|
}
|
2013-01-16 06:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::Reset()
|
|
|
|
{
|
|
|
|
mReceiveVgsFlag = false;
|
2013-11-18 07:41:16 +00:00
|
|
|
mDialingRequestProcessed = true;
|
2013-01-16 06:13:58 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
mConnectionState = BTHF_CONNECTION_STATE_DISCONNECTED;
|
|
|
|
mAudioState = BTHF_AUDIO_STATE_DISCONNECTED;
|
2013-06-05 08:53:22 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
// Phone & Device CIND
|
2013-01-16 06:13:58 +00:00
|
|
|
ResetCallArray();
|
2013-11-18 07:41:16 +00:00
|
|
|
mCallSetupState = nsITelephonyProvider::CALL_STATE_DISCONNECTED;
|
|
|
|
mBattChg = 5;
|
|
|
|
mService = 0;
|
|
|
|
mRoam = 0;
|
|
|
|
mSignal = 0;
|
|
|
|
|
|
|
|
mController = nullptr;
|
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());
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE(InitHfpInterface(), false);
|
|
|
|
|
2013-06-20 01:19:31 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
NS_ENSURE_TRUE(obs, false);
|
|
|
|
|
|
|
|
if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false)) ||
|
2013-09-09 11:54:56 +00:00
|
|
|
NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
2013-06-20 01:19:31 +00:00
|
|
|
BT_WARNING("Failed to add observers!");
|
|
|
|
return false;
|
2012-10-09 04:59:33 +00:00
|
|
|
}
|
2012-10-03 05:53:39 +00:00
|
|
|
|
2013-06-20 01:19:31 +00:00
|
|
|
hal::RegisterBatteryObserver(this);
|
|
|
|
|
2013-09-09 11:54:56 +00:00
|
|
|
mListener = new BluetoothRilListener();
|
2013-11-26 06:11:06 +00:00
|
|
|
NS_ENSURE_TRUE(mListener->Listen(true), 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();
|
2013-06-20 01:20:16 +00:00
|
|
|
rv = settingsLock->Get(AUDIO_VOLUME_BT_SCO_ID, callback);
|
2012-11-19 07:10:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2012-10-25 10:50:41 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BluetoothHfpManager::InitHfpInterface()
|
|
|
|
{
|
|
|
|
const bt_interface_t* btInf = GetBluetoothInterface();
|
|
|
|
NS_ENSURE_TRUE(btInf, false);
|
|
|
|
|
|
|
|
if (sBluetoothHfpInterface) {
|
|
|
|
sBluetoothHfpInterface->cleanup();
|
|
|
|
sBluetoothHfpInterface = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bthf_interface_t *interface = (bthf_interface_t *)
|
|
|
|
btInf->get_profile_interface(BT_PROFILE_HANDSFREE_ID);
|
|
|
|
NS_ENSURE_TRUE(interface, false);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(BT_STATUS_SUCCESS ==
|
|
|
|
interface->init(&sBluetoothHfpCallbacks), false);
|
|
|
|
sBluetoothHfpInterface = interface;
|
2013-04-19 09:08:00 +00:00
|
|
|
|
2012-10-03 05:53:39 +00:00
|
|
|
return true;
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BluetoothHfpManager::~BluetoothHfpManager()
|
|
|
|
{
|
2013-11-26 06:11:06 +00:00
|
|
|
if (!mListener->Listen(false)) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Failed to stop listening RIL");
|
2012-09-27 12:24:06 +00:00
|
|
|
}
|
|
|
|
mListener = nullptr;
|
|
|
|
|
2013-06-20 01:19:31 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
NS_ENSURE_TRUE_VOID(obs);
|
|
|
|
|
|
|
|
if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
|
2013-09-09 11:54:56 +00:00
|
|
|
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID))) {
|
2013-06-20 01:19:31 +00:00
|
|
|
BT_WARNING("Failed to remove observers!");
|
|
|
|
}
|
|
|
|
|
|
|
|
hal::UnregisterBatteryObserver(this);
|
2013-11-18 07:41:16 +00:00
|
|
|
DeinitHfpInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::DeinitHfpInterface()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(GetBluetoothInterface());
|
|
|
|
|
|
|
|
if (sBluetoothHfpInterface) {
|
|
|
|
sBluetoothHfpInterface->cleanup();
|
|
|
|
sBluetoothHfpInterface = nullptr;
|
|
|
|
}
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
BluetoothHfpManager*
|
|
|
|
BluetoothHfpManager::Get()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-07-19 02:27:07 +00:00
|
|
|
// If sBluetoothHfpManager already exists, exit early
|
|
|
|
if (sBluetoothHfpManager) {
|
|
|
|
return sBluetoothHfpManager;
|
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
|
2013-08-13 07:04:34 +00:00
|
|
|
NS_ENSURE_FALSE(sInShutdown, nullptr);
|
2012-10-03 05:53:39 +00:00
|
|
|
|
2013-07-19 02:27:07 +00:00
|
|
|
// Create a new instance, register, and return
|
2013-04-05 00:54:22 +00:00
|
|
|
BluetoothHfpManager* manager = new BluetoothHfpManager();
|
|
|
|
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
2012-10-03 05:53:39 +00:00
|
|
|
|
2013-07-19 02:27:07 +00:00
|
|
|
sBluetoothHfpManager = manager;
|
|
|
|
return sBluetoothHfpManager;
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BluetoothHfpManager::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
|
|
|
|
HandleVolumeChanged(nsDependentString(aData));
|
|
|
|
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
|
|
|
HandleShutdown();
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-02 10:32:57 +00:00
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::Notify(const hal::BatteryInformation& aBatteryInfo)
|
2013-08-02 10:32:57 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
// Range of battery level: [0, 1], double
|
|
|
|
// Range of CIND::BATTCHG: [0, 5], int
|
|
|
|
mBattChg = (int) ceil(aBatteryInfo.level() * 5.0);
|
|
|
|
UpdateDeviceCIND();
|
|
|
|
}
|
2013-08-02 10:32:57 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessConnectionState(bthf_connection_state_t aState,
|
|
|
|
bt_bdaddr_t* aBdAddress)
|
|
|
|
{
|
|
|
|
BT_LOGR("%s: state %d", __FUNCTION__, aState);
|
2013-07-30 09:34:56 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
mConnectionState = aState;
|
2013-09-11 12:56:48 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
if (aState == BTHF_CONNECTION_STATE_CONNECTED) {
|
2013-11-21 12:17:07 +00:00
|
|
|
BdAddressTypeToString(aBdAddress, mDeviceAddress);
|
2013-11-18 07:41:16 +00:00
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
|
|
|
|
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
|
|
|
|
} else if (aState == BTHF_CONNECTION_STATE_DISCONNECTED) {
|
|
|
|
DisconnectSco();
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
|
|
|
|
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
|
2013-09-11 12:56:48 +00:00
|
|
|
}
|
2012-10-01 07:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::ProcessAudioState(bthf_audio_state_t aState,
|
|
|
|
bt_bdaddr_t* aBdAddress)
|
2012-10-01 07:44:48 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
BT_LOGR("%s: state %d", __FUNCTION__, aState);
|
2012-10-01 07:44:48 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
mAudioState = aState;
|
2012-10-01 07:44:48 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
if (aState == BTHF_AUDIO_STATE_CONNECTED ||
|
|
|
|
aState == BTHF_AUDIO_STATE_DISCONNECTED) {
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
|
|
|
|
NS_LITERAL_STRING(BLUETOOTH_SCO_STATUS_CHANGED_ID));
|
2013-05-10 11:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 01:20:16 +00:00
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::ProcessAnswerCall()
|
2012-09-25 10:18:38 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
|
|
|
NS_LITERAL_STRING("ATA"));
|
|
|
|
}
|
2012-09-25 10:18:38 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessHangupCall()
|
|
|
|
{
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
|
|
|
NS_LITERAL_STRING("CHUP"));
|
|
|
|
}
|
2012-09-25 10:18:38 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessVolumeControl(bthf_volume_type_t aType, int aVolume)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(aVolume >= 0 && aVolume <= 15);
|
2012-09-25 10:18:38 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
if (aType == BTHF_VOLUME_TYPE_MIC) {
|
|
|
|
mCurrentVgm = aVolume;
|
|
|
|
} else if (aType == BTHF_VOLUME_TYPE_SPK) {
|
|
|
|
// Adjust volume by headset
|
|
|
|
mReceiveVgsFlag = true;
|
|
|
|
NS_ENSURE_TRUE_VOID(aVolume != mCurrentVgs);
|
2012-09-25 10:18:38 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
nsString data;
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
data.AppendInt(aVolume);
|
|
|
|
os->NotifyObservers(nullptr, "bluetooth-volume-change", data.get());
|
2012-09-25 10:18:38 +00:00
|
|
|
}
|
2013-11-18 07:41:16 +00:00
|
|
|
}
|
2012-09-25 10:18:38 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessDtmfCmd(char aDtmf)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(IsValidDtmf(aDtmf));
|
2012-09-25 10:18:38 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
nsAutoCString message("VTS=");
|
|
|
|
message += aDtmf;
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
|
|
|
NS_ConvertUTF8toUTF16(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessAtChld(bthf_chld_type_t aChld)
|
|
|
|
{
|
|
|
|
nsAutoCString message("CHLD=");
|
|
|
|
message.AppendInt((int)aChld);
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
|
|
|
NS_ConvertUTF8toUTF16(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BluetoothHfpManager::ProcessDialCall(char *aNumber)
|
|
|
|
{
|
|
|
|
nsAutoCString message(aNumber);
|
|
|
|
if (message.IsEmpty()) {
|
|
|
|
// Redial: BLDN
|
|
|
|
mDialingRequestProcessed = false;
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
|
|
|
NS_LITERAL_STRING("BLDN"));
|
|
|
|
} else {
|
|
|
|
nsAutoCString newMsg("ATD");
|
|
|
|
|
|
|
|
if (message[0] == '>') {
|
|
|
|
// Memory dial: ATD>xxx
|
|
|
|
mDialingRequestProcessed = false;
|
|
|
|
newMsg += message;
|
|
|
|
} else {
|
|
|
|
// Dial number: ATDxxx
|
|
|
|
int end = message.FindChar(';');
|
|
|
|
if (end < 0) {
|
|
|
|
BT_WARNING("Couldn't get the number to dial");
|
|
|
|
SendResponse(BTHF_AT_RESPONSE_OK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
newMsg += nsDependentCSubstring(message, 0, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
|
|
|
NS_ConvertUTF8toUTF16(newMsg));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDialingRequestProcessed) {
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessAtCnum()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(!mMsisdn.IsEmpty());
|
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
|
|
|
|
nsAutoCString message("+CNUM: ,\"");
|
|
|
|
message.Append(NS_ConvertUTF16toUTF8(mMsisdn).get());
|
|
|
|
message.AppendLiteral("\",");
|
|
|
|
message.AppendInt(BTHF_CALL_ADDRTYPE_UNKNOWN);
|
|
|
|
message.AppendLiteral(",,4");
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->formatted_at_response(message.get()));
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->at_response(BTHF_AT_RESPONSE_OK, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessAtCind()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
|
|
|
|
int numActive = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_CONNECTED);
|
|
|
|
int numHeld = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_HELD);
|
|
|
|
|
|
|
|
bt_status_t status = sBluetoothHfpInterface->cind_response(
|
|
|
|
mService,
|
|
|
|
numActive,
|
|
|
|
numHeld,
|
|
|
|
ConvertToBthfCallState(mCallSetupState),
|
|
|
|
mSignal,
|
|
|
|
mRoam,
|
|
|
|
mBattChg);
|
|
|
|
NS_ENSURE_TRUE_VOID(status == BT_STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessAtCops()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->cops_response(
|
|
|
|
NS_ConvertUTF16toUTF8(mOperatorName).get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessAtClcc()
|
|
|
|
{
|
|
|
|
uint32_t callNumbers = mCurrentCallArray.Length();
|
|
|
|
uint32_t i;
|
|
|
|
for (i = 1; i < callNumbers; i++) {
|
|
|
|
SendCLCC(mCurrentCallArray[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCdmaSecondCall.mNumber.IsEmpty()) {
|
|
|
|
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
|
|
|
|
MOZ_ASSERT(i == 2);
|
|
|
|
|
|
|
|
SendCLCC(mCdmaSecondCall, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ProcessUnknownAt(char *aAtString)
|
|
|
|
{
|
|
|
|
BT_LOGR("%s: [%s]", __FUNCTION__, aAtString);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->at_response(BTHF_AT_RESPONSE_ERROR, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Notify Gecko observers
|
|
|
|
nsCOMPtr<nsIObserverService> obs =
|
|
|
|
do_GetService("@mozilla.org/observer-service;1");
|
|
|
|
NS_ENSURE_TRUE_VOID(obs);
|
|
|
|
|
|
|
|
if (NS_FAILED(obs->NotifyObservers(this, NS_ConvertUTF16toUTF8(aType).get(),
|
|
|
|
mDeviceAddress.get()))) {
|
|
|
|
BT_WARNING("Failed to notify observsers!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch an event of status change
|
|
|
|
bool status;
|
|
|
|
nsAutoString eventName;
|
|
|
|
if (aType.EqualsLiteral(BLUETOOTH_HFP_STATUS_CHANGED_ID)) {
|
|
|
|
status = IsConnected();
|
|
|
|
eventName.AssignLiteral(HFP_STATUS_CHANGED_ID);
|
|
|
|
} else if (aType.EqualsLiteral(BLUETOOTH_SCO_STATUS_CHANGED_ID)) {
|
|
|
|
status = IsScoConnected();
|
|
|
|
eventName.AssignLiteral(SCO_STATUS_CHANGED_ID);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchStatusChangedEvent(eventName, mDeviceAddress, status);
|
|
|
|
|
|
|
|
// Notify profile controller
|
|
|
|
if (aType.EqualsLiteral(BLUETOOTH_HFP_STATUS_CHANGED_ID)) {
|
|
|
|
if (IsConnected()) {
|
|
|
|
MOZ_ASSERT(mListener);
|
|
|
|
|
|
|
|
// Enumerate current calls
|
|
|
|
mListener->EnumerateCalls();
|
|
|
|
|
|
|
|
OnConnect(EmptyString());
|
|
|
|
} else if (mConnectionState == BTHF_CONNECTION_STATE_DISCONNECTED) {
|
|
|
|
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
|
|
|
OnDisconnect(EmptyString());
|
2013-11-21 12:17:10 +00:00
|
|
|
|
|
|
|
Reset();
|
2013-11-18 07:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
|
|
|
|
{
|
|
|
|
BluetoothValue v;
|
|
|
|
InfallibleTArray<BluetoothNamedValue> parameters;
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command");
|
|
|
|
NS_NAMED_LITERAL_STRING(name, "command");
|
|
|
|
|
|
|
|
v = nsString(aCommand);
|
|
|
|
parameters.AppendElement(BluetoothNamedValue(name, v));
|
|
|
|
|
|
|
|
if (!BroadcastSystemMessage(type, parameters)) {
|
|
|
|
BT_WARNING("Failed to broadcast system message to dialer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
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":10}
|
|
|
|
// {"key":"volumedown", "value":2}
|
|
|
|
JSContext* cx = nsContentUtils::GetSafeJSContext();
|
|
|
|
NS_ENSURE_TRUE_VOID(cx);
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> val(cx);
|
|
|
|
NS_ENSURE_TRUE_VOID(JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val));
|
|
|
|
NS_ENSURE_TRUE_VOID(val.isObject());
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> obj(cx, &val.toObject());
|
|
|
|
JS::Rooted<JS::Value> key(cx);
|
|
|
|
if (!JS_GetProperty(cx, obj, "key", &key) || !key.isString()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool match;
|
|
|
|
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO_ID, &match) ||
|
|
|
|
!match) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
if (!JS_GetProperty(cx, obj, "value", &value) ||
|
|
|
|
!value.isNumber()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-25 10:18:38 +00:00
|
|
|
|
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;
|
2013-06-20 01:20:16 +00:00
|
|
|
return;
|
2012-10-25 10:50:41 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 07:10:38 +00:00
|
|
|
// Only send volume back when there's a connected headset
|
2013-04-19 09:08:00 +00:00
|
|
|
if (IsConnected()) {
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->volume_control(BTHF_VOLUME_TYPE_SPK,
|
|
|
|
mCurrentVgs));
|
2012-10-25 10:50:41 +00:00
|
|
|
}
|
2012-09-25 10:18:38 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 01:20:16 +00:00
|
|
|
void
|
2013-11-26 06:11:06 +00:00
|
|
|
BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
|
2012-12-20 07:28:51 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMobileConnectionProvider> connection =
|
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
2013-06-20 01:20:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(connection);
|
2012-12-20 07:28:51 +00:00
|
|
|
|
2013-07-18 02:52:20 +00:00
|
|
|
nsCOMPtr<nsIDOMMozMobileConnectionInfo> voiceInfo;
|
2013-11-26 06:11:06 +00:00
|
|
|
connection->GetVoiceConnectionInfo(aClientId, getter_AddRefs(voiceInfo));
|
2013-06-20 01:20:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(voiceInfo);
|
2012-12-20 07:28:51 +00:00
|
|
|
|
2013-11-26 06:11:06 +00:00
|
|
|
nsString type;
|
|
|
|
voiceInfo->GetType(type);
|
|
|
|
mPhoneType = GetPhoneType(type);
|
|
|
|
|
2012-12-20 07:28:51 +00:00
|
|
|
bool roaming;
|
|
|
|
voiceInfo->GetRoaming(&roaming);
|
2013-11-18 07:41:16 +00:00
|
|
|
mRoam = (roaming) ? 1 : 0;
|
2012-12-20 07:28:51 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
// Service
|
2012-12-20 07:28:51 +00:00
|
|
|
nsString regState;
|
|
|
|
voiceInfo->GetState(regState);
|
2013-11-18 07:41:16 +00:00
|
|
|
mService = (regState.EqualsLiteral("registered")) ? 1 : 0;
|
2012-12-20 07:28:51 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
// Signal
|
2012-12-20 07:28:51 +00:00
|
|
|
JS::Value value;
|
|
|
|
voiceInfo->GetRelSignalStrength(&value);
|
|
|
|
if (!value.isNumber()) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Failed to get relSignalStrength in BluetoothHfpManager");
|
2013-06-20 01:20:16 +00:00
|
|
|
return;
|
2012-12-20 07:28:51 +00:00
|
|
|
}
|
2013-11-18 07:41:16 +00:00
|
|
|
mSignal = (int)ceil(value.toNumber() / 20.0);
|
2012-12-20 07:28:51 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
UpdateDeviceCIND();
|
2013-01-23 01:22:08 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
// Operator name
|
2013-07-18 02:52:20 +00:00
|
|
|
nsCOMPtr<nsIDOMMozMobileNetworkInfo> network;
|
|
|
|
voiceInfo->GetNetwork(getter_AddRefs(network));
|
2013-06-20 01:20:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(network);
|
2013-01-23 01:22:08 +00:00
|
|
|
network->GetLongName(mOperatorName);
|
|
|
|
|
2013-05-15 09:12:48 +00:00
|
|
|
// According to GSM 07.07, "<format> indicates if the format is alphanumeric
|
|
|
|
// or numeric; long alphanumeric format can be upto 16 characters long and
|
|
|
|
// short format up to 8 characters (refer GSM MoU SE.13 [9])..."
|
|
|
|
// However, we found that the operator name may sometimes be longer than 16
|
|
|
|
// characters. After discussion, we decided to fix this here but not in RIL
|
|
|
|
// or modem.
|
|
|
|
//
|
|
|
|
// Please see Bug 871366 for more information.
|
|
|
|
if (mOperatorName.Length() > 16) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("The operator name was longer than 16 characters. We cut it.");
|
2013-05-15 09:12:48 +00:00
|
|
|
mOperatorName.Left(mOperatorName, 16);
|
|
|
|
}
|
2012-12-20 07:28:51 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 01:20:16 +00:00
|
|
|
void
|
2013-11-26 06:11:06 +00:00
|
|
|
BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId)
|
2012-12-17 09:44:32 +00:00
|
|
|
{
|
2013-05-30 10:56:11 +00:00
|
|
|
nsCOMPtr<nsIIccProvider> icc =
|
2012-12-17 09:44:32 +00:00
|
|
|
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
2013-05-30 10:56:11 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(icc);
|
2012-12-17 09:44:32 +00:00
|
|
|
|
2013-07-18 02:52:20 +00:00
|
|
|
nsCOMPtr<nsIDOMMozIccInfo> iccInfo;
|
2013-11-26 06:11:06 +00:00
|
|
|
icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo));
|
2013-06-20 01:20:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(iccInfo);
|
2013-08-21 03:02:24 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMMozGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
|
|
|
|
NS_ENSURE_TRUE_VOID(gsmIccInfo);
|
|
|
|
gsmIccInfo->GetMsisdn(mMsisdn);
|
2012-12-17 09:44:32 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 01:20:16 +00:00
|
|
|
void
|
2012-10-03 05:53:39 +00:00
|
|
|
BluetoothHfpManager::HandleShutdown()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-07-19 02:27:07 +00:00
|
|
|
sInShutdown = true;
|
2013-09-06 11:20:43 +00:00
|
|
|
Disconnect(nullptr);
|
2013-05-10 11:01:10 +00:00
|
|
|
DisconnectSco();
|
2013-07-19 02:27:07 +00:00
|
|
|
sBluetoothHfpManager = nullptr;
|
2012-10-03 05:53:39 +00:00
|
|
|
}
|
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::SendCLCC(Call& aCall, int aIndex)
|
2012-09-26 13:34:55 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(aCall.mState !=
|
|
|
|
nsITelephonyProvider::CALL_STATE_DISCONNECTED);
|
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
|
|
|
|
bthf_call_state_t callState = ConvertToBthfCallState(aCall.mState);
|
|
|
|
|
|
|
|
if (mPhoneType == PhoneType::CDMA && aIndex == 1 && aCall.IsActive()) {
|
|
|
|
callState = (mCdmaSecondCall.IsActive()) ? BTHF_CALL_STATE_HELD :
|
|
|
|
BTHF_CALL_STATE_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_status_t status = sBluetoothHfpInterface->clcc_response(
|
|
|
|
aIndex,
|
|
|
|
aCall.mDirection,
|
|
|
|
callState,
|
|
|
|
BTHF_CALL_TYPE_VOICE,
|
|
|
|
BTHF_CALL_MPTY_TYPE_SINGLE,
|
|
|
|
NS_ConvertUTF16toUTF8(aCall.mNumber).get(),
|
|
|
|
aCall.mType);
|
|
|
|
NS_ENSURE_TRUE_VOID(status == BT_STATUS_SUCCESS);
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 06:39:12 +00:00
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::SendLine(const char* aMessage)
|
2012-10-01 07:04:01 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->formatted_at_response(aMessage));
|
2012-10-01 07:04:01 +00:00
|
|
|
}
|
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::SendResponse(bthf_at_response_t aResponseCode)
|
2012-09-26 13:34:55 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->at_response(aResponseCode, 0));
|
2012-09-26 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 04:40:17 +00:00
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::UpdatePhoneCIND(uint32_t aCallIndex, bool aSend)
|
2013-10-17 04:40:17 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
// Update callsetup state
|
|
|
|
uint16_t callState = mCurrentCallArray[aCallIndex].mState;
|
|
|
|
if (callState == nsITelephonyProvider::CALL_STATE_CONNECTED ||
|
|
|
|
callState == nsITelephonyProvider::CALL_STATE_HELD) {
|
|
|
|
mCallSetupState = nsITelephonyProvider::CALL_STATE_DISCONNECTED;
|
|
|
|
} else {
|
|
|
|
mCallSetupState = callState;
|
2013-10-17 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
2013-04-19 09:08:00 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
int numActive = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_CONNECTED);
|
|
|
|
int numHeld = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_HELD);
|
|
|
|
bthf_call_state_t bthfCallState = ConvertToBthfCallState(mCallSetupState);
|
|
|
|
nsAutoCString number = NS_ConvertUTF16toUTF8(mCurrentCallArray[aCallIndex].mNumber);
|
|
|
|
bthf_call_addrtype_t type = mCurrentCallArray[aCallIndex].mType;
|
2012-09-27 02:24:39 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
BT_LOGR("%s: [%d] state %d => BTHF: active[%d] held[%d] state[%d]",
|
|
|
|
__FUNCTION__, aCallIndex, callState, numActive, numHeld, bthfCallState);
|
2012-09-27 02:24:39 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->phone_state_change(
|
|
|
|
numActive, numHeld, bthfCallState, number.get(), type));
|
2012-09-27 02:24:39 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:15:22 +00:00
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::UpdateDeviceCIND()
|
2012-09-27 05:15:22 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->device_status_notification(
|
|
|
|
(bthf_network_state_t) mService,
|
|
|
|
(bthf_service_type_t) mRoam,
|
|
|
|
mSignal,
|
|
|
|
mBattChg));
|
2013-01-28 11:28:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 06:58:51 +00:00
|
|
|
uint32_t
|
|
|
|
BluetoothHfpManager::FindFirstCall(uint16_t aState)
|
|
|
|
{
|
|
|
|
uint32_t callLength = mCurrentCallArray.Length();
|
|
|
|
|
|
|
|
for (uint32_t i = 1; i < callLength; ++i) {
|
|
|
|
if (mCurrentCallArray[i].mState == aState) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
BluetoothHfpManager::GetNumberOfCalls(uint16_t aState)
|
|
|
|
{
|
|
|
|
uint32_t num = 0;
|
|
|
|
uint32_t callLength = mCurrentCallArray.Length();
|
|
|
|
|
|
|
|
for (uint32_t i = 1; i < callLength; ++i) {
|
|
|
|
if (mCurrentCallArray[i].mState == aState) {
|
|
|
|
++num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bthf_call_state_t
|
|
|
|
BluetoothHfpManager::ConvertToBthfCallState(int aCallState)
|
|
|
|
{
|
|
|
|
bthf_call_state_t state;
|
|
|
|
|
|
|
|
// Refer to AOSP BluetoothPhoneService.convertCallState
|
|
|
|
if (aCallState == nsITelephonyProvider::CALL_STATE_INCOMING) {
|
|
|
|
state = (FindFirstCall(nsITelephonyProvider::CALL_STATE_CONNECTED)) ?
|
|
|
|
BTHF_CALL_STATE_WAITING :
|
|
|
|
BTHF_CALL_STATE_INCOMING;
|
|
|
|
} else if (aCallState == nsITelephonyProvider::CALL_STATE_DIALING) {
|
|
|
|
state = BTHF_CALL_STATE_DIALING;
|
|
|
|
} else if (aCallState == nsITelephonyProvider::CALL_STATE_ALERTING) {
|
|
|
|
state = BTHF_CALL_STATE_ALERTING;
|
|
|
|
} else if (aCallState == nsITelephonyProvider::CALL_STATE_CONNECTED) {
|
|
|
|
state = BTHF_CALL_STATE_ACTIVE;
|
|
|
|
} else if (aCallState == nsITelephonyProvider::CALL_STATE_HELD) {
|
|
|
|
state = BTHF_CALL_STATE_HELD;
|
|
|
|
} else { // disconnected
|
|
|
|
state = BTHF_CALL_STATE_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2013-01-28 11:28:51 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
|
|
|
|
uint16_t aCallState,
|
2013-07-15 12:54:07 +00:00
|
|
|
const nsAString& aError,
|
2013-01-28 11:28:51 +00:00
|
|
|
const nsAString& aNumber,
|
2013-05-10 09:47:16 +00:00
|
|
|
const bool aIsOutgoing,
|
2013-01-28 11:28:51 +00:00
|
|
|
bool aSend)
|
|
|
|
{
|
2013-04-19 09:08:00 +00:00
|
|
|
if (!IsConnected()) {
|
|
|
|
// Normal case. No need to print out warnings.
|
2013-01-28 11:28:51 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-03-02 04:04:59 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mState = aCallState;
|
2013-11-18 07:41:16 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mNumber = aNumber;
|
|
|
|
mCurrentCallArray[aCallIndex].mDirection = (aIsOutgoing) ?
|
|
|
|
BTHF_CALL_DIRECTION_OUTGOING :
|
|
|
|
BTHF_CALL_DIRECTION_INCOMING;
|
2013-01-16 06:13:58 +00:00
|
|
|
// Same logic as implementation in ril_worker.js
|
|
|
|
if (aNumber.Length() && aNumber[0] == '+') {
|
2013-11-18 07:41:16 +00:00
|
|
|
mCurrentCallArray[aCallIndex].mType = BTHF_CALL_ADDRTYPE_INTERNATIONAL;
|
2012-10-31 03:53:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
UpdatePhoneCIND(aCallIndex, aSend);
|
2012-10-31 03:53:36 +00:00
|
|
|
|
2012-09-27 05:15:33 +00:00
|
|
|
switch (aCallState) {
|
2013-03-06 09:53:23 +00:00
|
|
|
case nsITelephonyProvider::CALL_STATE_DIALING:
|
2013-11-18 07:41:16 +00:00
|
|
|
// We've send Dialer a dialing request and this is the response.
|
2013-05-31 12:43:18 +00:00
|
|
|
if (!mDialingRequestProcessed) {
|
2013-11-18 07:41:16 +00:00
|
|
|
SendResponse(BTHF_AT_RESPONSE_OK);
|
2013-05-31 12:43:18 +00:00
|
|
|
mDialingRequestProcessed = true;
|
2013-05-09 14:10:28 +00:00
|
|
|
}
|
2012-09-27 05:15:33 +00:00
|
|
|
break;
|
2013-01-28 11:28:51 +00:00
|
|
|
|
2013-03-06 09:53:23 +00:00
|
|
|
case nsITelephonyProvider::CALL_STATE_DISCONNECTED:
|
2013-05-28 06:58:51 +00:00
|
|
|
// -1 is necessary because call 0 is an invalid (padding) call object.
|
|
|
|
if (mCurrentCallArray.Length() - 1 ==
|
|
|
|
GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_DISCONNECTED)) {
|
2013-06-24 04:10:07 +00:00
|
|
|
// In order to let user hear busy tone via connected Bluetooth headset,
|
|
|
|
// we postpone the timing of dropping SCO.
|
2013-11-18 07:41:16 +00:00
|
|
|
if (aError.Equals(NS_LITERAL_STRING("BusyError"))) {
|
|
|
|
// FIXME: UpdatePhoneCIND later since it causes SCO close but
|
|
|
|
// Dialer is still playing busy tone via HF.
|
|
|
|
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_CLOSE_SCO);
|
2013-06-24 04:10:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 06:58:51 +00:00
|
|
|
ResetCallArray();
|
2013-01-28 11:28:51 +00:00
|
|
|
}
|
2012-09-27 05:15:33 +00:00
|
|
|
break;
|
2013-11-18 07:41:16 +00:00
|
|
|
|
2012-09-27 05:15:33 +00:00
|
|
|
default:
|
2013-05-08 06:16:51 +00:00
|
|
|
break;
|
2012-09-27 05:15:33 +00:00
|
|
|
}
|
2012-09-27 05:15:22 +00:00
|
|
|
}
|
2012-10-11 05:49:11 +00:00
|
|
|
|
2013-10-17 04:40:17 +00:00
|
|
|
PhoneType
|
|
|
|
BluetoothHfpManager::GetPhoneType(const nsAString& aType)
|
|
|
|
{
|
|
|
|
// FIXME: Query phone type from RIL after RIL implements new API (bug 912019)
|
|
|
|
if (aType.EqualsLiteral("gsm") || aType.EqualsLiteral("gprs") ||
|
|
|
|
aType.EqualsLiteral("edge") || aType.EqualsLiteral("umts") ||
|
|
|
|
aType.EqualsLiteral("hspa") || aType.EqualsLiteral("hsdpa") ||
|
|
|
|
aType.EqualsLiteral("hsupa") || aType.EqualsLiteral("hspa+")) {
|
|
|
|
return PhoneType::GSM;
|
|
|
|
} else if (aType.EqualsLiteral("is95a") || aType.EqualsLiteral("is95b") ||
|
|
|
|
aType.EqualsLiteral("1xrtt") || aType.EqualsLiteral("evdo0") ||
|
|
|
|
aType.EqualsLiteral("evdoa") || aType.EqualsLiteral("evdob")) {
|
|
|
|
return PhoneType::CDMA;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PhoneType::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::UpdateSecondNumber(const nsAString& aNumber)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
|
|
|
|
|
|
|
|
// Always regard second call as incoming call since v1.2 RIL
|
|
|
|
// doesn't support outgoing second call in CDMA.
|
2013-11-18 07:41:16 +00:00
|
|
|
mCdmaSecondCall.mDirection = BTHF_CALL_DIRECTION_INCOMING;
|
2013-10-17 04:40:17 +00:00
|
|
|
|
|
|
|
mCdmaSecondCall.mNumber = aNumber;
|
2013-11-18 07:41:16 +00:00
|
|
|
if (aNumber[0] == '+') {
|
|
|
|
mCdmaSecondCall.mType = BTHF_CALL_ADDRTYPE_INTERNATIONAL;
|
|
|
|
}
|
2013-10-17 04:40:17 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
// FIXME: check CDMA + bluedroid
|
|
|
|
//UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, true);
|
2013-10-17 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 02:38:13 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::AnswerWaitingCall()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
|
|
|
|
|
|
|
|
// Pick up second call. First call is held now.
|
|
|
|
mCdmaSecondCall.mState = nsITelephonyProvider::CALL_STATE_CONNECTED;
|
2013-11-18 07:41:16 +00:00
|
|
|
// FIXME: check CDMA + bluedroid
|
|
|
|
//UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
|
2013-10-16 02:38:13 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
//sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
|
|
|
|
//SendCommand("+CIEV: ", CINDType::CALLHELD);
|
2013-10-16 02:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::IgnoreWaitingCall()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
|
|
|
|
|
|
|
|
mCdmaSecondCall.Reset();
|
2013-11-18 07:41:16 +00:00
|
|
|
// FIXME: check CDMA + bluedroid
|
|
|
|
//UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
|
2013-10-16 02:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::ToggleCalls()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
|
|
|
|
|
|
|
|
// Toggle acitve and held calls
|
|
|
|
mCdmaSecondCall.mState = (mCdmaSecondCall.IsActive()) ?
|
|
|
|
nsITelephonyProvider::CALL_STATE_HELD :
|
|
|
|
nsITelephonyProvider::CALL_STATE_CONNECTED;
|
|
|
|
}
|
2012-10-11 05:49:11 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::ConnectSco()
|
2013-05-10 06:39:12 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-05-22 11:08:21 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE(!sInShutdown, false);
|
|
|
|
NS_ENSURE_TRUE(IsConnected() && !IsScoConnected(), false);
|
|
|
|
NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
|
2013-05-10 06:39:12 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bt_bdaddr_t deviceBdAddress;
|
|
|
|
StringToBdAddressType(mDeviceAddress, &deviceBdAddress);
|
|
|
|
NS_ENSURE_TRUE(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->connect_audio(&deviceBdAddress), false);
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
return true;
|
2013-05-10 11:01:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::DisconnectSco()
|
2013-05-10 11:01:10 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE(IsScoConnected(), false);
|
|
|
|
NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bt_bdaddr_t deviceBdAddress;
|
|
|
|
StringToBdAddressType(mDeviceAddress, &deviceBdAddress);
|
|
|
|
NS_ENSURE_TRUE(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->disconnect_audio(&deviceBdAddress), false);
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
return true;
|
2013-05-10 11:01:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::IsScoConnected()
|
2013-05-10 11:01:10 +00:00
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
return (mAudioState == BTHF_AUDIO_STATE_CONNECTED);
|
2013-05-10 11:01:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 00:54:22 +00:00
|
|
|
bool
|
|
|
|
BluetoothHfpManager::IsConnected()
|
|
|
|
{
|
2013-11-18 07:41:16 +00:00
|
|
|
return (mConnectionState == BTHF_CONNECTION_STATE_SLC_CONNECTED ||
|
|
|
|
mConnectionState == BTHF_CONNECTION_STATE_CONNECTED);
|
2013-04-05 00:54:22 +00:00
|
|
|
}
|
2013-04-26 10:48:21 +00:00
|
|
|
|
|
|
|
void
|
2013-11-18 07:41:16 +00:00
|
|
|
BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
|
|
|
BluetoothProfileController* aController)
|
2013-05-10 11:01:10 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-11-18 07:41:16 +00:00
|
|
|
MOZ_ASSERT(aController && !mController);
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-07-19 02:27:07 +00:00
|
|
|
if (sInShutdown) {
|
2013-11-18 07:41:16 +00:00
|
|
|
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
|
|
|
return;
|
2013-05-10 11:01:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bt_bdaddr_t deviceBdAddress;
|
|
|
|
StringToBdAddressType(aDeviceAddress, &deviceBdAddress);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->connect(&deviceBdAddress));
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
mDeviceAddress = aDeviceAddress;
|
|
|
|
mController = aController;
|
2013-05-10 11:01:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
|
2013-05-10 11:01:10 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
bt_bdaddr_t deviceBdAddress;
|
|
|
|
StringToBdAddressType(mDeviceAddress, &deviceBdAddress);
|
|
|
|
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
|
|
|
|
sBluetoothHfpInterface->disconnect(&deviceBdAddress));
|
2013-05-10 11:01:10 +00:00
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
MOZ_ASSERT(!mController);
|
|
|
|
mController = aController;
|
2013-05-10 11:01:10 +00:00
|
|
|
}
|
2013-06-08 15:26:01 +00:00
|
|
|
|
2013-09-06 11:20:43 +00:00
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On the one hand, notify the controller that we've done for outbound
|
|
|
|
* connections. On the other hand, we do nothing for inbound connections.
|
|
|
|
*/
|
|
|
|
NS_ENSURE_TRUE_VOID(mController);
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
mController->OnConnect(aErrorStr);
|
|
|
|
mController = nullptr;
|
2013-09-06 11:20:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On the one hand, notify the controller that we've done for outbound
|
|
|
|
* connections. On the other hand, we do nothing for inbound connections.
|
|
|
|
*/
|
|
|
|
NS_ENSURE_TRUE_VOID(mController);
|
|
|
|
|
2013-11-18 07:41:16 +00:00
|
|
|
mController->OnDisconnect(aErrorStr);
|
|
|
|
mController = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
|
|
|
|
{
|
|
|
|
// Bluedroid handles this part
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
|
|
|
|
const nsAString& aServiceUuid,
|
|
|
|
int aChannel)
|
|
|
|
{
|
|
|
|
// Bluedroid handles this part
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
|
|
|
|
{
|
|
|
|
aDeviceAddress = mDeviceAddress;
|
2013-09-06 11:20:43 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 01:19:31 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(BluetoothHfpManager, nsIObserver)
|