dom/bluetooth/bluez/BluetoothHfpManager.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__
michael@0 8 #define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
michael@0 9
michael@0 10 #include "BluetoothCommon.h"
michael@0 11 #include "BluetoothHfpManagerBase.h"
michael@0 12 #ifdef MOZ_B2G_RIL
michael@0 13 #include "BluetoothRilListener.h"
michael@0 14 #endif
michael@0 15 #include "BluetoothSocketObserver.h"
michael@0 16 #include "mozilla/ipc/UnixSocket.h"
michael@0 17 #include "mozilla/Hal.h"
michael@0 18
michael@0 19 BEGIN_BLUETOOTH_NAMESPACE
michael@0 20
michael@0 21 class BluetoothReplyRunnable;
michael@0 22 class BluetoothSocket;
michael@0 23
michael@0 24 #ifdef MOZ_B2G_RIL
michael@0 25 class Call;
michael@0 26
michael@0 27 /**
michael@0 28 * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
michael@0 29 * and 3GPP 27.007" in Bluetooth hands-free profile 1.6
michael@0 30 */
michael@0 31 enum BluetoothCmeError {
michael@0 32 AG_FAILURE = 0,
michael@0 33 NO_CONNECTION_TO_PHONE = 1,
michael@0 34 OPERATION_NOT_ALLOWED = 3,
michael@0 35 OPERATION_NOT_SUPPORTED = 4,
michael@0 36 PIN_REQUIRED = 5,
michael@0 37 SIM_NOT_INSERTED = 10,
michael@0 38 SIM_PIN_REQUIRED = 11,
michael@0 39 SIM_PUK_REQUIRED = 12,
michael@0 40 SIM_FAILURE = 13,
michael@0 41 SIM_BUSY = 14,
michael@0 42 INCORRECT_PASSWORD = 16,
michael@0 43 SIM_PIN2_REQUIRED = 17,
michael@0 44 SIM_PUK2_REQUIRED = 18,
michael@0 45 MEMORY_FULL = 20,
michael@0 46 INVALID_INDEX = 21,
michael@0 47 MEMORY_FAILURE = 23,
michael@0 48 TEXT_STRING_TOO_LONG = 24,
michael@0 49 INVALID_CHARACTERS_IN_TEXT_STRING = 25,
michael@0 50 DIAL_STRING_TOO_LONG = 26,
michael@0 51 INVALID_CHARACTERS_IN_DIAL_STRING = 27,
michael@0 52 NO_NETWORK_SERVICE = 30,
michael@0 53 NETWORK_TIMEOUT = 31,
michael@0 54 NETWORK_NOT_ALLOWED = 32
michael@0 55 };
michael@0 56
michael@0 57 enum PhoneType {
michael@0 58 NONE, // no connection
michael@0 59 GSM,
michael@0 60 CDMA
michael@0 61 };
michael@0 62
michael@0 63 class Call {
michael@0 64 public:
michael@0 65 Call();
michael@0 66 void Reset();
michael@0 67 bool IsActive();
michael@0 68
michael@0 69 uint16_t mState;
michael@0 70 bool mDirection; // true: incoming call; false: outgoing call
michael@0 71 bool mIsConference;
michael@0 72 nsString mNumber;
michael@0 73 int mType;
michael@0 74 };
michael@0 75 #endif // MOZ_B2G_RIL
michael@0 76
michael@0 77 class BluetoothHfpManager : public BluetoothSocketObserver
michael@0 78 , public BluetoothHfpManagerBase
michael@0 79 , public BatteryObserver
michael@0 80 {
michael@0 81 public:
michael@0 82 BT_DECL_HFP_MGR_BASE
michael@0 83 virtual void GetName(nsACString& aName)
michael@0 84 {
michael@0 85 aName.AssignLiteral("HFP/HSP");
michael@0 86 }
michael@0 87
michael@0 88 static BluetoothHfpManager* Get();
michael@0 89 ~BluetoothHfpManager();
michael@0 90
michael@0 91 // The following functions are inherited from BluetoothSocketObserver
michael@0 92 virtual void ReceiveSocketData(
michael@0 93 BluetoothSocket* aSocket,
michael@0 94 nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
michael@0 95 virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
michael@0 96 virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
michael@0 97 virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
michael@0 98
michael@0 99 bool Listen();
michael@0 100 /**
michael@0 101 * This function set up a Synchronous Connection (SCO) link for HFP.
michael@0 102 * Service Level Connection (SLC) should be established before SCO setup
michael@0 103 * process.
michael@0 104 * If SLC haven't been established, this function will return false and
michael@0 105 * send a request to set up SCO ater HfpManager receive AT+CMER, unless we are
michael@0 106 * connecting HSP socket rather than HFP socket.
michael@0 107 *
michael@0 108 * @param aRunnable Indicate a BluetoothReplyRunnable to execute this
michael@0 109 * function. The default value is nullpter
michael@0 110 * @return <code>true</code> if SCO established successfully
michael@0 111 */
michael@0 112 bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
michael@0 113 bool DisconnectSco();
michael@0 114 bool ListenSco();
michael@0 115
michael@0 116 #ifdef MOZ_B2G_RIL
michael@0 117 /**
michael@0 118 * @param aSend A boolean indicates whether we need to notify headset or not
michael@0 119 */
michael@0 120 void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
michael@0 121 const nsAString& aError, const nsAString& aNumber,
michael@0 122 const bool aIsOutgoing, const bool aIsConference,
michael@0 123 bool aSend);
michael@0 124 void HandleIccInfoChanged(uint32_t aClientId);
michael@0 125 void HandleVoiceConnectionChanged(uint32_t aClientId);
michael@0 126
michael@0 127 // CDMA-specific functions
michael@0 128 void UpdateSecondNumber(const nsAString& aNumber);
michael@0 129 void AnswerWaitingCall();
michael@0 130 void IgnoreWaitingCall();
michael@0 131 void ToggleCalls();
michael@0 132 #endif
michael@0 133
michael@0 134 private:
michael@0 135 class CloseScoTask;
michael@0 136 class GetVolumeTask;
michael@0 137 #ifdef MOZ_B2G_RIL
michael@0 138 class RespondToBLDNTask;
michael@0 139 class SendRingIndicatorTask;
michael@0 140 #endif
michael@0 141
michael@0 142 friend class CloseScoTask;
michael@0 143 friend class GetVolumeTask;
michael@0 144 #ifdef MOZ_B2G_RIL
michael@0 145 friend class RespondToBLDNTask;
michael@0 146 friend class SendRingIndicatorTask;
michael@0 147 #endif
michael@0 148 friend class BluetoothHfpManagerObserver;
michael@0 149
michael@0 150 BluetoothHfpManager();
michael@0 151 void HandleShutdown();
michael@0 152 void HandleVolumeChanged(const nsAString& aData);
michael@0 153
michael@0 154 bool Init();
michael@0 155 void Notify(const hal::BatteryInformation& aBatteryInfo);
michael@0 156 #ifdef MOZ_B2G_RIL
michael@0 157 void ResetCallArray();
michael@0 158 uint32_t FindFirstCall(uint16_t aState);
michael@0 159 uint32_t GetNumberOfCalls(uint16_t aState);
michael@0 160 uint32_t GetNumberOfConCalls();
michael@0 161 uint32_t GetNumberOfConCalls(uint16_t aState);
michael@0 162 PhoneType GetPhoneType(const nsAString& aType);
michael@0 163 #endif
michael@0 164
michael@0 165 void NotifyConnectionStatusChanged(const nsAString& aType);
michael@0 166 void NotifyDialer(const nsAString& aCommand);
michael@0 167
michael@0 168 #ifdef MOZ_B2G_RIL
michael@0 169 void SendCCWA(const nsAString& aNumber, int aType);
michael@0 170 bool SendCLCC(const Call& aCall, int aIndex);
michael@0 171 #endif
michael@0 172 bool SendCommand(const char* aCommand, uint32_t aValue = 0);
michael@0 173 bool SendLine(const char* aMessage);
michael@0 174 #ifdef MOZ_B2G_RIL
michael@0 175 void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend = true);
michael@0 176 #endif
michael@0 177 void OnScoConnectSuccess();
michael@0 178 void OnScoConnectError();
michael@0 179 void OnScoDisconnect();
michael@0 180
michael@0 181 int mCurrentVgs;
michael@0 182 int mCurrentVgm;
michael@0 183 #ifdef MOZ_B2G_RIL
michael@0 184 bool mBSIR;
michael@0 185 bool mCCWA;
michael@0 186 bool mCLIP;
michael@0 187 #endif
michael@0 188 bool mCMEE;
michael@0 189 bool mCMER;
michael@0 190 bool mConnectScoRequest;
michael@0 191 bool mSlcConnected;
michael@0 192 bool mIsHsp;
michael@0 193 #ifdef MOZ_B2G_RIL
michael@0 194 bool mFirstCKPD;
michael@0 195 int mNetworkSelectionMode;
michael@0 196 PhoneType mPhoneType;
michael@0 197 #endif
michael@0 198 bool mReceiveVgsFlag;
michael@0 199 #ifdef MOZ_B2G_RIL
michael@0 200 bool mDialingRequestProcessed;
michael@0 201 #endif
michael@0 202 nsString mDeviceAddress;
michael@0 203 #ifdef MOZ_B2G_RIL
michael@0 204 nsString mMsisdn;
michael@0 205 nsString mOperatorName;
michael@0 206
michael@0 207 nsTArray<Call> mCurrentCallArray;
michael@0 208 nsAutoPtr<BluetoothRilListener> mListener;
michael@0 209 #endif
michael@0 210 nsRefPtr<BluetoothProfileController> mController;
michael@0 211 nsRefPtr<BluetoothReplyRunnable> mScoRunnable;
michael@0 212
michael@0 213 // If a connection has been established, mSocket will be the socket
michael@0 214 // communicating with the remote socket. We maintain the invariant that if
michael@0 215 // mSocket is non-null, mHandsfreeSocket and mHeadsetSocket must be null (and
michael@0 216 // vice versa).
michael@0 217 nsRefPtr<BluetoothSocket> mSocket;
michael@0 218
michael@0 219 // Server sockets. Once an inbound connection is established, it will hand
michael@0 220 // over the ownership to mSocket, and get a new server socket while Listen()
michael@0 221 // is called.
michael@0 222 nsRefPtr<BluetoothSocket> mHandsfreeSocket;
michael@0 223 nsRefPtr<BluetoothSocket> mHeadsetSocket;
michael@0 224 nsRefPtr<BluetoothSocket> mScoSocket;
michael@0 225 mozilla::ipc::SocketConnectionStatus mScoSocketStatus;
michael@0 226
michael@0 227 #ifdef MOZ_B2G_RIL
michael@0 228 // CDMA-specific variable
michael@0 229 Call mCdmaSecondCall;
michael@0 230 #endif
michael@0 231 };
michael@0 232
michael@0 233 END_BLUETOOTH_NAMESPACE
michael@0 234
michael@0 235 #endif

mercurial