2012-09-26 13:34:55 +00: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-10 06:39:12 +00:00
|
|
|
#include "BluetoothProfileManagerBase.h"
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-09-09 11:54:56 +00:00
|
|
|
#include "BluetoothRilListener.h"
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-04-05 00:54:22 +00:00
|
|
|
#include "BluetoothSocketObserver.h"
|
2012-09-26 13:34:55 +00:00
|
|
|
#include "mozilla/ipc/UnixSocket.h"
|
2013-06-20 01:19:31 +00:00
|
|
|
#include "mozilla/Hal.h"
|
2012-09-26 13:34:55 +00:00
|
|
|
|
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
|
2013-04-05 00:54:22 +00:00
|
|
|
class BluetoothReplyRunnable;
|
|
|
|
class BluetoothSocket;
|
2013-10-29 08:12:46 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-01-16 06:13:58 +00:00
|
|
|
class Call;
|
2012-09-26 13:34:55 +00:00
|
|
|
|
2013-01-11 06:00:04 +00: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-17 04:40:17 +00: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 08:12:46 +00:00
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-17 04:40:17 +00:00
|
|
|
|
2013-04-05 00:54:22 +00:00
|
|
|
class BluetoothHfpManager : public BluetoothSocketObserver
|
2013-05-10 06:39:12 +00:00
|
|
|
, public BluetoothProfileManagerBase
|
2013-06-20 01:19:31 +00:00
|
|
|
, public BatteryObserver
|
2012-09-26 13:34:55 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-06-08 15:26:01 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-06-20 01:19:31 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2013-11-12 03:59:01 +00:00
|
|
|
BT_DECL_PROFILE_MGR_BASE
|
|
|
|
virtual void GetName(nsACString& aName)
|
|
|
|
{
|
|
|
|
aName.AssignLiteral("HFP/HSP");
|
|
|
|
}
|
2013-06-08 15:26:01 +00:00
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
static BluetoothHfpManager* Get();
|
2013-04-05 00:54:22 +00:00
|
|
|
~BluetoothHfpManager();
|
|
|
|
|
2013-09-06 11:20:43 +00:00
|
|
|
// The following functions are inherited from BluetoothSocketObserver
|
2013-04-05 00:54:22 +00:00
|
|
|
virtual void ReceiveSocketData(
|
2013-04-05 00:55:55 +00:00
|
|
|
BluetoothSocket* aSocket,
|
2013-04-05 00:54:22 +00:00
|
|
|
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
|
2013-09-06 11:20:43 +00:00
|
|
|
virtual void OnSocketConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
|
2013-01-16 06:13:41 +00:00
|
|
|
bool Listen();
|
2013-05-10 11:01:10 +00:00
|
|
|
bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
|
|
|
|
bool DisconnectSco();
|
|
|
|
bool ListenSco();
|
2013-11-12 03:59:01 +00:00
|
|
|
bool IsScoConnected();
|
2013-01-16 06:13:41 +00:00
|
|
|
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-01-28 11:28:51 +00: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 12:54:07 +00:00
|
|
|
const nsAString& aError, const nsAString& aNumber,
|
|
|
|
const bool aIsOutgoing, bool aSend);
|
2013-11-11 18:40:50 +00:00
|
|
|
void HandleIccInfoChanged();
|
|
|
|
void HandleVoiceConnectionChanged();
|
2013-05-10 09:47:16 +00:00
|
|
|
|
2013-10-17 04:40:17 +00:00
|
|
|
// CDMA-specific functions
|
|
|
|
void UpdateSecondNumber(const nsAString& aNumber);
|
2013-10-16 02:38:13 +00:00
|
|
|
void AnswerWaitingCall();
|
|
|
|
void IgnoreWaitingCall();
|
|
|
|
void ToggleCalls();
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-10-17 04:40:17 +00:00
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
private:
|
2013-06-24 04:10:07 +00:00
|
|
|
class CloseScoTask;
|
2013-01-16 06:13:41 +00:00
|
|
|
class GetVolumeTask;
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-05-09 14:10:28 +00:00
|
|
|
class RespondToBLDNTask;
|
2013-04-05 00:54:22 +00:00
|
|
|
class SendRingIndicatorTask;
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-04-05 00:54:22 +00:00
|
|
|
|
2013-06-24 04:10:07 +00:00
|
|
|
friend class CloseScoTask;
|
2013-01-16 06:13:41 +00:00
|
|
|
friend class GetVolumeTask;
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-05-09 14:10:28 +00:00
|
|
|
friend class RespondToBLDNTask;
|
2013-04-05 00:54:22 +00:00
|
|
|
friend class SendRingIndicatorTask;
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2012-10-06 00:11:24 +00:00
|
|
|
friend class BluetoothHfpManagerObserver;
|
2013-01-16 06:13:41 +00:00
|
|
|
|
2012-09-26 13:34:55 +00:00
|
|
|
BluetoothHfpManager();
|
2013-06-20 01:20:16 +00:00
|
|
|
void HandleShutdown();
|
|
|
|
void HandleVolumeChanged(const nsAString& aData);
|
2012-12-17 09:44:32 +00:00
|
|
|
|
2012-10-06 00:11:24 +00:00
|
|
|
bool Init();
|
2013-06-20 01:19:31 +00:00
|
|
|
void Notify(const hal::BatteryInformation& aBatteryInfo);
|
2013-01-16 06:13:58 +00:00
|
|
|
void Reset();
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-01-16 06:13:58 +00:00
|
|
|
void ResetCallArray();
|
2013-05-28 06:58:51 +00:00
|
|
|
uint32_t FindFirstCall(uint16_t aState);
|
|
|
|
uint32_t GetNumberOfCalls(uint16_t aState);
|
2013-10-17 04:40:17 +00:00
|
|
|
PhoneType GetPhoneType(const nsAString& aType);
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-01-28 11:28:51 +00:00
|
|
|
|
2013-08-02 10:32:57 +00:00
|
|
|
void NotifyConnectionStatusChanged(const nsAString& aType);
|
2013-09-11 12:56:48 +00:00
|
|
|
void NotifyDialer(const nsAString& aCommand);
|
2013-01-28 11:28:51 +00:00
|
|
|
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-17 04:40:17 +00:00
|
|
|
void SendCCWA(const nsAString& aNumber, int aType);
|
|
|
|
bool SendCLCC(const Call& aCall, int aIndex);
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-06-05 08:53:22 +00:00
|
|
|
bool SendCommand(const char* aCommand, uint32_t aValue = 0);
|
2013-01-16 06:13:41 +00:00
|
|
|
bool SendLine(const char* aMessage);
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-06-07 08:54:13 +00:00
|
|
|
void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend = true);
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-05-10 11:01:10 +00:00
|
|
|
void OnScoConnectSuccess();
|
|
|
|
void OnScoConnectError();
|
|
|
|
void OnScoDisconnect();
|
2013-01-28 11:28:51 +00:00
|
|
|
|
2012-09-27 02:24:39 +00:00
|
|
|
int mCurrentVgs;
|
2013-01-07 08:58:59 +00:00
|
|
|
int mCurrentVgm;
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-06-05 08:53:22 +00:00
|
|
|
bool mBSIR;
|
2013-01-16 06:17:41 +00:00
|
|
|
bool mCCWA;
|
2012-12-17 15:24:35 +00:00
|
|
|
bool mCLIP;
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-01-11 06:00:04 +00:00
|
|
|
bool mCMEE;
|
2013-01-09 06:05:34 +00:00
|
|
|
bool mCMER;
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-04-19 09:08:06 +00:00
|
|
|
bool mFirstCKPD;
|
2013-01-23 01:22:08 +00:00
|
|
|
int mNetworkSelectionMode;
|
2013-10-17 04:40:17 +00:00
|
|
|
PhoneType mPhoneType;
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2012-10-25 10:50:41 +00:00
|
|
|
bool mReceiveVgsFlag;
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-05-31 12:43:18 +00:00
|
|
|
bool mDialingRequestProcessed;
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-05-10 11:01:10 +00:00
|
|
|
nsString mDeviceAddress;
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-12-17 09:44:32 +00:00
|
|
|
nsString mMsisdn;
|
2013-01-23 01:22:08 +00:00
|
|
|
nsString mOperatorName;
|
2013-01-16 06:13:58 +00:00
|
|
|
|
|
|
|
nsTArray<Call> mCurrentCallArray;
|
2013-09-09 11:54:56 +00:00
|
|
|
nsAutoPtr<BluetoothRilListener> mListener;
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2013-10-01 07:26:40 +00:00
|
|
|
nsRefPtr<BluetoothProfileController> mController;
|
2013-05-10 11:01:10 +00:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> mScoRunnable;
|
2013-04-19 09:08:00 +00: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-05 00:54:22 +00:00
|
|
|
nsRefPtr<BluetoothSocket> mSocket;
|
2013-04-19 09:08:00 +00: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 11:01:10 +00:00
|
|
|
nsRefPtr<BluetoothSocket> mScoSocket;
|
|
|
|
SocketConnectionStatus mScoSocketStatus;
|
2013-10-17 04:40:17 +00:00
|
|
|
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-17 04:40:17 +00:00
|
|
|
// CDMA-specific variable
|
|
|
|
Call mCdmaSecondCall;
|
2013-10-29 08:12:46 +00:00
|
|
|
#endif
|
2012-09-26 13:34:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|