Bug 1050126: Convert Bluetooth Handsfree data types in |BluetoothHandsfreeInterface| (under bluetooth2/), r=btian

With this patch |BluetoothHandsfreeInterface| is responsible for converting all
Bluetooth data types to Bluedroid types. All callers have been adapted.
This commit is contained in:
Thomas Zimmermann 2014-08-15 13:41:19 +02:00
Родитель 14cb6b6d80
Коммит f1e6d82238
5 изменённых файлов: 390 добавлений и 111 удалений

Просмотреть файл

@ -187,6 +187,57 @@ enum BluetoothSocketType {
EL2CAP = 4
};
enum BluetoothHandsfreeAtResponse {
HFP_AT_RESPONSE_ERROR,
HFP_AT_RESPONSE_OK
};
enum BluetoothHandsfreeCallAddressType {
HFP_CALL_ADDRESS_TYPE_UNKNOWN,
HFP_CALL_ADDRESS_TYPE_INTERNATIONAL
};
enum BluetoothHandsfreeCallDirection {
HFP_CALL_DIRECTION_OUTGOING,
HFP_CALL_DIRECTION_INCOMING
};
enum BluetoothHandsfreeCallMode {
HFP_CALL_MODE_VOICE,
HFP_CALL_MODE_DATA,
HFP_CALL_MODE_FAX
};
enum BluetoothHandsfreeCallMptyType {
HFP_CALL_MPTY_TYPE_SINGLE,
HFP_CALL_MPTY_TYPE_MULTI
};
enum BluetoothHandsfreeCallState {
HFP_CALL_STATE_ACTIVE,
HFP_CALL_STATE_HELD,
HFP_CALL_STATE_DIALING,
HFP_CALL_STATE_ALERTING,
HFP_CALL_STATE_INCOMING,
HFP_CALL_STATE_WAITING,
HFP_CALL_STATE_IDLE
};
enum BluetoothHandsfreeNetworkState {
HFP_NETWORK_STATE_NOT_AVAILABLE,
HFP_NETWORK_STATE_AVAILABLE
};
enum BluetoothHandsfreeServiceType {
HFP_SERVICE_TYPE_HOME,
HFP_SERVICE_TYPE_ROAMING
};
enum BluetoothHandsfreeVolumeType {
HFP_VOLUME_TYPE_SPEAKER,
HFP_VOLUME_TYPE_MICROPHONE
};
class BluetoothSignal;
typedef mozilla::Observer<BluetoothSignal> BluetoothSignalObserver;

Просмотреть файл

@ -233,6 +233,139 @@ Convert(BluetoothSocketType aIn, btsock_type_t& aOut)
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeAtResponse aIn, bthf_at_response_t& aOut)
{
static const bthf_at_response_t sAtResponse[] = {
CONVERT(HFP_AT_RESPONSE_ERROR, BTHF_AT_RESPONSE_ERROR),
CONVERT(HFP_AT_RESPONSE_OK, BTHF_AT_RESPONSE_OK)
};
if (aIn >= MOZ_ARRAY_LENGTH(sAtResponse)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sAtResponse[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeCallAddressType aIn, bthf_call_addrtype_t& aOut)
{
static const bthf_call_addrtype_t sCallAddressType[] = {
CONVERT(HFP_CALL_ADDRESS_TYPE_UNKNOWN, BTHF_CALL_ADDRTYPE_UNKNOWN),
CONVERT(HFP_CALL_ADDRESS_TYPE_INTERNATIONAL,
BTHF_CALL_ADDRTYPE_INTERNATIONAL)
};
if (aIn >= MOZ_ARRAY_LENGTH(sCallAddressType)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sCallAddressType[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeCallDirection aIn, bthf_call_direction_t& aOut)
{
static const bthf_call_direction_t sCallDirection[] = {
CONVERT(HFP_CALL_DIRECTION_OUTGOING, BTHF_CALL_DIRECTION_OUTGOING),
CONVERT(HFP_CALL_DIRECTION_INCOMING, BTHF_CALL_DIRECTION_INCOMING)
};
if (aIn >= MOZ_ARRAY_LENGTH(sCallDirection)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sCallDirection[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeCallMode aIn, bthf_call_mode_t& aOut)
{
static const bthf_call_mode_t sCallMode[] = {
CONVERT(HFP_CALL_MODE_VOICE, BTHF_CALL_TYPE_VOICE),
CONVERT(HFP_CALL_MODE_DATA, BTHF_CALL_TYPE_DATA),
CONVERT(HFP_CALL_MODE_FAX, BTHF_CALL_TYPE_FAX)
};
if (aIn >= MOZ_ARRAY_LENGTH(sCallMode)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sCallMode[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeCallMptyType aIn, bthf_call_mpty_type_t& aOut)
{
static const bthf_call_mpty_type_t sCallMptyType[] = {
CONVERT(HFP_CALL_MPTY_TYPE_SINGLE, BTHF_CALL_MPTY_TYPE_SINGLE),
CONVERT(HFP_CALL_MPTY_TYPE_MULTI, BTHF_CALL_MPTY_TYPE_MULTI)
};
if (aIn >= MOZ_ARRAY_LENGTH(sCallMptyType)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sCallMptyType[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeCallState aIn, bthf_call_state_t& aOut)
{
static const bthf_call_state_t sCallState[] = {
CONVERT(HFP_CALL_STATE_ACTIVE, BTHF_CALL_STATE_ACTIVE),
CONVERT(HFP_CALL_STATE_HELD, BTHF_CALL_STATE_HELD),
CONVERT(HFP_CALL_STATE_DIALING, BTHF_CALL_STATE_DIALING),
CONVERT(HFP_CALL_STATE_ALERTING, BTHF_CALL_STATE_ALERTING),
CONVERT(HFP_CALL_STATE_INCOMING, BTHF_CALL_STATE_INCOMING),
CONVERT(HFP_CALL_STATE_WAITING, BTHF_CALL_STATE_WAITING),
CONVERT(HFP_CALL_STATE_IDLE, BTHF_CALL_STATE_IDLE)
};
if (aIn >= MOZ_ARRAY_LENGTH(sCallState)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sCallState[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeNetworkState aIn, bthf_network_state_t& aOut)
{
static const bthf_network_state_t sNetworkState[] = {
CONVERT(HFP_NETWORK_STATE_NOT_AVAILABLE, BTHF_NETWORK_STATE_NOT_AVAILABLE),
CONVERT(HFP_NETWORK_STATE_AVAILABLE, BTHF_NETWORK_STATE_AVAILABLE)
};
if (aIn >= MOZ_ARRAY_LENGTH(sNetworkState)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sNetworkState[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeServiceType aIn, bthf_service_type_t& aOut)
{
static const bthf_service_type_t sServiceType[] = {
CONVERT(HFP_SERVICE_TYPE_HOME, BTHF_SERVICE_TYPE_HOME),
CONVERT(HFP_SERVICE_TYPE_ROAMING, BTHF_SERVICE_TYPE_ROAMING)
};
if (aIn >= MOZ_ARRAY_LENGTH(sServiceType)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sServiceType[aIn];
return NS_OK;
}
static nsresult
Convert(BluetoothHandsfreeVolumeType aIn, bthf_volume_type_t& aOut)
{
static const bthf_volume_type_t sVolumeType[] = {
CONVERT(HFP_VOLUME_TYPE_SPEAKER, BTHF_VOLUME_TYPE_SPK),
CONVERT(HFP_VOLUME_TYPE_MICROPHONE, BTHF_VOLUME_TYPE_MIC)
};
if (aIn >= MOZ_ARRAY_LENGTH(sVolumeType)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sVolumeType[aIn];
return NS_OK;
}
//
// Result handling
//
@ -885,10 +1018,17 @@ BluetoothHandsfreeInterface::Cleanup(BluetoothHandsfreeResultHandler* aRes)
/* Connect / Disconnect */
void
BluetoothHandsfreeInterface::Connect(bt_bdaddr_t* aBdAddr,
BluetoothHandsfreeInterface::Connect(const nsAString& aBdAddr,
BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->connect(aBdAddr);
bt_status_t status;
bt_bdaddr_t bdAddr;
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
status = mInterface->connect(&bdAddr);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
@ -897,10 +1037,17 @@ BluetoothHandsfreeInterface::Connect(bt_bdaddr_t* aBdAddr,
}
void
BluetoothHandsfreeInterface::Disconnect(bt_bdaddr_t* aBdAddr,
BluetoothHandsfreeResultHandler* aRes)
BluetoothHandsfreeInterface::Disconnect(
const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->disconnect(aBdAddr);
bt_status_t status;
bt_bdaddr_t bdAddr;
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
status = mInterface->disconnect(&bdAddr);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
@ -910,9 +1057,16 @@ BluetoothHandsfreeInterface::Disconnect(bt_bdaddr_t* aBdAddr,
void
BluetoothHandsfreeInterface::ConnectAudio(
bt_bdaddr_t* aBdAddr, BluetoothHandsfreeResultHandler* aRes)
const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->connect_audio(aBdAddr);
bt_status_t status;
bt_bdaddr_t bdAddr;
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
status = mInterface->connect_audio(&bdAddr);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
@ -922,9 +1076,16 @@ BluetoothHandsfreeInterface::ConnectAudio(
void
BluetoothHandsfreeInterface::DisconnectAudio(
bt_bdaddr_t* aBdAddr, BluetoothHandsfreeResultHandler* aRes)
const nsAString& aBdAddr, BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->disconnect_audio(aBdAddr);
bt_status_t status;
bt_bdaddr_t bdAddr;
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr))) {
status = mInterface->disconnect_audio(&bdAddr);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
@ -962,9 +1123,17 @@ BluetoothHandsfreeInterface::StopVoiceRecognition(
void
BluetoothHandsfreeInterface::VolumeControl(
bthf_volume_type_t aType, int aVolume, BluetoothHandsfreeResultHandler* aRes)
BluetoothHandsfreeVolumeType aType, int aVolume,
BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->volume_control(aType, aVolume);
bt_status_t status;
bthf_volume_type_t type = BTHF_VOLUME_TYPE_SPK;
if (NS_SUCCEEDED(Convert(aType, type))) {
status = mInterface->volume_control(type, aVolume);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
@ -976,11 +1145,21 @@ BluetoothHandsfreeInterface::VolumeControl(
void
BluetoothHandsfreeInterface::DeviceStatusNotification(
bthf_network_state_t aNtkState, bthf_service_type_t aSvcType, int aSignal,
BluetoothHandsfreeNetworkState aNtkState,
BluetoothHandsfreeServiceType aSvcType, int aSignal,
int aBattChg, BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->device_status_notification(
aNtkState, aSvcType, aSignal, aBattChg);
bt_status_t status;
bthf_network_state_t ntkState = BTHF_NETWORK_STATE_NOT_AVAILABLE;
bthf_service_type_t svcType = BTHF_SERVICE_TYPE_HOME;
if (NS_SUCCEEDED(Convert(aNtkState, ntkState)) &&
NS_SUCCEEDED(Convert(aSvcType, svcType))) {
status = mInterface->device_status_notification(ntkState, svcType,
aSignal, aBattChg);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
@ -1005,12 +1184,22 @@ BluetoothHandsfreeInterface::CopsResponse(
void
BluetoothHandsfreeInterface::CindResponse(
int aSvc, int aNumActive, int aNumHeld, bthf_call_state_t aCallSetupState,
int aSignal, int aRoam, int aBattChg, BluetoothHandsfreeResultHandler* aRes)
int aSvc, int aNumActive, int aNumHeld,
BluetoothHandsfreeCallState aCallSetupState,
int aSignal, int aRoam, int aBattChg,
BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->cind_response(aSvc, aNumActive, aNumHeld,
aCallSetupState, aSignal,
aRoam, aBattChg);
bt_status_t status;
bthf_call_state_t callSetupState = BTHF_CALL_STATE_ACTIVE;
if (NS_SUCCEEDED(Convert(aCallSetupState, callSetupState))) {
status = mInterface->cind_response(aSvc, aNumActive, aNumHeld,
callSetupState, aSignal,
aRoam, aBattChg);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::CindResponse, status);
@ -1030,11 +1219,18 @@ BluetoothHandsfreeInterface::FormattedAtResponse(
}
void
BluetoothHandsfreeInterface::AtResponse(bthf_at_response_t aResponseCode,
int aErrorCode,
BluetoothHandsfreeResultHandler* aRes)
BluetoothHandsfreeInterface::AtResponse(
BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->at_response(aResponseCode, aErrorCode);
bt_status_t status;
bthf_at_response_t responseCode = BTHF_AT_RESPONSE_ERROR;
if (NS_SUCCEEDED(Convert(aResponseCode, responseCode))) {
status = mInterface->at_response(responseCode, aErrorCode);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
@ -1044,12 +1240,34 @@ BluetoothHandsfreeInterface::AtResponse(bthf_at_response_t aResponseCode,
void
BluetoothHandsfreeInterface::ClccResponse(
int aIndex, bthf_call_direction_t aDir, bthf_call_state_t aState,
bthf_call_mode_t aMode, bthf_call_mpty_type_t aMpty, const char* aNumber,
bthf_call_addrtype_t aType, BluetoothHandsfreeResultHandler* aRes)
int aIndex,
BluetoothHandsfreeCallDirection aDir,
BluetoothHandsfreeCallState aState,
BluetoothHandsfreeCallMode aMode,
BluetoothHandsfreeCallMptyType aMpty,
const nsAString& aNumber,
BluetoothHandsfreeCallAddressType aType,
BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->clcc_response(aIndex, aDir, aState, aMode,
aMpty, aNumber, aType);
bt_status_t status;
bthf_call_direction_t dir = BTHF_CALL_DIRECTION_OUTGOING;
bthf_call_state_t state = BTHF_CALL_STATE_ACTIVE;
bthf_call_mode_t mode = BTHF_CALL_TYPE_VOICE;
bthf_call_mpty_type_t mpty = BTHF_CALL_MPTY_TYPE_SINGLE;
bthf_call_addrtype_t type = BTHF_CALL_ADDRTYPE_UNKNOWN;
if (NS_SUCCEEDED(Convert(aDir, dir)) &&
NS_SUCCEEDED(Convert(aState, state)) &&
NS_SUCCEEDED(Convert(aMode, mode)) &&
NS_SUCCEEDED(Convert(aMpty, mpty)) &&
NS_SUCCEEDED(Convert(aType, type))) {
status = mInterface->clcc_response(aIndex, dir, state, mode, mpty,
NS_ConvertUTF16toUTF8(aNumber).get(),
type);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::ClccResponse, status);
@ -1060,12 +1278,23 @@ BluetoothHandsfreeInterface::ClccResponse(
void
BluetoothHandsfreeInterface::PhoneStateChange(int aNumActive, int aNumHeld,
bthf_call_state_t aCallSetupState, const char* aNumber,
bthf_call_addrtype_t aType, BluetoothHandsfreeResultHandler* aRes)
BluetoothHandsfreeCallState aCallSetupState, const nsAString& aNumber,
BluetoothHandsfreeCallAddressType aType,
BluetoothHandsfreeResultHandler* aRes)
{
bt_status_t status = mInterface->phone_state_change(aNumActive, aNumHeld,
aCallSetupState,
aNumber, aType);
bt_status_t status;
bthf_call_state_t callSetupState = BTHF_CALL_STATE_ACTIVE;
bthf_call_addrtype_t type = BTHF_CALL_ADDRTYPE_UNKNOWN;
if (NS_SUCCEEDED(Convert(aCallSetupState, callSetupState)) &&
NS_SUCCEEDED(Convert(aType, type))) {
status = mInterface->phone_state_change(
aNumActive, aNumHeld, callSetupState,
NS_ConvertUTF16toUTF8(aNumber).get(), type);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::PhoneStateChange, status);

Просмотреть файл

@ -123,13 +123,13 @@ public:
/* Connect / Disconnect */
void Connect(bt_bdaddr_t* aBdAddr,
void Connect(const nsAString& aBdAddr,
BluetoothHandsfreeResultHandler* aRes);
void Disconnect(bt_bdaddr_t* aBdAddr,
void Disconnect(const nsAString& aBdAddr,
BluetoothHandsfreeResultHandler* aRes);
void ConnectAudio(bt_bdaddr_t* aBdAddr,
void ConnectAudio(const nsAString& aBdAddr,
BluetoothHandsfreeResultHandler* aRes);
void DisconnectAudio(bt_bdaddr_t* aBdAddr,
void DisconnectAudio(const nsAString& aBdAddr,
BluetoothHandsfreeResultHandler* aRes);
/* Voice Recognition */
@ -139,13 +139,13 @@ public:
/* Volume */
void VolumeControl(bthf_volume_type_t aType, int aVolume,
void VolumeControl(BluetoothHandsfreeVolumeType aType, int aVolume,
BluetoothHandsfreeResultHandler* aRes);
/* Device status */
void DeviceStatusNotification(bthf_network_state_t aNtkState,
bthf_service_type_t aSvcType,
void DeviceStatusNotification(BluetoothHandsfreeNetworkState aNtkState,
BluetoothHandsfreeServiceType aSvcType,
int aSignal, int aBattChg,
BluetoothHandsfreeResultHandler* aRes);
@ -154,24 +154,27 @@ public:
void CopsResponse(const char* aCops,
BluetoothHandsfreeResultHandler* aRes);
void CindResponse(int aSvc, int aNumActive, int aNumHeld,
bthf_call_state_t aCallSetupState, int aSignal,
BluetoothHandsfreeCallState aCallSetupState, int aSignal,
int aRoam, int aBattChg,
BluetoothHandsfreeResultHandler* aRes);
void FormattedAtResponse(const char* aRsp,
BluetoothHandsfreeResultHandler* aRes);
void AtResponse(bthf_at_response_t aResponseCode, int aErrorCode,
void AtResponse(BluetoothHandsfreeAtResponse aResponseCode, int aErrorCode,
BluetoothHandsfreeResultHandler* aRes);
void ClccResponse(int aIndex, bthf_call_direction_t aDir,
bthf_call_state_t aState, bthf_call_mode_t aMode,
bthf_call_mpty_type_t aMpty, const char* aNumber,
bthf_call_addrtype_t aType,
void ClccResponse(int aIndex, BluetoothHandsfreeCallDirection aDir,
BluetoothHandsfreeCallState aState,
BluetoothHandsfreeCallMode aMode,
BluetoothHandsfreeCallMptyType aMpty,
const nsAString& aNumber,
BluetoothHandsfreeCallAddressType aType,
BluetoothHandsfreeResultHandler* aRes);
/* Phone State */
void PhoneStateChange(int aNumActive, int aNumHeld,
bthf_call_state_t aCallSetupState,
const char* aNumber, bthf_call_addrtype_t aType,
BluetoothHandsfreeCallState aCallSetupState,
const nsAString& aNumber,
BluetoothHandsfreeCallAddressType aType,
BluetoothHandsfreeResultHandler* aRes);
protected:

Просмотреть файл

@ -251,7 +251,7 @@ private:
if (!sBluetoothHfpManager->mDialingRequestProcessed) {
sBluetoothHfpManager->mDialingRequestProcessed = true;
sBluetoothHfpManager->SendResponse(BTHF_AT_RESPONSE_ERROR);
sBluetoothHfpManager->SendResponse(HFP_AT_RESPONSE_ERROR);
}
}
};
@ -325,11 +325,13 @@ void
Call::Set(const nsAString& aNumber, const bool aIsOutgoing)
{
mNumber = aNumber;
mDirection = (aIsOutgoing) ? BTHF_CALL_DIRECTION_OUTGOING :
BTHF_CALL_DIRECTION_INCOMING;
mDirection = (aIsOutgoing) ? HFP_CALL_DIRECTION_OUTGOING :
HFP_CALL_DIRECTION_INCOMING;
// Same logic as implementation in ril_worker.js
if (aNumber.Length() && aNumber[0] == '+') {
mType = BTHF_CALL_ADDRTYPE_INTERNATIONAL;
mType = HFP_CALL_ADDRESS_TYPE_INTERNATIONAL;
} else {
mType = HFP_CALL_ADDRESS_TYPE_UNKNOWN;
}
}
@ -337,9 +339,9 @@ void
Call::Reset()
{
mState = nsITelephonyService::CALL_STATE_DISCONNECTED;
mDirection = BTHF_CALL_DIRECTION_OUTGOING;
mDirection = HFP_CALL_DIRECTION_OUTGOING;
mNumber.Truncate();
mType = BTHF_CALL_ADDRTYPE_UNKNOWN;
mType = HFP_CALL_ADDRESS_TYPE_UNKNOWN;
}
bool
@ -383,8 +385,8 @@ BluetoothHfpManager::Reset()
// Phone & Device CIND
ResetCallArray();
mBattChg = 5;
mService = 0;
mRoam = 0;
mService = HFP_NETWORK_STATE_NOT_AVAILABLE;
mRoam = HFP_SERVICE_TYPE_HOME;
mSignal = 0;
mController = nullptr;
@ -751,7 +753,7 @@ BluetoothHfpManager::ProcessAtChld(bthf_chld_type_t aChld)
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_ConvertUTF8toUTF16(message));
SendResponse(BTHF_AT_RESPONSE_OK);
SendResponse(HFP_AT_RESPONSE_OK);
}
void BluetoothHfpManager::ProcessDialCall(char *aNumber)
@ -783,7 +785,7 @@ void BluetoothHfpManager::ProcessDialCall(char *aNumber)
newMsg += StringHead(message, message.Length() - 1);
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_ConvertUTF8toUTF16(newMsg));
SendResponse(BTHF_AT_RESPONSE_OK);
SendResponse(HFP_AT_RESPONSE_OK);
}
}
@ -800,7 +802,7 @@ BluetoothHfpManager::ProcessAtCnum()
SendLine(message.get());
}
SendResponse(BTHF_AT_RESPONSE_OK);
SendResponse(HFP_AT_RESPONSE_OK);
}
class CindResponseResultHandler MOZ_FINAL
@ -821,7 +823,8 @@ BluetoothHfpManager::ProcessAtCind()
int numActive = GetNumberOfCalls(nsITelephonyService::CALL_STATE_CONNECTED);
int numHeld = GetNumberOfCalls(nsITelephonyService::CALL_STATE_HELD);
bthf_call_state_t callState = ConvertToBthfCallState(GetCallSetupState());
BluetoothHandsfreeCallState callState =
ConvertToBluetoothHandsfreeCallState(GetCallSetupState());
sBluetoothHfpInterface->CindResponse(mService, numActive, numHeld,
callState, mSignal, mRoam, mBattChg,
@ -865,7 +868,7 @@ BluetoothHfpManager::ProcessAtClcc()
SendCLCC(mCdmaSecondCall, 2);
}
SendResponse(BTHF_AT_RESPONSE_OK);
SendResponse(HFP_AT_RESPONSE_OK);
}
class AtResponseResultHandler MOZ_FINAL
@ -886,7 +889,7 @@ BluetoothHfpManager::ProcessUnknownAt(char *aAtString)
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
sBluetoothHfpInterface->AtResponse(BTHF_AT_RESPONSE_ERROR, 0,
sBluetoothHfpInterface->AtResponse(HFP_AT_RESPONSE_ERROR, 0,
new AtResponseResultHandler());
}
@ -1053,7 +1056,7 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
// Only send volume back when there's a connected headset
if (IsConnected()) {
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
sBluetoothHfpInterface->VolumeControl(BTHF_VOLUME_TYPE_SPK, mCurrentVgs,
sBluetoothHfpInterface->VolumeControl(HFP_VOLUME_TYPE_SPEAKER, mCurrentVgs,
new VolumeControlResultHandler());
}
}
@ -1076,13 +1079,15 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
// Roam
bool roaming;
voiceInfo->GetRoaming(&roaming);
mRoam = (roaming) ? 1 : 0;
mRoam = (roaming) ? HFP_SERVICE_TYPE_ROAMING : HFP_SERVICE_TYPE_HOME;
// Service
nsString regState;
voiceInfo->GetState(regState);
int service = (regState.EqualsLiteral("registered")) ? 1 : 0;
BluetoothHandsfreeNetworkState service =
(regState.EqualsLiteral("registered")) ? HFP_NETWORK_STATE_AVAILABLE :
HFP_NETWORK_STATE_NOT_AVAILABLE;
if (service != mService) {
// Notify BluetoothRilListener of service change
mListener->ServiceChanged(aClientId, service);
@ -1163,21 +1168,22 @@ BluetoothHfpManager::SendCLCC(Call& aCall, int aIndex)
nsITelephonyService::CALL_STATE_DISCONNECTED);
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
bthf_call_state_t callState = ConvertToBthfCallState(aCall.mState);
BluetoothHandsfreeCallState callState =
ConvertToBluetoothHandsfreeCallState(aCall.mState);
if (mPhoneType == PhoneType::CDMA && aIndex == 1 && aCall.IsActive()) {
callState = (mCdmaSecondCall.IsActive()) ? BTHF_CALL_STATE_HELD :
BTHF_CALL_STATE_ACTIVE;
callState = (mCdmaSecondCall.IsActive()) ? HFP_CALL_STATE_HELD :
HFP_CALL_STATE_ACTIVE;
}
if (callState == BTHF_CALL_STATE_INCOMING &&
if (callState == HFP_CALL_STATE_INCOMING &&
FindFirstCall(nsITelephonyService::CALL_STATE_CONNECTED)) {
callState = BTHF_CALL_STATE_WAITING;
callState = HFP_CALL_STATE_WAITING;
}
sBluetoothHfpInterface->ClccResponse(
aIndex, aCall.mDirection, callState, BTHF_CALL_TYPE_VOICE,
BTHF_CALL_MPTY_TYPE_SINGLE, NS_ConvertUTF16toUTF8(aCall.mNumber).get(),
aIndex, aCall.mDirection, callState, HFP_CALL_MODE_VOICE,
HFP_CALL_MPTY_TYPE_SINGLE, aCall.mNumber,
aCall.mType, new ClccResponseResultHandler());
}
@ -1202,7 +1208,7 @@ BluetoothHfpManager::SendLine(const char* aMessage)
}
void
BluetoothHfpManager::SendResponse(bthf_at_response_t aResponseCode)
BluetoothHfpManager::SendResponse(BluetoothHandsfreeAtResponse aResponseCode)
{
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
@ -1228,18 +1234,17 @@ BluetoothHfpManager::UpdatePhoneCIND(uint32_t aCallIndex)
int numActive = GetNumberOfCalls(nsITelephonyService::CALL_STATE_CONNECTED);
int numHeld = GetNumberOfCalls(nsITelephonyService::CALL_STATE_HELD);
bthf_call_state_t callSetupState =
ConvertToBthfCallState(GetCallSetupState());
nsAutoCString number =
NS_ConvertUTF16toUTF8(mCurrentCallArray[aCallIndex].mNumber);
bthf_call_addrtype_t type = mCurrentCallArray[aCallIndex].mType;
BluetoothHandsfreeCallState callSetupState =
ConvertToBluetoothHandsfreeCallState(GetCallSetupState());
BluetoothHandsfreeCallAddressType type = mCurrentCallArray[aCallIndex].mType;
BT_LOGR("[%d] state %d => BTHF: active[%d] held[%d] setupstate[%d]",
aCallIndex, mCurrentCallArray[aCallIndex].mState,
numActive, numHeld, callSetupState);
sBluetoothHfpInterface->PhoneStateChange(
numActive, numHeld, callSetupState, number.get(), type,
numActive, numHeld, callSetupState,
mCurrentCallArray[aCallIndex].mNumber, type,
new PhoneStateChangeResultHandler());
}
@ -1260,8 +1265,8 @@ BluetoothHfpManager::UpdateDeviceCIND()
{
if (sBluetoothHfpInterface) {
sBluetoothHfpInterface->DeviceStatusNotification(
(bthf_network_state_t) mService,
(bthf_service_type_t) mRoam,
mService,
mRoam,
mSignal,
mBattChg, new DeviceStatusNotificationResultHandler());
}
@ -1315,24 +1320,24 @@ BluetoothHfpManager::GetCallSetupState()
return nsITelephonyService::CALL_STATE_DISCONNECTED;
}
bthf_call_state_t
BluetoothHfpManager::ConvertToBthfCallState(int aCallState)
BluetoothHandsfreeCallState
BluetoothHfpManager::ConvertToBluetoothHandsfreeCallState(int aCallState) const
{
bthf_call_state_t state;
BluetoothHandsfreeCallState state;
// Refer to AOSP BluetoothPhoneService.convertCallState
if (aCallState == nsITelephonyService::CALL_STATE_INCOMING) {
state = BTHF_CALL_STATE_INCOMING;
state = HFP_CALL_STATE_INCOMING;
} else if (aCallState == nsITelephonyService::CALL_STATE_DIALING) {
state = BTHF_CALL_STATE_DIALING;
state = HFP_CALL_STATE_DIALING;
} else if (aCallState == nsITelephonyService::CALL_STATE_ALERTING) {
state = BTHF_CALL_STATE_ALERTING;
state = HFP_CALL_STATE_ALERTING;
} else if (aCallState == nsITelephonyService::CALL_STATE_CONNECTED) {
state = BTHF_CALL_STATE_ACTIVE;
state = HFP_CALL_STATE_ACTIVE;
} else if (aCallState == nsITelephonyService::CALL_STATE_HELD) {
state = BTHF_CALL_STATE_HELD;
state = HFP_CALL_STATE_HELD;
} else { // disconnected
state = BTHF_CALL_STATE_IDLE;
state = HFP_CALL_STATE_IDLE;
}
return state;
@ -1406,7 +1411,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
case nsITelephonyService::CALL_STATE_DIALING:
// We've send Dialer a dialing request and this is the response.
if (!mDialingRequestProcessed) {
SendResponse(BTHF_AT_RESPONSE_OK);
SendResponse(HFP_AT_RESPONSE_OK);
mDialingRequestProcessed = true;
}
break;
@ -1519,9 +1524,7 @@ BluetoothHfpManager::ConnectSco()
NS_ENSURE_TRUE(IsConnected() && !IsScoConnected(), false);
NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
bt_bdaddr_t deviceBdAddress;
StringToBdAddressType(mDeviceAddress, &deviceBdAddress);
sBluetoothHfpInterface->ConnectAudio(&deviceBdAddress,
sBluetoothHfpInterface->ConnectAudio(mDeviceAddress,
new ConnectAudioResultHandler());
return true;
@ -1544,9 +1547,7 @@ BluetoothHfpManager::DisconnectSco()
NS_ENSURE_TRUE(IsScoConnected(), false);
NS_ENSURE_TRUE(sBluetoothHfpInterface, false);
bt_bdaddr_t deviceBdAddress;
StringToBdAddressType(mDeviceAddress, &deviceBdAddress);
sBluetoothHfpInterface->DisconnectAudio(&deviceBdAddress,
sBluetoothHfpInterface->DisconnectAudio(mDeviceAddress,
new DisconnectAudioResultHandler());
return true;
@ -1613,13 +1614,10 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
return;
}
bt_bdaddr_t deviceBdAddress;
StringToBdAddressType(aDeviceAddress, &deviceBdAddress);
mDeviceAddress = aDeviceAddress;
mController = aController;
sBluetoothHfpInterface->Connect(&deviceBdAddress,
sBluetoothHfpInterface->Connect(mDeviceAddress,
new ConnectResultHandler(this));
}
@ -1664,12 +1662,9 @@ BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
return;
}
bt_bdaddr_t deviceBdAddress;
StringToBdAddressType(mDeviceAddress, &deviceBdAddress);
mController = aController;
sBluetoothHfpInterface->Disconnect(&deviceBdAddress,
sBluetoothHfpInterface->Disconnect(mDeviceAddress,
new DisconnectResultHandler(this));
}

Просмотреть файл

@ -66,8 +66,8 @@ public:
uint16_t mState;
nsString mNumber;
bthf_call_direction_t mDirection; // 0: outgoing call; 1: incoming call
bthf_call_addrtype_t mType;
BluetoothHandsfreeCallDirection mDirection;
BluetoothHandsfreeCallAddressType mType;
};
class BluetoothHfpManager : public BluetoothHfpManagerBase
@ -152,21 +152,22 @@ private:
uint32_t GetNumberOfCalls(uint16_t aState);
uint16_t GetCallSetupState();
bool IsTransitionState(uint16_t aCallState, bool aIsConference);
bthf_call_state_t ConvertToBthfCallState(int aCallState);
BluetoothHandsfreeCallState
ConvertToBluetoothHandsfreeCallState(int aCallState) const;
void UpdatePhoneCIND(uint32_t aCallIndex);
void UpdateDeviceCIND();
void SendCLCC(Call& aCall, int aIndex);
void SendLine(const char* aMessage);
void SendResponse(bthf_at_response_t aResponseCode);
void SendResponse(BluetoothHandsfreeAtResponse aResponseCode);
int mConnectionState;
int mPrevConnectionState;
int mAudioState;
// Device CIND
int mBattChg;
int mService;
int mRoam;
BluetoothHandsfreeNetworkState mService;
BluetoothHandsfreeServiceType mRoam;
int mSignal;
int mCurrentVgs;