Bug 911986 - [HFP] Implement RilListener for voice connection and ICC info change, r=echou

This commit is contained in:
Ben Tian 2013-09-09 19:54:56 +08:00
parent 2ecba30868
commit f06d3327ac
7 changed files with 394 additions and 198 deletions

View File

@ -54,8 +54,6 @@
#define CR_LF "\xd\xa";
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
#define MOBILE_CONNECTION_ICCINFO_CHANGED_ID "mobile-connection-iccinfo-changed"
#define MOBILE_CONNECTION_VOICE_CHANGED_ID "mobile-connection-voice-changed"
#define AUDIO_VOLUME_BT_SCO_ID "audio.volume.bt_sco"
using namespace mozilla;
@ -203,10 +201,6 @@ BluetoothHfpManager::Observe(nsISupports* aSubject,
HandleVolumeChanged(nsDependentString(aData));
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
HandleShutdown();
} else if (!strcmp(aTopic, MOBILE_CONNECTION_ICCINFO_CHANGED_ID)) {
HandleIccInfoChanged();
} else if (!strcmp(aTopic, MOBILE_CONNECTION_VOICE_CHANGED_ID)) {
HandleVoiceConnectionChanged();
} else {
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
return NS_ERROR_UNEXPECTED;
@ -372,16 +366,14 @@ BluetoothHfpManager::Init()
NS_ENSURE_TRUE(obs, false);
if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false)) ||
NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false)) ||
NS_FAILED(obs->AddObserver(this, MOBILE_CONNECTION_ICCINFO_CHANGED_ID, false)) ||
NS_FAILED(obs->AddObserver(this, MOBILE_CONNECTION_VOICE_CHANGED_ID, false))) {
NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
BT_WARNING("Failed to add observers!");
return false;
}
hal::RegisterBatteryObserver(this);
mListener = new BluetoothTelephonyListener();
mListener = new BluetoothRilListener();
if (!mListener->StartListening()) {
NS_WARNING("Failed to start listening RIL");
return false;
@ -421,9 +413,7 @@ BluetoothHfpManager::~BluetoothHfpManager()
NS_ENSURE_TRUE_VOID(obs);
if (NS_FAILED(obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) ||
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID)) ||
NS_FAILED(obs->RemoveObserver(this, MOBILE_CONNECTION_ICCINFO_CHANGED_ID)) ||
NS_FAILED(obs->RemoveObserver(this, MOBILE_CONNECTION_VOICE_CHANGED_ID))) {
NS_FAILED(obs->RemoveObserver(this, MOZSETTINGS_CHANGED_ID))) {
BT_WARNING("Failed to remove observers!");
}
@ -1454,6 +1444,7 @@ void
BluetoothHfpManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket);
MOZ_ASSERT(mListener);
// Success to create a SCO socket
if (aSocket == mScoSocket) {
@ -1482,10 +1473,8 @@ BluetoothHfpManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
mHandsfreeSocket = nullptr;
}
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(TELEPHONY_PROVIDER_CONTRACTID);
NS_ENSURE_TRUE_VOID(provider);
provider->EnumerateCalls(mListener->GetListener());
// Enumerate current calls
mListener->EnumerateCalls();
mFirstCKPD = true;

View File

@ -9,8 +9,8 @@
#include "BluetoothCommon.h"
#include "BluetoothProfileManagerBase.h"
#include "BluetoothRilListener.h"
#include "BluetoothSocketObserver.h"
#include "BluetoothTelephonyListener.h"
#include "mozilla/ipc/UnixSocket.h"
#include "mozilla/Hal.h"
@ -92,6 +92,8 @@ public:
void HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
const nsAString& aError, const nsAString& aNumber,
const bool aIsOutgoing, bool aSend);
void HandleIccInfoChanged();
void HandleVoiceConnectionChanged();
bool IsConnected();
bool IsScoConnected();
@ -109,10 +111,8 @@ private:
friend class BluetoothHfpManagerObserver;
BluetoothHfpManager();
void HandleIccInfoChanged();
void HandleShutdown();
void HandleVolumeChanged(const nsAString& aData);
void HandleVoiceConnectionChanged();
bool Init();
void Notify(const hal::BatteryInformation& aBatteryInfo);
@ -150,7 +150,7 @@ private:
nsString mOperatorName;
nsTArray<Call> mCurrentCallArray;
nsAutoPtr<BluetoothTelephonyListener> mListener;
nsAutoPtr<BluetoothRilListener> mListener;
nsRefPtr<BluetoothReplyRunnable> mRunnable;
BluetoothProfileController* mController;
nsRefPtr<BluetoothReplyRunnable> mScoRunnable;

View File

@ -0,0 +1,336 @@
/* -*- 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/. */
#include "BluetoothRilListener.h"
#include "BluetoothHfpManager.h"
#include "nsIIccProvider.h"
#include "nsIMobileConnectionProvider.h"
#include "nsITelephonyProvider.h"
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
#include "nsString.h"
USING_BLUETOOTH_NAMESPACE
namespace {
/**
* IccListener
*/
class IccListener : public nsIIccListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIICCLISTENER
IccListener() { }
};
NS_IMPL_ISUPPORTS1(IccListener, nsIIccListener)
NS_IMETHODIMP
IccListener::NotifyIccInfoChanged()
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleIccInfoChanged();
return NS_OK;
}
NS_IMETHODIMP
IccListener::NotifyStkCommand(const nsAString & aMessage)
{
return NS_OK;
}
NS_IMETHODIMP
IccListener::NotifyStkSessionEnd()
{
return NS_OK;
}
NS_IMETHODIMP
IccListener::NotifyIccCardLockError(const nsAString & lockType,
uint32_t retryCount)
{
return NS_OK;
}
NS_IMETHODIMP
IccListener::NotifyCardStateChanged()
{
return NS_OK;
}
/**
* MobileConnectionListener
*/
class MobileConnectionListener : public nsIMobileConnectionListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMOBILECONNECTIONLISTENER
MobileConnectionListener() { }
};
NS_IMPL_ISUPPORTS1(MobileConnectionListener, nsIMobileConnectionListener)
NS_IMETHODIMP
MobileConnectionListener::NotifyVoiceChanged()
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleVoiceConnectionChanged();
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionListener::NotifyDataChanged()
{
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionListener::NotifyUssdReceived(const nsAString & message,
bool sessionEnded)
{
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionListener::NotifyDataError(const nsAString & message)
{
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionListener::NotifyCFStateChange(bool success,
uint16_t action,
uint16_t reason,
const nsAString& number,
uint16_t timeSeconds,
uint16_t serviceClass)
{
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionListener::NotifyEmergencyCbModeChanged(bool active,
uint32_t timeoutMs)
{
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionListener::NotifyOtaStatusChanged(const nsAString & status)
{
return NS_OK;
}
/**
* TelephonyListener Implementation
*/
class TelephonyListener : public nsITelephonyListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITELEPHONYLISTENER
TelephonyListener() { }
};
NS_IMPL_ISUPPORTS1(TelephonyListener, nsITelephonyListener)
NS_IMETHODIMP
TelephonyListener::CallStateChanged(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
bool aIsActive,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, EmptyString(), aNumber,
aIsOutgoing, true);
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::EnumerateCallState(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString_internal& aNumber,
bool aIsActive,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, EmptyString(), aNumber,
aIsOutgoing, false);
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::NotifyError(int32_t aCallIndex,
const nsAString& aError)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
if (aCallIndex > 0) {
// In order to not miss any related call state transition.
// It's possible that 3G network signal lost for unknown reason.
// If a call is released abnormally, NotifyError() will be called,
// instead of CallStateChanged(). We need to reset the call array state
// via setting CALL_STATE_DISCONNECTED
hfp->HandleCallStateChanged(aCallIndex,
nsITelephonyProvider::CALL_STATE_DISCONNECTED,
aError, EmptyString(), false, true);
NS_WARNING("Reset the call state due to call transition ends abnormally");
}
NS_WARNING(NS_ConvertUTF16toUTF8(aError).get());
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::ConferenceCallStateChanged(uint16_t aCallState)
{
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::EnumerateCallStateComplete()
{
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::SupplementaryServiceNotification(int32_t aCallIndex,
uint16_t aNotification)
{
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::NotifyCdmaCallWaiting(const nsAString& aNumber)
{
return NS_OK;
}
} // anonymous namespace
/**
* BluetoothRilListener
*/
BluetoothRilListener::BluetoothRilListener()
{
mIccListener = new IccListener();
mMobileConnectionListener = new MobileConnectionListener();
mTelephonyListener = new TelephonyListener();
}
bool
BluetoothRilListener::StartListening()
{
NS_ENSURE_TRUE(StartIccListening(), false);
NS_ENSURE_TRUE(StartMobileConnectionListening(), false);
NS_ENSURE_TRUE(StartTelephonyListening(), false);
return true;
}
bool
BluetoothRilListener::StopListening()
{
NS_ENSURE_TRUE(StopIccListening(), false);
NS_ENSURE_TRUE(StopMobileConnectionListening(), false);
NS_ENSURE_TRUE(StopTelephonyListening(), false);
return true;
}
void
BluetoothRilListener::EnumerateCalls()
{
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(TELEPHONY_PROVIDER_CONTRACTID);
NS_ENSURE_TRUE_VOID(provider);
provider->EnumerateCalls(mTelephonyListener);
}
// private
bool
BluetoothRilListener::StartIccListening()
{
nsCOMPtr<nsIIccProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->RegisterIccMsg(mIccListener);
return NS_SUCCEEDED(rv);
}
bool
BluetoothRilListener::StopIccListening()
{
nsCOMPtr<nsIIccProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->UnregisterIccMsg(mIccListener);
return NS_SUCCEEDED(rv);
}
bool
BluetoothRilListener::StartMobileConnectionListening()
{
nsCOMPtr<nsIMobileConnectionProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->
RegisterMobileConnectionMsg(mMobileConnectionListener);
return NS_SUCCEEDED(rv);
}
bool
BluetoothRilListener::StopMobileConnectionListening()
{
nsCOMPtr<nsIMobileConnectionProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->
UnregisterMobileConnectionMsg(mMobileConnectionListener);
return NS_SUCCEEDED(rv);
}
bool
BluetoothRilListener::StartTelephonyListening()
{
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(TELEPHONY_PROVIDER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->RegisterListener(mTelephonyListener);
return NS_SUCCEEDED(rv);
}
bool
BluetoothRilListener::StopTelephonyListening()
{
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(TELEPHONY_PROVIDER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->UnregisterListener(mTelephonyListener);
return NS_SUCCEEDED(rv);
}

View File

@ -0,0 +1,47 @@
/* -*- 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_bluetoothrillistener_h__
#define mozilla_dom_bluetooth_bluetoothrillistener_h__
#include "BluetoothCommon.h"
#include "nsCOMPtr.h"
class nsIIccListener;
class nsIMobileConnectionListener;
class nsITelephonyListener;
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothRilListener
{
public:
BluetoothRilListener();
bool StartListening();
bool StopListening();
void EnumerateCalls();
private:
bool StartIccListening();
bool StopIccListening();
bool StartMobileConnectionListening();
bool StopMobileConnectionListening();
bool StartTelephonyListening();
bool StopTelephonyListening();
nsCOMPtr<nsIIccListener> mIccListener;
nsCOMPtr<nsIMobileConnectionListener> mMobileConnectionListener;
nsCOMPtr<nsITelephonyListener> mTelephonyListener;
};
END_BLUETOOTH_NAMESPACE
#endif

View File

@ -1,143 +0,0 @@
/* -*- 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/. */
#include "BluetoothTelephonyListener.h"
#include "BluetoothHfpManager.h"
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
#include "nsString.h"
USING_BLUETOOTH_NAMESPACE
namespace {
class TelephonyListener : public nsITelephonyListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITELEPHONYLISTENER
TelephonyListener() { }
};
NS_IMPL_ISUPPORTS1(TelephonyListener, nsITelephonyListener)
NS_IMETHODIMP
TelephonyListener::CallStateChanged(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
bool aIsActive,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, EmptyString(), aNumber,
aIsOutgoing, true);
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::ConferenceCallStateChanged(uint16_t aCallState)
{
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::EnumerateCallStateComplete()
{
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::EnumerateCallState(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString_internal& aNumber,
bool aIsActive,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, EmptyString(), aNumber,
aIsOutgoing, false);
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::SupplementaryServiceNotification(int32_t aCallIndex,
uint16_t aNotification)
{
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::NotifyError(int32_t aCallIndex,
const nsAString& aError)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
if (aCallIndex > 0) {
// In order to not miss any related call state transition.
// It's possible that 3G network signal lost for unknown reason.
// If a call is released abnormally, NotifyError() will be called,
// instead of CallStateChanged(). We need to reset the call array state
// via setting CALL_STATE_DISCONNECTED
hfp->HandleCallStateChanged(aCallIndex,
nsITelephonyProvider::CALL_STATE_DISCONNECTED,
aError, EmptyString(), false, true);
NS_WARNING("Reset the call state due to call transition ends abnormally");
}
NS_WARNING(NS_ConvertUTF16toUTF8(aError).get());
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::NotifyCdmaCallWaiting(const nsAString& aNumber)
{
return NS_OK;
}
} // anonymous namespace
BluetoothTelephonyListener::BluetoothTelephonyListener()
{
mTelephonyListener = new TelephonyListener();
}
bool
BluetoothTelephonyListener::StartListening()
{
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(TELEPHONY_PROVIDER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->RegisterListener(mTelephonyListener);
NS_ENSURE_SUCCESS(rv, false);
return true;
}
bool
BluetoothTelephonyListener::StopListening()
{
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(TELEPHONY_PROVIDER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->UnregisterListener(mTelephonyListener);
return NS_FAILED(rv) ? false : true;
}
nsITelephonyListener*
BluetoothTelephonyListener::GetListener()
{
return mTelephonyListener;
}

View File

@ -1,33 +0,0 @@
/* -*- 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_bluetoothtelephonylistener_h__
#define mozilla_dom_bluetooth_bluetoothtelephonylistener_h__
#include "BluetoothCommon.h"
#include "nsCOMPtr.h"
#include "nsITelephonyProvider.h"
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothTelephonyListener
{
public:
BluetoothTelephonyListener();
bool StartListening();
bool StopListening();
nsITelephonyListener* GetListener();
private:
nsCOMPtr<nsITelephonyListener> mTelephonyListener;
};
END_BLUETOOTH_NAMESPACE
#endif

View File

@ -49,7 +49,7 @@ if CONFIG['MOZ_B2G_BT']:
if CONFIG['MOZ_B2G_RIL']:
CPP_SOURCES += [
'BluetoothTelephonyListener.cpp',
'BluetoothRilListener.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':