2012-09-26 06:34:55 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
|
|
|
#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
|
|
|
|
|
|
|
#include "BluetoothCommon.h"
|
2013-05-09 23:39:12 -07:00
|
|
|
#include "BluetoothProfileManagerBase.h"
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-09-09 04:54:56 -07:00
|
|
|
#include "BluetoothRilListener.h"
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-04-04 17:54:22 -07:00
|
|
|
#include "BluetoothSocketObserver.h"
|
2012-09-26 06:34:55 -07:00
|
|
|
#include "mozilla/ipc/UnixSocket.h"
|
2013-06-19 18:19:31 -07:00
|
|
|
#include "mozilla/Hal.h"
|
2012-09-26 06:34:55 -07:00
|
|
|
|
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
|
2013-04-04 17:54:22 -07:00
|
|
|
class BluetoothReplyRunnable;
|
|
|
|
class BluetoothSocket;
|
2013-10-29 01:12:46 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-01-15 22:13:58 -08:00
|
|
|
class Call;
|
2012-09-26 06:34:55 -07:00
|
|
|
|
2013-01-10 22:00:04 -08:00
|
|
|
/**
|
|
|
|
* These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
|
|
|
|
* and 3GPP 27.007" in Bluetooth hands-free profile 1.6
|
|
|
|
*/
|
|
|
|
enum BluetoothCmeError {
|
|
|
|
AG_FAILURE = 0,
|
|
|
|
NO_CONNECTION_TO_PHONE = 1,
|
|
|
|
OPERATION_NOT_ALLOWED = 3,
|
|
|
|
OPERATION_NOT_SUPPORTED = 4,
|
|
|
|
PIN_REQUIRED = 5,
|
|
|
|
SIM_NOT_INSERTED = 10,
|
|
|
|
SIM_PIN_REQUIRED = 11,
|
|
|
|
SIM_PUK_REQUIRED = 12,
|
|
|
|
SIM_FAILURE = 13,
|
|
|
|
SIM_BUSY = 14,
|
|
|
|
INCORRECT_PASSWORD = 16,
|
|
|
|
SIM_PIN2_REQUIRED = 17,
|
|
|
|
SIM_PUK2_REQUIRED = 18,
|
|
|
|
MEMORY_FULL = 20,
|
|
|
|
INVALID_INDEX = 21,
|
|
|
|
MEMORY_FAILURE = 23,
|
|
|
|
TEXT_STRING_TOO_LONG = 24,
|
|
|
|
INVALID_CHARACTERS_IN_TEXT_STRING = 25,
|
|
|
|
DIAL_STRING_TOO_LONG = 26,
|
|
|
|
INVALID_CHARACTERS_IN_DIAL_STRING = 27,
|
|
|
|
NO_NETWORK_SERVICE = 30,
|
|
|
|
NETWORK_TIMEOUT = 31,
|
|
|
|
NETWORK_NOT_ALLOWED = 32
|
|
|
|
};
|
|
|
|
|
2013-10-16 21:40:17 -07:00
|
|
|
enum PhoneType {
|
|
|
|
NONE, // no connection
|
|
|
|
GSM,
|
|
|
|
CDMA
|
|
|
|
};
|
|
|
|
|
|
|
|
class Call {
|
|
|
|
public:
|
|
|
|
Call();
|
|
|
|
void Reset();
|
|
|
|
bool IsActive();
|
|
|
|
|
|
|
|
uint16_t mState;
|
|
|
|
bool mDirection; // true: incoming call; false: outgoing call
|
|
|
|
nsString mNumber;
|
|
|
|
int mType;
|
|
|
|
};
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-16 21:40:17 -07:00
|
|
|
|
2013-04-04 17:54:22 -07:00
|
|
|
class BluetoothHfpManager : public BluetoothSocketObserver
|
2013-05-09 23:39:12 -07:00
|
|
|
, public BluetoothProfileManagerBase
|
2013-06-19 18:19:31 -07:00
|
|
|
, public BatteryObserver
|
2012-09-26 06:34:55 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-06-08 08:26:01 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-06-19 18:19:31 -07:00
|
|
|
NS_DECL_NSIOBSERVER
|
2013-11-11 19:59:01 -08:00
|
|
|
BT_DECL_PROFILE_MGR_BASE
|
|
|
|
virtual void GetName(nsACString& aName)
|
|
|
|
{
|
|
|
|
aName.AssignLiteral("HFP/HSP");
|
|
|
|
}
|
2013-06-08 08:26:01 -07:00
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
static BluetoothHfpManager* Get();
|
2013-04-04 17:54:22 -07:00
|
|
|
~BluetoothHfpManager();
|
|
|
|
|
2013-09-06 04:20:43 -07:00
|
|
|
// The following functions are inherited from BluetoothSocketObserver
|
2013-04-04 17:54:22 -07:00
|
|
|
virtual void ReceiveSocketData(
|
2013-04-04 17:55:55 -07:00
|
|
|
BluetoothSocket* aSocket,
|
2013-04-04 17:54:22 -07:00
|
|
|
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
|
2013-09-06 04:20:43 -07:00
|
|
|
virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
|
2013-01-15 22:13:41 -08:00
|
|
|
bool Listen();
|
2013-11-25 19:28:10 -08:00
|
|
|
/**
|
|
|
|
* This function set up a Synchronous Connection (SCO) link for HFP.
|
|
|
|
* Service Level Connection (SLC) should be established before SCO setup
|
|
|
|
* process.
|
|
|
|
* If SLC haven't been established, this function will return false and send a
|
|
|
|
* request to set up SCO ater HfpManager receive AT+CMER.
|
|
|
|
*
|
|
|
|
* @param aRunnable Indicate a BluetoothReplyRunnable to execute this
|
|
|
|
* function. The default value is nullpter
|
|
|
|
* @return <code>true</code> if SCO established successfully
|
|
|
|
*/
|
2013-05-10 04:01:10 -07:00
|
|
|
bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
|
|
|
|
bool DisconnectSco();
|
|
|
|
bool ListenSco();
|
2013-11-11 19:59:01 -08:00
|
|
|
bool IsScoConnected();
|
2013-01-15 22:13:41 -08:00
|
|
|
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-01-28 03:28:51 -08:00
|
|
|
/**
|
|
|
|
* @param aSend A boolean indicates whether we need to notify headset or not
|
|
|
|
*/
|
|
|
|
void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
|
2013-07-15 05:54:07 -07:00
|
|
|
const nsAString& aError, const nsAString& aNumber,
|
|
|
|
const bool aIsOutgoing, bool aSend);
|
2013-11-11 10:40:50 -08:00
|
|
|
void HandleIccInfoChanged();
|
|
|
|
void HandleVoiceConnectionChanged();
|
2013-05-10 02:47:16 -07:00
|
|
|
|
2013-10-16 21:40:17 -07:00
|
|
|
// CDMA-specific functions
|
|
|
|
void UpdateSecondNumber(const nsAString& aNumber);
|
2013-10-15 19:38:13 -07:00
|
|
|
void AnswerWaitingCall();
|
|
|
|
void IgnoreWaitingCall();
|
|
|
|
void ToggleCalls();
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-10-16 21:40:17 -07:00
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
private:
|
2013-06-23 21:10:07 -07:00
|
|
|
class CloseScoTask;
|
2013-01-15 22:13:41 -08:00
|
|
|
class GetVolumeTask;
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-05-09 07:10:28 -07:00
|
|
|
class RespondToBLDNTask;
|
2013-04-04 17:54:22 -07:00
|
|
|
class SendRingIndicatorTask;
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-04-04 17:54:22 -07:00
|
|
|
|
2013-06-23 21:10:07 -07:00
|
|
|
friend class CloseScoTask;
|
2013-01-15 22:13:41 -08:00
|
|
|
friend class GetVolumeTask;
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-05-09 07:10:28 -07:00
|
|
|
friend class RespondToBLDNTask;
|
2013-04-04 17:54:22 -07:00
|
|
|
friend class SendRingIndicatorTask;
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2012-10-05 17:11:24 -07:00
|
|
|
friend class BluetoothHfpManagerObserver;
|
2013-01-15 22:13:41 -08:00
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
BluetoothHfpManager();
|
2013-06-19 18:20:16 -07:00
|
|
|
void HandleShutdown();
|
|
|
|
void HandleVolumeChanged(const nsAString& aData);
|
2012-12-17 01:44:32 -08:00
|
|
|
|
2012-10-05 17:11:24 -07:00
|
|
|
bool Init();
|
2013-06-19 18:19:31 -07:00
|
|
|
void Notify(const hal::BatteryInformation& aBatteryInfo);
|
2013-01-15 22:13:58 -08:00
|
|
|
void Reset();
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-01-15 22:13:58 -08:00
|
|
|
void ResetCallArray();
|
2013-05-27 23:58:51 -07:00
|
|
|
uint32_t FindFirstCall(uint16_t aState);
|
|
|
|
uint32_t GetNumberOfCalls(uint16_t aState);
|
2013-10-16 21:40:17 -07:00
|
|
|
PhoneType GetPhoneType(const nsAString& aType);
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-01-28 03:28:51 -08:00
|
|
|
|
2013-08-02 03:32:57 -07:00
|
|
|
void NotifyConnectionStatusChanged(const nsAString& aType);
|
2013-09-11 05:56:48 -07:00
|
|
|
void NotifyDialer(const nsAString& aCommand);
|
2013-01-28 03:28:51 -08:00
|
|
|
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-16 21:40:17 -07:00
|
|
|
void SendCCWA(const nsAString& aNumber, int aType);
|
|
|
|
bool SendCLCC(const Call& aCall, int aIndex);
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-06-05 01:53:22 -07:00
|
|
|
bool SendCommand(const char* aCommand, uint32_t aValue = 0);
|
2013-01-15 22:13:41 -08:00
|
|
|
bool SendLine(const char* aMessage);
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-06-07 01:54:13 -07:00
|
|
|
void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend = true);
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-05-10 04:01:10 -07:00
|
|
|
void OnScoConnectSuccess();
|
|
|
|
void OnScoConnectError();
|
|
|
|
void OnScoDisconnect();
|
2013-01-28 03:28:51 -08:00
|
|
|
|
2012-09-26 19:24:39 -07:00
|
|
|
int mCurrentVgs;
|
2013-01-07 00:58:59 -08:00
|
|
|
int mCurrentVgm;
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-06-05 01:53:22 -07:00
|
|
|
bool mBSIR;
|
2013-01-15 22:17:41 -08:00
|
|
|
bool mCCWA;
|
2012-12-17 07:24:35 -08:00
|
|
|
bool mCLIP;
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-01-10 22:00:04 -08:00
|
|
|
bool mCMEE;
|
2013-01-08 22:05:34 -08:00
|
|
|
bool mCMER;
|
2013-11-25 19:28:10 -08:00
|
|
|
bool mConnectScoRequest;
|
|
|
|
bool mSlcConnected;
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-04-19 02:08:06 -07:00
|
|
|
bool mFirstCKPD;
|
2013-01-22 17:22:08 -08:00
|
|
|
int mNetworkSelectionMode;
|
2013-10-16 21:40:17 -07:00
|
|
|
PhoneType mPhoneType;
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2012-10-25 03:50:41 -07:00
|
|
|
bool mReceiveVgsFlag;
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-05-31 05:43:18 -07:00
|
|
|
bool mDialingRequestProcessed;
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-05-10 04:01:10 -07:00
|
|
|
nsString mDeviceAddress;
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-12-17 01:44:32 -08:00
|
|
|
nsString mMsisdn;
|
2013-01-22 17:22:08 -08:00
|
|
|
nsString mOperatorName;
|
2013-01-15 22:13:58 -08:00
|
|
|
|
|
|
|
nsTArray<Call> mCurrentCallArray;
|
2013-09-09 04:54:56 -07:00
|
|
|
nsAutoPtr<BluetoothRilListener> mListener;
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2013-10-01 00:26:40 -07:00
|
|
|
nsRefPtr<BluetoothProfileController> mController;
|
2013-05-10 04:01:10 -07:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> mScoRunnable;
|
2013-04-19 02:08:00 -07:00
|
|
|
|
|
|
|
// If a connection has been established, mSocket will be the socket
|
|
|
|
// communicating with the remote socket. We maintain the invariant that if
|
|
|
|
// mSocket is non-null, mHandsfreeSocket and mHeadsetSocket must be null (and
|
|
|
|
// vice versa).
|
2013-04-04 17:54:22 -07:00
|
|
|
nsRefPtr<BluetoothSocket> mSocket;
|
2013-04-19 02:08:00 -07:00
|
|
|
|
|
|
|
// Server sockets. Once an inbound connection is established, it will hand
|
|
|
|
// over the ownership to mSocket, and get a new server socket while Listen()
|
|
|
|
// is called.
|
|
|
|
nsRefPtr<BluetoothSocket> mHandsfreeSocket;
|
|
|
|
nsRefPtr<BluetoothSocket> mHeadsetSocket;
|
2013-05-10 04:01:10 -07:00
|
|
|
nsRefPtr<BluetoothSocket> mScoSocket;
|
|
|
|
SocketConnectionStatus mScoSocketStatus;
|
2013-10-16 21:40:17 -07:00
|
|
|
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-16 21:40:17 -07:00
|
|
|
// CDMA-specific variable
|
|
|
|
Call mCdmaSecondCall;
|
2013-10-29 01:12:46 -07:00
|
|
|
#endif
|
2012-09-26 06:34:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|