<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.17116" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>
<DIV><FONT face=Arial size=2>Hi Kate,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>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 size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>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 size=2>For btchat, I execute this function just before
QBluetoothLocalDevice().name() in the main application context.</FONT></DIV>
<DIV><FONT face=Arial size=2>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 size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>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 size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>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 size=2>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 size=2>But then I have similar problems into the
AndroidBroadcastReceiver::initialize() method when calling
env->RegisterNatives(jQtBroadcastReceiverClass).</FONT></DIV>
<DIV><FONT face=Arial size=2>So I tried a similar patch to fix this issue by
first issuing:</FONT></DIV>
<DIV><FONT face=Arial size=2>
JNIThreadHelper env;</FONT></DIV>
<DIV><FONT face=Arial size=2>
jQtBroadcastReceiverClass =
env->FindClass("org/kde/necessitas/mobile/QtBroadcastReceiver");</FONT></DIV>
<DIV><FONT face=Arial size=2>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 size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Note that the</FONT></DIV>
<DIV><FONT face=Arial size=2>
jQtBroadcastReceiverClass =
env->FindClass("org/kde/necessitas/mobile/QtBroadcastReceiver");</FONT></DIV>
<DIV><FONT face=Arial size=2>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 size=2>I can't understand why this call is only valid at
library load time.</FONT></DIV>
<DIV><FONT face=Arial size=2>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 size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Do you have an idea to progress on this subject
?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thank you for your help.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Dominique RETY</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></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; font-color: black"><B>From:</B>
<A title=kate.alhola@gmail.com href="mailto:kate.alhola@gmail.com">Kate
Alhola</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=dominiquerety@hotmail.fr
href="mailto:dominiquerety@hotmail.fr">Dominique Rety</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=necessitas-devel@kde.org
href="mailto:necessitas-devel@kde.org">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/">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 class=im>
<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 class=im>
<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 class=h5>
<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></BODY></HTML>