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