dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     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 <hardware/bluetooth.h>
    11 #include <hardware/bt_hf.h>
    13 #include "BluetoothCommon.h"
    14 #include "BluetoothHfpManagerBase.h"
    15 #include "BluetoothRilListener.h"
    16 #include "BluetoothSocketObserver.h"
    17 #include "mozilla/ipc/UnixSocket.h"
    18 #include "mozilla/Hal.h"
    20 BEGIN_BLUETOOTH_NAMESPACE
    22 class BluetoothReplyRunnable;
    23 class BluetoothSocket;
    24 class Call;
    26 /**
    27  * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
    28  * and 3GPP 27.007" in Bluetooth hands-free profile 1.6
    29  */
    30 enum BluetoothCmeError {
    31   AG_FAILURE = 0,
    32   NO_CONNECTION_TO_PHONE = 1,
    33   OPERATION_NOT_ALLOWED = 3,
    34   OPERATION_NOT_SUPPORTED = 4,
    35   PIN_REQUIRED = 5,
    36   SIM_NOT_INSERTED = 10,
    37   SIM_PIN_REQUIRED = 11,
    38   SIM_PUK_REQUIRED = 12,
    39   SIM_FAILURE = 13,
    40   SIM_BUSY = 14,
    41   INCORRECT_PASSWORD = 16,
    42   SIM_PIN2_REQUIRED = 17,
    43   SIM_PUK2_REQUIRED = 18,
    44   MEMORY_FULL = 20,
    45   INVALID_INDEX = 21,
    46   MEMORY_FAILURE = 23,
    47   TEXT_STRING_TOO_LONG = 24,
    48   INVALID_CHARACTERS_IN_TEXT_STRING = 25,
    49   DIAL_STRING_TOO_LONG = 26,
    50   INVALID_CHARACTERS_IN_DIAL_STRING = 27,
    51   NO_NETWORK_SERVICE = 30,
    52   NETWORK_TIMEOUT = 31,
    53   NETWORK_NOT_ALLOWED = 32
    54 };
    56 enum PhoneType {
    57   NONE, // no connection
    58   GSM,
    59   CDMA
    60 };
    62 class Call {
    63 public:
    64   Call();
    65   void Set(const nsAString& aNumber, const bool aIsOutgoing);
    66   void Reset();
    67   bool IsActive();
    69   uint16_t mState;
    70   nsString mNumber;
    71   bthf_call_direction_t mDirection; // 0: outgoing call; 1: incoming call
    72   bthf_call_addrtype_t mType;
    73 };
    75 class BluetoothHfpManager : public BluetoothHfpManagerBase
    76                           , public BatteryObserver
    77 {
    78 public:
    79   BT_DECL_HFP_MGR_BASE
    80   virtual void GetName(nsACString& aName)
    81   {
    82     aName.AssignLiteral("HFP/HSP");
    83   }
    85   static BluetoothHfpManager* Get();
    86   virtual ~BluetoothHfpManager();
    88   bool ConnectSco();
    89   bool DisconnectSco();
    91   /**
    92    * @param aSend A boolean indicates whether we need to notify headset or not
    93    */
    94   void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
    95                               const nsAString& aError, const nsAString& aNumber,
    96                               const bool aIsOutgoing, const bool aIsConference,
    97                               bool aSend);
    98   void HandleIccInfoChanged(uint32_t aClientId);
    99   void HandleVoiceConnectionChanged(uint32_t aClientId);
   101   // Bluedroid hfp callback handlers
   102   void ProcessConnectionState(bthf_connection_state_t aState, bt_bdaddr_t* aBdAddress);
   103   void ProcessAudioState(bthf_audio_state_t aState, bt_bdaddr_t* aBdAddress);
   104   void ProcessAnswerCall();
   105   void ProcessHangupCall();
   106   void ProcessVolumeControl(bthf_volume_type_t aType, int aVolume);
   107   void ProcessDialCall(char *aNumber);
   108   void ProcessDtmfCmd(char aDtmf);
   109   void ProcessAtChld(bthf_chld_type_t aChld);
   110   void ProcessAtCnum();
   111   void ProcessAtCind();
   112   void ProcessAtCops();
   113   void ProcessAtClcc();
   114   void ProcessUnknownAt(char *aAtString);
   115   void ProcessKeyPressed();
   117   // CDMA-specific functions
   118   void UpdateSecondNumber(const nsAString& aNumber);
   119   void AnswerWaitingCall();
   120   void IgnoreWaitingCall();
   121   void ToggleCalls();
   123 private:
   124   class GetVolumeTask;
   125   class CloseScoTask;
   126   class RespondToBLDNTask;
   127   class MainThreadTask;
   129   friend class BluetoothHfpManagerObserver;
   130   friend class GetVolumeTask;
   131   friend class CloseScoTask;
   132   friend class RespondToBLDNTask;
   133   friend class MainThreadTask;
   135   BluetoothHfpManager();
   136   bool Init();
   137   bool InitHfpInterface();
   138   void DeinitHfpInterface();
   140   void HandleShutdown();
   141   void HandleVolumeChanged(const nsAString& aData);
   142   void Notify(const hal::BatteryInformation& aBatteryInfo);
   144   void NotifyConnectionStateChanged(const nsAString& aType);
   145   void NotifyDialer(const nsAString& aCommand);
   147   PhoneType GetPhoneType(const nsAString& aType);
   148   void ResetCallArray();
   149   uint32_t FindFirstCall(uint16_t aState);
   150   uint32_t GetNumberOfCalls(uint16_t aState);
   151   uint16_t GetCallSetupState();
   152   bool IsTransitionState(uint16_t aCallState, bool aIsConference);
   153   bthf_call_state_t ConvertToBthfCallState(int aCallState);
   155   void UpdatePhoneCIND(uint32_t aCallIndex);
   156   void UpdateDeviceCIND();
   157   void SendCLCC(Call& aCall, int aIndex);
   158   void SendLine(const char* aMessage);
   159   void SendResponse(bthf_at_response_t aResponseCode);
   161   int mConnectionState;
   162   int mPrevConnectionState;
   163   int mAudioState;
   164   // Device CIND
   165   int mBattChg;
   166   int mService;
   167   int mRoam;
   168   int mSignal;
   170   int mCurrentVgs;
   171   int mCurrentVgm;
   172   bool mReceiveVgsFlag;
   173   bool mDialingRequestProcessed;
   174   PhoneType mPhoneType;
   175   nsString mDeviceAddress;
   176   nsString mMsisdn;
   177   nsString mOperatorName;
   179   nsTArray<Call> mCurrentCallArray;
   180   nsAutoPtr<BluetoothRilListener> mListener;
   181   nsRefPtr<BluetoothProfileController> mController;
   183   // CDMA-specific variable
   184   Call mCdmaSecondCall;
   185 };
   187 END_BLUETOOTH_NAMESPACE
   189 #endif

mercurial