1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bluetooth/bluez/BluetoothHfpManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,235 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__ 1.11 +#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__ 1.12 + 1.13 +#include "BluetoothCommon.h" 1.14 +#include "BluetoothHfpManagerBase.h" 1.15 +#ifdef MOZ_B2G_RIL 1.16 +#include "BluetoothRilListener.h" 1.17 +#endif 1.18 +#include "BluetoothSocketObserver.h" 1.19 +#include "mozilla/ipc/UnixSocket.h" 1.20 +#include "mozilla/Hal.h" 1.21 + 1.22 +BEGIN_BLUETOOTH_NAMESPACE 1.23 + 1.24 +class BluetoothReplyRunnable; 1.25 +class BluetoothSocket; 1.26 + 1.27 +#ifdef MOZ_B2G_RIL 1.28 +class Call; 1.29 + 1.30 +/** 1.31 + * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07 1.32 + * and 3GPP 27.007" in Bluetooth hands-free profile 1.6 1.33 + */ 1.34 +enum BluetoothCmeError { 1.35 + AG_FAILURE = 0, 1.36 + NO_CONNECTION_TO_PHONE = 1, 1.37 + OPERATION_NOT_ALLOWED = 3, 1.38 + OPERATION_NOT_SUPPORTED = 4, 1.39 + PIN_REQUIRED = 5, 1.40 + SIM_NOT_INSERTED = 10, 1.41 + SIM_PIN_REQUIRED = 11, 1.42 + SIM_PUK_REQUIRED = 12, 1.43 + SIM_FAILURE = 13, 1.44 + SIM_BUSY = 14, 1.45 + INCORRECT_PASSWORD = 16, 1.46 + SIM_PIN2_REQUIRED = 17, 1.47 + SIM_PUK2_REQUIRED = 18, 1.48 + MEMORY_FULL = 20, 1.49 + INVALID_INDEX = 21, 1.50 + MEMORY_FAILURE = 23, 1.51 + TEXT_STRING_TOO_LONG = 24, 1.52 + INVALID_CHARACTERS_IN_TEXT_STRING = 25, 1.53 + DIAL_STRING_TOO_LONG = 26, 1.54 + INVALID_CHARACTERS_IN_DIAL_STRING = 27, 1.55 + NO_NETWORK_SERVICE = 30, 1.56 + NETWORK_TIMEOUT = 31, 1.57 + NETWORK_NOT_ALLOWED = 32 1.58 +}; 1.59 + 1.60 +enum PhoneType { 1.61 + NONE, // no connection 1.62 + GSM, 1.63 + CDMA 1.64 +}; 1.65 + 1.66 +class Call { 1.67 +public: 1.68 + Call(); 1.69 + void Reset(); 1.70 + bool IsActive(); 1.71 + 1.72 + uint16_t mState; 1.73 + bool mDirection; // true: incoming call; false: outgoing call 1.74 + bool mIsConference; 1.75 + nsString mNumber; 1.76 + int mType; 1.77 +}; 1.78 +#endif // MOZ_B2G_RIL 1.79 + 1.80 +class BluetoothHfpManager : public BluetoothSocketObserver 1.81 + , public BluetoothHfpManagerBase 1.82 + , public BatteryObserver 1.83 +{ 1.84 +public: 1.85 + BT_DECL_HFP_MGR_BASE 1.86 + virtual void GetName(nsACString& aName) 1.87 + { 1.88 + aName.AssignLiteral("HFP/HSP"); 1.89 + } 1.90 + 1.91 + static BluetoothHfpManager* Get(); 1.92 + ~BluetoothHfpManager(); 1.93 + 1.94 + // The following functions are inherited from BluetoothSocketObserver 1.95 + virtual void ReceiveSocketData( 1.96 + BluetoothSocket* aSocket, 1.97 + nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE; 1.98 + virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE; 1.99 + virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE; 1.100 + virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE; 1.101 + 1.102 + bool Listen(); 1.103 + /** 1.104 + * This function set up a Synchronous Connection (SCO) link for HFP. 1.105 + * Service Level Connection (SLC) should be established before SCO setup 1.106 + * process. 1.107 + * If SLC haven't been established, this function will return false and 1.108 + * send a request to set up SCO ater HfpManager receive AT+CMER, unless we are 1.109 + * connecting HSP socket rather than HFP socket. 1.110 + * 1.111 + * @param aRunnable Indicate a BluetoothReplyRunnable to execute this 1.112 + * function. The default value is nullpter 1.113 + * @return <code>true</code> if SCO established successfully 1.114 + */ 1.115 + bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr); 1.116 + bool DisconnectSco(); 1.117 + bool ListenSco(); 1.118 + 1.119 +#ifdef MOZ_B2G_RIL 1.120 + /** 1.121 + * @param aSend A boolean indicates whether we need to notify headset or not 1.122 + */ 1.123 + void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState, 1.124 + const nsAString& aError, const nsAString& aNumber, 1.125 + const bool aIsOutgoing, const bool aIsConference, 1.126 + bool aSend); 1.127 + void HandleIccInfoChanged(uint32_t aClientId); 1.128 + void HandleVoiceConnectionChanged(uint32_t aClientId); 1.129 + 1.130 + // CDMA-specific functions 1.131 + void UpdateSecondNumber(const nsAString& aNumber); 1.132 + void AnswerWaitingCall(); 1.133 + void IgnoreWaitingCall(); 1.134 + void ToggleCalls(); 1.135 +#endif 1.136 + 1.137 +private: 1.138 + class CloseScoTask; 1.139 + class GetVolumeTask; 1.140 +#ifdef MOZ_B2G_RIL 1.141 + class RespondToBLDNTask; 1.142 + class SendRingIndicatorTask; 1.143 +#endif 1.144 + 1.145 + friend class CloseScoTask; 1.146 + friend class GetVolumeTask; 1.147 +#ifdef MOZ_B2G_RIL 1.148 + friend class RespondToBLDNTask; 1.149 + friend class SendRingIndicatorTask; 1.150 +#endif 1.151 + friend class BluetoothHfpManagerObserver; 1.152 + 1.153 + BluetoothHfpManager(); 1.154 + void HandleShutdown(); 1.155 + void HandleVolumeChanged(const nsAString& aData); 1.156 + 1.157 + bool Init(); 1.158 + void Notify(const hal::BatteryInformation& aBatteryInfo); 1.159 +#ifdef MOZ_B2G_RIL 1.160 + void ResetCallArray(); 1.161 + uint32_t FindFirstCall(uint16_t aState); 1.162 + uint32_t GetNumberOfCalls(uint16_t aState); 1.163 + uint32_t GetNumberOfConCalls(); 1.164 + uint32_t GetNumberOfConCalls(uint16_t aState); 1.165 + PhoneType GetPhoneType(const nsAString& aType); 1.166 +#endif 1.167 + 1.168 + void NotifyConnectionStatusChanged(const nsAString& aType); 1.169 + void NotifyDialer(const nsAString& aCommand); 1.170 + 1.171 +#ifdef MOZ_B2G_RIL 1.172 + void SendCCWA(const nsAString& aNumber, int aType); 1.173 + bool SendCLCC(const Call& aCall, int aIndex); 1.174 +#endif 1.175 + bool SendCommand(const char* aCommand, uint32_t aValue = 0); 1.176 + bool SendLine(const char* aMessage); 1.177 +#ifdef MOZ_B2G_RIL 1.178 + void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend = true); 1.179 +#endif 1.180 + void OnScoConnectSuccess(); 1.181 + void OnScoConnectError(); 1.182 + void OnScoDisconnect(); 1.183 + 1.184 + int mCurrentVgs; 1.185 + int mCurrentVgm; 1.186 +#ifdef MOZ_B2G_RIL 1.187 + bool mBSIR; 1.188 + bool mCCWA; 1.189 + bool mCLIP; 1.190 +#endif 1.191 + bool mCMEE; 1.192 + bool mCMER; 1.193 + bool mConnectScoRequest; 1.194 + bool mSlcConnected; 1.195 + bool mIsHsp; 1.196 +#ifdef MOZ_B2G_RIL 1.197 + bool mFirstCKPD; 1.198 + int mNetworkSelectionMode; 1.199 + PhoneType mPhoneType; 1.200 +#endif 1.201 + bool mReceiveVgsFlag; 1.202 +#ifdef MOZ_B2G_RIL 1.203 + bool mDialingRequestProcessed; 1.204 +#endif 1.205 + nsString mDeviceAddress; 1.206 +#ifdef MOZ_B2G_RIL 1.207 + nsString mMsisdn; 1.208 + nsString mOperatorName; 1.209 + 1.210 + nsTArray<Call> mCurrentCallArray; 1.211 + nsAutoPtr<BluetoothRilListener> mListener; 1.212 +#endif 1.213 + nsRefPtr<BluetoothProfileController> mController; 1.214 + nsRefPtr<BluetoothReplyRunnable> mScoRunnable; 1.215 + 1.216 + // If a connection has been established, mSocket will be the socket 1.217 + // communicating with the remote socket. We maintain the invariant that if 1.218 + // mSocket is non-null, mHandsfreeSocket and mHeadsetSocket must be null (and 1.219 + // vice versa). 1.220 + nsRefPtr<BluetoothSocket> mSocket; 1.221 + 1.222 + // Server sockets. Once an inbound connection is established, it will hand 1.223 + // over the ownership to mSocket, and get a new server socket while Listen() 1.224 + // is called. 1.225 + nsRefPtr<BluetoothSocket> mHandsfreeSocket; 1.226 + nsRefPtr<BluetoothSocket> mHeadsetSocket; 1.227 + nsRefPtr<BluetoothSocket> mScoSocket; 1.228 + mozilla::ipc::SocketConnectionStatus mScoSocketStatus; 1.229 + 1.230 +#ifdef MOZ_B2G_RIL 1.231 + // CDMA-specific variable 1.232 + Call mCdmaSecondCall; 1.233 +#endif 1.234 +}; 1.235 + 1.236 +END_BLUETOOTH_NAMESPACE 1.237 + 1.238 +#endif