This discovery process is one that I have not tested yet because I use other approach, I do discovery and pairing with Android Settings->Bluetooth <br>and then inquire mac address or bound devices from Android. There inquiry of bound devices is known important missing feature of Qt Mobility Connectivity.<br>
I have plan least propose it to be added in future releases. At the moment I have implementation for Linux/Dbus/Bluez and Android/JNI/Bluez.<br><br>I have not yet tried discovery with Android QTM Connectivity for fthis reason. Other reason is that pairing functions on QBluetoothLocalDevice are empty,<br>
not implemented yet.<br><br>It is very obvious that same root cause of bugs I fixed exists also on discovery part but I have not yet had time to look them.<br><br>Kate<br><br><div class="gmail_quote">On Wed, Jan 9, 2013 at 12:05 PM, Dominique Rety <span dir="ltr"><<a href="mailto:dominiquerety@hotmail.fr" target="_blank">dominiquerety@hotmail.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div bgcolor="#ffffff">
<div><font face="Arial">Hi all,</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">To my understanding, before connecting a bluetooth
device it is necessary to perform discovering to get the remote MAC
address.</font></div>
<div><font face="Arial">Do you successfully go through this step when
testing Bluetooth in your environment ?</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Device discovering involves the broadcast
receiver, which is started from
QBluetoothLocalDevice::startDiscovery</font></div>
<div><font face="Arial">Therefore it seems to me that the patch consisting
in reloading the btAdapterClass must also be applied to the
startDiscovery(), cancelDiscovery() and isDiscovering() methods.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">While trying to go further in my tests, I noticed
that AndroidBroadcastReceiver suffers from the same syndrome.</font></div>
<div><font face="Arial">Then I tried to reload jQtBroadcastReceiverClass
from "org/kde/necessitas/mobile/QtBroadcastReceiver", but without success
(class not found).</font></div>
<div><font face="Arial">QtBroadcastReceiver is an extension of the
BroadcastReceiver Java class (cf. QtBroadcastReceiver.java)</font></div>
<div><font face="Arial">I can successfully load jQtBroadcastReceiverClass
from "android/content/BroadcastReceiver", but of course the program fails later
because the class doesn't contain the expected extensions.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Do you have any explanation why it is possible to
find a class from "android/bluetooth/BluetoothAdapter" or from
"android/content/BroadcastReceiver", but not from
"org/kde/necessitas/mobile/QtBroadcastReceiver" ?</font></div>
<div><font face="Arial">More generally, why any FindClass performed
during the connectivity library load work fine but must be repeated at program
run time ? Why some Java classes could become no more accessible ?</font></div>
<div><font face="Arial">Is there a change in Qt loading logic that can
explain this ? How to investigate in this direction ?</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">I will be happy if I can make a contribution to
diagnose these problems.</font></div><span class="HOEnZb"><font color="#888888">
<div><font face="Arial"></font> </div>
<div><font face="Arial">Dominique Rety</font></div></font></span><div><div class="h5">
<div><font face="Arial"></font> </div>
<div><font face="Arial"></font> </div>
<div style="FONT:10pt arial">----- Original Message -----
<div style="BACKGROUND:#e4e4e4"><b>From:</b> <a title="dominiquerety@hotmail.fr" href="mailto:dominiquerety@hotmail.fr" target="_blank">Dominique
Rety</a> </div>
<div><b>To:</b> <a title="kate.alhola@gmail.com" href="mailto:kate.alhola@gmail.com" target="_blank">Kate Alhola</a> </div>
<div><b>Cc:</b> <a title="necessitas-devel@kde.org" href="mailto:necessitas-devel@kde.org" target="_blank">necessitas-devel@kde.org</a> </div>
<div><b>Sent:</b> Friday, January 04, 2013 2:52 PM</div>
<div><b>Subject:</b> Re: Crash when using Bluetooth</div></div>
<div><br></div>
<div>
<div><font face="Arial">Hi Kate,</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">I continue trying to operate the btchat sample,
which implements functionalities very closed to those we have to use in our
project.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Before receiving your patch, I tried a solution
consisting in moving the initialization code for the connectivity library
(contained in JNI_OnLoad) to a separate function executed just before the
first call to the library.</font></div>
<div><font face="Arial">For btchat, I execute this function just before
QBluetoothLocalDevice().name() in the main application context.</font></div>
<div><font face="Arial">This solution works (I can get the device name
without JNI ERROR), probably because the initialization code is performed in a
thread context that remains valid.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">I also tried your patches, which solve the get name
JNI ERROR as well. Your solution is probably better if it works without any
constraint on the initialization thread context.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">However, all of this only partly solves
the problem. When I try to connect through the btchat application, I got an
other JNI ERROR when the device discovery logic starts.</font></div>
<div><font face="Arial">I have applied your patch to the
QBluetoothLocalDevice::startDiscovery() cancelDiscovery() and isDiscovering()
methods. This enables the code to continue a bit.</font></div>
<div><font face="Arial">But then I have similar problems into the
AndroidBroadcastReceiver::initialize() method when calling
env->RegisterNatives(jQtBroadcastReceiverClass).</font></div>
<div><font face="Arial">So I tried a similar patch to fix this issue by
first issuing:</font></div>
<div><font face="Arial">
JNIThreadHelper env;</font></div>
<div><font face="Arial">
jQtBroadcastReceiverClass =
env->FindClass("org/kde/necessitas/mobile/QtBroadcastReceiver");</font></div>
<div><font face="Arial">Unfortunately, this call returns a NULL and I get a
FATAL EXCEPTION, java.lang.NoClassDefFoundError:
org/kde/necessitas/mobile/QtBroadcastReceiver.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Note that the</font></div>
<div><font face="Arial">
jQtBroadcastReceiverClass =
env->FindClass("org/kde/necessitas/mobile/QtBroadcastReceiver");</font></div>
<div><font face="Arial">is performed once <u>with success</u> in the
AndroidBroadcastReceiver::loadJavaClass() method, which is called at
libQtConnectivity library loading time, from JNI_OnLoad.</font></div>
<div><font face="Arial">I can't understand why this call is only valid at
library load time.</font></div>
<div><font face="Arial">I'm not sure that trying to apply a similar patch
in this situation would be a solution to this issue.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Do you have an idea to progress on this subject
?</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Thank you for your help.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Dominique RETY</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial"></font> </div></div>
<blockquote style="PADDING-RIGHT:0px;PADDING-LEFT:5px;MARGIN-LEFT:5px;BORDER-LEFT:#000000 2px solid;MARGIN-RIGHT:0px">
<div style="FONT:10pt arial">----- Original Message ----- </div>
<div style="BACKGROUND:#e4e4e4;FONT:10pt arial"><b>From:</b>
<a title="kate.alhola@gmail.com" href="mailto:kate.alhola@gmail.com" target="_blank">Kate
Alhola</a> </div>
<div style="FONT:10pt arial"><b>To:</b> <a title="dominiquerety@hotmail.fr" href="mailto:dominiquerety@hotmail.fr" target="_blank">Dominique Rety</a> </div>
<div style="FONT:10pt arial"><b>Cc:</b> <a title="necessitas-devel@kde.org" href="mailto:necessitas-devel@kde.org" target="_blank">necessitas-devel@kde.org</a> </div>
<div style="FONT:10pt arial"><b>Sent:</b> Thursday, January 03, 2013 2:59
PM</div>
<div style="FONT:10pt arial"><b>Subject:</b> Re: Crash when using
Bluetooth</div>
<div><br></div>On Wed, Dec 26, 2012 at 7:33 PM, Dominique Rety <span dir="ltr"><<a href="mailto:dominiquerety@hotmail.fr" target="_blank">dominiquerety@hotmail.fr</a>></span> wrote:<br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><u></u>
<div dir="auto" bgcolor="#ffffff">
<div>
<div><font face="Arial">Hi Kate,</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Thank you for your answer.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">I tried some traces and modifications into the lib
QtConnectivity without success. It seems to me that functions into the
library already contain calls to JNIThreadHelper class that should setup the
Java environment by performing jvm->AttachCurrentThread(), but this
doesn't solve the problem.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">At the same time, I performed some basic bluetooth
tests directly through Java Eclipse
(BluetoothAdapter.getDefaultAdapter.getName), which work fine on Nexus 7
with Android 4.2.</font></div>
<div><font face="Arial">However, our project contains some legacy parts that
have already been developed in C, and using Qt would be the very best way to
integrate them. Therefore I will only envision to implement a direct bridge
between Java and C parts as a last resort if I can't find a viable
solution with Qt.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Consequently, I am very interested by your patches
even before the next release, which could be helpful for us to take a
decision for our development. Overriding and deploying the default
Necessitas lib QtConnectivity is not a problem for me, at least for test
purpose.</font></div></div></div></blockquote>
<div><br>Now patches are on Review board <a href="https://git.reviewboard.kde.org/r/108113/" target="_blank">https://git.reviewboard.kde.org/r/108113/</a>
. I would be happy if you could try them.<br><br>Sorry about delays publishing
them <br><br><br>Kate<br> </div>
<blockquote class="gmail_quote" style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid">
<div dir="auto" bgcolor="#ffffff">
<div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Regards,</font></div>
<div><font face="Arial">Dominique</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial"></font> </div>
<div><font face="Arial"></font> </div></div>
<blockquote dir="ltr" style="PADDING-RIGHT:0px;PADDING-LEFT:5px;MARGIN-LEFT:5px;BORDER-LEFT:#000000 2px solid;MARGIN-RIGHT:0px">
<div>
<div style="FONT:10pt arial">----- Original Message ----- </div>
<div style="BACKGROUND:#e4e4e4;FONT:10pt arial"><b>From:</b> <a title="kate.alhola@gmail.com" href="mailto:kate.alhola@gmail.com" target="_blank">Kate Alhola</a> </div>
<div style="FONT:10pt arial"><b>To:</b> <a title="dominiquerety@hotmail.fr" href="mailto:dominiquerety@hotmail.fr" target="_blank">Dominique Rety</a>
</div></div>
<div>
<div style="FONT:10pt arial"><b>Cc:</b> <a title="necessitas-devel@kde.org" href="mailto:necessitas-devel@kde.org%3E" target="_blank"><necessitas-devel@kde.org></a> </div>
<div style="FONT:10pt arial"><b>Sent:</b> Wednesday, December 26, 2012
4:36 PM</div>
<div style="FONT:10pt arial"><b>Subject:</b> Re: Crash when using
Bluetooth</div>
<div><br></div></div>
<div>
<div>
<div>On 13.12.2012, at 16.41, Dominique Rety <<a href="mailto:dominiquerety@hotmail.fr" target="_blank">dominiquerety@hotmail.fr</a>> wrote:</div>
<div><br></div>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial">Hi,</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">I am currently developing a telecommunication
project involving Blutooth communication between Android devices. For
this purpose, I'm trying to use Necessitas Bluetooth support and I
experiment very similar problems that are described in the "Crash when
using Bluetooth" (Kate Alhola) archive thread.</font></div>
<div><font face="Arial"></font> </div></div></div></blockquote>
<div><br></div>
<div>There is several issues in current necessitas libQtConnectivity
version. I have hopefully fixed most of them and i have version of
libQtConnectivity that least works with my own applocation. I try to
deliver patches to necessitas project so that fixes could be included in
next release. </div><br>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial">Environment:</font></div>
<div><font face="Arial">Java JDK 1.7.0_09<br>Qt Creator 2.5.83 Based on Qt
4.8.3 running on Linux Suze<br>Kit = Necessitas Qt 4.8.2 for Android
armv7a<br>Compiler = Android GCC (arm-4.4.3)<br>Android target SDK =
android-16<br>Deploy to Nexus 7 with Android version 4.2.</font></div>
<div><font face="Arial"><font size="+0"><font face="Arial"></font></font></font> </div>
<div><font face="Arial">I firstly tried to deploy the btchat sample and I
faced the same problem:</font></div>
<div><font face="Arial">JNI ERROR (app bug): accessed stale local
reference 0xe680001d (index 7 in a table of size 4)<br>VM
aborting<br>Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread
13965 (.example.btchat)</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Setting traces in different source files of
the connectivity library, I also noticed that the error happens when
trying to use some member functions of QBluetoothLocalDevice (btchat
sample requests for the local device name from the main
function).</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">I tried to bypass this problem by only creating
the QBluetoothLocalDevice without requesting for the device name in the
btchat application. The program then starts correctly.</font></div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">In the btchat application, the "Connect" button
calls the QBluetoothServiceDiscoveryAgent::start function. This function
randomly processes the request because it relies on discoveryState and
deviceAddress members, which seem not to be initialized : either the
discovery process freezes or the program aborts with an error (if
luckily discoveryState and deviceAddress members get consistent values).
I didn't try any further investigation. It seems to me that the
connectivity library is compiled with qbluetoothlocaldevice_p.cpp, which
just contains empty functions for the QBluetoothLocalDevice class,
instead of a customized source for Android.</font></div>
<div><font face="Arial"></font> </div></div></div></blockquote>
<div><br></div>
<div>Yes, that's case. The QBluetoothLocalDevice initializes static
handles to java virtual machine that are then referenced by other modules.
I have made fixes to several parts of libQtConnectivity</div>
<div><br></div><br>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial">Is Bluetooth support for Android in Necessitas
complete ?</font></div></div></div></blockquote>
<div><br></div>
<div>Most of, some functions are still missing but there are some bugs in
current version</div><br>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial">Is the btchat sample expected to work
properly with Android ?</font></div></div></div></blockquote>
<div><br></div>
<div>I have not tried that one</div><br>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial">Is there any specific configuration issue I could
miss ?</font></div></div></div></blockquote>
<div><br></div>
<div>That's good question, what is origin of the bugs, does it work with
older android</div>
<div>Versions ? The source reason of bugs is JNI handles alocation that
conflict with</div>
<div>Current thread structure and some that handles are expired when used.
I have only tested with</div>
<div>Android 4.x</div><br>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial">Is there any corrective or complement software I
could download ?</font></div></div></div></blockquote>
<div><br></div>
<div>I could make my patches avaiable before next release but
overriding default necessitas libQtConnectivity requires some
tricks</div><br>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial">How can I progress on this issue ? What is the
best way to get help and advices ?</font></div></div></div></blockquote>
<div><br></div>This list works fine.
<div><br></div>
<div>Kate</div>
<div><br>
<blockquote type="cite">
<div>
<div>
<div><font face="Arial"></font> </div>
<div><font face="Arial">Regards,</font></div>
<div><font face="Arial">Dominique RETY</font></div>
<div><font face="Arial"><a>dominiquerety@hotmail.fr</a></font></div>
<div><font face="Arial"></font> </div></div></div></blockquote>
<blockquote type="cite">
<div><span>_______________________________________________</span><br><span>Necessitas-devel
mailing list</span><br><span><a href="mailto:Necessitas-devel@kde.org" target="_blank">Necessitas-devel@kde.org</a></span><br><span><a href="https://mail.kde.org/mailman/listinfo/necessitas-devel" target="_blank">https://mail.kde.org/mailman/listinfo/necessitas-devel</a></span><br>
</div></blockquote></div></div></div></blockquote></div></blockquote></div><br></blockquote></div></div></div>
</blockquote></div><br>