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-04-04 17:54:22 -07:00
|
|
|
#include "BluetoothSocketObserver.h"
|
2013-03-06 01:53:23 -08:00
|
|
|
#include "BluetoothTelephonyListener.h"
|
2012-09-26 06:34:55 -07:00
|
|
|
#include "mozilla/ipc/UnixSocket.h"
|
2012-09-25 03:18:38 -07:00
|
|
|
#include "nsIObserver.h"
|
2012-09-26 06:34:55 -07:00
|
|
|
|
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
|
2013-04-04 17:45:06 -07:00
|
|
|
class BluetoothHfpManagerObserver;
|
2013-04-04 17:54:22 -07:00
|
|
|
class BluetoothReplyRunnable;
|
|
|
|
class BluetoothSocket;
|
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-04-04 17:54:22 -07:00
|
|
|
class BluetoothHfpManager : public BluetoothSocketObserver
|
2013-05-09 23:39:12 -07:00
|
|
|
, public BluetoothProfileManagerBase
|
2012-09-26 06:34:55 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static BluetoothHfpManager* Get();
|
2013-04-04 17:54:22 -07:00
|
|
|
~BluetoothHfpManager();
|
|
|
|
|
|
|
|
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-04-04 17:55:55 -07:00
|
|
|
virtual void OnConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
virtual void OnConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
|
|
|
virtual void OnDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
|
2013-05-09 23:39:12 -07:00
|
|
|
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
|
|
|
|
const nsAString& aServiceUuid,
|
|
|
|
int aChannel) MOZ_OVERRIDE;
|
2013-05-22 04:08:21 -07:00
|
|
|
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
|
2013-01-15 22:13:41 -08:00
|
|
|
|
2013-05-22 04:08:21 -07:00
|
|
|
void Connect(const nsAString& aDeviceAddress,
|
2012-10-05 03:48:05 -07:00
|
|
|
const bool aIsHandsfree,
|
2012-09-26 06:34:55 -07:00
|
|
|
BluetoothReplyRunnable* aRunnable);
|
|
|
|
void Disconnect();
|
2013-01-15 22:13:41 -08:00
|
|
|
bool Listen();
|
2013-05-10 04:01:10 -07:00
|
|
|
bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
|
|
|
|
bool DisconnectSco();
|
|
|
|
bool ListenSco();
|
2013-01-15 22:13:41 -08:00
|
|
|
|
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-05-10 02:47:16 -07:00
|
|
|
const nsAString& aNumber, const bool aIsOutgoing,
|
|
|
|
bool aSend);
|
|
|
|
|
2013-04-04 17:54:22 -07:00
|
|
|
bool IsConnected();
|
2013-05-10 04:01:10 -07:00
|
|
|
bool IsScoConnected();
|
2013-04-26 03:48:21 -07:00
|
|
|
void GetAddress(nsAString& aDeviceAddress);
|
2012-10-02 22:53:39 -07:00
|
|
|
|
2012-09-26 06:34:55 -07:00
|
|
|
private:
|
2013-01-15 22:13:41 -08:00
|
|
|
class GetVolumeTask;
|
2013-05-09 07:10:28 -07:00
|
|
|
class RespondToBLDNTask;
|
2013-04-04 17:54:22 -07:00
|
|
|
class SendRingIndicatorTask;
|
|
|
|
|
2013-01-15 22:13:41 -08:00
|
|
|
friend class GetVolumeTask;
|
2013-05-09 07:10:28 -07:00
|
|
|
friend class RespondToBLDNTask;
|
2013-04-04 17:54:22 -07:00
|
|
|
friend class SendRingIndicatorTask;
|
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();
|
2012-12-17 01:44:32 -08:00
|
|
|
nsresult HandleIccInfoChanged();
|
2012-12-19 23:28:51 -08:00
|
|
|
nsresult HandleShutdown();
|
|
|
|
nsresult HandleVolumeChanged(const nsAString& aData);
|
|
|
|
nsresult HandleVoiceConnectionChanged();
|
2012-12-17 01:44:32 -08:00
|
|
|
|
2012-10-05 17:11:24 -07:00
|
|
|
bool Init();
|
|
|
|
void Cleanup();
|
2013-01-15 22:13:58 -08:00
|
|
|
void Reset();
|
|
|
|
void ResetCallArray();
|
2013-01-28 03:28:51 -08:00
|
|
|
|
|
|
|
void NotifyDialer(const nsAString& aCommand);
|
2013-05-10 23:06:16 -07:00
|
|
|
void NotifyStatusChanged(const nsAString& aType);
|
2013-05-10 04:01:10 -07:00
|
|
|
void NotifyAudioManager(const nsAString& aAddress);
|
2013-01-28 03:28:51 -08:00
|
|
|
|
|
|
|
bool SendCommand(const char* aCommand, uint8_t aValue = 0);
|
2013-01-15 22:13:41 -08:00
|
|
|
bool SendLine(const char* aMessage);
|
2013-01-28 03:28:51 -08:00
|
|
|
void UpdateCIND(uint8_t aType, uint8_t aValue, bool aSend);
|
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-01-15 22:13:58 -08:00
|
|
|
uint32_t mCurrentCallIndex;
|
2013-01-15 22:17:41 -08:00
|
|
|
bool mCCWA;
|
2012-12-17 07:24:35 -08:00
|
|
|
bool mCLIP;
|
2013-01-10 22:00:04 -08:00
|
|
|
bool mCMEE;
|
2013-01-08 22:05:34 -08:00
|
|
|
bool mCMER;
|
2013-04-19 02:08:06 -07:00
|
|
|
bool mFirstCKPD;
|
2013-01-22 17:22:08 -08:00
|
|
|
int mNetworkSelectionMode;
|
2012-10-25 03:50:41 -07:00
|
|
|
bool mReceiveVgsFlag;
|
2013-05-09 07:10:28 -07:00
|
|
|
bool mBLDNProcessed;
|
2013-05-22 04:08:21 -07:00
|
|
|
bool mIsHandsfree;
|
|
|
|
bool mNeedsUpdatingSdpRecords;
|
2013-05-10 04:01:10 -07:00
|
|
|
nsString mDeviceAddress;
|
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-03-06 01:53:23 -08:00
|
|
|
nsAutoPtr<BluetoothTelephonyListener> mListener;
|
2012-11-07 15:48:39 -08:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
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;
|
2012-09-26 06:34:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|