mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 939672 - Patch 1/2: [bluedroid] Add fallback BluetoothHfpManager, r=gyeh
--HG-- rename : dom/bluetooth/bluedroid/BluetoothHfpManager.cpp => dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp rename : dom/bluetooth/bluedroid/BluetoothHfpManager.h => dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
This commit is contained in:
parent
4b6621275d
commit
c16cd5a358
183
dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.cpp
Normal file
183
dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.cpp
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
/* -*- 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 "base/basictypes.h"
|
||||||
|
#include "BluetoothHfpManager.h"
|
||||||
|
#include "BluetoothProfileController.h"
|
||||||
|
#include "mozilla/Services.h"
|
||||||
|
#include "mozilla/StaticPtr.h"
|
||||||
|
#include "nsIObserverService.h"
|
||||||
|
#include "nsThreadUtils.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
USING_BLUETOOTH_NAMESPACE
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
|
||||||
|
bool sInShutdown = false;
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nsIObserver function
|
||||||
|
*/
|
||||||
|
NS_IMETHODIMP
|
||||||
|
BluetoothHfpManager::Observe(nsISupports* aSubject,
|
||||||
|
const char* aTopic,
|
||||||
|
const char16_t* aData)
|
||||||
|
{
|
||||||
|
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||||
|
HandleShutdown();
|
||||||
|
} else {
|
||||||
|
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BluetoothProfileManagerBase functions
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||||
|
BluetoothProfileController* aController)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aController);
|
||||||
|
|
||||||
|
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aController);
|
||||||
|
|
||||||
|
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
BluetoothHfpManager::IsConnected()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
|
||||||
|
{
|
||||||
|
aDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
|
||||||
|
const nsAString& aServiceUuid,
|
||||||
|
int aChannel)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BluetoothHfpManagerBase function
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
BluetoothHfpManager::IsScoConnected()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non-inherited functions
|
||||||
|
*/
|
||||||
|
// static
|
||||||
|
BluetoothHfpManager*
|
||||||
|
BluetoothHfpManager::Get()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
// If sBluetoothHfpManager already exists, exit early
|
||||||
|
if (sBluetoothHfpManager) {
|
||||||
|
return sBluetoothHfpManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're in shutdown, don't create a new instance
|
||||||
|
NS_ENSURE_FALSE(sInShutdown, nullptr);
|
||||||
|
|
||||||
|
// Create a new instance and return
|
||||||
|
BluetoothHfpManager* manager = new BluetoothHfpManager();
|
||||||
|
NS_ENSURE_TRUE(manager->Init(), nullptr);
|
||||||
|
|
||||||
|
sBluetoothHfpManager = manager;
|
||||||
|
return sBluetoothHfpManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
BluetoothHfpManager::Init()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||||
|
NS_ENSURE_TRUE(obs, false);
|
||||||
|
|
||||||
|
if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
|
||||||
|
BT_WARNING("Failed to add observers!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BluetoothHfpManager::HandleShutdown()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
sInShutdown = true;
|
||||||
|
sBluetoothHfpManager = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
BluetoothHfpManager::ConnectSco()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO:
|
||||||
|
* Implement ConnectSco() for applications that want to create SCO link
|
||||||
|
* without a HFP connection (e.g., VoIP).
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
BluetoothHfpManager::DisconnectSco()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO:
|
||||||
|
* Implement DisconnectSco() for applications that want to destroy SCO link
|
||||||
|
* without a HFP connection (e.g., VoIP).
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS1(BluetoothHfpManager, nsIObserver)
|
47
dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.h
Normal file
47
dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.h
Normal 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_bluetoothhfpmanager_h__
|
||||||
|
#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
|
||||||
|
|
||||||
|
#include "BluetoothHfpManagerBase.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback BluetoothHfpManager is built for non-phone devices (e.g., tablets).
|
||||||
|
* These devices has no radio interface and the build flag MOZ_B2G_RIL is
|
||||||
|
* disabled. To prevent build breaks of accessing radio interface, we implement
|
||||||
|
* fallback BluetoothHfpManager with empty functions to keep original
|
||||||
|
* BluetoothHfpManager away from numerous #ifdef/#endif statements.
|
||||||
|
*/
|
||||||
|
|
||||||
|
BEGIN_BLUETOOTH_NAMESPACE
|
||||||
|
|
||||||
|
class BluetoothHfpManager : public BluetoothHfpManagerBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIOBSERVER
|
||||||
|
BT_DECL_HFP_MGR_BASE
|
||||||
|
virtual void GetName(nsACString& aName)
|
||||||
|
{
|
||||||
|
aName.AssignLiteral("Fallback HFP/HSP");
|
||||||
|
}
|
||||||
|
|
||||||
|
static BluetoothHfpManager* Get();
|
||||||
|
virtual ~BluetoothHfpManager() { }
|
||||||
|
|
||||||
|
bool ConnectSco();
|
||||||
|
bool DisconnectSco();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BluetoothHfpManager() { }
|
||||||
|
bool Init();
|
||||||
|
void HandleShutdown();
|
||||||
|
};
|
||||||
|
|
||||||
|
END_BLUETOOTH_NAMESPACE
|
||||||
|
|
||||||
|
#endif
|
@ -44,7 +44,6 @@ if CONFIG['MOZ_B2G_BT']:
|
|||||||
elif CONFIG['MOZ_B2G_BT_BLUEDROID']:
|
elif CONFIG['MOZ_B2G_BT_BLUEDROID']:
|
||||||
SOURCES += [
|
SOURCES += [
|
||||||
'bluedroid/BluetoothA2dpManager.cpp',
|
'bluedroid/BluetoothA2dpManager.cpp',
|
||||||
'bluedroid/BluetoothHfpManager.cpp',
|
|
||||||
'bluedroid/BluetoothOppManager.cpp',
|
'bluedroid/BluetoothOppManager.cpp',
|
||||||
'bluedroid/BluetoothServiceBluedroid.cpp',
|
'bluedroid/BluetoothServiceBluedroid.cpp',
|
||||||
'bluedroid/BluetoothSocket.cpp',
|
'bluedroid/BluetoothSocket.cpp',
|
||||||
@ -53,6 +52,22 @@ if CONFIG['MOZ_B2G_BT']:
|
|||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'bluedroid',
|
'bluedroid',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if CONFIG['MOZ_B2G_RIL']:
|
||||||
|
SOURCES += [
|
||||||
|
'bluedroid/hfp/BluetoothHfpManager.cpp',
|
||||||
|
]
|
||||||
|
LOCAL_INCLUDES += [
|
||||||
|
'bluedroid/hfp',
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
SOURCES += [
|
||||||
|
'bluedroid/hfp-fallback/BluetoothHfpManager.cpp',
|
||||||
|
]
|
||||||
|
LOCAL_INCLUDES += [
|
||||||
|
'bluedroid/hfp-fallback',
|
||||||
|
]
|
||||||
|
|
||||||
DEFINES['MOZ_B2G_BT_BLUEDROID'] = True
|
DEFINES['MOZ_B2G_BT_BLUEDROID'] = True
|
||||||
elif CONFIG['MOZ_ENABLE_DBUS']:
|
elif CONFIG['MOZ_ENABLE_DBUS']:
|
||||||
SOURCES += [
|
SOURCES += [
|
||||||
|
Loading…
Reference in New Issue
Block a user