зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1056539: Cleanup Bluetooth Handsfree manager (under bluetooth2/), r=btian
This patch removes the unusued callback code from Bluetooth's Handsfree manager.
This commit is contained in:
Родитель
a3c3f0346f
Коммит
c6d11f4e48
|
@ -37,15 +37,6 @@
|
|||
#define BT_HF_DISPATCH_MAIN(args...) \
|
||||
NS_DispatchToMainThread(new MainThreadTask(args))
|
||||
|
||||
/**
|
||||
* Process bluedroid callbacks with corresponding handlers.
|
||||
*/
|
||||
#define BT_HF_PROCESS_CB(func, args...) \
|
||||
do { \
|
||||
NS_ENSURE_TRUE_VOID(sBluetoothHfpManager); \
|
||||
sBluetoothHfpManager->func(args); \
|
||||
} while(0)
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
@ -76,122 +67,6 @@ enum MainThreadTaskCmd {
|
|||
POST_TASK_CLOSE_SCO
|
||||
};
|
||||
|
||||
static void
|
||||
ConnectionStateCallback(bthf_connection_state_t state, bt_bdaddr_t* bd_addr)
|
||||
{
|
||||
BT_HF_PROCESS_CB(ProcessConnectionState, state, bd_addr);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
UnknownAtCallback(char *at_string)
|
||||
{
|
||||
BT_HF_PROCESS_CB(ProcessUnknownAt, at_string);
|
||||
}
|
||||
|
||||
static void
|
||||
KeyPressedCallback()
|
||||
{
|
||||
BT_HF_PROCESS_CB(ProcessKeyPressed);
|
||||
}
|
||||
|
||||
static bthf_callbacks_t sBluetoothHfpCallbacks = {
|
||||
sizeof(sBluetoothHfpCallbacks),
|
||||
ConnectionStateCallback,
|
||||
AudioStateCallback,
|
||||
VoiceRecognitionCallback,
|
||||
AnswerCallCallback,
|
||||
HangupCallCallback,
|
||||
VolumeControlCallback,
|
||||
DialCallCallback,
|
||||
DtmfCmdCallback,
|
||||
NoiceReductionCallback,
|
||||
AtChldCallback,
|
||||
AtCnumCallback,
|
||||
AtCindCallback,
|
||||
AtCopsCallback,
|
||||
AtClccCallback,
|
||||
UnknownAtCallback,
|
||||
KeyPressedCallback
|
||||
};
|
||||
|
||||
static bool
|
||||
IsValidDtmf(const char aChar) {
|
||||
// Valid DTMF: [*#0-9ABCD]
|
||||
|
@ -665,277 +540,6 @@ BluetoothHfpManager::Notify(const hal::BatteryInformation& aBatteryInfo)
|
|||
UpdateDeviceCIND();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessConnectionState(bthf_connection_state_t aState,
|
||||
bt_bdaddr_t* aBdAddress)
|
||||
{
|
||||
BT_LOGR("state %d", aState);
|
||||
|
||||
mPrevConnectionState = mConnectionState;
|
||||
mConnectionState = aState;
|
||||
|
||||
if (aState == BTHF_CONNECTION_STATE_SLC_CONNECTED) {
|
||||
BdAddressTypeToString(aBdAddress, mDeviceAddress);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessAudioState(bthf_audio_state_t aState,
|
||||
bt_bdaddr_t* aBdAddress)
|
||||
{
|
||||
BT_LOGR("state %d", aState);
|
||||
|
||||
mAudioState = aState;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessAnswerCall()
|
||||
{
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
||||
NS_LITERAL_STRING("ATA"));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessHangupCall()
|
||||
{
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
||||
NS_LITERAL_STRING("CHUP"));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessVolumeControl(bthf_volume_type_t aType,
|
||||
int aVolume)
|
||||
{
|
||||
NS_ENSURE_TRUE_VOID(aVolume >= 0 && aVolume <= 15);
|
||||
|
||||
if (aType == BTHF_VOLUME_TYPE_MIC) {
|
||||
mCurrentVgm = aVolume;
|
||||
} else if (aType == BTHF_VOLUME_TYPE_SPK) {
|
||||
mReceiveVgsFlag = true;
|
||||
|
||||
if (aVolume == mCurrentVgs) {
|
||||
// Keep current volume
|
||||
return;
|
||||
}
|
||||
|
||||
nsString data;
|
||||
data.AppendInt(aVolume);
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_SCO_VOLUME_CHANGED, data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessDtmfCmd(char aDtmf)
|
||||
{
|
||||
NS_ENSURE_TRUE_VOID(IsValidDtmf(aDtmf));
|
||||
|
||||
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));
|
||||
|
||||
SendResponse(HFP_AT_RESPONSE_OK);
|
||||
}
|
||||
|
||||
void BluetoothHfpManager::ProcessDialCall(char *aNumber)
|
||||
{
|
||||
nsAutoCString message(aNumber);
|
||||
|
||||
// There are three cases based on aNumber,
|
||||
// 1) Empty value: Redial, BLDN
|
||||
// 2) >xxx: Memory dial, ATD>xxx
|
||||
// 3) xxx: Normal dial, ATDxxx
|
||||
// We need to respond OK/Error for dial requests for every case listed above,
|
||||
// 1) and 2): Respond in either RespondToBLDNTask or
|
||||
// HandleCallStateChanged()
|
||||
// 3): Respond here
|
||||
if (message.IsEmpty()) {
|
||||
mDialingRequestProcessed = false;
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
||||
NS_LITERAL_STRING("BLDN"));
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN);
|
||||
} else if (message[0] == '>') {
|
||||
mDialingRequestProcessed = false;
|
||||
nsAutoCString newMsg("ATD");
|
||||
newMsg += StringHead(message, message.Length() - 1);
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
||||
NS_ConvertUTF8toUTF16(newMsg));
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN);
|
||||
} else {
|
||||
nsAutoCString newMsg("ATD");
|
||||
newMsg += StringHead(message, message.Length() - 1);
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
||||
NS_ConvertUTF8toUTF16(newMsg));
|
||||
SendResponse(HFP_AT_RESPONSE_OK);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessAtCnum()
|
||||
{
|
||||
if (!mMsisdn.IsEmpty()) {
|
||||
nsAutoCString message("+CNUM: ,\"");
|
||||
message.Append(NS_ConvertUTF16toUTF8(mMsisdn).get());
|
||||
message.AppendLiteral("\",");
|
||||
message.AppendInt(BTHF_CALL_ADDRTYPE_UNKNOWN);
|
||||
message.AppendLiteral(",,4");
|
||||
|
||||
SendLine(message.get());
|
||||
}
|
||||
|
||||
SendResponse(HFP_AT_RESPONSE_OK);
|
||||
}
|
||||
|
||||
class CindResponseResultHandler MOZ_FINAL
|
||||
: public BluetoothHandsfreeResultHandler
|
||||
{
|
||||
public:
|
||||
void OnError(BluetoothStatus aStatus) MOZ_OVERRIDE
|
||||
{
|
||||
BT_WARNING("BluetoothHandsfreeInterface::CindResponse failed: %d",
|
||||
(int)aStatus);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessAtCind()
|
||||
{
|
||||
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
||||
|
||||
int numActive = GetNumberOfCalls(nsITelephonyService::CALL_STATE_CONNECTED);
|
||||
int numHeld = GetNumberOfCalls(nsITelephonyService::CALL_STATE_HELD);
|
||||
BluetoothHandsfreeCallState callState =
|
||||
ConvertToBluetoothHandsfreeCallState(GetCallSetupState());
|
||||
|
||||
sBluetoothHfpInterface->CindResponse(mService, numActive, numHeld,
|
||||
callState, mSignal, mRoam, mBattChg,
|
||||
new CindResponseResultHandler());
|
||||
}
|
||||
|
||||
class CopsResponseResultHandler MOZ_FINAL
|
||||
: public BluetoothHandsfreeResultHandler
|
||||
{
|
||||
public:
|
||||
void OnError(BluetoothStatus aStatus) MOZ_OVERRIDE
|
||||
{
|
||||
BT_WARNING("BluetoothHandsfreeInterface::CopsResponse failed: %d",
|
||||
(int)aStatus);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessAtCops()
|
||||
{
|
||||
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
||||
|
||||
sBluetoothHfpInterface->CopsResponse(
|
||||
NS_ConvertUTF16toUTF8(mOperatorName).get(),
|
||||
new CopsResponseResultHandler());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
SendResponse(HFP_AT_RESPONSE_OK);
|
||||
}
|
||||
|
||||
class AtResponseResultHandler MOZ_FINAL
|
||||
: public BluetoothHandsfreeResultHandler
|
||||
{
|
||||
public:
|
||||
void OnError(BluetoothStatus aStatus) MOZ_OVERRIDE
|
||||
{
|
||||
BT_WARNING("BluetoothHandsfreeInterface::AtResponse failed: %d",
|
||||
(int)aStatus);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessUnknownAt(char *aAtString)
|
||||
{
|
||||
BT_LOGR("[%s]", aAtString);
|
||||
|
||||
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
||||
|
||||
sBluetoothHfpInterface->AtResponse(HFP_AT_RESPONSE_ERROR, 0,
|
||||
new AtResponseResultHandler());
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::ProcessKeyPressed()
|
||||
{
|
||||
bool hasActiveCall =
|
||||
(FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED) > 0);
|
||||
|
||||
// Refer to AOSP HeadsetStateMachine.processKeyPressed
|
||||
if (FindFirstCall(nsITelephonyService::CALL_STATE_INCOMING)
|
||||
&& !hasActiveCall) {
|
||||
/**
|
||||
* Bluetooth HSP spec 4.2.2
|
||||
* There is an incoming call, notify Dialer to pick up the phone call
|
||||
* and SCO will be established after we get the CallStateChanged event
|
||||
* indicating the call is answered successfully.
|
||||
*/
|
||||
ProcessAnswerCall();
|
||||
} else if (hasActiveCall) {
|
||||
if (!IsScoConnected()) {
|
||||
/**
|
||||
* Bluetooth HSP spec 4.3
|
||||
* If there's no SCO, set up a SCO link.
|
||||
*/
|
||||
ConnectSco();
|
||||
} else {
|
||||
/**
|
||||
* Bluetooth HSP spec 4.5
|
||||
* There are two ways to release SCO: sending CHUP to dialer or closing
|
||||
* SCO socket directly. We notify dialer only if there is at least one
|
||||
* active call.
|
||||
*/
|
||||
ProcessHangupCall();
|
||||
}
|
||||
} else {
|
||||
// BLDN
|
||||
mDialingRequestProcessed = false;
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
|
||||
NS_LITERAL_STRING("BLDN"));
|
||||
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType)
|
||||
{
|
||||
|
@ -1209,6 +813,17 @@ BluetoothHfpManager::SendLine(const char* aMessage)
|
|||
aMessage, new FormattedAtResponseResultHandler());
|
||||
}
|
||||
|
||||
class AtResponseResultHandler MOZ_FINAL
|
||||
: public BluetoothHandsfreeResultHandler
|
||||
{
|
||||
public:
|
||||
void OnError(BluetoothStatus aStatus) MOZ_OVERRIDE
|
||||
{
|
||||
BT_WARNING("BluetoothHandsfreeInterface::AtResponse failed: %d",
|
||||
(int)aStatus);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothHfpManager::SendResponse(BluetoothHandsfreeAtResponse aResponseCode)
|
||||
{
|
||||
|
@ -1892,6 +1507,17 @@ BluetoothHfpManager::CnumNotification()
|
|||
SendResponse(HFP_AT_RESPONSE_OK);
|
||||
}
|
||||
|
||||
class CindResponseResultHandler MOZ_FINAL
|
||||
: public BluetoothHandsfreeResultHandler
|
||||
{
|
||||
public:
|
||||
void OnError(BluetoothStatus aStatus) MOZ_OVERRIDE
|
||||
{
|
||||
BT_WARNING("BluetoothHandsfreeInterface::CindResponse failed: %d",
|
||||
(int)aStatus);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothHfpManager::CindNotification()
|
||||
{
|
||||
|
@ -1909,6 +1535,17 @@ BluetoothHfpManager::CindNotification()
|
|||
new CindResponseResultHandler());
|
||||
}
|
||||
|
||||
class CopsResponseResultHandler MOZ_FINAL
|
||||
: public BluetoothHandsfreeResultHandler
|
||||
{
|
||||
public:
|
||||
void OnError(BluetoothStatus aStatus) MOZ_OVERRIDE
|
||||
{
|
||||
BT_WARNING("BluetoothHandsfreeInterface::CopsResponse failed: %d",
|
||||
(int)aStatus);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
BluetoothHfpManager::CopsNotification()
|
||||
{
|
||||
|
@ -1947,14 +1584,9 @@ BluetoothHfpManager::UnknownAtNotification(const nsACString& aAtString)
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCString atString(aAtString);
|
||||
BT_LOGR("[%s]", nsCString(aAtString).get());
|
||||
|
||||
BT_LOGR("[%s]", atString.get());
|
||||
|
||||
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
|
||||
|
||||
sBluetoothHfpInterface->AtResponse(HFP_AT_RESPONSE_ERROR, 0,
|
||||
new AtResponseResultHandler());
|
||||
SendResponse(HFP_AT_RESPONSE_ERROR);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -103,22 +103,6 @@ public:
|
|||
void HandleIccInfoChanged(uint32_t aClientId);
|
||||
void HandleVoiceConnectionChanged(uint32_t aClientId);
|
||||
|
||||
// Bluedroid hfp callback handlers
|
||||
void ProcessConnectionState(bthf_connection_state_t aState, bt_bdaddr_t* aBdAddress);
|
||||
void ProcessAudioState(bthf_audio_state_t aState, bt_bdaddr_t* aBdAddress);
|
||||
void ProcessAnswerCall();
|
||||
void ProcessHangupCall();
|
||||
void ProcessVolumeControl(bthf_volume_type_t aType, int aVolume);
|
||||
void ProcessDialCall(char *aNumber);
|
||||
void ProcessDtmfCmd(char aDtmf);
|
||||
void ProcessAtChld(bthf_chld_type_t aChld);
|
||||
void ProcessAtCnum();
|
||||
void ProcessAtCind();
|
||||
void ProcessAtCops();
|
||||
void ProcessAtClcc();
|
||||
void ProcessUnknownAt(char *aAtString);
|
||||
void ProcessKeyPressed();
|
||||
|
||||
// CDMA-specific functions
|
||||
void UpdateSecondNumber(const nsAString& aNumber);
|
||||
void AnswerWaitingCall();
|
||||
|
|
Загрузка…
Ссылка в новой задаче