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

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

mercurial