mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 790739: Patch 3 - Service and Manager changes for Bluetooth server sockets; r=cjones
This commit is contained in:
parent
c909c64c02
commit
156f92210d
@ -407,6 +407,25 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceObjectPath,
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothHfpManager::Listen()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
NS_WARNING("BluetoothService not available!");
|
||||
return false;
|
||||
}
|
||||
|
||||
nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::HANDSFREE_AG,
|
||||
BluetoothSocketType::RFCOMM,
|
||||
true,
|
||||
false,
|
||||
this);
|
||||
return NS_FAILED(rv) ? false : true;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothHfpManager::Disconnect()
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
bool SendLine(const char* aMessage);
|
||||
void CallStateChanged(int aCallIndex, int aCallState,
|
||||
const char* aNumber, bool aIsActive);
|
||||
|
||||
bool Listen();
|
||||
private:
|
||||
BluetoothHfpManager();
|
||||
|
||||
|
@ -286,6 +286,13 @@ public:
|
||||
BlobChild* aBlobChild,
|
||||
BluetoothReplyRunnable* aRunnable) = 0;
|
||||
|
||||
virtual nsresult
|
||||
ListenSocketViaService(int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer) = 0;
|
||||
|
||||
bool
|
||||
IsEnabled() const
|
||||
{
|
||||
|
@ -30,6 +30,21 @@ namespace BluetoothServiceUuidStr {
|
||||
static const char* ObjectPush = "00001105-0000-1000-8000-00805F9B34FB";
|
||||
}
|
||||
|
||||
// TODO/qdot: Move these back into gonk and make the service handler deal with
|
||||
// it there.
|
||||
//
|
||||
// Gotten from reading the "u8" values in B2G/external/bluez/src/adapter.c
|
||||
// These were hardcoded into android
|
||||
enum BluetoothReservedChannels {
|
||||
DIALUP_NETWORK = 1,
|
||||
HANDSFREE_AG = 10,
|
||||
HEADSET_AG = 11,
|
||||
OPUSH = 12,
|
||||
SIM_ACCESS = 15,
|
||||
PBAP_PSE = 19,
|
||||
FTP = 20,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,6 +226,19 @@ BluetoothServiceChildProcess::GetSocketViaService(
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
BluetoothServiceChildProcess::ListenSocketViaService(
|
||||
int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer)
|
||||
{
|
||||
MOZ_NOT_REACHED("This should never be called!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothServiceChildProcess::SetPinCodeInternal(
|
||||
const nsAString& aDeviceAddress,
|
||||
|
@ -101,6 +101,13 @@ public:
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer,
|
||||
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
|
||||
|
||||
virtual nsresult
|
||||
ListenSocketViaService(int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
SetPinCodeInternal(const nsAString& aDeviceAddress,
|
||||
const nsAString& aPinCode,
|
||||
|
@ -726,6 +726,29 @@ ExtractHandles(DBusMessage *aReply, nsTArray<uint32_t>& aOutHandles)
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
bool
|
||||
BluetoothDBusService::AddServiceRecords(const nsAString& aAdapterPath,
|
||||
const char* serviceName,
|
||||
unsigned long long uuidMsb,
|
||||
unsigned long long uuidLsb,
|
||||
int channel)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
DBusMessage *reply;
|
||||
reply = dbus_func_args(gThreadConnection->GetConnection(),
|
||||
NS_ConvertUTF16toUTF8(aAdapterPath).get(),
|
||||
DBUS_ADAPTER_IFACE, "AddRfcommServiceRecord",
|
||||
DBUS_TYPE_STRING, &serviceName,
|
||||
DBUS_TYPE_UINT64, &uuidMsb,
|
||||
DBUS_TYPE_UINT64, &uuidLsb,
|
||||
DBUS_TYPE_UINT16, &channel,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
return reply ? dbus_returns_uint32(reply) : -1;
|
||||
}
|
||||
|
||||
// static
|
||||
bool
|
||||
BluetoothDBusService::AddReservedServicesInternal(const nsAString& aAdapterPath,
|
||||
@ -2277,7 +2300,9 @@ public:
|
||||
|
||||
nsString address = GetAddressFromObjectPath(mObjectPath);
|
||||
nsString replyError;
|
||||
BluetoothUnixSocketConnector c(BluetoothSocketType::SCO, -1, mAuth, mEncrypt);
|
||||
BluetoothUnixSocketConnector* c =
|
||||
new BluetoothUnixSocketConnector(BluetoothSocketType::SCO, -1,
|
||||
mAuth, mEncrypt);
|
||||
|
||||
BluetoothScoManager* sco = BluetoothScoManager::Get();
|
||||
if (!mConsumer->ConnectSocket(c, NS_ConvertUTF16toUTF8(address).get())) {
|
||||
@ -2302,16 +2327,16 @@ private:
|
||||
bool mEncrypt;
|
||||
};
|
||||
|
||||
class CreateBluetoothSocketRunnable : public nsRunnable
|
||||
class ConnectBluetoothSocketRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
CreateBluetoothSocketRunnable(BluetoothReplyRunnable* aRunnable,
|
||||
UnixSocketConsumer* aConsumer,
|
||||
const nsAString& aObjectPath,
|
||||
const nsAString& aServiceUUID,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt)
|
||||
ConnectBluetoothSocketRunnable(BluetoothReplyRunnable* aRunnable,
|
||||
UnixSocketConsumer* aConsumer,
|
||||
const nsAString& aObjectPath,
|
||||
const nsAString& aServiceUUID,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt)
|
||||
: mRunnable(dont_AddRef(aRunnable)),
|
||||
mConsumer(aConsumer),
|
||||
mObjectPath(aObjectPath),
|
||||
@ -2325,14 +2350,14 @@ public:
|
||||
nsresult
|
||||
Run()
|
||||
{
|
||||
NS_WARNING("Running create socket!\n");
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
nsString address = GetAddressFromObjectPath(mObjectPath);
|
||||
int channel = GetDeviceServiceChannel(mObjectPath, mServiceUUID, 0x0004);
|
||||
BluetoothValue v;
|
||||
nsString replyError;
|
||||
BluetoothUnixSocketConnector c(mType, channel, mAuth, mEncrypt);
|
||||
BluetoothUnixSocketConnector* c =
|
||||
new BluetoothUnixSocketConnector(mType, channel, mAuth, mEncrypt);
|
||||
if (!mConsumer->ConnectSocket(c, NS_ConvertUTF16toUTF8(address).get())) {
|
||||
replyError.AssignLiteral("SocketConnectionError");
|
||||
DispatchBluetoothReply(mRunnable, v, replyError);
|
||||
@ -2395,7 +2420,7 @@ BluetoothDBusService::GetSocketViaService(const nsAString& aObjectPath,
|
||||
}
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
|
||||
nsRefPtr<nsRunnable> func(new CreateBluetoothSocketRunnable(runnable,
|
||||
nsRefPtr<nsRunnable> func(new ConnectBluetoothSocketRunnable(runnable,
|
||||
aConsumer,
|
||||
aObjectPath,
|
||||
aService, aType,
|
||||
@ -2424,3 +2449,64 @@ BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class ListenBluetoothSocketRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ListenBluetoothSocketRunnable(UnixSocketConsumer* aConsumer,
|
||||
int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt)
|
||||
: mConsumer(aConsumer)
|
||||
, mChannel(aChannel)
|
||||
, mType(aType)
|
||||
, mAuth(aAuth)
|
||||
, mEncrypt(aEncrypt)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
Run()
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
BluetoothUnixSocketConnector* c =
|
||||
new BluetoothUnixSocketConnector(mType, mChannel, mAuth, mEncrypt);
|
||||
if (!mConsumer->ListenSocket(c)) {
|
||||
NS_WARNING("Can't listen on socket!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<UnixSocketConsumer> mConsumer;
|
||||
int mChannel;
|
||||
BluetoothSocketType mType;
|
||||
bool mAuth;
|
||||
bool mEncrypt;
|
||||
};
|
||||
|
||||
nsresult
|
||||
BluetoothDBusService::ListenSocketViaService(int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
||||
if (!mConnection || !gThreadConnection) {
|
||||
NS_ERROR("Bluetooth service not started yet!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsRefPtr<nsRunnable> func(new ListenBluetoothSocketRunnable(aConsumer,
|
||||
aChannel, aType,
|
||||
aAuth,
|
||||
aEncrypt));
|
||||
if (NS_FAILED(mBluetoothCommandThread->Dispatch(func, NS_DISPATCH_NORMAL))) {
|
||||
NS_WARNING("Cannot dispatch firmware loading task!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -58,6 +58,20 @@ public:
|
||||
const nsAString& aDeviceAddress,
|
||||
nsAString& aDevicePath);
|
||||
|
||||
static bool
|
||||
AddServiceRecords(const nsAString& aAdapterPath,
|
||||
const char* serviceName,
|
||||
unsigned long long uuidMsb,
|
||||
unsigned long long uuidLsb,
|
||||
int channel);
|
||||
|
||||
static bool
|
||||
RemoveServiceRecords(const nsAString& aAdapterPath,
|
||||
const char* serviceName,
|
||||
unsigned long long uuidMsb,
|
||||
unsigned long long uuidLsb,
|
||||
int channel);
|
||||
|
||||
static bool
|
||||
AddReservedServicesInternal(const nsAString& aAdapterPath,
|
||||
const nsTArray<uint32_t>& aServices,
|
||||
@ -82,6 +96,13 @@ public:
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer,
|
||||
BluetoothReplyRunnable* aRunnable);
|
||||
|
||||
virtual nsresult
|
||||
ListenSocketViaService(int aChannel,
|
||||
BluetoothSocketType aType,
|
||||
bool aAuth,
|
||||
bool aEncrypt,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer);
|
||||
|
||||
virtual nsresult
|
||||
CreatePairedDeviceInternal(const nsAString& aAdapterPath,
|
||||
const nsAString& aDeviceAddress,
|
||||
|
@ -264,7 +264,7 @@ DBusMessage * dbus_func_args_error(DBusConnection *conn,
|
||||
int dbus_returns_int32(DBusMessage *reply)
|
||||
{
|
||||
DBusError err;
|
||||
int ret = -1;
|
||||
int32_t ret = -1;
|
||||
|
||||
dbus_error_init(&err);
|
||||
if (!dbus_message_get_args(reply, &err,
|
||||
@ -277,5 +277,21 @@ int dbus_returns_int32(DBusMessage *reply)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dbus_returns_uint32(DBusMessage *reply)
|
||||
{
|
||||
DBusError err;
|
||||
uint32_t ret = -1;
|
||||
|
||||
dbus_error_init(&err);
|
||||
if (!dbus_message_get_args(reply, &err,
|
||||
DBUS_TYPE_UINT32, &ret,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, reply);
|
||||
}
|
||||
|
||||
dbus_message_unref(reply);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -108,6 +108,8 @@ DBusMessage* dbus_func_args_timeout_valist(DBusConnection* conn,
|
||||
|
||||
int dbus_returns_int32(DBusMessage *reply);
|
||||
|
||||
int dbus_returns_uint32(DBusMessage *reply);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user