michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__ michael@0: #define mozilla_dom_bluetooth_bluetoothhfpmanager_h__ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "BluetoothCommon.h" michael@0: #include "BluetoothHfpManagerBase.h" michael@0: #include "BluetoothRilListener.h" michael@0: #include "BluetoothSocketObserver.h" michael@0: #include "mozilla/ipc/UnixSocket.h" michael@0: #include "mozilla/Hal.h" michael@0: michael@0: BEGIN_BLUETOOTH_NAMESPACE michael@0: michael@0: class BluetoothReplyRunnable; michael@0: class BluetoothSocket; michael@0: class Call; michael@0: michael@0: /** michael@0: * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07 michael@0: * and 3GPP 27.007" in Bluetooth hands-free profile 1.6 michael@0: */ michael@0: enum BluetoothCmeError { michael@0: AG_FAILURE = 0, michael@0: NO_CONNECTION_TO_PHONE = 1, michael@0: OPERATION_NOT_ALLOWED = 3, michael@0: OPERATION_NOT_SUPPORTED = 4, michael@0: PIN_REQUIRED = 5, michael@0: SIM_NOT_INSERTED = 10, michael@0: SIM_PIN_REQUIRED = 11, michael@0: SIM_PUK_REQUIRED = 12, michael@0: SIM_FAILURE = 13, michael@0: SIM_BUSY = 14, michael@0: INCORRECT_PASSWORD = 16, michael@0: SIM_PIN2_REQUIRED = 17, michael@0: SIM_PUK2_REQUIRED = 18, michael@0: MEMORY_FULL = 20, michael@0: INVALID_INDEX = 21, michael@0: MEMORY_FAILURE = 23, michael@0: TEXT_STRING_TOO_LONG = 24, michael@0: INVALID_CHARACTERS_IN_TEXT_STRING = 25, michael@0: DIAL_STRING_TOO_LONG = 26, michael@0: INVALID_CHARACTERS_IN_DIAL_STRING = 27, michael@0: NO_NETWORK_SERVICE = 30, michael@0: NETWORK_TIMEOUT = 31, michael@0: NETWORK_NOT_ALLOWED = 32 michael@0: }; michael@0: michael@0: enum PhoneType { michael@0: NONE, // no connection michael@0: GSM, michael@0: CDMA michael@0: }; michael@0: michael@0: class Call { michael@0: public: michael@0: Call(); michael@0: void Set(const nsAString& aNumber, const bool aIsOutgoing); michael@0: void Reset(); michael@0: bool IsActive(); michael@0: michael@0: uint16_t mState; michael@0: nsString mNumber; michael@0: bthf_call_direction_t mDirection; // 0: outgoing call; 1: incoming call michael@0: bthf_call_addrtype_t mType; michael@0: }; michael@0: michael@0: class BluetoothHfpManager : public BluetoothHfpManagerBase michael@0: , public BatteryObserver michael@0: { michael@0: public: michael@0: BT_DECL_HFP_MGR_BASE michael@0: virtual void GetName(nsACString& aName) michael@0: { michael@0: aName.AssignLiteral("HFP/HSP"); michael@0: } michael@0: michael@0: static BluetoothHfpManager* Get(); michael@0: virtual ~BluetoothHfpManager(); michael@0: michael@0: bool ConnectSco(); michael@0: bool DisconnectSco(); michael@0: michael@0: /** michael@0: * @param aSend A boolean indicates whether we need to notify headset or not michael@0: */ michael@0: void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState, michael@0: const nsAString& aError, const nsAString& aNumber, michael@0: const bool aIsOutgoing, const bool aIsConference, michael@0: bool aSend); michael@0: void HandleIccInfoChanged(uint32_t aClientId); michael@0: void HandleVoiceConnectionChanged(uint32_t aClientId); michael@0: michael@0: // Bluedroid hfp callback handlers michael@0: void ProcessConnectionState(bthf_connection_state_t aState, bt_bdaddr_t* aBdAddress); michael@0: void ProcessAudioState(bthf_audio_state_t aState, bt_bdaddr_t* aBdAddress); michael@0: void ProcessAnswerCall(); michael@0: void ProcessHangupCall(); michael@0: void ProcessVolumeControl(bthf_volume_type_t aType, int aVolume); michael@0: void ProcessDialCall(char *aNumber); michael@0: void ProcessDtmfCmd(char aDtmf); michael@0: void ProcessAtChld(bthf_chld_type_t aChld); michael@0: void ProcessAtCnum(); michael@0: void ProcessAtCind(); michael@0: void ProcessAtCops(); michael@0: void ProcessAtClcc(); michael@0: void ProcessUnknownAt(char *aAtString); michael@0: void ProcessKeyPressed(); michael@0: michael@0: // CDMA-specific functions michael@0: void UpdateSecondNumber(const nsAString& aNumber); michael@0: void AnswerWaitingCall(); michael@0: void IgnoreWaitingCall(); michael@0: void ToggleCalls(); michael@0: michael@0: private: michael@0: class GetVolumeTask; michael@0: class CloseScoTask; michael@0: class RespondToBLDNTask; michael@0: class MainThreadTask; michael@0: michael@0: friend class BluetoothHfpManagerObserver; michael@0: friend class GetVolumeTask; michael@0: friend class CloseScoTask; michael@0: friend class RespondToBLDNTask; michael@0: friend class MainThreadTask; michael@0: michael@0: BluetoothHfpManager(); michael@0: bool Init(); michael@0: bool InitHfpInterface(); michael@0: void DeinitHfpInterface(); michael@0: michael@0: void HandleShutdown(); michael@0: void HandleVolumeChanged(const nsAString& aData); michael@0: void Notify(const hal::BatteryInformation& aBatteryInfo); michael@0: michael@0: void NotifyConnectionStateChanged(const nsAString& aType); michael@0: void NotifyDialer(const nsAString& aCommand); michael@0: michael@0: PhoneType GetPhoneType(const nsAString& aType); michael@0: void ResetCallArray(); michael@0: uint32_t FindFirstCall(uint16_t aState); michael@0: uint32_t GetNumberOfCalls(uint16_t aState); michael@0: uint16_t GetCallSetupState(); michael@0: bool IsTransitionState(uint16_t aCallState, bool aIsConference); michael@0: bthf_call_state_t ConvertToBthfCallState(int aCallState); michael@0: michael@0: void UpdatePhoneCIND(uint32_t aCallIndex); michael@0: void UpdateDeviceCIND(); michael@0: void SendCLCC(Call& aCall, int aIndex); michael@0: void SendLine(const char* aMessage); michael@0: void SendResponse(bthf_at_response_t aResponseCode); michael@0: michael@0: int mConnectionState; michael@0: int mPrevConnectionState; michael@0: int mAudioState; michael@0: // Device CIND michael@0: int mBattChg; michael@0: int mService; michael@0: int mRoam; michael@0: int mSignal; michael@0: michael@0: int mCurrentVgs; michael@0: int mCurrentVgm; michael@0: bool mReceiveVgsFlag; michael@0: bool mDialingRequestProcessed; michael@0: PhoneType mPhoneType; michael@0: nsString mDeviceAddress; michael@0: nsString mMsisdn; michael@0: nsString mOperatorName; michael@0: michael@0: nsTArray mCurrentCallArray; michael@0: nsAutoPtr mListener; michael@0: nsRefPtr mController; michael@0: michael@0: // CDMA-specific variable michael@0: Call mCdmaSecondCall; michael@0: }; michael@0: michael@0: END_BLUETOOTH_NAMESPACE michael@0: michael@0: #endif