dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,189 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_bluetooth_bluetoothhfpmanager_h__
    1.11 +#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
    1.12 +
    1.13 +#include <hardware/bluetooth.h>
    1.14 +#include <hardware/bt_hf.h>
    1.15 +
    1.16 +#include "BluetoothCommon.h"
    1.17 +#include "BluetoothHfpManagerBase.h"
    1.18 +#include "BluetoothRilListener.h"
    1.19 +#include "BluetoothSocketObserver.h"
    1.20 +#include "mozilla/ipc/UnixSocket.h"
    1.21 +#include "mozilla/Hal.h"
    1.22 +
    1.23 +BEGIN_BLUETOOTH_NAMESPACE
    1.24 +
    1.25 +class BluetoothReplyRunnable;
    1.26 +class BluetoothSocket;
    1.27 +class Call;
    1.28 +
    1.29 +/**
    1.30 + * These costants are defined in 4.33.2 "AT Capabilities Re-Used from GSM 07.07
    1.31 + * and 3GPP 27.007" in Bluetooth hands-free profile 1.6
    1.32 + */
    1.33 +enum BluetoothCmeError {
    1.34 +  AG_FAILURE = 0,
    1.35 +  NO_CONNECTION_TO_PHONE = 1,
    1.36 +  OPERATION_NOT_ALLOWED = 3,
    1.37 +  OPERATION_NOT_SUPPORTED = 4,
    1.38 +  PIN_REQUIRED = 5,
    1.39 +  SIM_NOT_INSERTED = 10,
    1.40 +  SIM_PIN_REQUIRED = 11,
    1.41 +  SIM_PUK_REQUIRED = 12,
    1.42 +  SIM_FAILURE = 13,
    1.43 +  SIM_BUSY = 14,
    1.44 +  INCORRECT_PASSWORD = 16,
    1.45 +  SIM_PIN2_REQUIRED = 17,
    1.46 +  SIM_PUK2_REQUIRED = 18,
    1.47 +  MEMORY_FULL = 20,
    1.48 +  INVALID_INDEX = 21,
    1.49 +  MEMORY_FAILURE = 23,
    1.50 +  TEXT_STRING_TOO_LONG = 24,
    1.51 +  INVALID_CHARACTERS_IN_TEXT_STRING = 25,
    1.52 +  DIAL_STRING_TOO_LONG = 26,
    1.53 +  INVALID_CHARACTERS_IN_DIAL_STRING = 27,
    1.54 +  NO_NETWORK_SERVICE = 30,
    1.55 +  NETWORK_TIMEOUT = 31,
    1.56 +  NETWORK_NOT_ALLOWED = 32
    1.57 +};
    1.58 +
    1.59 +enum PhoneType {
    1.60 +  NONE, // no connection
    1.61 +  GSM,
    1.62 +  CDMA
    1.63 +};
    1.64 +
    1.65 +class Call {
    1.66 +public:
    1.67 +  Call();
    1.68 +  void Set(const nsAString& aNumber, const bool aIsOutgoing);
    1.69 +  void Reset();
    1.70 +  bool IsActive();
    1.71 +
    1.72 +  uint16_t mState;
    1.73 +  nsString mNumber;
    1.74 +  bthf_call_direction_t mDirection; // 0: outgoing call; 1: incoming call
    1.75 +  bthf_call_addrtype_t mType;
    1.76 +};
    1.77 +
    1.78 +class BluetoothHfpManager : public BluetoothHfpManagerBase
    1.79 +                          , public BatteryObserver
    1.80 +{
    1.81 +public:
    1.82 +  BT_DECL_HFP_MGR_BASE
    1.83 +  virtual void GetName(nsACString& aName)
    1.84 +  {
    1.85 +    aName.AssignLiteral("HFP/HSP");
    1.86 +  }
    1.87 +
    1.88 +  static BluetoothHfpManager* Get();
    1.89 +  virtual ~BluetoothHfpManager();
    1.90 +
    1.91 +  bool ConnectSco();
    1.92 +  bool DisconnectSco();
    1.93 +
    1.94 +  /**
    1.95 +   * @param aSend A boolean indicates whether we need to notify headset or not
    1.96 +   */
    1.97 +  void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
    1.98 +                              const nsAString& aError, const nsAString& aNumber,
    1.99 +                              const bool aIsOutgoing, const bool aIsConference,
   1.100 +                              bool aSend);
   1.101 +  void HandleIccInfoChanged(uint32_t aClientId);
   1.102 +  void HandleVoiceConnectionChanged(uint32_t aClientId);
   1.103 +
   1.104 +  // Bluedroid hfp callback handlers
   1.105 +  void ProcessConnectionState(bthf_connection_state_t aState, bt_bdaddr_t* aBdAddress);
   1.106 +  void ProcessAudioState(bthf_audio_state_t aState, bt_bdaddr_t* aBdAddress);
   1.107 +  void ProcessAnswerCall();
   1.108 +  void ProcessHangupCall();
   1.109 +  void ProcessVolumeControl(bthf_volume_type_t aType, int aVolume);
   1.110 +  void ProcessDialCall(char *aNumber);
   1.111 +  void ProcessDtmfCmd(char aDtmf);
   1.112 +  void ProcessAtChld(bthf_chld_type_t aChld);
   1.113 +  void ProcessAtCnum();
   1.114 +  void ProcessAtCind();
   1.115 +  void ProcessAtCops();
   1.116 +  void ProcessAtClcc();
   1.117 +  void ProcessUnknownAt(char *aAtString);
   1.118 +  void ProcessKeyPressed();
   1.119 +
   1.120 +  // CDMA-specific functions
   1.121 +  void UpdateSecondNumber(const nsAString& aNumber);
   1.122 +  void AnswerWaitingCall();
   1.123 +  void IgnoreWaitingCall();
   1.124 +  void ToggleCalls();
   1.125 +
   1.126 +private:
   1.127 +  class GetVolumeTask;
   1.128 +  class CloseScoTask;
   1.129 +  class RespondToBLDNTask;
   1.130 +  class MainThreadTask;
   1.131 +
   1.132 +  friend class BluetoothHfpManagerObserver;
   1.133 +  friend class GetVolumeTask;
   1.134 +  friend class CloseScoTask;
   1.135 +  friend class RespondToBLDNTask;
   1.136 +  friend class MainThreadTask;
   1.137 +
   1.138 +  BluetoothHfpManager();
   1.139 +  bool Init();
   1.140 +  bool InitHfpInterface();
   1.141 +  void DeinitHfpInterface();
   1.142 +
   1.143 +  void HandleShutdown();
   1.144 +  void HandleVolumeChanged(const nsAString& aData);
   1.145 +  void Notify(const hal::BatteryInformation& aBatteryInfo);
   1.146 +
   1.147 +  void NotifyConnectionStateChanged(const nsAString& aType);
   1.148 +  void NotifyDialer(const nsAString& aCommand);
   1.149 +
   1.150 +  PhoneType GetPhoneType(const nsAString& aType);
   1.151 +  void ResetCallArray();
   1.152 +  uint32_t FindFirstCall(uint16_t aState);
   1.153 +  uint32_t GetNumberOfCalls(uint16_t aState);
   1.154 +  uint16_t GetCallSetupState();
   1.155 +  bool IsTransitionState(uint16_t aCallState, bool aIsConference);
   1.156 +  bthf_call_state_t ConvertToBthfCallState(int aCallState);
   1.157 +
   1.158 +  void UpdatePhoneCIND(uint32_t aCallIndex);
   1.159 +  void UpdateDeviceCIND();
   1.160 +  void SendCLCC(Call& aCall, int aIndex);
   1.161 +  void SendLine(const char* aMessage);
   1.162 +  void SendResponse(bthf_at_response_t aResponseCode);
   1.163 +
   1.164 +  int mConnectionState;
   1.165 +  int mPrevConnectionState;
   1.166 +  int mAudioState;
   1.167 +  // Device CIND
   1.168 +  int mBattChg;
   1.169 +  int mService;
   1.170 +  int mRoam;
   1.171 +  int mSignal;
   1.172 +
   1.173 +  int mCurrentVgs;
   1.174 +  int mCurrentVgm;
   1.175 +  bool mReceiveVgsFlag;
   1.176 +  bool mDialingRequestProcessed;
   1.177 +  PhoneType mPhoneType;
   1.178 +  nsString mDeviceAddress;
   1.179 +  nsString mMsisdn;
   1.180 +  nsString mOperatorName;
   1.181 +
   1.182 +  nsTArray<Call> mCurrentCallArray;
   1.183 +  nsAutoPtr<BluetoothRilListener> mListener;
   1.184 +  nsRefPtr<BluetoothProfileController> mController;
   1.185 +
   1.186 +  // CDMA-specific variable
   1.187 +  Call mCdmaSecondCall;
   1.188 +};
   1.189 +
   1.190 +END_BLUETOOTH_NAMESPACE
   1.191 +
   1.192 +#endif

mercurial