This patch adds error handling to all interface methods of Bluedroid's
daemon backend. If an error occures while sending a command to the daemon,
the methods dispatch an error.
With this patch, the dispatch method of Bluetooth runnables simply returns
if the supplied runnable is nullptr. This makes is easy to handle cases
where the caller of a Bluetooth interface method is not interested in the
result.
It seems impossible right now to update Bluetooths daemon. This leaves
dogfooders without bluetooth support. This patch restores the old back-
end code for Bluetooth until bug 1130288 has been solved.
There is |aPDU.Consume(1)| at the beginning, so |aPDU.GetSize()| becomes 1
less than the actual data length we want to parse. As a result, |memchr()|
will always fail by missing the final character by using |aPDU.GetSize()| as
its |num| parameter.
This patch adds proper selection of the Bluetooth backend. The backend
is configurable via environment property 'ro.moz.bluetooth.backend'. The
default value is bluetoothd.
On systems that are not Android 4.2 or later, the code does not return
a backend. These systems should use BlueZ instead.
cppcheck identified the extra ')' at the end of these macros. This code must
not be compiled in any of our standard configurations.
--HG--
extra : rebase_source : 4044d377e3a15ef725ac276ab54a192df63a8eb6
This patch adds support for a random postfix for bluetoothd's socket
name. The postfix is re-generated for every instance of the daemon.
This prevents name collisions between mutliple sessions and malicious
programs from taking over the connection easily.
Currently, Gecko connects to a running instance of bluetoothd when
it starts the daemon backend. This contains a race condition between
the startup of the daemon and the startup of Gecko.
This patch changes the initialization and cleanup of Bluetooth's
daemon backend so that the Bluetooth daemon connects to Gecko. The
daemon process is now started as part of the initialization and
quits during shutdown. The steps are strictly ordered, so no race
condition exists.
The initialization and cleanup procedures should now be compatible
with BlueZ 5.
The class |BluetoothDaemonChannel| for the bluetoothd channels
supports reference counting. This patch fixes the respective
variable to use |nsRefPtr| instead of |nsAutoPtr|.
BluetoothOppManager.IsConnected() couldn't represent the connection status
of Opp profile since it only return true if there is an ongoing
file-transfer session.
This function was used to named |IsTransferring()| in Bug 827267, however,
it was renamed to |IsConnected()| when Bug 842948 landed.
This patch merges BluetoothUtils.{cpp,h} from BlueZ and Bluedroid
backends. The resulting files of the same name are located in the
generic code's directory.
This change requires a rebuild of dependency information, so the
patch touches CLOBBER as well.
--HG--
rename : dom/bluetooth/bluedroid/BluetoothUtils.cpp => dom/bluetooth/BluetoothUtils.cpp
rename : dom/bluetooth/bluedroid/BluetoothUtils.h => dom/bluetooth/BluetoothUtils.h
This patch replaces |ToggleBtAck| with |AcknowledgeToggleBt| in
|BluetoothServiceBluedroid::AdapterStateChangedNotification| and
cleans up the remaining runnables used by this method.
All runnables need to be handled in the same patch, because the
order of operation must not be changed.
|AcknowledgeToggleBt| completes a Bluetooth start or stop operation
in the context of |BluetoothService|; That was done by |ToggleBtAck|
before.
This patch replaces |ToggleBtAck| with calls to |AcknowledgeToggleBt|
in |BluetoothServiceBluedroid| for all the trivial cases.
|ToggleBtAck| completes a start of stop operation on the main thread.
This patch moves the runnable's functionality into |BluetoothService|
and makes it available for methods running on the main thread.
This patch converts all interface runnables in Bluetooth's daemon
backend by generic result runnables. Init operator classes replace
unpack functions. Init operator classes will warn about unused data
at the end of a PDU.
This patch converts all notification runnables in Bluetooth's daemon
backend to use the generic implementation. Unpack functions are replaced
by init operator classes. The init operator classes also validate the
complete unpacking of a PDU and warn about unused trailing data.
A backend notification runnable in Bluetooth is used to transfer
a notification from the I/O thread to the main thread; an interface
runnable transfers and executes a result handler. Both are currently
implemented by the Bluetooth backends.
This patch adds new runnables that are independend from any backend
code or data structures.
This patch adds support for the Bluetooth daemon's Core module. It
provides the basic Bluetooth functionality, such as searching and
pairing with devices, and accessing device properties.
This patch adds the core interfaces and the Setup module for
the Bluetooth Daemon. The Setup module implements commands
for enabling and disabling Bluetooth profiles in the daemon.
The cast-and-assign pattern for retrieving file descriptors is prone to
SIGBUS signals on platforms that don't support unaligned memory access.
This patch fixes the problem by copying the received data directly.
|SocketMessageWatcher| currently allocates a large amount of memory
for holding ancillary data. The only actually transfered value is a
file descriptor. This patch fixes the buffer size accordingly.
The data class in |SocketIOSendTask| is now a template parameter, instead
of being hard-coded to |UnixSocketRawData|. The patch also adds soem minor
cleanups to the file.
Bluetooth profile managers just return an error if a profile interface is
not available. Doing so breaks the initialization and cleanup routines. This
patch changes the profile managers to still report an error, but signal
progress to the given result runnable.
Bluetooth's RSSI property is encoded as pointer to a signed 8-bit
value. Gecko currently interprets this as pointer to a 32-bit
value; so the result of dereferencing the pointer is undefined.
This patch fixes the bug by interpreting the RSSI property correctly.
This patch moves BluetoothInterface.{cpp,h} to the generic section
of Gecko's Bluetooth code, and the Bluedroid implementation into
the new files BluetoothHalImplementation.{cpp,h}.
BluetoothHalImplementation.{cpp,h} contains all Bluedroid-specific
code. The classes in BluetoothInterface.{cpp,h} are now interfaces
for Gecko.
--HG--
rename : dom/bluetooth/bluedroid/BluetoothInterface.cpp => dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
This patch moves BluetoothInterface.{cpp,h} to the generic section
of Gecko's Bluetooth code, and the Bluedroid implementation into
the new files BluetoothHalImplementation.{cpp,h}.
BluetoothHalImplementation.{cpp,h} contains all Bluedroid-specific
code. The classes in BluetoothInterface.{cpp,h} are now interfaces
for Gecko.
--HG--
rename : dom/bluetooth/bluedroid/BluetoothInterface.cpp => dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
Calling read on a socket that has been closed for reading by the
peer, read returns 0. The socket is still readable however, so
polling and reading will return constant results of 0 received
bytes.
With this patch, if a socket's peer shuts down reading or if
we reached the EOF, we stop watching the file descriptor for
readability. |SocketIOBase| will detect this case exactly once
and initiate the socket's shutdown.
All interfaces for Bluetooth profiles are now always available, so we
don't have to check for specific versions of Bluedroid. Instead, we
try to call the methods, and check their results.
The methods of |BluetoothAVRCPInterface| are now always available. On
Android versions before 18, which don't support AVRCP, they always
fail with STATUS_UNSUPPORTED.
The C++ compiler for Flatfish lacks support for initialized arrays of
C-string pointers. This patch fixes the problem by using a switch
statement for the string conversion of A2DP connection states.
The patch removes unused callbacks and helper runnables from the
Bluedroid implementation of BluetoothA2DPManager. It also removes
the last Bluedroid-specific code from BluetoothUtils.{cpp,h}.
The helper runnables where necessary to perform certain operations on
the main thread after having received a callback from Bluedroid. The
new notification methods already run on the main thread, so the helper
runnables can be replaced by direct calls.
This patch adds Bluetooth A2DP and AVRCP notifications to Gecko's
A2DP manager. The code has been taken from taken from the callback
implementations, and adapted to run on the main thread. No further
cleanups have been applied.
This patch adds A2DP and AVRCP notifications and callbacks to
Gecko's Bluedroid interface. Support for AVRCP depends on the
version of the Android base system and is only available on
versions 18, 19 or later.
|MainThreadTask| performs different operations on the main thread,
depending on a given command flag. There is only one command, CLOSE_SCO,
in use.
This patch removes the command infrastructure and replaces |MainThreadTask|
by |CloseScoRunnable|, which implements only this single operation.
A number of notifications dispatch runnables to the main thread for
invoking actions. This is not requireed, as notifications already
run on the main thread. This patch merges the runnable's code into
the respective notifications.
This patch replaces Handsfree callbacks by notifications. One
important change is that the first call to |BluetoothHandsfreeManager::Get|
now happens during initialization. Hence the Handsfree manager is now setup
immediately, instead of later at use.
The patch adds notifications support to the Handsfree manager. Each
notification's method is taken from the respective callback code, with
changes to the arguments' data types.
The notification interface consists of virtual methods that are
invoked form the Bluetooth backend on certain events. The Handsfree
manager can implement the methods to handle these events.
This patch removes unsued code from |BluetoothServiceBluedroid|, related
functions, and cleans up the file. It
* removes callbacks,
* removes callback helper tasks,
* removes helper functions, and
* cleans up global variables.
Bluedroid callbacks were usually called on a separate thread that
was specific to this task. So Gecko's Bluetooth Core contained a
number of runnables for executing callback operations on the main
thread.
Since all notifications always run on the main thread, the extra
runnables are not required any longer. This patch integrates them
into the notification methods where possible.
This patch adds the Gecko-side of the Core notifications. The current
implementation of the notification methods has been copied from the
repsective Bluedroid callback methods, with only minor changes to adapt
them to Gecko data types.
A notification is a callback from the Bluetooth backend to inform
Gecko about a event. Bluedroid uses function pointers for this, but
in Gecko we use method calls instead.
Gecko implements notification handlers for the Bluetooth backend. The
backend converts incomming events to Gecko types and forwards them to
the registered notification handler.
This patch adds some runnable classes for running class methods on
the main thread. This is the base of the upcomming notification
mechanism for Bluetooth.
This patch fixes array initialization in the |Convert| functions of
|BluetoothInterface|. Designated initializers are not supported by
all compilers, so we wrap them into a macro and only used them when
possible.
This patch cleans up the interface of Bluedroid's |BluetoothScoket|
to look more similar the interface of |UnixSocketConsumer|, from
which it descends.
This patch converts Bluedroid status codes in Gecko to the
backend-neutral data type |BluetoothStatus|. All error handlers
have been adapted. The Bluedroid type |bt_status_t| only remains
in |BluetoothInterface|.
With this patch |BluetoothHandsfreeInterface| is responsible for converting all
Bluetooth data types to Bluedroid types. All callers have been adapted.
The linker mixes up |ConnectResultHandler| from BluetoothSocket.cpp
and BluetoothHfpManager.cpp. Consequently one of them gets removed
when linking libxul.so.
This patch works around the problem by renaming |ConnectResultHandler|
in BluetoothSocket.cpp to |ConnectSocketResultHandler|.
When sending a |BluetoothInterfaceRunnable3<>| to the main thread,
in the case of BluetoothSocketResultHandler, the connect and accept
operations transfer string objects by reference from the I/O thread.
When the reference is accessed, the actual string might be removed
already.
The patch fixes the problem by storing the strings as value in the
runnable object.
The Bluedroid code uses indices into global arrays while pairing
with devices. These arrays might get changed in between and the
indices become incorrect. The result is undefined.
The patch fixes the problem by using the value, a reply runnable,
directly for array lookups. No indices are required.
This bug was fixed in bluetooth2/ already, but not yet backported.
Recent patches to Bluetooth introduced asynchronous initialization of
profile manager. The code in hfp-fallback was not adapted then. This
patch updates the broken code.
Profile managers use the new class |BluetoothProfileResultHandler|
to signal the result of initializing of cleaning up operations to
|BluetoothServiceBluedroid|. |BluetoothServiceBluedroid| proceeds
once all profile handlers have finished.
Future patches will build upon this patch to create completely
asynchronous profile managers.
This patch adds a missing include statement for <errno.h> to
BluetoothInterface.cpp. This fixes the build for flatfish
devices. For safety, the patch also adds an include statement
for <unistd.h>, which might be necessary for several functions.
Currently, BluetoothSocket leaks its file descriptor on close
operations. With this patch when Gecko closes an instance of
BluetoothSocket, the file descriptor is now closed as well.
This patch removes all code related to socket setup from Bluedroid's
BluetoothSocket. The socket setup is handled by BluetoothInterface;
transparantly to its users.
Since most of the socket setup is now hidden, a comment was added to
DroidSocketImpl that explains the connection phases in server and
client.
This patch moves the accept phase of Bluedroid's |Listen| to the
implementation of BluetoothInterface. |BluetoothInterface::Accept|
handles Bluedroid's socket-setup messages and executes the result
handler with the received file descriptor and data.
Bluedroid's internal socket setup transfers 2 messages and possibly
a file descriptor as the first data of a socket connection.
This patch moves the socket-setup code for the |Connect| call to
the implementation of BluetoothInterface. BluetoothSocket only
handles the socket setup of |Listen|, and general socket state.
In preparaton of moving the Bluedroid socket setup to BluetoothInterface,
this patch introduces connection states for Bluetooth sockets. There are
4 states,
- Disconnected,
- Listening,
- Connecting, and
- Connected.
All sockets start in Disconnected and transition to Connected via one
of the other states. Server socket transition through Listening, Client
sockets transition through Connecting. There is currently a lot of code
duplication in read and write methods. This will be cleaned up when the
connection setup is handled by BluetoothInterface.
The result-handler class contains a method for each interface
in the Core profile and a method for failed calls. The patch
also adds runnable classes that execute a result handler's
method on the main thread.
This patch adds classes around all Bluedroid interfaces that are
currently used by Gecko. These are Core, Socket, Handsfree, A2DP,
and AVRCP.
All arguments and return values are still Bluedroid types and
constants. Future patches will convert them to interface-neutral
artifacts.