Bug 1038591: Convert Bluetooth Handsfree data types in |BluetoothHandsfreeInterface|, r=shuang

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-06 11:45:05 +02:00
Родитель 75d7fb0176
Коммит b7264fc980
5 изменённых файлов: 388 добавлений и 111 удалений

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

@ -139,6 +139,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;

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

@ -223,6 +223,138 @@ 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[] = {
[HFP_AT_RESPONSE_ERROR] = BTHF_AT_RESPONSE_ERROR,
[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[] = {
[HFP_CALL_ADDRESS_TYPE_UNKNOWN] = BTHF_CALL_ADDRTYPE_UNKNOWN,
[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[] = {
[HFP_CALL_DIRECTION_OUTGOING] = BTHF_CALL_DIRECTION_OUTGOING,
[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[] = {
[HFP_CALL_MODE_VOICE] = BTHF_CALL_TYPE_VOICE,
[HFP_CALL_MODE_DATA] = BTHF_CALL_TYPE_DATA,
[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[] = {
[HFP_CALL_MPTY_TYPE_SINGLE] = BTHF_CALL_MPTY_TYPE_SINGLE,
[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[] = {
[HFP_CALL_STATE_ACTIVE] = BTHF_CALL_STATE_ACTIVE,
[HFP_CALL_STATE_HELD] = BTHF_CALL_STATE_HELD,
[HFP_CALL_STATE_DIALING] = BTHF_CALL_STATE_DIALING,
[HFP_CALL_STATE_ALERTING] = BTHF_CALL_STATE_ALERTING,
[HFP_CALL_STATE_INCOMING] = BTHF_CALL_STATE_INCOMING,
[HFP_CALL_STATE_WAITING] = BTHF_CALL_STATE_WAITING,
[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[] = {
[HFP_NETWORK_STATE_NOT_AVAILABLE] = BTHF_NETWORK_STATE_NOT_AVAILABLE,
[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[] = {
[HFP_SERVICE_TYPE_HOME] = BTHF_SERVICE_TYPE_HOME,
[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[] = {
[HFP_VOLUME_TYPE_SPEAKER] = BTHF_VOLUME_TYPE_SPK,
[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
//
@ -875,10 +1007,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(
@ -887,10 +1026,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(
@ -900,9 +1046,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(
@ -912,9 +1065,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(
@ -952,9 +1112,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(
@ -966,11 +1134,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(
@ -995,12 +1173,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);
@ -1020,11 +1208,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(
@ -1034,12 +1229,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);
@ -1050,12 +1267,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
@ -379,8 +381,8 @@ BluetoothHfpManager::Cleanup()
mConnectionState = BTHF_CONNECTION_STATE_DISCONNECTED;
mPrevConnectionState = BTHF_CONNECTION_STATE_DISCONNECTED;
mBattChg = 5;
mService = 0;
mRoam = 0;
mService = HFP_NETWORK_STATE_NOT_AVAILABLE;
mRoam = HFP_SERVICE_TYPE_HOME;
mSignal = 0;
mController = nullptr;
@ -745,7 +747,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)
@ -777,7 +779,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);
}
}
@ -794,7 +796,7 @@ BluetoothHfpManager::ProcessAtCnum()
SendLine(message.get());
}
SendResponse(BTHF_AT_RESPONSE_OK);
SendResponse(HFP_AT_RESPONSE_OK);
}
class CindResponseResultHandler MOZ_FINAL
@ -815,7 +817,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,
@ -859,7 +862,7 @@ BluetoothHfpManager::ProcessAtClcc()
SendCLCC(mCdmaSecondCall, 2);
}
SendResponse(BTHF_AT_RESPONSE_OK);
SendResponse(HFP_AT_RESPONSE_OK);
}
class AtResponseResultHandler MOZ_FINAL
@ -880,7 +883,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());
}
@ -1047,7 +1050,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());
}
}
@ -1070,7 +1073,7 @@ 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;
@ -1081,7 +1084,8 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
// Notify BluetoothRilListener of service change
mListener->ServiceChanged(aClientId, service);
}
mService = service;
mService = service ? HFP_NETWORK_STATE_AVAILABLE :
HFP_NETWORK_STATE_NOT_AVAILABLE;
// Signal
JSContext* cx = nsContentUtils::GetSafeJSContext();
@ -1157,21 +1161,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());
}
@ -1196,7 +1201,7 @@ BluetoothHfpManager::SendLine(const char* aMessage)
}
void
BluetoothHfpManager::SendResponse(bthf_at_response_t aResponseCode)
BluetoothHfpManager::SendResponse(BluetoothHandsfreeAtResponse aResponseCode)
{
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
@ -1222,18 +1227,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());
}
@ -1254,8 +1258,8 @@ BluetoothHfpManager::UpdateDeviceCIND()
{
if (sBluetoothHfpInterface) {
sBluetoothHfpInterface->DeviceStatusNotification(
(bthf_network_state_t) mService,
(bthf_service_type_t) mRoam,
mService,
mRoam,
mSignal,
mBattChg, new DeviceStatusNotificationResultHandler());
}
@ -1309,24 +1313,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;
@ -1400,7 +1404,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;
@ -1513,9 +1517,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;
@ -1538,9 +1540,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;
@ -1607,13 +1607,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));
}
@ -1658,12 +1655,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
@ -153,21 +153,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;